Skip to content

Instantly share code, notes, and snippets.

@casouri
Last active February 3, 2018 15:54
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 casouri/67186ec98b05e67e090258281511697f to your computer and use it in GitHub Desktop.
Save casouri/67186ec98b05e67e090258281511697f to your computer and use it in GitHub Desktop.
change exclamation marks in macro definition to something else, because "!" makes me uncomfortable when I read them a lot in code.
(defun change-macro-in-buffer (str)
"change-macro-in-buffer(STR)
Change all defmacro's name that follows macro! convention to macro(STR) convention.
For example, macro! to macro|.
In a word, change all the \"!\"s in macro name to STRs.
Because exclamation marks makes my uncomfortable and I can."
(while (re-search-forward "defmacro.+?!" nil t)
(replace-match (replace-regexp-in-string "!" str (match-string 0)))))
(defun macro-replace-!-with-| ()
"Change all (def macro macro!) to (defmacro macro|)."
(interactive)
(change-macro-in-buffer "|"))
(defun change-macro-in-file (f)
"change-macro-in-file(FILE)
Calls `macro-replace-!-with-|' with STR in FILE."
(save-excursion
(find-file f)
(macro-replace-!-with-|)
(write-file f)
(kill-buffer (current-buffer))))
(defun change-macro-in-dir (dir)
"change-macro-in-file(DIR)
Calls `change-macro-in-file' with STR in every elisp file in DIR."
(mapc #'change-macro-in-file
(directory-files dir t ".el$")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment