emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Patch to highlight current line number [nlinum.el]


From: Stefan Monnier
Subject: Re: Patch to highlight current line number [nlinum.el]
Date: Mon, 18 Jul 2016 09:40:23 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

>> You might like to look at nhexl-mode to see how I've done that in
>> a similar context (tho the nhexl-mode approach is not really right
>> either).
> I believe that is in reference to the use of post-command-hook, correct?

Not specifically.  Just that it does something similar.

>> I think it'd be better to use pre-redisplay-functions, but I haven't
>> played with that option yet, and post-command-hook is easier to work with.
> Thanks.

Actually, after thinking about it, I got to the conclusion that as long
as you don't try to handle the multiple-window case correctly, you're
probably better off with post-command-hook.

>> In any case, the hard thing to get right (which you haven't tried to
>> solve and neither have I in nhexl-mode) is when the buffer is displayed
>> in several windows (in which case each window will want to highlight
>> potentially different line numbers since each window has a different
>> `point`).
> I see .. so you are suggesting to highlight the line at the window point,
> instead of the line where (point) is, correct?

More or less.  Try M-x nhexl-mode RET and the C-x 5 2 and then move
around the buffer and compare the two window's highlighting of the
"current line".  You'll see that only one of the two is correct.

> From quick trial, I saw the line numbers change in the whole buffer even
> when I moved the cursor horizontally.

You need to always call it with point at BOL.

> In the below updated patch, I attempt to do this (code commented out
> in the patch), but failed.  I tried removing the text properties on
> the current and last lines, but it is not working.  I'll give more
> time to understand tomorrow.  But if you can point out the issue with
> those remove-text-properties, that will be great.

Sorry, the problem didn't jump at me.  They look pretty good.

FWIW in hexl-mode, instead of removing the `fontified' property, I just
directly called the function that refreshes the overlays.  Not sure why
I did that (seems less efficient/elegant than your approach).

>> Also I think it'd just always use the `linum` face, as in
>> 
>> (put-text-property 0 width 'face
>> (if current-line-p
>> '(nlinum-current-line-face linum)
>> 'linum)
>> str))
>> 
>> Tho it's clearly a question of taste.

> I tried implementing that, but doesn't work as I expected.
> nlinum-current-line-face is already inheriting linum face.

Clearly the above change should come with the corresponding change in
nlinum-current-line-face (i.e. it shouldn't inherit from `linum' face
any more).  But either way is OK.

Oh, and nowadays the convention is to use "-face" only for
names of variables whose value is a face, but not for the face names
themselves.  The font-lock-foo-face faces are the main exceptions
because they're already so omnipresent.

> reduces further by 0.9 (or so it looks like). So I end up with the current
> line number face at 0.81 height and the rest of the line numbers at 0.9.

That's right.

> I have also made one cosmetic change .. Instead of `t' as argument values,
> I have replaced them with `:local' or `:contextual' as appropriate.

Fine.  I often use 'local (rather than :local) for that same purpose,
but I don't really care about the color of this shed.

> +(defvar-local nlinum--last-line 0
> +  "Store line number where the point was before it moved to the current
> line.")

No reason to keep this as a global var (but I'd rename
nlinum--current-line to nlinum--last-line).

> +(defun nlinum--current-line-update ()
> +  "Update current line number, flush text properties for last and current
> line."

Actually, it shouldn't (and doesn't) flush text-properties.  It should
only update the current-line highlighting or cause it to be
updated later.


        Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]