aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2025-02-26 09:13:04 -0500
committerStefan Monnier2025-02-26 09:13:04 -0500
commit5815bd52279fdedc752f9f92ace86f8243fbd604 (patch)
tree31af829fba3b40573c89c79f66fd09065f761195
parent5d75c6e44da9f27d28ff60d5dee308f2247a1cf5 (diff)
downloademacs-5815bd52279fdedc752f9f92ace86f8243fbd604.tar.gz
emacs-5815bd52279fdedc752f9f92ace86f8243fbd604.zip
(define-ibuffer-op): Minor tweak to Shipmints's patch
* lisp/ibuf-macs.el (define-ibuffer-op): Evaluate `(active-)opstring` args when defining the operation rather than every time the operation is used. Move the `:autoload-end` marker back to the level of `progn`.
-rw-r--r--lisp/ibuf-macs.el87
1 files changed, 46 insertions, 41 deletions
diff --git a/lisp/ibuf-macs.el b/lisp/ibuf-macs.el
index 4595d24da11..22db912be52 100644
--- a/lisp/ibuf-macs.el
+++ b/lisp/ibuf-macs.el
@@ -221,19 +221,20 @@ buffer object.
221 (defalias ',(intern (concat (if (string-match "^ibuffer-do" (symbol-name op)) 221 (defalias ',(intern (concat (if (string-match "^ibuffer-do" (symbol-name op))
222 "" "ibuffer-do-") 222 "" "ibuffer-do-")
223 (symbol-name op))) 223 (symbol-name op)))
224 (lambda ,args 224 (let ((,opstring-sym ,opstring)
225 ,(if (stringp documentation) 225 (,active-opstring-sym ,active-opstring))
226 documentation 226 (lambda ,args
227 (format "%s marked buffers." (if (functionp active-opstring) 227 ,(if (stringp documentation)
228 (funcall active-opstring) 228 documentation
229 active-opstring))) 229 (format "%s marked buffers." (if (functionp active-opstring)
230 ,(if (not (null interactive)) 230 ;; FIXME: Unused?
231 `(interactive ,interactive) 231 (funcall active-opstring)
232 '(interactive)) 232 active-opstring)))
233 (cl-assert (derived-mode-p 'ibuffer-mode)) 233 ,(if (not (null interactive))
234 (setq ibuffer-did-modification nil) 234 `(interactive ,interactive)
235 (let ((,opstring-sym ,opstring) 235 '(interactive))
236 (,active-opstring-sym ,active-opstring)) 236 (cl-assert (derived-mode-p 'ibuffer-mode))
237 (setq ibuffer-did-modification nil)
237 (let ((marked-names (,(pcase mark 238 (let ((marked-names (,(pcase mark
238 (:deletion 239 (:deletion
239 'ibuffer-deletion-marked-buffer-names) 240 'ibuffer-deletion-marked-buffer-names)
@@ -243,7 +244,8 @@ buffer object.
243 (cl-assert (get-text-property (line-beginning-position) 244 (cl-assert (get-text-property (line-beginning-position)
244 'ibuffer-properties) 245 'ibuffer-properties)
245 nil "No buffer on this line") 246 nil "No buffer on this line")
246 (setq marked-names (list (buffer-name (ibuffer-current-buffer)))) 247 (setq marked-names
248 (list (buffer-name (ibuffer-current-buffer))))
247 (ibuffer-set-mark ,(pcase mark 249 (ibuffer-set-mark ,(pcase mark
248 (:deletion 250 (:deletion
249 'ibuffer-deletion-char) 251 'ibuffer-deletion-char)
@@ -258,6 +260,7 @@ buffer object.
258 `((ibuffer-redisplay t) 260 `((ibuffer-redisplay t)
259 (message (concat "Operation finished; " 261 (message (concat "Operation finished; "
260 (if (functionp ,opstring-sym) 262 (if (functionp ,opstring-sym)
263 ;; FIXME: Unused?
261 (funcall ,opstring-sym) 264 (funcall ,opstring-sym)
262 ,opstring-sym) 265 ,opstring-sym)
263 " %s %s") 266 " %s %s")
@@ -266,40 +269,42 @@ buffer object.
266 (inner-body (if complex 269 (inner-body (if complex
267 `(progn ,@body) 270 `(progn ,@body)
268 `(progn 271 `(progn
269 (with-current-buffer buf 272 (with-current-buffer buf
270 (save-excursion 273 (save-excursion
271 ,@body)) 274 ,@body))
272 t))) 275 t)))
273 (body `(let ((_ ,before) ; pre-operation form. 276 (body
274 (count 277 `(let ((_ ,before) ; pre-operation form.
275 (,(pcase mark 278 (count
276 (:deletion 279 (,(pcase mark
277 'ibuffer-map-deletion-lines) 280 (:deletion
278 (_ 281 'ibuffer-map-deletion-lines)
279 'ibuffer-map-marked-lines)) 282 (_
280 (lambda (buf mark) 283 'ibuffer-map-marked-lines))
281 ;; Silence warning for code that doesn't 284 (lambda (buf mark)
282 ;; use `mark'. 285 ;; Silence warning for code that doesn't
283 (ignore mark) 286 ;; use `mark'.
284 ,(if (eq modifier-p :maybe) 287 (ignore mark)
285 `(let ((ibuffer-tmp-previous-buffer-modification 288 ,(if (eq modifier-p :maybe)
286 (buffer-modified-p buf))) 289 `(let ((ibuffer-tmp-previous-buffer-modification
287 (prog1 ,inner-body 290 (buffer-modified-p buf)))
288 (when (not (eq ibuffer-tmp-previous-buffer-modification 291 (prog1 ,inner-body
289 (buffer-modified-p buf))) 292 (unless (eq ibuffer-tmp-previous-buffer-modification
290 (setq 293 (buffer-modified-p buf))
291 ibuffer-did-modification t)))) 294 (setq
292 inner-body))))) 295 ibuffer-did-modification t))))
293 ,finish))) 296 inner-body)))))
297 ,finish)))
294 (if dangerous 298 (if dangerous
295 `(when (ibuffer-confirm-operation-on 299 `(when (ibuffer-confirm-operation-on
296 (if (functionp ,active-opstring-sym) 300 (if (functionp ,active-opstring-sym)
301 ;; FIXME: Unused?
297 (funcall ,active-opstring-sym) 302 (funcall ,active-opstring-sym)
298 ,active-opstring-sym) 303 ,active-opstring-sym)
299 marked-names) 304 marked-names)
300 ,body) 305 ,body)
301 body)))) 306 body))))))
302 :autoload-end))))) 307 :autoload-end)))
303 308
304;;;###autoload 309;;;###autoload
305(cl-defmacro define-ibuffer-filter (name documentation 310(cl-defmacro define-ibuffer-filter (name documentation