-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit-efuns.el
143 lines (124 loc) · 4.36 KB
/
init-efuns.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
(defun kg/split-below-and-move ()
(interactive)
(split-window-below)
(other-window 1))
(defun kg/split-right-and-move ()
(interactive)
(split-window-right)
(other-window 1))
(defun kg/beginning-of-line-dwim ()
"Toggle between moving point to the first non-whitespace character, and the start of the line."
(interactive)
(let ((start-position (point)))
;; Move to the first non-whitespace character.
(back-to-indentation)
;; If we haven't moved position, go to start of the line.
(when (= (point) start-position)
(move-beginning-of-line nil))))
(defun kg/duplicate-start-of-line-or-region ()
"Duplicate start of line or region."
(interactive)
(if mark-active
(kg/duplicate-region)
(kg/duplicate-start-of-line)))
(defun kg/duplicate-start-of-line ()
"Duplicate start of line."
(let ((text (buffer-substring (point)
(beginning-of-thing 'line))))
(forward-line)
(push-mark)
(insert text)
(open-line 1)))
(defun kg/duplicate-region ()
"Duplicate start of region."
(let* ((end (region-end))
(text (buffer-substring (region-beginning)
end)))
(goto-char end)
(insert text)
(push-mark end)
(setq deactivate-mark nil)
(exchange-point-and-mark)))
(defun kg/set-fringe-background ()
"Set the fringe background to the same color as the regular background."
(interactive)
(custom-set-faces
`(fringe ((t (:background ,(face-background 'default)))))))
(add-hook 'after-init-hook #'kg/set-fringe-background)
(defun kg/reset-ui ()
"Reset some UI components after changing a theme."
(interactive)
;; (fringe-mode 10)
(fringe-mode '(0 . 0))
(kg/set-fringe-background)
(setq linum-format "%5d "))
(defun kg/rename-this-buffer-and-file ()
"Rename current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(cond ((get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name))
(t
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name
(file-name-nondirectory new-name))))))))
(defun kg/delete-this-buffer-and-file ()
"Remove file connected to current buffer and kill buffer."
(interactive)
(let ((filename (buffer-file-name))
(buffer (current-buffer))
(name (buffer-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(when (yes-or-no-p "Are you sure you want to remove this file? ")
(delete-file filename)
(kill-buffer buffer)
(message "File '%s' successfully removed" filename)))))
(defun kg/search-marked-region-if-available (start end)
"Pre-fill counsel-rg with marked region if available."
(interactive "r")
(if (use-region-p)
(let ((regionp (buffer-substring start end)))
(counsel-rg regionp))
(counsel-rg)))
(defun kg/show-user-config ()
(interactive)
(find-file "~/.emacs.d/init-user.el"))
(defun kg/toggle-maximize-buffer ()
"Maximize buffer"
(interactive)
(if (= 1 (length (window-list)))
(jump-to-register '_)
(progn
(window-configuration-to-register '_)
(delete-other-windows))))
(defun kg/isearch-query-replace-symbol-at-point ()
"Run `query-replace-regexp' for the symbol at point."
(interactive)
(isearch-forward-symbol-at-point)
(isearch-query-replace-regexp))
(defun kg/create-tags (dir-name)
"Create tags file."
(interactive "Directory: ")
(shell-command
(format "%s -f TAGS -e -R %s" ctags-path (directory-file-name dir-name))))
;; taken from https://github.com/howardabrams/dot-files/blob/master/emacs.org#unfill-paragraph
(defun kg/unfill-paragraph ()
"Convert a multi-line paragraph into a single line of text."
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(defun kg/magit-status-fullscreen (prefix)
(interactive)
(magit-status)
(unless prefix
(delete-other-windows)))
(provide 'init-efuns)