Re: emacs c++ code completion help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Armin Moradi wrote:

Here we go, I got it working:
Download these files:
auto-complete.el
auto-complete-cpp.el
auto-complete-gtags.el
auto-complete-semantic.el
auto-complete-yasnippet.el

put them in a directory, let's say ~/.emacs.d/elisp/

then add this to your ~/.emacs file:

====================
(add-to-list 'load-path "~/.emacs.d/elisp")
(require 'auto-complete)
(global-auto-complete-mode)
====================

It worked for me, but let me know if it worked for you too!  (the
auto-completion is really nice btw!)


I couldn't get it to auto-complete C++ keywords _not_ present in the buffer. So I changed my auto-complete-cpp.el (attached below). I made some minor changes to an example code posted on the emacs wiki page to include auto-complete both from the current buffer and from a list of keywords defined in auto-complete-cpp.el.

Now my .emacs looks like this,

;; load path for elisp files
(add-to-list 'load-path "~/.emacs.d/elisp")

;; autocomplete extension
(require 'auto-complete)
(when (require 'auto-complete nil t)
  (require 'auto-complete-cpp)

  (global-auto-complete-mode))

--
Suvayu

Open source is the future. It sets us free.
(require 'auto-complete)

;; (defvar ac-c++-sources
;;   '(ac-source-c++-keywords))

;; (ac-define-dictionary-source
;;  ac-source-c++-keywords
;;  '("and" "bool" "compl" "do" "export" "goto" "namespace" "or_eq" "return"
;;    "struct" "try" "using" "xor" "and_eq" "break" "const" "double" "extern"
;;    "if" "new" "private" "short" "switch" "typedef" "virtual" "xor_eq" "asm"
;;    "case" "const_cast" "dynamic_cast" "false" "inline" "not" "protected" 
;;    "signed" "template" "typeid" "void" "auto" "catch" "continue" "else" 
;;    "float" "int" "not_eq" "public" "sizeof" "this" "typename" "volatile"
;;    "bitand" "char" "default" "enum" "for" "long" "operator" "register"
;;    "static" "throw" "union" "wchar_t" "bitor" "class" "delete" "explicit"
;;    "friend" "mutable" "or" "reinterpret_cast" "static_cast" "true" 
;;    "unsigned" "while"))

;; (defun ac-c++-setup ()
;;   (setq ac-sources (append ac-c++-sources ac-sources)))

;; (defun ac-c++-init ()
;;   (add-hook 'c++-mode-hook 'ac-c++-setup))

(defconst c++-keywords 
  (sort 
   (list "and" "bool" "compl" "do" "export" "goto" "namespace" "or_eq" "return"
	 "struct" "try" "using" "xor" "and_eq" "break" "const" "double" "extern"
	 "if" "new" "private" "short" "switch" "typedef" "virtual" "xor_eq" "asm"
	 "case" "const_cast" "dynamic_cast" "false" "inline" "not" "protected" 
	 "signed" "template" "typeid" "void" "auto" "catch" "continue" "else" 
	 "float" "int" "not_eq" "public" "sizeof" "this" "typename" "volatile"
	 "bitand" "char" "default" "enum" "for" "long" "operator" "register"
	 "static" "throw" "union" "wchar_t" "bitor" "class" "delete" "explicit"
	 "friend" "mutable" "or" "reinterpret_cast" "static_cast" "true" 
	 "unsigned" "while" "include" ) #'(lambda (a b) (> (length a) (length b)))))

(defvar ac-source-c++
  '((candidates
     . (lambda ()
	 (all-completions ac-target c++-keywords))))
  "Source for c++ keywords.")

(add-hook 'c++-mode-hook
	  (lambda ()
;;	    (make-local-variable 'ac-sources)
	    (setq ac-sources '(ac-source-abbrev ac-source-words-in-buffer ac-source-c++))))

(provide 'auto-complete-cpp)
-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux