Skip to content

Instantly share code, notes, and snippets.

@vale981
Last active November 3, 2018 12:43
Show Gist options
  • Save vale981/e16e0f38c315890323e6665e5a6ebd56 to your computer and use it in GitHub Desktop.
Save vale981/e16e0f38c315890323e6665e5a6ebd56 to your computer and use it in GitHub Desktop.
Replace Character Sequences in Emacs for Syntactic Sugar
(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