forked from kmroz/rmoo
-
Notifications
You must be signed in to change notification settings - Fork 5
/
prefix.el
44 lines (39 loc) · 1.58 KB
/
prefix.el
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;;; Prefix/suffix regions with strings
;;;
;;; Original Author: Ron Tapia <[email protected]>
;;; Revised by: mattcamp
(defun surround-region (before prefix suffix after &optional start end)
"Place specified strings before, PREFIXing each line, SUFFIXing
each line, and AFTER the specified region. When called interactively,
acts on the current region."
(interactive "sBefore: \nsPrefix: \nsSuffix: \nsAfter: \nr")
(save-excursion
(narrow-to-region (or start (region-beginning)) (or end (region-end)))
(goto-char (point-min))
(untabify (point-min) (point-max))
(if (not (equal before "")) (insert before "\n"))
(while (re-search-forward "^\\(.*\\)$" (1- (point-max)) "end")
(replace-match (concat prefix "\\1" suffix) t))
(forward-char 1)
(insert after)
(widen)))
(defun prefix-region-with-string (prefix &optional suffix)
"Get string from user, and prefix each line of the current region with it.
If current-prefix-arg (\\[universal-argument]), prompt for string to suffix to region as well."
(interactive (list (read-string "Prefix: ")
(if current-prefix-arg
(read-string "Suffix: ")
"")))
(surround-region "" prefix suffix ""))
(defun prefix-region-with-quote ()
"Prefix current region with the quote character (\")."
(interactive)
(prefix-region-with-string "\""))
(defun prefix-region-with-pose ()
"Prefix current region with the pose character (:)."
(interactive)
(prefix-region-with-string ":"))
(defun prefix-region-with-> ()
"Prefix current region with the > character."
(interactive)
(prefix-region-with-string ">"))