Disabling 'linum-mode' for speedbar when global 'linum-mode' is active - emacs

I have linum-mode enabled globally in my Emacs configuration. Being enabled globally means it is also applied to the speedbar which is undesirable.
The only suggestion I found for this issue, was in the archived Emacs help mailing list, which suggests the following speedbar-mode-hook:
(add-hook 'speedbar-mode-hook (lambda () (linum-mode -1)))
Unfortunately adding this to my configuration doesn't have the desired effect and the speedbar still has line numbers.
Edit: the above add-hook seems to work correctly after all, at least for Emacs >= 24.3. Leaving question for reference purposes since there isn't any other relating to this matter on StackOverflow.

You can use speedbar-before-popup-hook hook for achieving what you want:
(add-hook 'speedbar-before-popup-hook (lambda () (linum-mode -1)))
I am not sure why the generic mode hook is not working, though.

Related

What happened to the ido-imenu in ruby-mode function in Emacs24?

Emacs 23.2 in emacs-starter-kit v1 has C-x C-i (or ido-imenu) (similar to Sublime Text's Cmd+R). Emacs24 in emacs-starter-kit v2 lacks this function. I found this github issue and a fix, which try to recreate the functionality. While this ido-imenu works in elisp-mode, it stopped working in ruby-mode. I get:
imenu--make-index-alist: No items suitable for an index found in this buffer
Has anyone figured out how to get this to work?
Why was this taken out of Emacs24?
Is there a new replacement for this function?
Since the function is part of ESK (as opposed to something budled with Emacs) you'd probably do best to report the bug upstream. On a related note ESK main competitor Emacs Prelude offers the same functionality (bound to C-c i by default) and it seems to be working fine with ruby-mode in Emacs 24. Here you can find more on ido-imenu.
So I finally figured it out, after reading the Defining an Imenu Menu for a Mode section on emacs-wiki again.
Short answer: you need to add this bit to your customization. Feel free to add more types to the list (I am happy with just methods).
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable imenu-generic-expression)
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1)
))))
Longer answer: I first tried to define a ruby-imenu-generic-expression function and set that to imenu-generic-expression by using the ruby-mode-hook:
(defvar ruby-imenu-generic-expression
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1))
"The imenu regex to parse an outline of the ruby file")
(defun ruby-set-imenu-generic-expression ()
(make-local-variable 'imenu-generic-expression)
(make-local-variable 'imenu-create-index-function)
(setq imenu-create-index-function 'imenu-default-create-index-function)
(setq imenu-generic-expression ruby-imenu-generic-expression))
(add-hook 'ruby-mode-hook 'ruby-set-imenu-generic-expression)
This however did not work (I would get the same error as before). More reading of the Defining an Imenu Menu for a Mode section showed me the way. Now, I'm not an elisp expert, so here's my hypothesis: basically, the above method works for modes where the
major mode supports a buffer local copy of the “real” variable, ‘imenu-generic-expression’. If your mode doesn’t do it, you will have to rely on a hook.
The example for foo-mode made it clear how to do it for ruby-mode. So it appears that ruby-mode does not have a buffer-local copy of the real imenu-generic-expression variable. I still can't explain why it worked in Emacs 23.2 (with ESK v1) but does not on Emacs24, but hey at least I found a working solution.

How to get whitespace-mode enabled only for certain modes

I'm trying to get emacs whitespace-mode enabled automatically only in certain modes. According to the documentation, enabling global-whitespace-mode and setting the whitespace-global-modes variable should do exactly that. But I can't get it to work correctly.
In my .emacs.el I have:
(require 'whitespace)
(global-whitespace-mode t)
(setq whitespace-global-modes '(c-mode c++-mode))
but the definition of whitespace-global-modes seems to be ignored; global-whitespace-mode is enabled in every buffer. I know that I've got the variable name correctly, because C-h v whitespace-global-modes tells me:
whitespace-global-modes's value is (c-mode c++mode)
Documentation:
Modes for which global `whitespace-mode' is automagically turned on.
...
So what am I doing wrong? Have I misunderstood the purpose of whitespace-global-modes?
I'm running emacs 23.2.1.
Apparently the meaning of whitespace-global-modes is very different from what you (and I) understand.
How about trying
(require 'whitespace)
(add-hook 'c-mode-hook
(function (lambda ()
(whitespace-mode t))))
and repeating the same thing for c++-mode?
It turns out that the commands in my .emacs.el were (almost) working after all. What confused me was that "WS" appears in the modeline of all buffers, even though only C and C++ buffers were getting the effect of whitespace-mode, as desired.
The other problem was that I had a typo: c++mode rather than c++-mode.

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 - 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.

Can't use (setq *-mode) instead of (global-*-mode) in Emacs

I use (global-hl-line-mode) to enable hl-line-mode, But i want to use
it in certain mode like cc-mode, so i add this line to mode-hook,
(setq hl-line-mode t), it doesn't work, i enable hl-line-mode use
M-x, it shows disabled, which means at first, it's really enabled, but
i can't see any highlight.
Same problem occurs to linum-mode, maybe there are others.
Anyone knows what's wrong with it?
Thanks.
In general, it's a good idea to turn the mode on through the function call, rather than just setting the variable. The function call will set the variable for you, and likely do some other work.
Try this:
(add-hook 'c-mode-common-hook
(lambda () (hl-line-mode 1)
(linum-mode 1)))