0

When I narrow an org mode header into a subtree(using command org-narrow-to-subtree) in vanilla Emacs, the line number counts from 1 in the subtree, but when I create a subtree in Doom Emacs, the line number counts from the original line number(e.g. if the header is on the 8000th line in the original file, the header in the subtree still starts from 8000, instead of 1). How can I make it count from 1 in the subtree?

enter image description here

3
  • 1
    What line numbering mode are you using? display-line-numbers-mode (available since emacs 26) is both faster than older line-number modes (it's implemented in C not elisp I believe) and for me has the behaviour you say you want (i.e. when narrowed it counts from 1). – Croad Langshan Mar 10 at 11:08
  • @CroadLangshan Thanks, but I believe I'm using display-line-numbers-mode because I've checked the value of display-line-numbers-mode, which is t. I also tried disabling the mode by running the display-line-numbers-mode command, the line numbers disappeared. Rerun the command redisplayed line numbers. So I think I'm using this mode to show line numbers. – Searene Mar 11 at 6:20
  • What emacs version are you using? I'm using 27.1, and the docs for variable display-line-numbers say "If the value is t, display the absolute number of each line of a buffer shown in a window. Absolute line numbers count from the beginning of the current narrowing, or from buffer beginning.". You might also poke around in variables starting with display-line (something like ivy or helm together with C-h v is helpful for that, or M-x customize-group <RET> display-line-numbers <RET>) – Croad Langshan Mar 11 at 12:12
1

Put this in an appropriate place in your emacs configuration (not sure what file that is for doom):

(custom-set-variables
   '(display-line-numbers-widen nil))

I think you could use setq-default instead if you like, but I hear there are some subtleties that make custom-set-variables a better choice for customize-able variables -- it's OK to use custom-set-variables in your ordinary emacs config however you like -- just don't edit by hand the special customize call that is commented with ;; custom-set-variables was added by Custom. unless you know what you're doing.

Alternatively, you can use M-x customize-variable <RET> display-line-numbers-widen <RET>.

2
  • Thanks, it worked! And as you said, only customize-variable worked. setq didn't work. Maybe customize-variable has higher priority. – Searene Mar 11 at 12:48
  • 1
    Ah it automatically becomes buffer-local when set, so probably you'd have to use setq-default if you want to set a global default value across buffers (though since this is C-implemented, maybe it's even more special than that? Haven't tested). Corrected my answer – Croad Langshan Mar 12 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.