Emacs imenu integration with cedet code auto-completion - emacs

Hi I can't integrate the imenu with the CEDET code completion. what appears when I invoke auto-completion is another buffer with the possible words.
reference
My .emacs file:
(require 'color-theme)
(color-theme-initialize)
(color-theme-blue-mood)
;; Load CEDET
(load-file "/home/user/cedet-1/common/cedet.el")
(global-ede-mode 1) ; Enable the Project management system
(semantic-load-enable-code-helpers) ; Enable prototype help and smart completion
(global-srecode-minor-mode 1) ; Enable template insertion menu
;; control + space
(global-set-key [?\C- ] 'semantic-complete-analyze-inline)
(load-library "completion")
(global-set-key (kbd "C-.") 'complete)
(defun my-semantic-hook ()
(imenu-add-to-menubar "TAGS"))
(add-hook 'semantic-init-hooks 'my-semantic-hook)

I'm not entirely sure what you are asking, but I'll guess that when you select C-SPC, you expect a menu to pop up? The code completion engine uses a bunch of different completion output mechanisms, but a menu isn't one of them because the Emacs menu system grabs focus, and prevents further typing. If you just want a menu, then you should bind C-SPC to semantic-ia-complete-symbol-menu instead.
Imenu is a tool that shows all tags in a buffer in a menu. Completion is a system by which Emacs provides a list of possible words that will complete some symbol. They are not related with the sole exception of when Imenu's tag collection mechanism is used by by a completion prompt, which CEDET does not enable.

Related

completing-read-default auto-focus candidate window

How to automatically set focus to window with displayed candidates (after tab punch) in default emacs read with autocompletion?
I can not use IDO nor other autocompletion systems in my case because I need to browse through 80k+ candidates, and only autocompletion system which can handle this is the default one.
I will be glad for any useful pointers.
EDIT
After some research, I get to work following imperfect solution:
(define-key minibuffer-local-completion-map
(kbd "<tab>")
(lambda ()
(interactive)
(call-interactively 'minibuffer-complete)
(call-interactively 'switch-to-completions)))
(define-key completion-list-mode-map
(kbd "C-f")
'isearch-forward)
Only problem is, after I enter completing-read-default, I must first hit TAB to open window with candidates (with newly added autofocus). But I want it to open window with candidates immediately without need to hit TAB. How to do it? I tried to call minibuffer-complete after call to completing-read-default but it doesnt opened window with candidates, only standard minibuffer prompt.
After some pain, I finally found solution
(defun custom/default-completing-read (question candidates)
(run-at-time "0.5" nil
(lambda ()
(minibuffer-complete)
(switch-to-completions)
(isearch-forward)))
(completing-read-default question candidates))
After call, it invokes default (written in C) completion system which can handle tons and tons of candidates without problems with automatic jump into candidate selection with isearch-forward enabled.
Hope it will help someone in future ...

Use only two functions from the evil package as keybinding

I want to get the search at point functionality ("*" and "#") in emacs.
So I want to use "*" and "#" from the emacs evil-mode, as this is one of the suggestions. However, I don't want anything else from the evil-mode, just those two functions!
This is my .emacs file:
(package-initialize)
(evil-mode 1) ;; enable evil-mode
(global-set-key (kbd "C-*") 'evil-search-symbol-forward)
(global-set-key (kbd "C-#") 'evil-search-symbol-backward)
Now the keybindings work, but I loaded the whole evil-mode, so it messes up my standard emacs keybindings like "C-y" for yank.
If I don't load the evil-mode in the .emacs file, I get the error:
Symbol's function definition is void: evil-search-symbol-forward
#event_jr's answer mentions highlight-symbols, which is probably a much more lightweight way to do what you want.
However, if you really want to use the evil version, you can (require 'evil) in your .emacs file without turning it on (ie, leave off the (evil-mode 1) statement).
Meanwhile, the functions you want are actually named evil-search-word-forward and evil-search-word-backward, not the ...-symbol-... version you saw on the wiki page (which is probably outdated).
You should use highlight-symbols for symbol jumping and highlighting.

Load iMenu at initialization

I'm sorry of r a very basic question. I am trying to load iMenu in GNU Emacs at the initialization. Usually it loads by executing M-x imenu-add-menubar-index. I understand I need to put something into my ~/.emacs file, but everything I tried does not work.
I'm new to GNU Emacs and Lisp, what do I need to put there for the index menu to be generated automatically?
You can have an Imenu "Index" menu bar item available for all buffers that belong to a certain major mode by adding imenu-add-menubar-index to its mode hook. For example,
(add-hook 'c-mode-hook #'imenu-add-menubar-index) ; c
(add-hook 'python-mode-hook #'imenu-add-menubar-index) ; python

Emacs auto-complete

since I can't get CEDET to work for automatic code-completion (aka intelli-sense in the MS-world), after trying several times (no, it's just not working!), I've decided to use auto-complete, which works "quite fine" for me.
Unfortunately, auto-complete has an annoying behaviour when it comes to quit the imenu with its suggestions.
auto-complete starts imenu, no matter how many suggestions it has. So, if there's only one suggestion, the menu appears.
1.
To exit the imenu, I have to use the LEFT or RIGHT keys in order to make the menu disappear. ESC-ESC-ESC does not have any effect.
Is there any way, to modify these two behaviors?
Here's an excerpt of my .emacs file showing the auto-complete relevant stuff:
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
(setq ac-delay 0.5) ;; eclipse uses 500ms
Kind regards,
mefiX
'Stop autocompleting' can be set by adding the following to your .emacs:
(define-key ac-completing-map "\ESC/" 'ac-stop)
...or alternatively you can use C-g as the default Emacs StopSomething command :)
As for showing the completion in a menu when there's only one candidate, I'm not really sure what other behaviour you'd want?

Emacs: Using and initializing CEDET

I'm using Emacs with CEDET and auto complete for code completion. Originally I set up CEDET so it loads at Emacs start up every time.
However, this took quite a long time, so i thought it would be clever to load it just if needed, i.e. - in my case - when entering C++-Mode.
So I moved the original function into a lambda that is called when entering C++-mode:
; cscope for c(++) programming (finding symbols, etc.)
(require 'xcscope)
; C++ stuff
(add-hook 'c++-mode-hook
(lambda ()
(load-file "/usr/share/emacs/site-lisp/cedet-common/cedet.el")
(global-ede-mode 1) ; enable project management system
(semantic-load-enable-code-helpers) ; enable prototype help and smart completion
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/elisp/ac-dict")
(add-to-list 'ac-sources 'ac-source-semantic)
(local-set-key (kbd "C-:") 'semantic-ia-complete-symbol-menu) ; set shortcut for auto completion.
(local-set-key (kbd "C-.") 'ac-complete-semantic)
(ac-config-default)
)
)
There are no errors, but I have the following problem: When Emacs enters C++-mode for the first time, code completion does not work properly. But if Emacs enters C++-mode the second time, everything works just fine.
Does anybody know what I'm doing wrong?
CEDET initialization sets up C and C++ mode hooks of it's own. If it installs it's hook while it is running the same hook, then it won't run, and your first buffer won't have initialized.
What you could do is load CEDET at startup, but then init the code helpers in the C mode hook. That way C++ mode will initialize with mode-local, but the extra functions will be installed after the hook runs, so that may work. I hadn't tried it myself.
I think EDE mode isn't slow, so it is probably ok to do that at init time too.