Emacs auto-complete - emacs

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?

Related

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.

Emacs and vala-mode

I am using vala-mode to edit Vala code in Emacs. However, I want to change two things in vala-mode:
I want to indent with 4 spaces instead of 2 spaces (which is my Emacs default).
I want to enable auto-completion inside vala-mode.
Auto-completion works in all modes except for vala-mode, and I want the 4 spaces indentation only for vala-mode, not all modes. However, I don't know how to make these changes only for vala-mode.
Thank you.
Something like this should work:
(add-hook 'vala-mode-hook (lambda () (setq c-basic-offset 4)))
I have never used vala-mode, but it looks like it is based on cc-mode so that setting c-basic-offset might work. For info on how to set c-basic-offset in a style, see the documentation at
(info "(ccmode)Customizing Indentation")
I saw that the indentation issue was fixed but not the auto complete feature. If you are using the auto complete package, then in your init.el or .emacs you can simply put:
(require 'auto-complete-config)
(add-to-list 'ac-modes 'vala-mode)
You will then have auto complete locally. Thats one way of doing it. Also there is a Yasnippet package for vala that is available in MELPA (https://github.com/gopar/vala-snippets)

why eldoc mode makes emacs use 100% cpu?

when i use eldoc,i add this to .emacs:
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
and then when i use emacs,the emacs will use 100% cpu and it stucks.
but when i delete this code in .emacs,the emacs works.
anyone has idea about this?Or how to debug the problem.
Or anyother way to substitute for the eldoc mode
You can run M-x toggle-debug-on-quit RET, then C-g will bring up a backtrace of what it is doing at the moment. You can update the question with the result if you can't figure out the problem at that point.
An alternate way is to comment out the rest of your .emacs file (everything except eldoc-mode stuff) and then uncomment pieces of it and see where things break. It's probably the interaction of eldoc with something else since eldoc has always worked great for me.
You might also want to check the value of eldoc-documentation-function to see if it's set to something weird.

Forcing haskell-indent-mode over haskell-indentation-mode in haskell-mode 2.7?

I'm an Emacs user with no skills with regards to configuring the editor. After I upgraded from haskell-mode 2.4 to 2.7, I've noticed two changes:
Indentation is different somehow, in a way I don't quite like. I can't quite put my finger on what it is.
More importantly: If I have cua-mode enabled and highlight a block of text, backspace/delete does not delete the entire block, just the previous/next character from my marker.
I see that haskell-mode 2.7 uses the minor mode haskell-indentation-mode by default, while 2.4's behaviour has been preserved in the form of haskell-indent-mode. If I first turn off the former, and then on the latter, the behaviour I want is restored (i.e. indentation feels like before, and backspace/delete deletes highlighted blocks).
I can't, however, get this to happen automatically whenever I open a file with a .hs suffix. I've tried various things resembling
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent-mode)
and the likes of it, but I either end up with the standard mode or with plain haskell-mode without indent and doc.
Any ideas?
Solution (thanks to nominolo):
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indent)
(remove-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(defun my-haskell-mode-hook ()
(haskell-indentation-mode -1) ;; turn off, just to be sure
(haskell-indent-mode 1) ;; turn on indent-mode
)
The best way to configure such things is by writing a custom hook:
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(defun my-haskell-mode-hook ()
(haskell-indentation-mode -1) ;; turn off, just to be sure
(haskell-indent-mode 1) ;; turn on indent-mode
;; further customisations go here. For example:
(setq locale-coding-system 'utf-8 )
(flyspell-prog-mode) ;; spell-checking in comments and strings
;; etc.
)
You could also stick an anonymous function in there, but having a named function is easier if you want to experiment with some settings. Just redefining the function (and re-opening a Haskell file) will give you the new behaviour.

Emacs imenu integration with cedet code auto-completion

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.