;; (assert (string= (tags-sort-tags-string "zee bee cee") "bee cee zee") t "Tags not sorted.") (defun tags-sort-tags-string (string) "Return an alphabetically-sorted list of words in this string." (save-match-data (mapconcat 'identity (sort (mapcar 'downcase (split-string string)) 'string<) " "))) (defun tags-sort-tags () "Find the first line beginning with Tags: tag tag tag and sort the tags alphabetically." (interactive) (goto-char (point-min)) (when (re-search-forward "^Tags: \\(.+\\)" nil t) (replace-match (tags-sort-tags-string (match-string 1)) t t nil 1))) ;; (assert (string-match (tags-make-emacs-search-regexp '("bee")) "bee cee")) ;; (assert (string-match (tags-make-emacs-search-regexp '("cee")) "bee cee")) ;; (assert (string-match (tags-make-emacs-search-regexp '("cee" "bee")) "bee cee")) ;; (assert (null (string-match (tags-make-emacs-search-regexp '("zee" "cee")) "bee cee"))) ;; (assert (null (string-match (tags-make-emacs-search-regexp '("cee" "b")) "bee cee"))) (defun tags-make-emacs-search-regexp (tags) "Convert TAGS to a regular expression." (concat "\\b" (mapconcat 'downcase (sort tags 'string<) "\\b+\\(.+\\b\\)*") "\\b")) (defun tags-make-grep-search-regexp (tags) "Convert TAGS to a regular expression." (concat "\b" (mapconcat 'downcase (sort tags 'string<) "\b+\(.+\b\)*") "\b"))