From 5d75c6e44da9f27d28ff60d5dee308f2247a1cf5 Mon Sep 17 00:00:00 2001 From: shipmints Date: Mon, 24 Feb 2025 17:45:54 -0500 Subject: [PATCH] Improve 'define-ibuffer-op' macro (bug#76222) * lisp/ibuf-macs.el (define-ibuffer-op): Change defun to defalias and place it before the macro-local lets. * lisp/ibuffer.el: (ibuffer-do-toggle-lock): Remove declare-function. (ibuffer-do-toggle-read-only): Remove declare-function. (ibuffer-do-save): Remove declare-function. (ibuffer-do-delete): Remove declare-function. (ibuffer-do-toggle-modified): Remove declare-function. (ibuffer-do-kill-on-deletion-marks): Remove declare-function. --- lisp/ibuf-macs.el | 102 +++++++++++++++++++++++----------------------- lisp/ibuffer.el | 9 ---- 2 files changed, 51 insertions(+), 60 deletions(-) diff --git a/lisp/ibuf-macs.el b/lisp/ibuf-macs.el index 4a283420efd..4595d24da11 100644 --- a/lisp/ibuf-macs.el +++ b/lisp/ibuf-macs.el @@ -218,12 +218,10 @@ buffer object. (let ((opstring-sym (make-symbol "opstring")) (active-opstring-sym (make-symbol "active-opstring"))) `(progn - (let ((,opstring-sym ,opstring) - (,active-opstring-sym ,active-opstring)) - (defun ,(intern (concat (if (string-match "^ibuffer-do" (symbol-name op)) - "" "ibuffer-do-") - (symbol-name op))) - ,args + (defalias ',(intern (concat (if (string-match "^ibuffer-do" (symbol-name op)) + "" "ibuffer-do-") + (symbol-name op))) + (lambda ,args ,(if (stringp documentation) documentation (format "%s marked buffers." (if (functionp active-opstring) @@ -234,45 +232,47 @@ buffer object. '(interactive)) (cl-assert (derived-mode-p 'ibuffer-mode)) (setq ibuffer-did-modification nil) - (let ((marked-names (,(pcase mark - (:deletion - 'ibuffer-deletion-marked-buffer-names) - (_ - 'ibuffer-marked-buffer-names))))) - (when (null marked-names) - (cl-assert (get-text-property (line-beginning-position) - 'ibuffer-properties) - nil "No buffer on this line") - (setq marked-names (list (buffer-name (ibuffer-current-buffer)))) - (ibuffer-set-mark ,(pcase mark - (:deletion - 'ibuffer-deletion-char) - (_ - 'ibuffer-marked-char)))) - ,(let* ((finish (append - '(progn) - (if (eq modifier-p t) - '((setq ibuffer-did-modification t)) - ()) - (and after `(,after)) ; post-operation form. - `((ibuffer-redisplay t) - (message (concat "Operation finished; " - (if (functionp ,opstring-sym) - (funcall ,opstring-sym) - ,opstring-sym) - " %s %s") - count (ngettext "buffer" "buffers" - count))))) - (inner-body (if complex - `(progn ,@body) - `(progn + (let ((,opstring-sym ,opstring) + (,active-opstring-sym ,active-opstring)) + (let ((marked-names (,(pcase mark + (:deletion + 'ibuffer-deletion-marked-buffer-names) + (_ + 'ibuffer-marked-buffer-names))))) + (when (null marked-names) + (cl-assert (get-text-property (line-beginning-position) + 'ibuffer-properties) + nil "No buffer on this line") + (setq marked-names (list (buffer-name (ibuffer-current-buffer)))) + (ibuffer-set-mark ,(pcase mark + (:deletion + 'ibuffer-deletion-char) + (_ + 'ibuffer-marked-char)))) + ,(let* ((finish (append + '(progn) + (if (eq modifier-p t) + '((setq ibuffer-did-modification t)) + ()) + (and after `(,after)) ; post-operation form. + `((ibuffer-redisplay t) + (message (concat "Operation finished; " + (if (functionp ,opstring-sym) + (funcall ,opstring-sym) + ,opstring-sym) + " %s %s") + count (ngettext "buffer" "buffers" + count))))) + (inner-body (if complex + `(progn ,@body) + `(progn (with-current-buffer buf (save-excursion ,@body)) t))) - (body `(let ((_ ,before) ; pre-operation form. - (count - (,(pcase mark + (body `(let ((_ ,before) ; pre-operation form. + (count + (,(pcase mark (:deletion 'ibuffer-map-deletion-lines) (_ @@ -290,16 +290,16 @@ buffer object. (setq ibuffer-did-modification t)))) inner-body))))) - ,finish))) - (if dangerous - `(when (ibuffer-confirm-operation-on - (if (functionp ,active-opstring-sym) - (funcall ,active-opstring-sym) - ,active-opstring-sym) - marked-names) - ,body) - body)))) - :autoload-end)))) + ,finish))) + (if dangerous + `(when (ibuffer-confirm-operation-on + (if (functionp ,active-opstring-sym) + (funcall ,active-opstring-sym) + ,active-opstring-sym) + marked-names) + ,body) + body)))) + :autoload-end))))) ;;;###autoload (cl-defmacro define-ibuffer-filter (name documentation diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el index 53cf62b142b..95deb2db478 100644 --- a/lisp/ibuffer.el +++ b/lisp/ibuffer.el @@ -372,15 +372,6 @@ directory, like `default-directory'." (regexp :tag "From") (regexp :tag "To")))) -;; These declarations are here to avoid byte-compiler warnings about -;; functions defined later via 'define-ibuffer-op'. -(declare-function ibuffer-do-toggle-lock "ibuffer.el") -(declare-function ibuffer-do-toggle-read-only "ibuffer.el") -(declare-function ibuffer-do-save "ibuffer.el") -(declare-function ibuffer-do-delete "ibuffer.el") -(declare-function ibuffer-do-toggle-modified "ibuffer.el") -(declare-function ibuffer-do-kill-on-deletion-marks "ibuffer.el") - (defvar-keymap ibuffer--filter-map "RET" #'ibuffer-filter-by-mode "SPC" #'ibuffer-filter-chosen-by-completion