-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path+functions.el
108 lines (96 loc) · 3.45 KB
/
+functions.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
97
98
99
100
101
102
103
104
105
106
107
108
;;; +functions.el --- My Own Awesome™ Functions
(defun +boy/up-scroll (n)
"Scroll up marker and line N times."
(interactive "p")
(line-move-visual (* -1 n) t)
(unless (eq (window-start) (point-min))
(recenter (1+
(count-screen-lines
(save-excursion (beginning-of-visual-line))
(window-start))))))
(defun +boy/down-scroll (n)
"Scroll down marker and line N times."
(interactive "p")
(line-move-visual n t)
(let ((scroll-margin 0))
(recenter (1-
(count-screen-lines
(save-excursion (beginning-of-visual-line))
(window-start))))))
;; Delete a word forward without pasting in the kill-region
(defun +boy/delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument, do this that many times.
This command does not push text to `kill-ring'."
(interactive "p")
(delete-region
(point)
(progn
(forward-word arg)
(point))))
;; Delete a word backwards without modifying the kill-region
(defun +boy/backward-delete-word (arg)
"Delete characters backward until encountering the beginning of a word.
With argument, do this that many times.
This command does not push text to `kill-ring'."
(interactive "p")
(+boy/delete-word (- arg)))
;; "Like kill-line but without adding anything to the kill ring."
(defun +boy/kill-line (&optional arg)
"Delete the rest of the current line; if no nonblanks there, delete thru newline.
With prefix argument ARG, delete that many lines from point.
Negative arguments delete lines backward.
With zero argument, delete the text before point on the current line.
When calling from a program, nil means \"no arg\",
a number counts as a prefix arg.
If `show-trailing-whitespace' is non-nil, this command will just
delete the rest of the current line, even if there are no nonblanks
there.
If option `kill-whole-line' is non-nil, then this command deletes the whole line
including its terminating newline, when used at the beginning of a line
with no argument.
If the buffer is read-only, Emacs will beep and refrain from deleting
the line."
(interactive "P")
(delete-region
(point)
(progn
(if arg
(forward-visible-line (prefix-numeric-value arg))
(if (eobp)
(signal 'end-of-buffer nil))
(let ((end
(save-excursion
(end-of-visible-line) (point))))
(if (or (save-excursion
;; If trailing whitespace is visible,
;; don't treat it as nothing.
(unless show-trailing-whitespace
(skip-chars-forward " \t" end))
(= (point) end))
(and kill-whole-line (bolp)))
(forward-visible-line 1)
(goto-char end))))
(point))))
(defun +boy/macro-on ()
"Easily toggle the recording of macros on."
(interactive)
(define-key global-map (this-command-keys)
'+boy/macro-off)
(start-kbd-macro nil))
(defun +boy/macro-off ()
"Easily toggle the recording of macros off."
(interactive)
(define-key global-map (this-command-keys)
'+boy/macro-on)
(end-kbd-macro))
(defun +boy/copy-to-other-windows ()
"Copy the contents of the current window into all other visible windows."
(interactive)
(let ((src-buffer (current-buffer)))
(mapc
#'(lambda (win)
(with-selected-window win
(erase-buffer)
(insert-buffer-substring src-buffer)))
(cdr (window-list)))))