about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--init.el4
-rw-r--r--lisp/acdw.el90
2 files changed, 93 insertions, 1 deletions
diff --git a/init.el b/init.el index 91f8baa..7caa90e 100644 --- a/init.el +++ b/init.el
@@ -987,7 +987,9 @@ if ripgrep is installed, otherwise `consult-grep'."
987 (defun setup-paredit-mode () 987 (defun setup-paredit-mode ()
988 "Correct weirdnesses and set up paredit mode." 988 "Correct weirdnesses and set up paredit mode."
989 (paredit-mode +1) 989 (paredit-mode +1)
990 (define-key lisp-mode-shared-map (kbd "DEL") #'paredit-backward-delete)) 990 (let ((map lisp-mode-shared-map))
991 (define-key map (kbd "DEL") #'paredit-backward-delete)
992 (define-key map (kbd "C-M-;") #'comment-or-uncomment-sexp)))
991 993
992 (dolist (mode lispy-modes) 994 (dolist (mode lispy-modes)
993 (add-hook (intern (concat (symbol-name mode) "-hook")) 995 (add-hook (intern (concat (symbol-name mode) "-hook"))
diff --git a/lisp/acdw.el b/lisp/acdw.el index c48c4e3..8b87dd5 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -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)