-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric-copy.el
96 lines (77 loc) · 2.65 KB
/
generic-copy.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;
;; Mon Dec 27 12:02:22 2010
;;
;;
;; http://emacser.com/non-programmer.htm
;;
(defun get-point (symbol &optional arg)
"get the point"
(funcall symbol arg)
(point)
)
(defun copy-thing (begin-of-thing end-of-thing &optional arg)
"copy thing between beg & end into kill ring"
(save-excursion
(let ((beg (get-point begin-of-thing 1))
(end (get-point end-of-thing arg)))
(copy-region-as-kill beg end)))
)
(defun generic-copy-word (&optional arg)
"Copy words at point into kill-ring"
(interactive "P")
(copy-thing 'backward-word 'forward-word arg)
)
(defun generic-copy-line (&optional arg)
"Save current line into Kill-Ring without mark the line "
(interactive "P")
(copy-thing 'beginning-of-line 'end-of-line arg)
)
(defun generic-copy-whole-line (arg)
"Copy lines (as many as prefix argument) in the kill ring"
(interactive "p")
(kill-ring-save (line-beginning-position)
(line-beginning-position (+ 1 arg)))
(message "%d line%s copied" arg (if (= 1 arg) "" "s")))
(defun generic-copy-paragraph (&optional arg)
"Copy paragraphes at point"
(interactive "P")
(copy-thing 'backward-paragraph 'forward-paragraph arg)
)
(defun beginning-of-string(&optional arg)
" "
(re-search-backward "[ \t]" (line-beginning-position) 3 1)
(if (looking-at "[\t ]") (goto-char (+ (point) 1)) )
)
(defun end-of-string(&optional arg)
" "
(re-search-forward "[ \t]" (line-end-position) 3 arg)
(if (looking-back "[\t ]") (goto-char (- (point) 1)) )
)
(defun generic-copy-string(&optional arg)
" Try to copy a string and paste it to the mark
When used in shell-mode, it will paste string on shell prompt by default "
(interactive "P")
(copy-thing 'beginning-of-string 'end-of-string arg)
)
(defun beginning-of-parenthesis(&optional arg)
" "
(re-search-backward "[[<(?\"]" (line-beginning-position) 3 1)
(if (looking-at "[[<(?\"]") (goto-char (+ (point) 1)) )
)
(defun end-of-parenthesis(&optional arg)
" "
(re-search-forward "[]>)?\"]" (line-end-position) 3 arg)
(if (looking-back "[]>)?\"]") (goto-char (- (point) 1)) )
)
(defun generic-copy-parenthesis(&optional arg)
" Try to copy a parenthesis and paste it to the mark
When used in shell-mode, it will paste parenthesis on shell prompt by default "
(interactive "P")
(copy-thing 'beginning-of-parenthesis 'end-of-parenthesis arg)
)
(global-set-key (kbd "C-c l") 'generic-copy-whole-line)
(global-set-key (kbd "C-c L") 'generic-copy-line)
(global-set-key (kbd "C-c w") 'generic-copy-word)
(global-set-key (kbd "C-c l") 'generic-copy-line)
(global-set-key (kbd "C-c p") 'generic-copy-paragraph)
(provide 'generic-copy)