unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] * lisp/ibuffer.el: Add ability to (un-)mark or delete buffers in the region.
@ 2015-12-12 21:45 foudfou
  2015-12-14 17:33 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: foudfou @ 2015-12-12 21:45 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 518 bytes --]

Hi All,

I recently realized in ibuffer that the region could no be used to select buffers. This can be done only with prefix and at point. Being able to visually select and mark (lots of) buffers in different places in a (big) buffer list is helpful though.

This is what this patch is about. It doesn't change previous behaviors, and just adds the ability to select with the region. For the sake of simplicity, I didn't modify current menu labels, the mode's help, nor renamed the impacted functions.

Cheers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ibuffer.el-Add-ability-to-un-mark-or-delete-buf.patch --]
[-- Type: text/x-patch; name="0001-lisp-ibuffer.el-Add-ability-to-un-mark-or-delete-buf.patch", Size: 3511 bytes --]

From 2f2766f23eec7fedf8b6848bb8a513585562fd3c Mon Sep 17 00:00:00 2001
From: foudfou <foudil.newbie+git@gmail.com>
Date: Sat, 12 Dec 2015 22:06:03 +0100
Subject: [PATCH] * lisp/ibuffer.el: Add ability to (un-)mark or delete buffers
 in the region.

---
 lisp/ibuffer.el | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 89477bd..e8920e0 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -1354,23 +1354,36 @@ ibuffer-toggle-marks
     (message "%s buffers marked" count))
   (ibuffer-redisplay t))
 
-(defun ibuffer-mark-forward (arg)
-  "Mark the buffer on this line, and move forward ARG lines.
+(defsubst ibuffer-get-region-and-prefix ()
+  (let ((arg (prefix-numeric-value current-prefix-arg)))
+    (if (use-region-p) (list (region-beginning) (region-end) arg)
+      (list nil nil arg))))
+
+(defun ibuffer-mark-forward (start end arg)
+  "Mark the buffers in the region, or ARG buffers.
 If point is on a group name, this function operates on that group."
-  (interactive "p")
-  (ibuffer-mark-interactive arg ibuffer-marked-char))
+  (interactive (ibuffer-get-region-and-prefix))
+  (ibuffer-mark-region-or-n-with-char start end arg ibuffer-marked-char))
 
-(defun ibuffer-unmark-forward (arg)
-  "Unmark the buffer on this line, and move forward ARG lines.
+(defun ibuffer-unmark-forward (start end arg)
+  "Unmark the buffers in the region, or ARG buffers.
 If point is on a group name, this function operates on that group."
-  (interactive "p")
-  (ibuffer-mark-interactive arg ?\s))
+  (interactive (ibuffer-get-region-and-prefix))
+  (ibuffer-mark-region-or-n-with-char start end arg ?\s))
 
 (defun ibuffer-unmark-backward (arg)
-  "Unmark the buffer on this line, and move backward ARG lines.
+  "Unmark the ARG previous buffers.
 If point is on a group name, this function operates on that group."
   (interactive "p")
-  (ibuffer-unmark-forward (- arg)))
+  (ibuffer-unmark-forward nil nil (- arg)))
+
+(defun ibuffer-mark-region-or-n-with-char (start end arg mark-char)
+  (if (use-region-p)
+      (let ((cur (point)) (line-count (count-lines start end)))
+        (goto-char start)
+        (ibuffer-mark-interactive line-count mark-char)
+        (goto-char cur))
+      (ibuffer-mark-interactive arg mark-char)))
 
 (defun ibuffer-mark-interactive (arg mark &optional movement)
   (ibuffer-assert-ibuffer-mode)
@@ -1409,16 +1422,16 @@ ibuffer-set-mark-1
 		       (list (ibuffer-current-buffer)
 			     mark))))
 
-(defun ibuffer-mark-for-delete (arg)
-  "Mark the buffers on ARG lines forward for deletion.
+(defun ibuffer-mark-for-delete (start end arg)
+  "Mark for deletion the buffers in the region, or ARG buffers.
 If point is on a group name, this function operates on that group."
-  (interactive "P")
-  (ibuffer-mark-interactive arg ibuffer-deletion-char 1))
+  (interactive (ibuffer-get-region-and-prefix))
+  (ibuffer-mark-region-or-n-with-char start end arg ibuffer-deletion-char))
 
 (defun ibuffer-mark-for-delete-backwards (arg)
-  "Mark the buffers on ARG lines backward for deletion.
+  "Mark for deletion the ARG previous buffers.
 If point is on a group name, this function operates on that group."
-  (interactive "P")
+  (interactive "p")
   (ibuffer-mark-interactive arg ibuffer-deletion-char -1))
 
 (defun ibuffer-current-buffer (&optional must-be-live)
-- 
2.6.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-12-14 20:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-12 21:45 [PATCH] * lisp/ibuffer.el: Add ability to (un-)mark or delete buffers in the region foudfou
2015-12-14 17:33 ` Eli Zaretskii
2015-12-14 18:29   ` John Wiegley
2015-12-14 19:10     ` Drew Adams
2015-12-14 19:52       ` [PATCH] * lisp/ibuffer.el: Add ability to (nu-)mark " John Wiegley
2015-12-14 20:07         ` John Wiegley

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).