]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve 'define-ibuffer-op' macro (bug#76222)
authorshipmints <shipmints@gmail.com>
Mon, 24 Feb 2025 22:45:54 +0000 (17:45 -0500)
committerEshel Yaron <me@eshelyaron.com>
Fri, 28 Feb 2025 11:18:14 +0000 (12:18 +0100)
* 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.

(cherry picked from commit 5d75c6e44da9f27d28ff60d5dee308f2247a1cf5)

lisp/ibuf-macs.el

index 9c43411e46d5cdb44e9fd17810b00bf7f49ede3d..f93818c120be54117e994a6b11a33adb99d95394 100644 (file)
@@ -211,74 +211,91 @@ buffer object.
 
 \(fn OP ARGS DOCUMENTATION (&key INTERACTIVE MARK MODIFIER-P DANGEROUS OPSTRING ACTIVE-OPSTRING BEFORE AFTER COMPLEX) &rest BODY)"
   (declare (indent 2) (doc-string 3))
-  `(progn
-     (defun ,(intern (concat (if (string-match "^ibuffer-do" (symbol-name op))
-                                "" "ibuffer-do-")
-                             (symbol-name op)))
-       ,args
-       ,(if (stringp documentation)
-           documentation
-         (format "%s marked buffers." active-opstring))
-       (interactive ,(or interactive "") ibuffer-mode)
-       (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; " opstring
-                                              " %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
-                                  (:deletion
-                                   'ibuffer-map-deletion-lines)
-                                  (_
-                                   'ibuffer-map-marked-lines))
-                                (lambda (buf mark)
-                                  ;; Silence warning for code that doesn't
-                                  ;; use `mark'.
-                                  (ignore mark)
-                                  ,(if (eq modifier-p :maybe)
-                                       `(let ((ibuffer-tmp-previous-buffer-modification
-                                               (buffer-modified-p buf)))
-                                          (prog1 ,inner-body
-                                            (when (not (eq ibuffer-tmp-previous-buffer-modification
-                                                           (buffer-modified-p buf)))
-                                              (setq ibuffer-did-modification t))))
-                                     inner-body)))))
-                         ,finish)))
-           (if dangerous
-               `(when (ibuffer-confirm-operation-on ,active-opstring marked-names)
-                  ,body)
-             body))))
-     :autoload-end))
+  (let ((opstring-sym (make-symbol "opstring"))
+        (active-opstring-sym (make-symbol "active-opstring")))
+    `(progn
+       (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)
+                                               (funcall active-opstring)
+                                             active-opstring)))
+           ,(if (not (null interactive))
+                `(interactive ,interactive)
+              '(interactive))
+           (cl-assert (derived-mode-p 'ibuffer-mode))
+           (setq ibuffer-did-modification nil)
+           (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
+                                       (:deletion
+                                        'ibuffer-map-deletion-lines)
+                                       (_
+                                        'ibuffer-map-marked-lines))
+                                    (lambda (buf mark)
+                                      ;; Silence warning for code that doesn't
+                                      ;; use `mark'.
+                                      (ignore mark)
+                                      ,(if (eq modifier-p :maybe)
+                                           `(let ((ibuffer-tmp-previous-buffer-modification
+                                                   (buffer-modified-p buf)))
+                                              (prog1 ,inner-body
+                                                (when (not (eq ibuffer-tmp-previous-buffer-modification
+                                                               (buffer-modified-p buf)))
+                                                  (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)))))
 
 ;;;###autoload
 (cl-defmacro define-ibuffer-filter (name documentation