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)
Related
Normally, I need to enable the auto-fill-mode, so I have it turned on in .emacs. But when editting PHP in php-mode, I'd like to not use auto-fill-mode. Is there way to set it in .emacs such that when I'm in PHP mode, the auto-fill-paragraph mode is automatically turned off and when I leave php-mode, it's automatically turned on, barring other overriding?
Update: a closer examination of the .emacs revealed that auto-fill is set up by
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(column-number-mode t)
...
'(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
...)
Some major-modes inherit certain settings from other modes (e.g., text-mode is used by many popular major modes). The following code snippet can be used to disable a feature for a particular major-mode using its mode hook:
(add-hook 'php-mode-hook (lambda ()
(auto-fill-mode -1) ))
It is sometimes helpful to check and see whether a particular feature has been enabled globally or locally, which in turn can give a clue as to whether that feature has been inherited by a major mode. In this case, the documentation for auto-fill-mode states as follows -- https://www.gnu.org/software/emacs/manual/html_node/emacs/Auto-Fill.html:
"Auto Fill mode is a buffer-local minor mode (see Minor Modes) in which lines are broken automatically when they become too wide. Breaking happens only when you type a <SPC> or <RET>."
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
Goal: I want to have show-trailing-whitespace enabled for all buffers save a few. Exceptions posing a problem are *Shell Command Output* and its cousin *Async Shell Command*.
I usually have show-trailing-whitespace customized to t. Therefore it is active in all new buffers.
I would also like to have it turned off for certain buffers, foremost amongst them *Shell Command Output*. This poses a problem for me:
The output buffer doesn't use a special mode; it is still in fundamental-mode. There is no fundamental-mode-hook that I could hook this setting into.
There is the after-major-mode-change-hook which is run when the major mode is changed to fundamental-mode, but the buffer starts out in that mode and therefore this hook is not run.
There doesn't seem to be a way to hook into get-buffer-create.
I know I can always advise the function get-buffer-create for this particular example, but I try to avoid that as much as possible.
Any hints?
You might be better off looking at the problem from the other side, and only set the var in those modes where you want to see trailing whitespace.
But I think you have a good point: these shell output buffers should not use fundamental-mode. It's probably time for M-x report-emacs-bug
In accordance with the accepted answer, here's a code snippet that enables trailing whitespaces highlighting for specific modes only:
(setq-default show-trailing-whitespace nil)
(defun namespace/show-trailing-whitespace ()
"Highlight trailing whitespaces in this buffer."
(setq-local show-trailing-whitespace t))
(dolist (hook '(prog-mode-hook text-mode-hook))
(add-hook hook 'namespace/show-trailing-whitespace))
This snippet is essentially taken from Steve Purcell's configuration.
I have an issue using Emacs 24.1.1 on Mac OS X. I'm editing Jade and CoffeeScript files, so I've turned on whitespace-mode for those file types.
What I'm seeing is that lines longer than 70 characters are highlighted with the whitespace-line font face, regardless of the setting of whitespace-line-column.
In this shot, it is clear that I've customized whitespace-line-column to track fill-column, and I've set fill-column to 120, but much shorter lines are being highlighted.
I've glanced over the code for the Jade mode and don't see anything that would explain the behavior, but I have only a passing understanding of Emacs Lisp.
Thanks in advance for any pointers!
You have to set whitespace-line-column before you activate whitespace-mode. That is, if you want to change its value it does not take effect unless you turn whitespace-mode off and on again. Ironically, that variable is not available for M-x customize until you have activated the mode once :-(
However, you can customize the global value of this variable by putting the following line in your .emacs file:
(setq whitespace-line-column 120)
Since your .emacs is evaluated when you start Emacs, the setting will take effect before you invoke whitespace-mode for the first time and should thus do what you want. If you don't want to set the value globally, but only for Jade files, put the following in your .emacs file instead:
(set (make-local-variable 'whitespace-line-column) 80)
(add-hook 'after-change-major-mode-hook
'(lambda () (when (eq major-mode 'jade-mode)
(setq whitespace-line-column 120))))
If you never want long lines to be highlighted specially at all, there is a third option you might want to consider. You could customize the variable whitespace-style (by typing M-x customize-variable ENTER whitespace-style ENTER) and in the value list remove the entries:
lines
lines-tail
(if any). This should turn off highlighting of long lines globally independent of the value of whitespace-line-column (again, only after you de- and re-activate whitespace mode).
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)