Rework embark word targeter

This commit is contained in:
Kiana Sheibani 2024-02-27 15:22:51 -05:00
parent 1934c157f2
commit dca02fa64c
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -1447,9 +1447,6 @@ Some of the targeting functions are a bit too general in what they accept. We'll
adjust the expression and identifier targeters to only work in ~prog-mode~ and the adjust the expression and identifier targeters to only work in ~prog-mode~ and the
"defun" targeter to only work in Emacs Lisp code. "defun" targeter to only work in Emacs Lisp code.
We'll also define a word targeter, since that was previously handled by the
identifier one.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun ~/embark-target-prog-mode (old-fn) (defun ~/embark-target-prog-mode (old-fn)
"Advise an embark target to only activate in `prog-mode'." "Advise an embark target to only activate in `prog-mode'."
@ -1463,11 +1460,21 @@ identifier one.
(advice-add #'embark-target-identifier-at-point :around #'~/embark-target-identifier) (advice-add #'embark-target-identifier-at-point :around #'~/embark-target-identifier)
(after! embark (after! embark
(embark-define-thingatpt-target defun emacs-lisp-mode) (embark-define-thingatpt-target defun emacs-lisp-mode))
#+end_src
; Word targeter We'll also define a word targeter, since that case was previously handled by the
(embark-define-thingatpt-target word identifier one.
text-mode help-mode Info-mode man-common)
#+begin_src emacs-lisp
(defun embark-target-word-at-point ()
"Target word at point."
(when (or (derived-mode-p 'text-mode 'help-mode 'Info-mode 'man-common)
(doom-point-in-comment-p))
(when-let ((bounds (bounds-of-thing-at-point 'word)))
(cons 'word (cons (buffer-substring (car bounds) (cdr bounds)) bounds)))))
(after! embark
(pushnew! embark-target-finders #'embark-target-word-at-point)) (pushnew! embark-target-finders #'embark-target-word-at-point))
#+end_src #+end_src