Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:8547615
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(defmacro sacha/def-wordsearch (name docstring skip-syntax-function re-search-function)
`(defun ,name ()
,docstring
(interactive)
(let ((cur (point)))
(,skip-syntax-function "w_")
(let ((current-word (current-word)))
(message "Searching for word: %s" current-word)
(goto-char
(if (,re-search-function
(concat "\\_<" (regexp-quote current-word) "\\_>") nil t)
(match-beginning 0)
cur))))))
 
(sacha/def-wordsearch sacha/search-word-forward
"Find the next occurrence of the current word."
skip-syntax-forward re-search-forward)
 
(sacha/def-wordsearch sacha/search-word-backward
"Find the previous occurrence of the current word."
skip-syntax-backward re-search-backward)
 
(global-set-key '[M-up] 'sacha/search-word-backward)
(global-set-key '[M-down] 'sacha/search-word-forward)
Owner

Note: This also turns the body of both functions into a macro and introduces a call to message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.