Skip to content

Instantly share code, notes, and snippets.

@kaushalmodi
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaushalmodi/dcb9e54fae158211f226 to your computer and use it in GitHub Desktop.
Save kaushalmodi/dcb9e54fae158211f226 to your computer and use it in GitHub Desktop.
;; http://emacs.stackexchange.com/a/7719/115
;; Matching words containing all given letters in any order
(defun my/match-word ()
"Matches words containing all chars d, l, s in any order: dollars solid
Match will fail if a word is missing any of those characters. e.g. dollar"
(interactive)
(let ((this-word (thing-at-point 'word)) ; get the word at point
(match))
(with-temp-buffer
(insert this-word)
(sort-regexp-fields nil "\\w" "\\&" (point-min) (point-max)) ; sort chars in word
(beginning-of-buffer)
;; Now that the chars are sorted alphabetically, you can search for
;; the letters in alphabetical order: d, l, s
(if (looking-at "\\w*[d]+\\w*[l]+\\w*[s]+\\w*")
(setq match t)
(setq match nil)))
(when match
(highlight-symbol-at-point))))
(defun my/match-word-whole-buffer ()
(interactive)
(beginning-of-buffer)
(forward-word)
(while (not (eobp))
(when (string-match "\\w\\{3,\\}" (thing-at-point 'word))
(my/match-word))
(forward-word)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment