-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
relative line numbers does not play well with folding #6536
Comments
Hey @ninrod, Thank you for your report. I would like to ask you to share output of |
You should report this upstream to the relative linum package. I should note that due to how folding and line numbers work in Emacs this would be nigh impossible to fix. |
@d12frosted here it is: #### System Info
- OS: darwin
- Emacs: 24.5.1
- Spacemacs: 0.105.21
- Spacemacs branch: master (rev. 0283f64)
- Graphic display: nil
- Distribution: spacemacs
- Editing style: hybrid
- Completion: helm
- Layers:
elisp:
(emacs-lisp git markdown org) |
@TheBB That's interesting, I find that difficult to believe because everyone in emacs community says emacs is infinitelly customizable and elisp is awesome, way better than vimscript, etc..., So I'd think that getting this feature right would be trivial. |
reported upstream (that's emacs itself) http://lists.gnu.org/archive/html/help-gnu-emacs/2016-07/msg00106.html |
I don't think they can help you. Relative linum is an external package, not part of emacs proper. |
Well, emacs should really provide a stock way to do this in 2016 I think. So if they can't help me do this from |
Not to burst your bubble, but the most likely way that would happen is for Emacs to come packaged with relative-linum, in which case you'll still need a feature request/bug fix there. |
Yeah there's like 3 packages that try to do this. nlinum, linum-relative, relative-line-numbers. and no one accounts for folding. maybe I'll have to file an issue to each one of them. Now, I don't know if they don't account for folding because it can't be done or because noone has never thought about this (which I find difficult to believe). |
Probably because getting information about how a buffer will be displayed in the end is quite tricky. There's many folding packages and since (I believe) most or all of them use overlays to do what they need, and overlays don't necessarily cover whole lines, it's even more complicated. |
@ninrod Just to clarify: Is the issue that neither Update: disregard -- I just tested it locally. I see the problem now -- it's that the relative line numbers displayed are inconsistent with how the jump behavior is working. (which, agreed -- renders them useless when code folding is enabled) |
correct. in your example, suppose you want to jump from the line with |
also note that you are pressing |
Have you tried relative-line-numbers with Disclaimer: as the author of relative-line-numbers, I feel obliged to mention that this package is buggy and pretty much abandoned. |
Yes! that works! but I get the following when starting emacs: Invalid face reference: font-lock-comment-delimiter-face
Invalid face reference: font-lock-comment-face
Invalid face reference: font-lock-comment-delimiter-face
Invalid face reference: font-lock-comment-face
Invalid face reference: font-lock-comment-delimiter-face
Invalid face reference: font-lock-comment-face
When done with a buffer, type C-x # @Fanael You package is great. It's pitty that you are not maintaining it anymore. So it is indeed possible to get relative-visible-line-numbers. But other relative-line-number package authors seem to find it difficult to implement. see coldnew/linum-relative#18, xcodebuild/nlinum-relative#12 nlinum-relative author specific reply was:
And that reply was given 9 days ago. @Fanael could you explain the specifics of why getting support for relative-visual-lines seems so difficult? |
It's not. Trust me.
You can always take over if you want.
Visual lines, or visible physical lines? Because I thought we're talking about the latter. If so, it's not difficult, it's just that (n)linum-relative use (n)linum, which are ill-suited for the job; relative-line-numbers is completely standalone and implements all the logic itself. Visual lines, now that's hard without serious help from the rendering engine, which is not there. |
@Fanael what is the difference between visual lines and visible physical lines? I want the line numbering scheme to consider as visible the current lines that are shown on the screen, folded or not. So if a line is representing a folded section, that line counts as 1 line only. In other words, say a buffer is displayed at the moment and it has 4 visible lines and those 4 visible lines represent folded sections. From the point of view of the plugin, there should be only 4 lines currently shown on the buffer, even if the physical file has more lines than that (it could have 4k lines, 1000 lines to each folded section). So if my cursor is on the first line, the mode should number the second line as 1, the third as 2, and the fourth as 3. Does that description fit |
@Fanael, now I see your point. We're talking about the latter, |
@Fanael, you mentioned that you don't use any form of line numbers anymore. What do you use to navigate vertically? |
I know it's not for me, but for me |
How is that of help to navigate vertically |
Those bindings are on the develop branch. On master they're bound to something else. |
people, the emacs mantainer is almost landing a fix for this in master. Checkout the scratch/line-numbers branch in emacs git repo. Here is a screenshot. |
People, I think we can close this an maybe reopen another issue to add support to the new native line numbers that just landed on master: https://lists.gnu.org/archive/html/emacs-devel/2017-07/msg00236.html |
@ninrod, I agree that we should move to built-in solution that works better than third-party tools. But we must maintain support of third-party solutions until new version of Emacs is released. Despite the fact that develop branch is err... development branch, many develop branch users use non HEAD version of Emacs. So... we still have time 😸 P. S. https://github.com/syl20bnr/spacemacs/issues?q=is%3Aopen+is%3Aissue+label%3A%22Line+numbers%22 |
Two years later the problem still seems to persist :/
How do I install this function? I cannot even find the branch. |
you don't need this anymore. emacs 26 already comes with this feature built in. in emacs 26: (defun ninrod/toggle-relative-line-numbers ()
"Toogle showing relative line numbers."
(interactive)
(if display-line-numbers
(setq display-line-numbers nil)
(progn
(setq display-line-numbers-current-absolute nil)
(setq display-line-numbers 'visual)))) |
Your theme should account for relative line numbers giving it the space it needs to display line number xyz. You can see that when emacs displays line 1, which has 1 char of spacing, emacs can display your line in a certain way. When you go down, that relative line number changes, for like 21, which has 2 char spacing, so emacs has to find another way to display your line. I think that is what is happening. |
I do not see how that would make sense, since the linenumbers are displaying 2 char numbers all the time in this example. 🤔 |
I see your point but in this case I guess you are not using just mono fonts for all bullets. |
I am a bit of a emacs-beginner, as you can maybe tell. I would really want that function to run by default but I cannot make it happen. |
@tbrodbeck There's an open PR about this: When it's pushed, then you can enable visual line numbers on startup from your UpdateThe PR is now on the |
Thanks, but how can I access it, now the commit is done? I tried the development channel, can't find it there. And how long would it take to reach the master channel that I usually use? What can I do till this happens? I tried to put something like |
@tbrodbeck you could try to use another theme, a simpler one and see if the problem persists. Also, try in other modes, like text mode. |
The bug is not too terrible actually and only happens in a small window size. First of all it would be nice to be able to activate this function by default (I am not a very experienced emacs user, as you can maybe tell ;), probably its quite easy to do that ) |
On the If you want to enable it by default in Updating your
|
Finally found the solution I was looking for btw. |
Guys, this is issue irrelevant now that we have native relative line numbers in emacs. |
Hi, how can I use the native relative line numbers in emacs? What is its behavior? Is there any current solution that combines the best of both worlds (namely, display relative numbers for physical lines that are visually present), which is the intuitive behavior most of us want? I also played with |
I think that the spacemacs folks can help you with that, but I can show you how I do it, directly: from https://github.com/ninrod/dotfiles/blob/master/emacs/boot.org#line-number-bootstrap (when (>= emacs-major-version 26)
(ninrod/add-to-hooks
#'(lambda ()
(setq-local display-line-numbers-current-absolute nil)
(setq display-line-numbers 'visual))
'(org-mode-hook
prog-mode-hook
markdown-mode-hook
conf-unix-mode-hook))) |
I found a working solution, actually.
dotspacemacs-line-numbers 'visual
;; Make evil-mode up/down operate in screen lines instead of logical lines
(define-key evil-motion-state-map "j" 'evil-next-visual-line)
(define-key evil-motion-state-map "k" 'evil-previous-visual-line)
;; Also in visual mode
(define-key evil-visual-state-map "j" 'evil-next-visual-line)
(define-key evil-visual-state-map "k" 'evil-previous-visual-line) Works almost perfect and as expected. But! Most disappointment thing what I realized that, sadly, line numbers just destroy performance of emacs scrolling, even if you would move inside a buffer with Ctr+D, U. It just forced me to disable line numbers at all recently. |
Yeah, that's what I also do except I rebound |
I've set this on my
.spacemacs.d/init.el
, as per the documentation:dotspacemacs-line-numbers 'relative
All works well until you get some folding in:
The whole point of relative line numbers is to give you an exact line offset to operate vertically inside the window.
Suppose I want to jump to function
user-config
in the screenshot above. A simple4j
would suffice. But I don't know that because spacemacs is saying that the line I want is 194 lines below the current line, which would be true if the file had no folding on. With folding on, it is not true anymore.So folding is rendering relative line numbers unusable at the present moment.
bonus: here's a side by side relative line number comparation between
spacemacs
(left) andvim
(right):The text was updated successfully, but these errors were encountered: