-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.el
50 lines (46 loc) · 1.55 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
;; Smooth scroll down
(defun my-down-scroll ()
"Scroll down and center the screen"
(interactive)
(forward-line)
(recenter))
;; Smooth scroll up
(defun my-up-scroll ()
"Scroll up and center the screen"
(interactive)
(previous-line 1 1)
(recenter))
;; Copy a paragraph and remove all extra spaces and line ends
(defun my-copy-paragraph (&optional beg end)
"Save the current region (or line) to the `kill-ring' after stripping extra whitespace and new lines"
(interactive
(if (region-active-p)
(list (region-beginning) (region-end))
(list (line-beginning-position) (line-end-position))))
(let ((my-text (buffer-substring-no-properties beg end)))
(with-temp-buffer
(insert my-text)
(goto-char 1)
(while (looking-at "[ \t\n]")
(delete-char 1))
(let ((fill-column 9333999))
(fill-region (point-min) (point-max)))
(kill-region (point-min) (point-max)))))
;; Delete a word forward without pasting in the kill-region
(defun my-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 my-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")
(my-delete-word (- arg)))