Skip to content

Instantly share code, notes, and snippets.

@ScatteredRay
Created November 28, 2012 03:26
Show Gist options
  • Save ScatteredRay/4158860 to your computer and use it in GitHub Desktop.
Save ScatteredRay/4158860 to your computer and use it in GitHub Desktop.
font-lock
(defun substitute-pattern (pattern symbol)
"Add a font lock hook to replace the matched part of PATTERN with the
Unicode symbol SYMBOL looked up with UNICODE-SYMBOL."
(interactive)
(font-lock-add-keywords
nil `((,pattern (0 (progn (put-text-property (match-beginning 1) (match-end 1)
'display ,symbol)
nil))))))
(defun substitute-patterns (patterns)
"Call SUBSTITUTE-PATTERN repeatedly."
(mapcar #'(lambda (x)
(substitute-pattern (car x)
(cdr x)))
patterns))
(defun pretty-coffee-symbols ()
(substitute-patterns '(("[ \t]\\(and\\)[ \t]" . "&&")
("[ \t]\\(not\\)[ \t]" . "!")
("[ \t]\\(or\\)[ \t]" . "||"))))
@ScatteredRay
Copy link
Author

(defun substitute-pattern (pattern symbol)
"Add a font lock hook to replace the matched part of PATTERN with the
Unicode symbol SYMBOL looked up with UNICODE-SYMBOL."
(interactive)
(font-lock-add-keywords
nil `((,pattern (0 (progn (put-text-property (match-beginning 1) (match-end 1)
'display ,symbol)
nil))))))

(defun substitute-patterns (patterns)
"Call SUBSTITUTE-PATTERN repeatedly."
(mapcar #'(lambda (x)
(substitute-pattern (car x)
(cdr x)))
patterns))

(defun pretty-coffee-symbols ()
(substitute-patterns '(("[ \t](and)[ \t]" . "&&")
("[ \t](not)[ \t]" . "!")
("[ \t](or)[ \t]" . "||"))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment