-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite-func.el
239 lines (190 loc) · 6.86 KB
/
site-func.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
;;; site-func.el --- utility functions definition in ~/.emacs config
;; Author: ht37 <[email protected]>
;; URL: https://github.com/hute37/emacs-site
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; h7 prefix
;;; Code:
;; ---( site.func: begin )-------------------------------------------------------
(message "SITE:FUNC - begin")
;; ---( ... )--------------------------------------------------------------
;;;////////////////////////////////////////////////////////////////
;;; @FUNCTIONS
;;;////////////////////////////////////////////////////////////////
(message "SITE:FUNCIONS")
;; ---( util )---------------------------------------------------------
;; Replace "yes or no" with y or n
(defun yes-or-no-p (arg)
"An alias for y-or-n-p, because I hate having to type 'yes' or 'no'."
(y-or-n-p arg))
;;;////////////////////////////////////////////////////////////////
;;; @MACRO
;;;////////////////////////////////////////////////////////////////
(message "SITE:MACRO")
;; ---( input macros )---------------------------------------------------------
(defun scroll-up-one ( )
"up-one."
(interactive)
(scroll-up 1))
(defun scroll-down-one ( )
"down-one."
(interactive)
(scroll-down 1))
;; ---( frames )---------------------------------------------------------
;;(require 'frame-cmds)
(defun toggle-fullscreen ()
"Toggle full screen on X11"
(interactive)
(when (eq window-system 'x)
(set-frame-parameter
nil 'fullscreen
(when (not (frame-parameter nil 'fullscreen)) 'fullboth))))
;; ---( wrap )---------------------------------------------------------
;; Toggles between line wrapping in the current buffer.
(defun toggle-line-wrapping ()
"Toggle between line wrapping in the current buffer."
(interactive)
(if (eq truncate-lines nil)
(progn
(setq truncate-lines t)
(redraw-display)
(message "Setting truncate-lines to t"))
(setq truncate-lines nil)
(redraw-display)
(message "Setting truncate-lines to nil"))
)
(defun xah-space-to-newline ()
"Replace space sequence to a newline char.
Works on current block or selection.
URL `http://xahlee.info/emacs/emacs/emacs_space_to_newline.html'
Version 2017-08-19"
(interactive)
(let* ( $p1 $p2 )
(if (use-region-p)
(progn
(setq $p1 (region-beginning))
(setq $p2 (region-end)))
(save-excursion
(if (re-search-backward "\n[ \t]*\n" nil "move")
(progn (re-search-forward "\n[ \t]*\n")
(setq $p1 (point)))
(setq $p1 (point)))
(re-search-forward "\n[ \t]*\n" nil "move")
(skip-chars-backward " \t\n" )
(setq $p2 (point))))
(save-excursion
(save-restriction
(narrow-to-region $p1 $p2)
(goto-char (point-min))
(while (re-search-forward " +" nil t)
(replace-match "\n" ))))))
(defun xah-newline-to-space () ;; xah-space-to-newline-2022-06-08
"Replace spaces to a newline in current block or selection.
If `universal-argument' is called first,
ask user to enter a character to replace.
URL `http://xahlee.info/emacs/emacs/emacs_space_to_newline.html'
Version: 2017-08-19 2021-11-28"
(interactive)
(let* ( $p1 $p2 )
(if (use-region-p)
(progn
(setq $p1 (region-beginning))
(setq $p2 (region-end)))
(save-excursion
(if (re-search-backward "\n[ \t]*\n" nil "move")
(progn (re-search-forward "\n[ \t]*\n")
(setq $p1 (point)))
(setq $p1 (point)))
(re-search-forward "\n[ \t]*\n" nil "move")
(skip-chars-backward " \t\n" )
(setq $p2 (point))))
(save-excursion
(save-restriction
(narrow-to-region $p1 $p2)
(goto-char (point-min))
(while (re-search-forward "\n+" nil t)
(replace-match " " ))))))
;; ---( kbd-macro )-----------------------------------------------------
(defun start-or-end-kbd-macro ()
;; A doc string. This is optional.
"Start defining a keyboard macro, or stop if we're already defining."
;; IMPORTANT: Any function bound to a key MUST have an interactive spec,
;; usually just the following line:
(interactive)
(if defining-kbd-macro
(end-kbd-macro)
(start-kbd-macro nil)))
;; ---( ascii )---------------------------------------------------------
(defun self-insert-backquote ( )
"insert backquote `."
(interactive)
(insert-char ?` 1))
(defun self-insert-tilde ( )
"insert tilde ~."
(interactive)
(insert-char ?~ 1))
;; ---( format )---------------------------------------------------------
;; Untabifies entire buffer.
(defun untabify-buffer ()
"Untabifies entire buffer."
(interactive)
(point-to-register 1)
(goto-char (point-min))
(untabify (point-min) (point-max))
(register-to-point 1)
)
;; Tabifies entire buffer.
(defun tabify-buffer ()
"Tabifies entire buffer."
(interactive)
(point-to-register 1)
(goto-char (point-min))
(tabify (point-min) (point-max))
(register-to-point 1)
)
(defun remove-trailing-ctl-M ()
"Propose to remove trailing ^M from a file."
(interactive)
(save-excursion
(goto-char (point-min))
(if (and (not (string-match ".gz$" (buffer-file-name)))
(search-forward-regexp "
$" nil t))
;: a ^M is found
(if (or (= (preceding-char) ?\^J)
(= (following-char) ?\^J) )
(if (y-or-n-p (format "Remove trailing ^M from %s? "
(buffer-file-name)))
(progn (goto-char (point-min))
(perform-replace "
" "" nil nil nil)
(pop-mark)
(save-buffer))
(message "No transformation."))))))
;; ---( format )---------------------------------------------------------
;; @see: https://github.com/seth/my-emacs-dot-d/blob/master/emacs-init.org
(defun google-search ()
"Googles a query or region if any."
(interactive)
(browse-url
(concat
"http://www.google.com/search?ie=utf-8&oe=utf-8&q="
(if mark-active
(buffer-substring (region-beginning) (region-end))
(read-string "Google: ")))))
;; ---( site.func: end )-------------------------------------------------------
(message "SITE:FUNC - end")
(provide 'site-func)
;;; site-func.el ends here