Created
May 31, 2014 11:45
-
-
Save matthew-ball/d50c79e6c9d873baa3e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;;; IMPORTANT: custom inserts | |
(defun surrounded-by-p (char) | |
"Returns t if word is surrounded by given char." | |
(save-excursion | |
(and (forward-word -1) | |
(equal char (char-before)) | |
(forward-word 1) | |
(equal char (char-after))))) | |
(defun surround-word (char &optional force) | |
"Surrounds word with given character. If force is nil and word is already surrounded by given character removes them." | |
(save-excursion | |
(if (not (surrounded-by-p char)) | |
(progn | |
(forward-word 1) | |
(insert char) | |
(forward-word -1) | |
(insert char) | |
t) | |
(forward-word 1) | |
(delete-char 1) | |
(forward-word -1) | |
(delete-char -1) | |
nil))) | |
(defmacro propertize-word (property character) | |
"Define functions for propertizing words with PROPERTY using CHARACTER." | |
`(defun ,(intern (format "%s-word" property)) (&optional force) | |
,(format "Insert a %s character (%c) before (and after) an input string." property character) | |
(interactive "p") | |
(surround-word ,character force))) | |
(propertize-word bold ?*) ;; => (bold-word) | |
(propertize-word italic ?/) ;; => (italic-word) | |
(propertize-word underline ?_) ;; => (underline-word) | |
(propertize-word verbatim ?~) ;; => (verbatim-word) | |
(propertize-word teletype ?=) ;; => (teletype-word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment