Skip to content
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

Highlight the chosen symbol/entity ala isearch-forward-symbol-at-point #269

Closed
jdtsmith opened this issue Jul 20, 2021 · 8 comments
Closed

Comments

@jdtsmith
Copy link

The command isearch-forward-symbol-at-point is in many ways like a tiny baby embark. It looks for a symbol at point, and sets you up for further action on it (search or occur for example). One of the features it has that I'm really missing with embark: it highlights the matched symbol temporarily, showing you what it will be taking action on. Here it is in action:

image

Would be great if embark stole this idea!

@oantolin
Copy link
Owner

oantolin commented Jul 20, 2021

That's an interesting idea but there are some subtleties. If you use Embark outside of the minibuffer, it displays what you will act on in the echo area. In part this is because it was easier but also because the target finders are under no obligation to return a portion of buffer text! Even pretty standard ones do not, for example Embark uses ffap for file names, and this returns full paths, not just whatever is found in the buffer. If you use embark-act on dired in (use-package dired ...) the target will actually be /usr/share/emacs/27.1/lisp/dired.el or whatever the appropriate path is on your system.

I guess most of the target finders that come with Embark do provide targets that are at least based on a portion of the buffer text, and this portion could be highlighted. But if we do this it could be slightly confusing that what is acted on does not exactly match what is highlighted.

@jdtsmith
Copy link
Author

jdtsmith commented Jul 20, 2021

Interesting thanks. I actually hadn't realized embark gives a report in the mini buffer of what it will act on!

From the start I was using the recommended which-key trick to prompt with the further key options immediately, which I find preferable to always having to C-h and select/sort (I believe Protesilaos Stavrou recommends this in some of his videos too). This trick apparently (and unfortunately) overwrites the mini buffer embark prompt of what it will be acting upon, which makes it feel like I'm "matching in the dark". Maybe I'll try without which-key, or maybe the trick could be modified to not stomp on embark's message?

I actually opened a related consult issue to get it to care about the symbol-at-point highlighted selection if that's set. It's an underused but cool native Emacs feature. Please feel free to close. Thanks for embark!

Edit: I would certainly enjoy the "matched portion" highlight idea you mention though, and personally wouldn't find it confusing at all as it is the "original source".

@oantolin
Copy link
Owner

Ah! Which-key strikes again. I wonder if there is anywhere to put the target in which-key's popup. That would probably be the best solution.

@oantolin
Copy link
Owner

Try this:

(setq embark-action-indicator
      (lambda (map &optional target)
        (which-key--show-keymap (format "Act on '%s'" target)
                                map nil nil 'no-paging)
        #'which-key--hide-popup-ignore-command))

I think it looks decent.

@oantolin
Copy link
Owner

I think I'm going to change the which-key recommendation to this:

(defun embark-which-key-indicator (fmt)
  (lambda (map &optional target)
    (which-key--show-keymap (format fmt target) map nil nil 'no-paging)
    #'which-key--hide-popup-ignore-command))

(setq embark-action-indicator (embark-which-key-indicator "Act on '%s'")
      embark-become-indicator (embark-which-key-indicator "Become"))

@jdtsmith
Copy link
Author

The last works quite well. Thanks.

@minad
Copy link
Contributor

minad commented Jul 25, 2021

@oantolin Why not implement this? The target finders could return both a string and optional bounds. Not worth the complication?

@oantolin
Copy link
Owner

Oh, I do think it is a good idea and was planning on doing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants