Last active
November 3, 2018 12:43
-
-
Save vale981/e16e0f38c315890323e6665e5a6ebd56 to your computer and use it in GitHub Desktop.
Replace Character Sequences in Emacs for Syntactic Sugar
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
(defmacro replace-seqs (chars modes) | |
`(progn ,@(loop for char in chars collect `(replace-seq ,(first char) ,(second char) ,modes)) | |
nil)) | |
(defmacro replace-seq (char replacement modes) | |
(let ((fname (gensym))) | |
`(progn | |
(defun ,fname () | |
(font-lock-add-keywords | |
nil | |
'((,char (0 | |
(progn | |
(compose-region (match-beginning 0) | |
(match-end 0) | |
,replacement) | |
nil)))))) | |
,@(loop for mode in modes collect `(add-hook ,mode (quote ,fname))) | |
nil))) | |
;;; Example | |
(replace-seqs (("#'" "⍘") ("\\<lambda\\>" "λ") ("\\<funcall\\>" "⨐")) ('slime-mode-hook 'emacs-lisp-mode-hook 'slime-repl-mode-hook)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment