From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Kaushal Modi <kaushal.modi@gmail.com>
Cc: code.falling@gmail.com, Emacs developers <emacs-devel@gnu.org>
Subject: Re: Patch to highlight current line number [nlinum.el]
Date: Mon, 18 Jul 2016 09:40:23 -0400 [thread overview]
Message-ID: <jwv1t2rhz7f.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAFyQvY23DKqvkdpiCz42ZWd99CoQP+oCQ6kM87527y7P7gCbHg@mail.gmail.com> (Kaushal Modi's message of "Mon, 18 Jul 2016 04:31:11 +0000")
>> 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
next prev parent reply other threads:[~2016-07-18 13:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-15 17:10 Patch to highlight current line number [nlinum.el] Kaushal Modi
2016-07-16 2:15 ` Stefan Monnier
2016-07-18 4:31 ` Kaushal Modi
2016-07-18 13:40 ` Stefan Monnier [this message]
2016-07-18 15:28 ` Kaushal Modi
2016-07-18 17:09 ` Stefan Monnier
2016-07-18 22:05 ` Kaushal Modi
2016-07-18 22:55 ` Kaushal Modi
2016-07-19 0:32 ` Stefan Monnier
2016-07-19 5:00 ` Kaushal Modi
2016-07-19 12:28 ` Stefan Monnier
2016-07-19 12:40 ` Kaushal Modi
2016-07-20 19:30 ` Stefan Monnier
2016-07-20 19:38 ` Kaushal Modi
2016-07-20 20:28 ` Stefan Monnier
2016-07-20 20:31 ` Kaushal Modi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv1t2rhz7f.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=code.falling@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=kaushal.modi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.