1 # contributor: Xah Lee (XahLee.org)
2 # name: Command that works on region or word
3 # key: x-word-or-region
5 ;; example of a command that works on current word or text selection
6 (defun down-case-word-or-region ()
7 "Lower case the current word or text selection."
10 (if (and transient-mark-mode mark-active)
11 (setq pos1 (region-beginning)
13 (setq pos1 (car (bounds-of-thing-at-point 'symbol))
14 pos2 (cdr (bounds-of-thing-at-point 'symbol))))
16 ; now, pos1 and pos2 are the starting and ending positions
17 ; of the current word, or current text selection if exists
19 ;; put your code here.
21 ;; Some example of things you might want to do
22 (downcase-region pos1 pos2) ; example of a func that takes region as args
23 (setq meat (buffer-substring-no-properties pos1 pos2)) ; grab the text.
24 (delete-region pos1 pos2) ; get rid of it
25 (insert "newText") ; insert your new text