diff options
Diffstat (limited to '.emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region')
| -rw-r--r-- | .emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region new file mode 100644 index 0000000..66a59e4 --- /dev/null +++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #name : Command that works on region or word | ||
| 2 | #contributor : Xah Lee | ||
| 3 | # -- | ||
| 4 | ;; example of a command that works on current word or text selection | ||
| 5 | (defun down-case-word-or-region () | ||
| 6 | "Lower case the current word or text selection." | ||
| 7 | (interactive) | ||
| 8 | (let (pos1 pos2 meat) | ||
| 9 | (if (and transient-mark-mode mark-active) | ||
| 10 | (setq pos1 (region-beginning) | ||
| 11 | pos2 (region-end)) | ||
| 12 | (setq pos1 (car (bounds-of-thing-at-point 'symbol)) | ||
| 13 | pos2 (cdr (bounds-of-thing-at-point 'symbol)))) | ||
| 14 | |||
| 15 | ; now, pos1 and pos2 are the starting and ending positions | ||
| 16 | ; of the current word, or current text selection if exists | ||
| 17 | |||
| 18 | ;; put your code here. | ||
| 19 | $0 | ||
| 20 | ;; Some example of things you might want to do | ||
| 21 | (downcase-region pos1 pos2) ; example of a func that takes region as args | ||
| 22 | (setq meat (buffer-substring-no-properties pos1 pos2)) ; grab the text. | ||
| 23 | (delete-region pos1 pos2) ; get rid of it | ||
| 24 | (insert "newText") ; insert your new text | ||
| 25 | |||
| 26 | ) | ||
| 27 | ) | ||
