File: word-or-region

package info (click to toggle)
yasnippet-snippets 1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,328 kB
  • sloc: lisp: 127; sh: 13; ada: 5; makefile: 2; python: 2
file content (28 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- mode: snippet -*-
# 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

  )
)