Last active
August 29, 2015 14:14
-
-
Save kaushalmodi/dcb9e54fae158211f226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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