unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: foudfou <foudil.newbie@gmail.com>
To: emacs-devel@gnu.org
Subject: [PATCH] * lisp/ibuffer.el: Add ability to (un-)mark or delete buffers in the region.
Date: Sat, 12 Dec 2015 22:45:09 +0100	[thread overview]
Message-ID: <566C9565.2000300@gmail.com> (raw)

[-- 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


             reply	other threads:[~2015-12-12 21:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-12 21:45 foudfou [this message]
2015-12-14 17:33 ` [PATCH] * lisp/ibuffer.el: Add ability to (un-)mark or delete buffers in the region 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=566C9565.2000300@gmail.com \
    --to=foudil.newbie@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).