linum-line
it 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 communitylinum-line
it 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?
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-hook
and 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.
add-hook
but it did not show the line numbers :-(
– alper
Jul 27 '20 at 17:09
emacs -q
- you apparently have a lot of stuff in your init file which causes problems. In any case, I "minimally tested" to make sure that the numbers show up when you start an isearch and go away when you exit.
– NickD
Jul 27 '20 at 17:34
emacs -q
. I will try to figure out what is prevents it by removing some lines. And thanks for the trick advice
– alper
Jul 27 '20 at 18:45
linum-mode
ornlinum
. – lawlist Jul 27 '20 at 1:43goto-line-with-feedback
if I want to see line-numbers but I don't know on the background which line-feature it is using – alper Jul 27 '20 at 1:47