Emacs and vala-mode - emacs

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)

Related

Line numbers only in certain modes

Is there a way to get line numbering only in specific modes, i.e Python, Java, C++, etc., rather than in every window? I thought I saw something about this the other day, but I can't find it.
Currently I'm set up that the default is just to have linum-mode on persistenly. It's kind of annoying in the shell.
Thanks.
Assuming you want to use it all major programming modes and you're using Emacs 24.x, you can use this snippet:
(add-hook 'prog-mode-hook 'linum-mode)
I didn't turn linum on globally.
Instead I turn linum on for the major mode in which I want it. For example:
(add-hook 'clojure-mode-hook '(lambda () (linum-on)))
or simply:
(add-hook 'clojure-mode-hook 'linum-mode)
Related here:
Turning on linum-mode when in python/c mode
and here:
Emacs Org-Mode: Turn off line numbers

Auto Completion with auto-complete OR predictive based on mode

I'm using emacs-snapshot (24.2.50) on Xubuntu 12.10. For completion I am currently using auto-complete (v1.4).
I have a pretty nice setup of auto-complete with various sources, including the semantic source for code completion of my c++ programming. However, I'd like to switch to predictive-mode for completion of LaTeX documents (I'm using AUCTeX for all LaTeX related stuff).
My current auto-complete config (for LaTeX; I omitted all non-LaTeX config) looks like this:
(require 'auto-complete-latex)
(require 'ac-math)
(add-to-list 'ac-modes 'latex-mode) ; make auto-complete aware of {{{latex-mode}}}
(defun ac-latex-mode-setup () ; add ac-sources to default ac-sources
(setq ac-sources
(append '(ac-source-math-latex ac-source-latex-commands)
ac-sources))
)
(add-hook 'LaTeX-mode-hook 'ac-latex-mode-setup)
After adding predictive to the load-path and doing the auto-load stuff as described here I tried to disable auto-complete for LaTeX-mode and enable predictive-mode in turn by exchanging the above code by this:
(defun ele/latex-mode-completion-setup ()
(auto-complete-mode -1)
(predictive-mode 1)
)
(add-hook 'LaTeX-mode-hook 'ele/latex-mode-completion-setup)
Unfortunately this doesn't work as expected: auto-complete is actually disabled but predictive-mode is not enabled and instead of using AUCTeX the build-in tex-mode is used.
I have uploaded all LaTeX related config here. Note that this is loaded after the above completion setup, but this is the case for the old auto-complete based setup as well. Also note that exchanging that order does not make a difference as far as I can tell. Furthermore I found that simply commenting the auto-complete config (first snippet I posted) results in the same behaviour: tex-mode is used instead of AUCTeX.
I don't want to switch to predictive-mode for all modes but I really like many features it provides when doing LaTeX editing.
Any suggestions?
(remove-hook
might clear the hook, not to run unwanted stuff - just a suggestion indeed

Auto-complete mode doesn't turn on automatically in ObjC buffers

I load auto-complete mode like this:
(let ((ac-path "path/to/auto-complete"))
(add-to-list 'load-path ac-path)
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories (concat ac-path "ac-dict"))
(ac-config-default))
It works fine with C major mode, but doesn't turn on automatically when I open ObjC files. I can still turn it on manually and it will work fine along with the ObjC major mode.
Here's a snippet from the docs regarding ObjC major mode:
The hook `c-mode-common-hook' is run with no args
at mode initialization, then `objc-mode-hook'.
If I understand correctly, auto-complete adds a hook to the c-mode-common-hook, but objc-mode-hook somehow overrides it. Is there a way to fix this?
Thanks.
While looking through the source code of auto-complete.el, I've stumbled upon this definition
(defcustom ac-modes
'(emacs-lisp-mode
lisp-interaction-mode
c-mode cc-mode c++-mode
java-mode clojure-mode scala-mode
scheme-mode
ocaml-mode tuareg-mode
perl-mode cperl-mode python-mode ruby-mode
ecmascript-mode javascript-mode js-mode js2-mode php-mode css-mode
makefile-mode sh-mode fortran-mode f90-mode ada-mode
xml-mode sgml-mode)
"Major modes `auto-complete-mode' can run on."
:type '(repeat symbol)
:group 'auto-complete)
It turns out that auto-complete doesn't have a true global mode. It is enabled only with those major modes that are included in the ac-modes variable.
So, adding the following line to the .emacs file has solved the issue for me.
; add this line after the auto-complete mode has been loaded
(add-to-list 'ac-modes 'objc-mode)
Use the following:
(defun my-objc-mode-hook ()
(auto-complete-mode 1))
(add-hook 'objc-mode-hook 'my-objc-mode-hook)
Note 1: The function auto-complete-mode is a toggle function, when called with no arguments.
Note 2: It's possible to add an anonymous function using lambda, but this have several drawbacks. The most important ones are: modifying the function and reevaluating the expression will add the modified function in addition to the earlier version and C-h v xxx will print the full unformatted lambda function, which typically is hopeless to read and understand.
(add-hook 'objc-mode-hook 'auto-complete-mode)
That should do it if you're using auto-complete-mode. You can add more complex things to mode hooks by doing:
(add-hook 'objc-mode-hook '(lambda ()
(something-with arguments)))
Note that both arguments to add-hook are quoted, this is necessary and if you add unquoted functions they will probably not work.

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 - how do I automatically enter minor modes when I enter a major mode?

I'm kind of a newb when it comes to emacs. I know about the .emacs file but have very little idea as to do anything more advanced than elementary stuff.
Whenever I enter latex-mode, I'd also like to automatically turn on flyspell-mode, reftex-mode, auto-fill-mode, and also set fill-column to 120. How do I edit my .emacs file to do this?
Thanks!
(add-hook 'latex-mode-hook
(function (lambda ()
(flymake-mode)
(reftex-mode)
(auto-fill-mode)
(setq fill-column 120))))
for example should work.
You can set a so-called hook to a major mode. Have a look at this page of the manual for some examples.