-
-
Notifications
You must be signed in to change notification settings - Fork 11
Add before/after hooks for goto-line-preview #10
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
Conversation
These hooks let the user set up something like: ```emacs-lisp (setq goto-line-preview-before-hook (lambda () (display-line-numbers-mode)) goto-line-preview-after-hook (lambda () (display-line-numbers-mode -1))) ```` Correctly run after hook in unwind-protect
@manuel-uberti Hi, sorry for the late response, because I have never used |
@jcs090218 no worries at all. I just like this package a lot and want to add what I think could be a nice customisation. Let's wait for them. :) |
The only use case that this doesn't work seamlessly in terms of yours (and my) example is the following: If you have a line-numbering mode enabled for some modes but not all, your example would always turn off the line numbering mode after using the In the end, I think hooks are a common convention for emacs customization and I'm fine doing this extra setup locally in my config, so it gets a 👍 from me. |
Thank you. If we can improve this PR and make the configuration on the user's side easier, I'm happy to do it. Just need some guidance. |
I think this PR is good to merge as is and if I get some time in the next few days, I can open another with the behavior I outlined here: #2 (comment) |
Great, thank you. :) |
The robust hook version looks like this: (setq
goto-line-preview-before-hook (lambda ()
(setq-local my/prev-line-number-state display-line-numbers-mode)
(display-line-numbers-mode))
goto-line-preview-after-hook (lambda () (unless my/prev-line-number-state
(display-line-numbers-mode -1)))) while the advice version is arguably much neater: (defun with-display-line-numbers (f &rest args)
(let ((display-line-numbers t))
(apply f args)))
(advice-add 'goto-line-preview :around #'with-display-line-numbers) I kinda feel like we should just include an example for the latter in the README & Commentary, and skip merging this PR...? |
It's OK to me if we go with the advice. |
I like the advice implementation and would be fine personally doing it this way since i'm using I did just open #11 as a way to simulate this behavior with alternate line numbering modes though. |
I personally like the hook method. Of course to resolve #2, |
I can't think of a personal use case other than this behavior we are talking about, but I can see some other user wanting to dim/hide other windows, or a different unknown idea. If you want to keep the complexity down here, adding empty hooks is a good way to let users add their own expansive ideas in their own |
@jcs090218 what about merging this (to give the chance to customise what happens before and after anyway, besides line numbering), and mention the |
Yeah, this is what I was thinking right now. Edit: I realized |
As you prefer, really. I usually don't use |
Since this is no harm to the package itself, I guess giving more options should be okay. |
For future reference, here is a version of @purcell's (defun with-display-line-numbers (f &rest args)
(let ((display-line-numbers t)
(display-line-numbers-offset
(if goto-line-preview--relative-p (- (line-number-at-pos)) 0)))
(apply f args)))
(advice-add 'goto-line-preview :around #'with-display-line-numbers)) I'm not sure where would be a good place to document this sort of thing. |
I think it would be fine if we document under |
These hooks let the user set up something like:
This is an attempt at fixing #2
I hope @purcell and @waymondo can share their opinions on this. Happy to fix anything that doesn't work as expected, of course.