Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
(defmacro sacha/def-wordsearch (name docstring skip-syntax-function re-search-function)
`(defun ,name ()
(let ((cur (point)))
(,skip-syntax-function "w_")
(let ((current-word (current-word)))
(message "Searching for word: %s" current-word)
(if (,re-search-function
(concat "\\_<" (regexp-quote current-word) "\\_>") nil t)
(match-beginning 0)
(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)
pipping commented Jan 21, 2014

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