-
Notifications
You must be signed in to change notification settings - Fork 0
/
em-methods.el
70 lines (60 loc) · 2.28 KB
/
em-methods.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
;; =================================================================
;; User defined methods
;; =================================================================
;; bind to key
(defun query-replace-reg-t (to-string)
(interactive (let (to)
(setq to (read-from-minibuffer
(format "Query-replace \"%s\" with: "
(get-register t))
nil nil nil
query-replace-to-history-variable nil t))
(list to)))
(perform-replace (get-register t) to-string t nil nil))
;; bind to key
(defun replace-string-reg-t (to-string)
(interactive (let (to)
(setq to (read-from-minibuffer
(format "Replace \"%s\" with: "
(get-register t))
nil nil nil
query-replace-to-history-variable nil t))
(list to)))
(perform-replace (get-register t) to-string nil nil nil))
;; copy from cua package
(defalias 'copy-rectangle-text 'cua-copy-rectangle-as-text-spc)
(defun cua-copy-rectangle-as-text-spc (&optional arg delete)
"Copy rectangle, but store as normal text."
(interactive "P")
(if cua--global-mark-active
(if delete
(cua--cut-rectangle-to-global-mark t)
(cua--copy-rectangle-to-global-mark t))
(let* ((rect (cua--extract-rectangle))
(text (mapconcat
(function (lambda (row) (concat row " ")))
rect "")))
(setq arg (cua--prefix-arg arg))
(if cua--register
(set-register cua--register text)
(kill-new text)))
(if delete
(cua--delete-rectangle))
(cua--deactivate)))
(defun goto-percent (percent)
"Goto PERCENT of buffer."
(interactive "nGoto percent:")
(goto-char (/ (* percent (point-max)) 100)))
;; bind to key
(defun jump-to-file-and-line ()
"Reads a line in the form FILENAME:LINE and, assuming a
relative path, opens that file in another window and jumps to the
line."
(interactive)
(let ((line (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(string-match "\\(.*\\):\\([0-9]+\\)" line)
(let ((file (match-string 1 line))
(lnum (match-string 2 line)))
(when (and file (file-exists-p (concat default-directory file)))
(find-file-other-window (concat default-directory file))
(and lnum (goto-line (string-to-number lnum)))))))