Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;; 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
You can’t perform that action at this time.