Line numbers only in certain modes - emacs

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

Related

How do I disable line numbers in Helm buffers?

I'm using linum to show line numbers. What I want is to have them enabled by default, but disabled in certain major modes, like eshell, compilation, etc.
This works well, but what I can't figure out is how to disable them in Helm buffers.
There doesn't seem to be a major mode I can hook into
(add-hook 'helm-before-initialize-hook '(lambda () (linum-mode 0))) turns off line numbers globally. Not sure how to disable linum for the current buffer only, since Helm buffers usually appear alongside another one
Tried advice around helm-find-files, but doesn't seem to work
I didn't have linum-off set up properly. It overrides a function which global-linum-mode calls, so the latter has to be active in order for it to work.
; init.el
(require 'linum-off)
(global-linum-mode t)

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)

How can I disable auto-fill mode in Emacs?

Today I got my new PC (Windows 7, 32 bit) and installed Vincelt Goulets Emacs. The only other thing I did was updating Org-mode.
Now, I am stuck with auto-fill-mode on every time I start Emacs new, which I hate. I would like to turn auto-fill-mode off, for now and forever. I even deleted my .emacs file, but auto-fill-mode was still turned on.
The only solution that worked was (a) a nasty workaround or (b) always typing M-x auto-fill-mode every time I start Emacs anew.
Is there a solution?
To be clear, the only thing the current .emacs file contains is: '(inhibit-startup-screen t)
Add to your .emacs,
(auto-fill-mode -1)
If there are hooks for specific modes, you will need to zap those as well. My suspicion is that you do not actually have auto-fill-mode on by default in all modes, but with the information you have supplied, at least this should be a starting point.
A reasonable safeguard would be to also disable auto-fill mode from `text-mode-hook':
(remove-hook 'text-mode-hook #'turn-on-auto-fill)
You may need something similar for other modes as well.
Assuming that he has not made fundamental changes, you have several paths:
You can just turn off the mode globally in your .emacs file:
(turn-off-auto-fill)
;; ...or (auto-fill-mode -1)
Since Emacs of that vintage also turns on auto-fill for text-mode, add:
(remove-hook 'text-mode-hook 'turn-on-auto-fill)
That should account for all the default places, but check the major mode hooks if you have other modes enabling this automatically.
If you'd like to keep it turned-on in most text-mode while disable auto-fill in specific modes, e.g. org-mode in my case, you could use the following:
;; turn on auto-fill for text-mode
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; turn off auto-fill for org-mode
(add-hook 'org-mode-hook 'turn-off-auto-fill)

How can I get emacs to show line numbers when the 'text-mode-hook appears not to be working?

I am trying to use setnu.el to give me line numbers in emacs, which as you might imagine I want in pretty much every mode. It seemed like the preffered way of doing this in Emacs is to use
(add-hook 'text-mode-hook 'turn-on-setnu-mode)
but this isn't working for me. Using
(add-hook 'emacs-lisp-mode-hook 'turn-on-setnu-mode)
works just fine when I am editing emacs lisp files, but I want line numbers in all my text viewing and don't want to have a special case for each kind of file in my init.d file. Help would be much appreciated.
Linum seems to be distributed with emacs >=22.
Try:
(require 'linum)
Then toggle the display of line numbers with
M-x linum-mode
http://web.student.tuwien.ac.at/~e0225855/linum/linum.html

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.