linum-lineit not enabled when emacs is started.
I just want to enable linum-mode (see the line numbers) during
I-search and disable it when
I-search: is ended. Is it possible?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
Ideally, one would not have to worry about line numbers at all: the various tools would cooperate to put you in the right place. However, there are holes in the coverage, so you occasionally need to know on what line you are and how to get to a given line.
As @lawlist points out, it would be preferable to use
display-line-number-mode - see the EmacsWiki page for details. That takes care of knowing where you are and, in my case, binding
goto-line to a key takes cares of the second. AFAIK, this is much more efficient than
linum-mode (which I am not using, but which, when I tried it out many years ago, was very unresponsive, although undoubtedly it is much better than it was).
If you still want to turn it on and off in
isearch, you can try using
isearch-mode-end-hook. Something like this (minimally tested):
(add-hook 'isearch-mode-hook (lambda () (linum-mode 1))) (add-hook 'isearch-mode-end-hook (lambda () (linum-mode 0)))
This is bog-standard emacs customization: the only thing that you have to research is whether the appropriate hooks are available, which is generally easy to do by using
C-h v isearch--hook TAB in this case, taking advantage on one hand of the universal convention of hook naming (
<prefix>-<type>-hook) and on the other hand the standard completion mechanism (which will expand the
-- in the middle, giving you all the variables that start with
isearch- and end with
-hook). IMO, this is a very useful trick and is worth remembering.