about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw.el134
1 files changed, 112 insertions, 22 deletions
diff --git a/lisp/acdw.el b/lisp/acdw.el index a1c364d..8b87dd5 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -28,21 +28,21 @@
28 (_ :other)) 28 (_ :other))
29 "Which computer system is currently being used.") 29 "Which computer system is currently being used.")
30 30
31(defmacro acdw/system (&rest arg) 31(defmacro acdw/system (&rest args)
32 "Convenience macro for interfacing with `acdw/system'. 32 "Convenience macro for interfacing with `acdw/system'.
33 33
34When called without arguments, it returns `acdw/system'. 34When called without arguments, it returns `acdw/system'. When
35When called with one argument, it returns (eq acdw/system ARG). 35called with one (symbol) argument, it returns (eq acdw/system
36When called with multiple arguments, it returns `pcase' over each argument." 36ARG). When called with multiple arguments or a list, it returns
37`pcase' over each argument."
37 (cond 38 (cond
38 ((not arg) acdw/system) 39 ((null args) acdw/system)
39 ((not (cdr arg)) 40 ((atom (car args))
40 `(when (eq acdw/system ,(car arg)) 41 `(when (eq acdw/system ,(car args))
41 ,(car arg))) 42 ,(car args)))
42 ((cdr arg) 43 (t
43 `(pcase acdw/system 44 `(pcase acdw/system
44 ,@arg)) 45 ,@args))))
45 (t (error "Wrong argument type: %s" (type-of arg)))))
46 46
47 47
48;;; Utility functions 48;;; Utility functions
@@ -65,17 +65,17 @@ When called with multiple arguments, it returns `pcase' over each argument."
65 file 65 file
66 nil))) 66 nil)))
67 67
68(defmacro hook-defun (name hooks &rest forms) 68;; (defmacro hook-defun (name hooks &rest forms)
69 "Define a function NAME that executes FORMS, and add it to 69;; "Define a function NAME that executes FORMS, and add it to
70each hook in HOOKS." 70;; each hook in HOOKS."
71 (declare (indent 2)) 71;; (declare (indent 2))
72 (let ((func-name (intern (concat "hook-defun-" (symbol-name name)))) 72;; (let ((func-name (intern (concat "hook-defun-" (symbol-name name))))
73 (hook-list (if (consp hooks) hooks (list hooks))) 73;; (hook-list (if (consp hooks) hooks (list hooks)))
74 (hook-defun-add-hook-list)) 74;; (hook-defun-add-hook-list))
75 `(progn 75;; `(progn
76 (defun ,func-name () "Defined by `hook-defun'." ,@forms) 76;; (defun ,func-name () "Defined by `hook-defun'." ,@forms)
77 ,@(dolist (hook hook-list hook-defun-add-hook-list) 77;; ,@(dolist (hook hook-list hook-defun-add-hook-list)
78 (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list))))) 78;; (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list)))))
79 79
80(defun kill-region-or-backward-word (arg) 80(defun kill-region-or-backward-word (arg)
81 "Kill region if active, or backward word if not." 81 "Kill region if active, or backward word if not."
@@ -106,6 +106,96 @@ is unfocused."
106 (message "%s... Done." ,message))) 106 (message "%s... Done." ,message)))
107 107
108 108
109;;; Comment-or-uncomment-sexp
110;; from https://endlessparentheses.com/a-comment-or-uncomment-sexp-command.html
111
112(defun uncomment-sexp (&optional n)
113 "Uncomment a sexp around point."
114 (interactive "P")
115 (let* ((initial-point (point-marker))
116 (inhibit-field-text-motion t)
117 (p)
118 (end (save-excursion
119 (when (elt (syntax-ppss) 4)
120 (re-search-backward comment-start-skip
121 (line-beginning-position)
122 t))
123 (setq p (point-marker))
124 (comment-forward (point-max))
125 (point-marker)))
126 (beg (save-excursion
127 (forward-line 0)
128 (while (and (not (bobp))
129 (= end (save-excursion
130 (comment-forward (point-max))
131 (point))))
132 (forward-line -1))
133 (goto-char (line-end-position))
134 (re-search-backward comment-start-skip
135 (line-beginning-position)
136 t)
137 (ignore-errors
138 (while (looking-at-p comment-start-skip)
139 (forward-char -1)))
140 (point-marker))))
141 (unless (= beg end)
142 (uncomment-region beg end)
143 (goto-char p)
144 ;; Indentify the "top-level" sexp inside the comment.
145 (while (and (ignore-errors (backward-up-list) t)
146 (>= (point) beg))
147 (skip-chars-backward (rx (syntax expression-prefix)))
148 (setq p (point-marker)))
149 ;; Re-comment everything before it.
150 (ignore-errors
151 (comment-region beg p))
152 ;; And everything after it.
153 (goto-char p)
154 (forward-sexp (or n 1))
155 (skip-chars-forward "\r\n[:blank:]")
156 (if (< (point) end)
157 (ignore-errors
158 (comment-region (point) end))
159 ;; If this is a closing delimiter, pull it up.
160 (goto-char end)
161 (skip-chars-forward "\r\n[:blank:]")
162 (when (eq 5 (car (syntax-after (point))))
163 (delete-indentation))))
164 ;; Without a prefix, it's more useful to leave point where
165 ;; it was.
166 (unless n
167 (goto-char initial-point))))
168
169(defun comment-sexp--raw ()
170 "Comment the sexp at point or ahead of point."
171 (pcase (or (bounds-of-thing-at-point 'sexp)
172 (save-excursion
173 (skip-chars-forward "\r\n[:blank:]")
174 (bounds-of-thing-at-point 'sexp)))
175 (`(,l . ,r)
176 (goto-char r)
177 (skip-chars-forward "\r\n[:blank:]")
178 (save-excursion
179 (comment-region l r))
180 (skip-chars-forward "\r\n[:blank:]"))))
181
182(defun comment-or-uncomment-sexp (&optional n)
183 "Comment the sexp at point and move past it.
184If already inside (or before) a comment, uncomment instead.
185With a prefix argument N, (un)comment that many sexps."
186 (interactive "P")
187 (if (or (elt (syntax-ppss) 4)
188 (< (save-excursion
189 (skip-chars-forward "\r\n[:blank:]")
190 (point))
191 (save-excursion
192 (comment-forward 1)
193 (point))))
194 (uncomment-sexp n)
195 (dotimes (_ (or n 1))
196 (comment-sexp--raw))))
197
198
109;;; Emacs configuration functions 199;;; Emacs configuration functions
110 200
111(defun emacs-git-pull-config (&optional remote branch) 201(defun emacs-git-pull-config (&optional remote branch)