New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Emacs 26's native line numbers #9362

Open
barischrooneyj opened this Issue Aug 4, 2017 · 35 comments

Comments

Projects
None yet
@barischrooneyj

barischrooneyj commented Aug 4, 2017

When dotspacemacs-line-numbers is true then if available use Emacs 26's display-line-numbers-mode instead of linum-mode.

According to emacs/NEWS it is "much faster and doesn't usurp the display margin for the line numbers."

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag Aug 7, 2017

Collaborator

Actually, if the feature is stable (not too buggy, work on API is finished) then we can add support for it, as long as there aren't any problems for users of currently supported versions. I think this feature will be a high priority once Emacs 26 is released, anyway.

Collaborator

bmag commented Aug 7, 2017

Actually, if the feature is stable (not too buggy, work on API is finished) then we can add support for it, as long as there aren't any problems for users of currently supported versions. I think this feature will be a high priority once Emacs 26 is released, anyway.

@LdBeth

This comment has been minimized.

Show comment
Hide comment
@LdBeth

LdBeth Oct 12, 2017

Emacs 26 pretest is out and we can start working on that.

LdBeth commented Oct 12, 2017

Emacs 26 pretest is out and we can start working on that.

@jsoo1

This comment has been minimized.

Show comment
Hide comment
@jsoo1

jsoo1 Dec 12, 2017

What's the status on this? I had a private branch with some work done but I didn't really know what I was doing or the best way to do it.

jsoo1 commented Dec 12, 2017

What's the status on this? I had a private branch with some work done but I didn't really know what I was doing or the best way to do it.

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag Dec 19, 2017

Collaborator

@jsoo1 AFAIK no one has been working on it. I'm not familiar with native line numbers API yet, so I can't tell you what the best way to configure it.

As for supporting both old and new Emacs versions simultaneously, a good way to do it is for both linum and native-line-numbers to be listed in the packages list (of spacemacs-base/packages.el) with a toggle that depends on the Emacs version. There are also some global bindings in spacemacs-base/keybindings.el (for code selection by mouse-clicking the line number) that might have a connection with linum. If they really depend on linum, then they will need to become conditional as well (and preferably something equivalent can be written for native-line-numbers).

Collaborator

bmag commented Dec 19, 2017

@jsoo1 AFAIK no one has been working on it. I'm not familiar with native line numbers API yet, so I can't tell you what the best way to configure it.

As for supporting both old and new Emacs versions simultaneously, a good way to do it is for both linum and native-line-numbers to be listed in the packages list (of spacemacs-base/packages.el) with a toggle that depends on the Emacs version. There are also some global bindings in spacemacs-base/keybindings.el (for code selection by mouse-clicking the line number) that might have a connection with linum. If they really depend on linum, then they will need to become conditional as well (and preferably something equivalent can be written for native-line-numbers).

@sdwolfz

This comment has been minimized.

Show comment
Hide comment
@sdwolfz

sdwolfz Dec 19, 2017

Collaborator

Just to let people know, I'm interested in this feature and I might take a swing at it over the winter holidays, but I would like emacs 26 to actually be released first.

Collaborator

sdwolfz commented Dec 19, 2017

Just to let people know, I'm interested in this feature and I might take a swing at it over the winter holidays, but I would like emacs 26 to actually be released first.

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag Dec 19, 2017

Collaborator

Just for general information, the first pretest for Emacs 26 was released ~2 months ago, so there's still some time to go before the final release. Usually there are a few pretest releases, followed by a few release candidates, and only then Emacs 26 will be officially released. Judging by past releases, this could take more than a few months.

I'd expect the API for native-line-numbers to be stable by the 1st RC, possibly even before.

Collaborator

bmag commented Dec 19, 2017

Just for general information, the first pretest for Emacs 26 was released ~2 months ago, so there's still some time to go before the final release. Usually there are a few pretest releases, followed by a few release candidates, and only then Emacs 26 will be officially released. Judging by past releases, this could take more than a few months.

I'd expect the API for native-line-numbers to be stable by the 1st RC, possibly even before.

@kommen

This comment has been minimized.

Show comment
Hide comment
@kommen

kommen Feb 1, 2018

linum-relative, which comes with Spacemacs, has already added support for, display-line-numbers-modes as a backend: coldnew/linum-relative@9fd6c7a

Permalink to the news section for Emacs 26 announcing display-line-numbers-mode as the link in the original issue comment is broken: https://github.com/emacs-mirror/emacs/blob/d42bd3a512dadd853d7fb828072a531d7f1d78b6/etc/NEWS.26#L492-L515

kommen commented Feb 1, 2018

linum-relative, which comes with Spacemacs, has already added support for, display-line-numbers-modes as a backend: coldnew/linum-relative@9fd6c7a

Permalink to the news section for Emacs 26 announcing display-line-numbers-mode as the link in the original issue comment is broken: https://github.com/emacs-mirror/emacs/blob/d42bd3a512dadd853d7fb828072a531d7f1d78b6/etc/NEWS.26#L492-L515

@azzamsa

This comment has been minimized.

Show comment
Hide comment
@azzamsa

azzamsa Mar 30, 2018

@barischrooneyj I think the link for your citation is here :)

Emacs now supports optional display of line numbers in the buffer.
This is similar to what 'linum-mode' provides, but much faster and
doesn't usurp the display margin for the line numbers

azzamsa commented Mar 30, 2018

@barischrooneyj I think the link for your citation is here :)

Emacs now supports optional display of line numbers in the buffer.
This is similar to what 'linum-mode' provides, but much faster and
doesn't usurp the display margin for the line numbers

@syvanpera

This comment has been minimized.

Show comment
Hide comment
@syvanpera

syvanpera Apr 18, 2018

Has there been any new development on this? I just recently switched to spacemacs and I had a hell of a time trying to get relative line numbering and git-gutter working. Then I switched to using the native line numbering and everything works like a charm and it feels a bit snappier to boot.

syvanpera commented Apr 18, 2018

Has there been any new development on this? I just recently switched to spacemacs and I had a hell of a time trying to get relative line numbering and git-gutter working. Then I switched to using the native line numbering and everything works like a charm and it feels a bit snappier to boot.

@jsoo1

This comment has been minimized.

Show comment
Hide comment
@jsoo1

jsoo1 Apr 18, 2018

I’ve been too busy to work on this. I have been waiting for your comment though, I’m glad to hear it’s worth it 😄.

jsoo1 commented Apr 18, 2018

I’ve been too busy to work on this. I have been waiting for your comment though, I’m glad to hear it’s worth it 😄.

@syvanpera

This comment has been minimized.

Show comment
Hide comment
@syvanpera

syvanpera Apr 18, 2018

At least for me, yes. Couldn't get the line numbers working properly with git-gutter. So far they've been working really well. Only difference to the old way is that the git-gutter markers are on the left side of the line numbers. I think they were the other way around in the old implementation, but at least for me, that's not an issue

syvanpera commented Apr 18, 2018

At least for me, yes. Couldn't get the line numbers working properly with git-gutter. So far they've been working really well. Only difference to the old way is that the git-gutter markers are on the left side of the line numbers. I think they were the other way around in the old implementation, but at least for me, that's not an issue

@jsoo1

This comment has been minimized.

Show comment
Hide comment
@jsoo1

jsoo1 Apr 18, 2018

Native line numbers are definitely a game changer. I think anyone who has more experience than I writing layers should start working on one.

jsoo1 commented Apr 18, 2018

Native line numbers are definitely a game changer. I think anyone who has more experience than I writing layers should start working on one.

@syvanpera

This comment has been minimized.

Show comment
Hide comment
@syvanpera

syvanpera Apr 18, 2018

I suppose writing a layer for it would be the simplest solution. But I feel this is really something that should be added to the core. If not to replace linum-mode (if spacemacs needs to support older Emacs than 26), then at least as an option by its side

syvanpera commented Apr 18, 2018

I suppose writing a layer for it would be the simplest solution. But I feel this is really something that should be added to the core. If not to replace linum-mode (if spacemacs needs to support older Emacs than 26), then at least as an option by its side

@syvanpera

This comment has been minimized.

Show comment
Hide comment
@syvanpera

syvanpera Apr 18, 2018

I took a look at the source for line number handling right now. But with my limited elisp experience it might be a bit out of my league for now

syvanpera commented Apr 18, 2018

I took a look at the source for line number handling right now. But with my limited elisp experience it might be a bit out of my league for now

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag May 14, 2018

Collaborator

I added support for native line numbers in #10675, but it might have some rough edges still. Could some of you please test the PR in normal usage and report any problems it has? If you run Emacs 26, the PR doesn't require any changes to your user configuration, it should use native line numbers automatically (unless you enabled nlinum layer, in this case you need to disable it).

Also, I'm not sure what the best behavior for SPC t n and SPC t r toggles, so if anyone has feedback or preferences, please share it on the PR page. The PR page has more details about the toggles situation.

Collaborator

bmag commented May 14, 2018

I added support for native line numbers in #10675, but it might have some rough edges still. Could some of you please test the PR in normal usage and report any problems it has? If you run Emacs 26, the PR doesn't require any changes to your user configuration, it should use native line numbers automatically (unless you enabled nlinum layer, in this case you need to disable it).

Also, I'm not sure what the best behavior for SPC t n and SPC t r toggles, so if anyone has feedback or preferences, please share it on the PR page. The PR page has more details about the toggles situation.

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag May 28, 2018

Collaborator

Develop branch now supports native line numbers for Emacs 26, which was released today. Details at 8f82486. For nlinum users, be aware that we are planning to deprecate the layer for Emacs 26 so it does not override the native line numbers.

Collaborator

bmag commented May 28, 2018

Develop branch now supports native line numbers for Emacs 26, which was released today. Details at 8f82486. For nlinum users, be aware that we are planning to deprecate the layer for Emacs 26 so it does not override the native line numbers.

@brandonwillard

This comment has been minimized.

Show comment
Hide comment
@brandonwillard

brandonwillard May 29, 2018

Are the modes set in :enabled-for-modes supposed to be exclusive (i.e. only line numbering for modes specified there and also not present in :disabled-for-modes)? The documentation for dotspacemacs-line-numbers seems to imply that, but that's not how spacemacs//linum-enabled-for-current-major-mode appears to work.

brandonwillard commented May 29, 2018

Are the modes set in :enabled-for-modes supposed to be exclusive (i.e. only line numbering for modes specified there and also not present in :disabled-for-modes)? The documentation for dotspacemacs-line-numbers seems to imply that, but that's not how spacemacs//linum-enabled-for-current-major-mode appears to work.

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag May 29, 2018

Collaborator

@brandonwillard Yes, they are supposed to be exclusive. There's a bug in the function. The following patch should fix it, can you confirm?

1 file changed, 6 insertions(+), 4 deletions(-)
layers/+spacemacs/spacemacs-defaults/funcs.el | 10 ++++++----

modified   layers/+spacemacs/spacemacs-defaults/funcs.el
@@ -1235,9 +1235,9 @@ Decision is based on `dotspacemacs-line-numbers'."
   ;; default `enabled-for-modes' to '(prog-mode text-mode), because it is a more
   ;; sensible default than enabling in all buffers - including Magit buffers,
   ;; terminal buffers, etc.
-  (let* ((enabled-for-modes (or (spacemacs/mplist-get dotspacemacs-line-numbers
-                                                      :enabled-for-modes)
-                                '(prog-mode text-mode)))
+  (let* ((user-enabled-for-modes (spacemacs/mplist-get dotspacemacs-line-numbers
+                                                       :enabled-for-modes))
+         (enabled-for-modes (or user-enabled-for-modes '(prog-mode text-mode)))
          (disabled-for-modes (spacemacs/mplist-get dotspacemacs-line-numbers
                                                    :disabled-for-modes))
          (enabled-for-parent (or (and (eq enabled-for-modes 'all) 'all)
@@ -1255,4 +1255,6 @@ Decision is based on `dotspacemacs-line-numbers'."
           ;; from disabled-for-parent)
           (not (spacemacs/derived-mode-p enabled-for-parent disabled-for-parent)))
      ;; current mode (or parent) not explicitly disabled
-     (not disabled-for-parent))))
+     (and (null user-enabled-for-modes)
+          disabled-for-modes
+          (not disabled-for-parent)))))
Collaborator

bmag commented May 29, 2018

@brandonwillard Yes, they are supposed to be exclusive. There's a bug in the function. The following patch should fix it, can you confirm?

1 file changed, 6 insertions(+), 4 deletions(-)
layers/+spacemacs/spacemacs-defaults/funcs.el | 10 ++++++----

modified   layers/+spacemacs/spacemacs-defaults/funcs.el
@@ -1235,9 +1235,9 @@ Decision is based on `dotspacemacs-line-numbers'."
   ;; default `enabled-for-modes' to '(prog-mode text-mode), because it is a more
   ;; sensible default than enabling in all buffers - including Magit buffers,
   ;; terminal buffers, etc.
-  (let* ((enabled-for-modes (or (spacemacs/mplist-get dotspacemacs-line-numbers
-                                                      :enabled-for-modes)
-                                '(prog-mode text-mode)))
+  (let* ((user-enabled-for-modes (spacemacs/mplist-get dotspacemacs-line-numbers
+                                                       :enabled-for-modes))
+         (enabled-for-modes (or user-enabled-for-modes '(prog-mode text-mode)))
          (disabled-for-modes (spacemacs/mplist-get dotspacemacs-line-numbers
                                                    :disabled-for-modes))
          (enabled-for-parent (or (and (eq enabled-for-modes 'all) 'all)
@@ -1255,4 +1255,6 @@ Decision is based on `dotspacemacs-line-numbers'."
           ;; from disabled-for-parent)
           (not (spacemacs/derived-mode-p enabled-for-parent disabled-for-parent)))
      ;; current mode (or parent) not explicitly disabled
-     (not disabled-for-parent))))
+     (and (null user-enabled-for-modes)
+          disabled-for-modes
+          (not disabled-for-parent)))))
@brandonwillard

This comment has been minimized.

Show comment
Hide comment
@brandonwillard

brandonwillard May 29, 2018

Should the following pass?

(ert-deftest spacemacs//linum-enabled-for-current-major-mode--disabled-and-enabled ()
  (let ((dotspacemacs-line-numbers '(:enabled-for-modes emacs-lisp-mode
                                     :disabled-for-modes prog-mode)))
    (let ((major-mode 'emacs-lisp-mode))
      (should (equal t (spacemacs//linum-enabled-for-current-major-mode))))))

Regardless, the patch appears to fix the original problem.

brandonwillard commented May 29, 2018

Should the following pass?

(ert-deftest spacemacs//linum-enabled-for-current-major-mode--disabled-and-enabled ()
  (let ((dotspacemacs-line-numbers '(:enabled-for-modes emacs-lisp-mode
                                     :disabled-for-modes prog-mode)))
    (let ((major-mode 'emacs-lisp-mode))
      (should (equal t (spacemacs//linum-enabled-for-current-major-mode))))))

Regardless, the patch appears to fix the original problem.

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag May 29, 2018

Collaborator

The first should pass, the second should fail, and the test call should be just:

(should (spacemacs//linum-enabled-for-current-major-mode))

I'm writing relevant tests right now.

Collaborator

bmag commented May 29, 2018

The first should pass, the second should fail, and the test call should be just:

(should (spacemacs//linum-enabled-for-current-major-mode))

I'm writing relevant tests right now.

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag May 29, 2018

Collaborator

Sorry, the second should also pass, I missed that it's a nil there and not a t.

Collaborator

bmag commented May 29, 2018

Sorry, the second should also pass, I missed that it's a nil there and not a t.

@brandonwillard

This comment has been minimized.

Show comment
Hide comment
@brandonwillard

brandonwillard May 29, 2018

Oh, I removed the second one because it seemed like other modes should be enabled when only specifying :disabled-for-modes.

brandonwillard commented May 29, 2018

Oh, I removed the second one because it seemed like other modes should be enabled when only specifying :disabled-for-modes.

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag May 29, 2018

Collaborator

When specifying :disabled-for-modes, all other modes that derive from prog-mode or text-mode should be enabled. The mode that was in that test didn't derive from them.

Collaborator

bmag commented May 29, 2018

When specifying :disabled-for-modes, all other modes that derive from prog-mode or text-mode should be enabled. The mode that was in that test didn't derive from them.

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag May 30, 2018

Collaborator

spacemacs//linum-enabled-for-current-major-mode should be fixed now

Collaborator

bmag commented May 30, 2018

spacemacs//linum-enabled-for-current-major-mode should be fixed now

@sdwolfz

This comment has been minimized.

Show comment
Hide comment
@sdwolfz

sdwolfz May 30, 2018

Collaborator

@bmag Line numbers work well for me 👍 .

The only inconvenience I have right now is that the line number "sidebar" is way to wide by default and I need to do:

(setq-default display-line-numbers-width nil)

in my dotspacemacs/user-config to get it back to normal.

I would preffer if we did not configure the width in the package init:

diff --git a/layers/+spacemacs/spacemacs-defaults/packages.el b/layers/+spacemacs/spacemacs-defaults/packages.el
index 0aad40b76..9e03522c7 100644
--- a/layers/+spacemacs/spacemacs-defaults/packages.el
+++ b/layers/+spacemacs/spacemacs-defaults/packages.el
@@ -186,7 +186,6 @@
     :defer t
     :init
     (progn
-      (setq-default display-line-numbers-width 4)
       (if (spacemacs/relative-line-numbers-p)
           (setq display-line-numbers-type 'relative)
         (setq display-line-numbers-type t))
Collaborator

sdwolfz commented May 30, 2018

@bmag Line numbers work well for me 👍 .

The only inconvenience I have right now is that the line number "sidebar" is way to wide by default and I need to do:

(setq-default display-line-numbers-width nil)

in my dotspacemacs/user-config to get it back to normal.

I would preffer if we did not configure the width in the package init:

diff --git a/layers/+spacemacs/spacemacs-defaults/packages.el b/layers/+spacemacs/spacemacs-defaults/packages.el
index 0aad40b76..9e03522c7 100644
--- a/layers/+spacemacs/spacemacs-defaults/packages.el
+++ b/layers/+spacemacs/spacemacs-defaults/packages.el
@@ -186,7 +186,6 @@
     :defer t
     :init
     (progn
-      (setq-default display-line-numbers-width 4)
       (if (spacemacs/relative-line-numbers-p)
           (setq display-line-numbers-type 'relative)
         (setq display-line-numbers-type t))
@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag Jun 1, 2018

Collaborator

@sdwolfz I changed it to match the setting for linum-format, but you're right it's a bit too big.

Collaborator

bmag commented Jun 1, 2018

@sdwolfz I changed it to match the setting for linum-format, but you're right it's a bit too big.

sdwolfz added a commit that referenced this issue Jun 2, 2018

@sdwolfz

This comment has been minimized.

Show comment
Hide comment
@sdwolfz

sdwolfz Jun 2, 2018

Collaborator

@bmag 👍 I've pushed the patch above to develop 0ebcc25.

Collaborator

sdwolfz commented Jun 2, 2018

@bmag 👍 I've pushed the patch above to develop 0ebcc25.

@mmcnl

This comment has been minimized.

Show comment
Hide comment
@mmcnl

mmcnl Jun 10, 2018

@bmag @sdwolfz Thanks for your work on this! Is there any way to add some padding to the right of the numbers? With linum-mode I was doing something like this (setq-default linum-relative-format "%2s ") to get some visual space between the numbers and the beginning of the code.

mmcnl commented Jun 10, 2018

@bmag @sdwolfz Thanks for your work on this! Is there any way to add some padding to the right of the numbers? With linum-mode I was doing something like this (setq-default linum-relative-format "%2s ") to get some visual space between the numbers and the beginning of the code.

@darkbaby123

This comment has been minimized.

Show comment
Hide comment
@darkbaby123

darkbaby123 Jun 11, 2018

@mmcnl I also set the line number with left/right margin. With new native line number I can solve left margin with display-line-numbers-width , but seems right margin is not supported?

darkbaby123 commented Jun 11, 2018

@mmcnl I also set the line number with left/right margin. With new native line number I can solve left margin with display-line-numbers-width , but seems right margin is not supported?

@mmcnl

This comment has been minimized.

Show comment
Hide comment
@mmcnl

mmcnl Jun 11, 2018

Thanks @darkbaby123. However, I'm interested in increasing the space between the numbers and the buffer text.
screen shot 2018-06-11 at 7 53 10 am
For example, if I do (setq display-line-numbers-width 10)
that does not change the space pointed to by the arrow. Does anyone know how to increase that space?

mmcnl commented Jun 11, 2018

Thanks @darkbaby123. However, I'm interested in increasing the space between the numbers and the buffer text.
screen shot 2018-06-11 at 7 53 10 am
For example, if I do (setq display-line-numbers-width 10)
that does not change the space pointed to by the arrow. Does anyone know how to increase that space?

@mmcnl

This comment has been minimized.

Show comment
Hide comment
@mmcnl

mmcnl Jun 12, 2018

Does anyone (e.g. @bmag or others) know how to increase the space to the right of the line numbers?

mmcnl commented Jun 12, 2018

Does anyone (e.g. @bmag or others) know how to increase the space to the right of the line numbers?

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag Jun 12, 2018

Collaborator

@mmcnl I couldn't find a way to increase the margin to the right of the line numbers: no variable, function or customize option that lets you change it. I also searched for a way to swap places between regular margin and line number margin and didn't find anything.

AFAICT it is a limitation of the line numbers implementation in Emacs 26, so I suggest opening an issue upstream at Emacs. (M-x report-emacs-bug)

Collaborator

bmag commented Jun 12, 2018

@mmcnl I couldn't find a way to increase the margin to the right of the line numbers: no variable, function or customize option that lets you change it. I also searched for a way to swap places between regular margin and line number margin and didn't find anything.

AFAICT it is a limitation of the line numbers implementation in Emacs 26, so I suggest opening an issue upstream at Emacs. (M-x report-emacs-bug)

@mmcnl

This comment has been minimized.

Show comment
Hide comment
@mmcnl

mmcnl Jun 12, 2018

@bmag Thanks so much for the research, much appreciated!

mmcnl commented Jun 12, 2018

@bmag Thanks so much for the research, much appreciated!

@Isimoro

This comment has been minimized.

Show comment
Hide comment
@Isimoro

Isimoro Jun 24, 2018

Adding text-mode or prog-mode to :disabled-for-modes does nothing on my system. For other modes it works fine. Tested with default configuration. Can you reproduce this?

Isimoro commented Jun 24, 2018

Adding text-mode or prog-mode to :disabled-for-modes does nothing on my system. For other modes it works fine. Tested with default configuration. Can you reproduce this?

@bmag

This comment has been minimized.

Show comment
Hide comment
@bmag

bmag Jun 27, 2018

Collaborator

@Isimoro thanks, I was able to reproduce it. Fixed by b54ea8e

Collaborator

bmag commented Jun 27, 2018

@Isimoro thanks, I was able to reproduce it. Fixed by b54ea8e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment