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

A symbol-overlay-jump-avy function for the symbol-overlay-map #65

Open
hmelman opened this issue Sep 9, 2020 · 7 comments
Open

A symbol-overlay-jump-avy function for the symbol-overlay-map #65

hmelman opened this issue Sep 9, 2020 · 7 comments

Comments

@hmelman
Copy link

hmelman commented Sep 9, 2020

I haven't tested this a ton but it seems to work and seems useful. Perhaps there are better ways to implement it. I'm sure you don't want to add a dependency on avy, but if the user has it installed, I think it would be useful to bind this to symbol-overlay-map for them.

(defun symbol-overlay-jump-avy ()
  "Jump to another occurance of symbol with avy."
  (interactive)
  (avy-with symbol-overlay-jump-avy
    (avy-process 
     (avy--regex-candidates (regexp-quote (thing-at-point 'symbol t))))))
(define-key symbol-overlay-map (kbd "'") 'symbol-overlay-jump-avy)
@purcell
Copy link
Collaborator

purcell commented Sep 9, 2020

Neat, but I feel like your symbol-overlay-jump-avy function doesn't do anything in particular to integrate with symbol-overlay. My take is that you could submit it for addition to avy.el as avy-jump-symbol-at-point or similar, and then indeed you might find it helpful in your personal config to bind it in symbol-overlay-map.

@hmelman
Copy link
Author

hmelman commented Sep 9, 2020

It's true, I originally created it as an avy function, and then realized I'd like it more as a symbol-overlay function. I think it fills in a nice use case to go with the other symbol-overlay-jump- functions. I'm still working on the version for avy, it supports avy-all-windows though I don't fully understand it yet. I guess the symbol-overlay version should use symbol-overlay-get-symbol in place of thing-at-point?

@purcell
Copy link
Collaborator

purcell commented Sep 9, 2020

I guess the symbol-overlay version should use symbol-overlay-get-symbol in place of thing-at-point

I think so, but I don't see much added value tbh, and I don't think we'd pull it into symbol-overlay itself due to the dependency, as you initially mentioned.

@hmelman
Copy link
Author

hmelman commented Sep 9, 2020

I assumed a few declare-functions and a featurep check around the define-key could ameliorate any warnings and dependency issues. This just feels to me like a nice way for symbol-overlay to leverage another popular package without having a hard dependency.

@purcell
Copy link
Collaborator

purcell commented Sep 9, 2020

This just feels to me like a nice way for symbol-overlay to leverage another popular package without having a hard dependency.

It's still a hard dependency if you can hit a key and get an error that some other package is not installed. It's possible to work around this, but it's bad practice, and I'd gripe about it if submitted to MELPA for my review. Generally if there's a little add-on like this, it's preferable to publish it as a separate package which declares its dependencies and byte-compiles cleanly.

@hmelman
Copy link
Author

hmelman commented Sep 10, 2020

I opened an issue with avy about this and will see what comes of it. abo-abo/avy#312

@uqix
Copy link

uqix commented Jan 13, 2024

Jumping for current symbol and among all symbols is so useful for me, hope it'll benefit others as well.

;; ### avy jump

(defun my/symbol-overlay/avy-jump ()
  (interactive)
  (avy-with my/symbol-overlay/avy-jump
    (avy-jump
     (symbol-overlay-regexp (symbol-overlay-get-symbol))
     :window-flip nil
     :beg nil
     :end nil)))

(keymap-set symbol-overlay-map "j" #'my/symbol-overlay/avy-jump)

;; ### avy jump among all

(defun my/symbol-overlay/avy-jump/all ()
  (interactive)
  (let* ((overlays (symbol-overlay-get-list 0))
         (symbols (seq-map
                   (lambda (overlay)
                     (overlay-get overlay 'symbol))
                   overlays))
         (symbols (seq-uniq symbols))
         (symbols-regex (seq-map
                         (lambda (symbol)
                           (symbol-overlay-regexp symbol))
                         symbols))
         (symbols-regex (string-join symbols-regex "\\|")))
    (message (format "regex: %s (%s)" symbols-regex (length symbols-regex)))
    (if (string-empty-p symbols-regex)
        (message "No symbol overlay")
      (avy-with my/symbol-overlay/avy-jump/all
        (avy-jump
         symbols-regex
         :window-flip nil
         :beg nil
         :end nil)))))

(keymap-global-set "s-o j" #'my/symbol-overlay/avy-jump/all)
(keymap-set symbol-overlay-map "J" #'my/symbol-overlay/avy-jump/all)

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