Created
November 1, 2011 16:31
-
-
Save kototama/1331024 to your computer and use it in GitHub Desktop.
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
(defun earmuffy (&optional arg) | |
(interactive "P") | |
(let* ((variable (thing-at-point 'sexp)) | |
(bounds (bounds-of-thing-at-point 'sexp)) | |
(current-point (point)) | |
(earmuffed-variable (concat "*" variable "*"))) | |
(save-excursion) | |
(kill-region (car bounds) (cdr bounds)) | |
(if arg | |
;; unearmuffy | |
(progn | |
(insert (substring variable 1 (- (length variable) 1))) | |
(goto-char (- current-point 1))) | |
;; earmuffy | |
(progn | |
(insert earmuffed-variable) | |
(goto-char (+ current-point 1)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This usage of save-excursion is pointless. This special form should be used as a "progn":
(save-excursion &rest body)
Save point, mark, and current buffer; execute body; restore those things.
Executes body just like 'progn'.
The values of point, mark and the current buffer are restored
even in case of abnormal exit (throw or error).
The state of activation of the mark is also restored.
This construct does not save 'deactivate-mark', and therefore
functions that change the buffer will still cause deactivation
of the mark at the end of the command. To prevent that, bind
'deactivate-mark' with 'let'.