Last active
December 15, 2015 14:29
-
-
Save EricCrosson/ea5a6f5df84ad897216b to your computer and use it in GitHub Desktop.
Some keybindings to insert common programming delimeters.
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 esc/define-displaced-yank (funcname data) | |
"Create a defun of name FUNCNAME that yanks and moves according | |
to DATA. DATA is of the form (STR, MOVE). STR is the string to | |
yank and MOVE is the number of chars to move backward. | |
Note that negative values of MOVE are valid." | |
(let ((funsymbol (intern (format "esc/yank-displaced-%s" funcname))) | |
(docstring (format "(insert \"%s\") and (backward-char %d). | |
This command can be prefixed, and will iterate N times." | |
(car data) (or (cadr data) 1))) | |
(char (car data)) | |
(back (or (cadr data) 1))) | |
`(defun ,funsymbol (&optional N) | |
,docstring | |
(interactive "p") | |
(dotimes (i (or N 1)) | |
(insert ,char) | |
(backward-char ,back))))) | |
(mapcar (lambda (function) | |
(let ((funcname (car function)) | |
(data (cdr function))) | |
(eval `(esc/define-displaced-yank ,funcname ,data)))) | |
'((parens "()") | |
(braces "{}") | |
(brackets "[]") | |
(brackets-with-colon "[:]") | |
(pipes "||") | |
(chevrons "<>") | |
(quotes "\"\"") | |
(single-quotes "''") | |
(stars "**") | |
(dollars "$$") | |
(equals "==") | |
;; a good example of code reuse | |
(ticks "`'") | |
(little-arrow "->" 0) | |
(doxygen-comment "/*! */" 3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment