Skip to content

Commit

Permalink
Have embark-{next,previous}-symbol act on symbol at point
Browse files Browse the repository at this point in the history
The old way, which prompted for a symbol, was very similar to existing
commands like isearch-forward-symbol or word-search-forward; and in
particular I couldn't really imagine anyone wanting to use the embark
versions directly (i.e., not through embark-act) given the existence
of isearch-forward-symbol, which even has a default binding. But these
new versions that act on the symbol at point are something you might
actually want to bind directly. And for the usage as actions they work
exactly as before.
  • Loading branch information
oantolin committed Mar 5, 2022
1 parent 8cb3f76 commit 913ccec
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions embark.el
Original file line number Diff line number Diff line change
Expand Up @@ -3624,25 +3624,29 @@ minibuffer, which means it can be used as an Embark action."
(unhighlight-regexp regexp)
(highlight-symbol-at-point))))

(defun embark-next-symbol (symbol)
"Jump to next occurrence of SYMBOL.
(defun embark-next-symbol ()
"Jump to next occurrence of symbol at point.
The search respects symbol boundaries."
(interactive "sSymbol: ")
(let ((regexp (format "\\_<%s\\_>" (regexp-quote symbol))))
(when (looking-at regexp)
(forward-symbol 1))
(unless (re-search-forward regexp nil t)
(user-error "Symbol `%s' not found" symbol))))

(defun embark-previous-symbol (symbol)
"Jump to previous occurrence SYMBOL.
(interactive)
(if-let ((symbol (thing-at-point 'symbol)))
(let ((regexp (format "\\_<%s\\_>" (regexp-quote symbol))))
(when (looking-at regexp)
(forward-symbol 1))
(unless (re-search-forward regexp nil t)
(user-error "Symbol `%s' not found" symbol)))
(user-error "No symbol at point")))

(defun embark-previous-symbol ()
"Jump to previous occurrence of symbol at point.
The search respects symbol boundaries."
(interactive "sSymbol: ")
(let ((regexp (format "\\_<%s\\_>" (regexp-quote symbol))))
(when (looking-back regexp (- (point) (length symbol)))
(forward-symbol -1))
(unless (re-search-backward regexp nil t)
(user-error "Symbol `%s' not found" symbol))))
(interactive)
(if-let ((symbol (thing-at-point 'symbol)))
(let ((regexp (format "\\_<%s\\_>" (regexp-quote symbol))))
(when (looking-back regexp (- (point) (length symbol)))
(forward-symbol -1))
(unless (re-search-backward regexp nil t)
(user-error "Symbol `%s' not found" symbol)))
(user-error "No symbol at point")))

(defun embark-compose-mail (address)
"Compose email to ADDRESS."
Expand Down

0 comments on commit 913ccec

Please sign in to comment.