summaryrefslogtreecommitdiffstats
path: root/emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2009-10-22 05:30:58 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2009-10-22 05:30:58 +0200
commitc13334d651b13d8b047cb3dc35ad3e1ef239013f (patch)
treece0361f3bbbe502af91b33f896644d5695680223 /emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region
parentff21663ded2283850f175e6de619feb5da91fef4 (diff)
downloaddotfiles-c13334d651b13d8b047cb3dc35ad3e1ef239013f.tar.gz
dotfiles-c13334d651b13d8b047cb3dc35ad3e1ef239013f.tar.xz
dotfiles-c13334d651b13d8b047cb3dc35ad3e1ef239013f.zip
added snippets for loading with module from dotfiles
Diffstat (limited to 'emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region')
-rw-r--r--emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region27
1 files changed, 27 insertions, 0 deletions
diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region b/emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region
new file mode 100644
index 0000000..66a59e4
--- /dev/null
+++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region
@@ -0,0 +1,27 @@
+#name : Command that works on region or word
+#contributor : Xah Lee
+# --
+;; example of a command that works on current word or text selection
+(defun down-case-word-or-region ()
+ "Lower case the current word or text selection."
+(interactive)
+(let (pos1 pos2 meat)
+ (if (and transient-mark-mode mark-active)
+ (setq pos1 (region-beginning)
+ pos2 (region-end))
+ (setq pos1 (car (bounds-of-thing-at-point 'symbol))
+ pos2 (cdr (bounds-of-thing-at-point 'symbol))))
+
+ ; now, pos1 and pos2 are the starting and ending positions
+ ; of the current word, or current text selection if exists
+
+ ;; put your code here.
+ $0
+ ;; Some example of things you might want to do
+ (downcase-region pos1 pos2) ; example of a func that takes region as args
+ (setq meat (buffer-substring-no-properties pos1 pos2)) ; grab the text.
+ (delete-region pos1 pos2) ; get rid of it
+ (insert "newText") ; insert your new text
+
+ )
+)