Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
997 B

5 years ago
  1. # -*- mode: snippet -*-
  2. # contributor: Xah Lee (XahLee.org)
  3. # name: Command that works on region or word
  4. # key: x-word-or-region
  5. # --
  6. ;; example of a command that works on current word or text selection
  7. (defun down-case-word-or-region ()
  8. "Lower case the current word or text selection."
  9. (interactive)
  10. (let (pos1 pos2 meat)
  11. (if (and transient-mark-mode mark-active)
  12. (setq pos1 (region-beginning)
  13. pos2 (region-end))
  14. (setq pos1 (car (bounds-of-thing-at-point 'symbol))
  15. 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
  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. )