Here and there I forget this rule and use earmuffs most of the time, so I decided to create an Emacs Lisp function to add/remove earmuffs to variable:
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)))))) |
Add it to your .emacs file and then place your cursor on a variable and call it with
M-x earmuffyto add earmuffs, or type
C-u M-x earmuffyto remove them.
Wouldn't it be nicer to have toggle-earmuffs, which detects what you currently have and toggle it?
ReplyDeleteI bit the bullet and implemented this: https://gist.github.com/1385279
ReplyDeleteThanks for providing a better implementation.
ReplyDeleteI'm experimenting with Emacs Lisp time to time but didn't read so much documentation about it yet so it's welcome to see improvement to my experiments.