From: Tino Calancha <tino.calancha@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Cc: tino.calancha@gmail.com
Subject: Ibuffer: w and B default to buffer at current line
Date: Wed, 14 Sep 2016 14:35:12 +0900 (JST) [thread overview]
Message-ID: <alpine.DEB.2.20.1609141431030.19349@calancha-pc> (raw)
[-- Attachment #1: Type: text/plain, Size: 8176 bytes --]
Hi,
i would like to apply following two patches.
I)
* lisp/ibuffer.el (ibuffer-get-marked-buffers):
Add an optional parameter BUFFER-AT-LINE: if non-nil and
there are no marked buffers, return the buffer at current line.
II)
Ibuffer: 'w' and 'B' default to the buffer at current line.
This is similar as dired-copy-filename-as-kill.
Before this patch, when there are no marked buffers
these commands signal an error:
"No buffers marked; use ’m’ to mark a buffer".
Append to kill ring when last command was a kill-region,
like in Dired.
Please, let me know if you have any concern about these patches.
Regards,
Tino
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From 2ede73551f974022ef30c9198940a8ec10d6dd5a Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Wed, 14 Sep 2016 13:46:03 +0900
Subject: [PATCH 1/2] ibuffer-get-marked-buffers: Default to buffer at
current
line
* lisp/ibuffer.el (ibuffer-get-marked-buffers):
Added optional arg BUFFER-AT-LINE: if non-nil and
there are no marked buffers, then return a list with
the buffer at current line.
(lisp/ibuffer.el): Use ibuffer-get-marked-buffers with non-nil argument.
* lisp/ibuf-ext.el (ibuffer-diff-with-file): Idem.
---
lisp/ibuf-ext.el | 4 +---
lisp/ibuffer.el | 26 ++++++++++++++++----------
2 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index f93957e..c4e37cb 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -1402,9 +1402,7 @@ ibuffer-diff-with-file
This requires the external program \"diff\" to be in your `exec-path'."
(interactive)
(require 'diff)
- (let ((marked-bufs (ibuffer-get-marked-buffers)))
- (when (null marked-bufs)
- (setq marked-bufs (list (ibuffer-current-buffer t))))
+ (let ((marked-bufs (ibuffer-get-marked-buffers 'buffer-at-line)))
(with-current-buffer (get-buffer-create "*Ibuffer Diff*")
(setq buffer-read-only nil)
(buffer-disable-undo (current-buffer))
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index 8e24629..3915a30 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -1143,9 +1143,7 @@ ibuffer-do-view-horizontally
(ibuffer-do-view-1 (if other-frame 'other-frame 'horizontally)))
(defun ibuffer-do-view-1 (type)
- (let ((marked-bufs (ibuffer-get-marked-buffers)))
- (when (null marked-bufs)
- (setq marked-bufs (list (ibuffer-current-buffer t))))
+ (let ((marked-bufs (ibuffer-get-marked-buffers 'buffer-at-line)))
(unless (and (eq type 'other-frame)
(not ibuffer-expert)
(> (length marked-bufs) 3)
@@ -2020,13 +2018,21 @@ ibuffer-map-lines
(ibuffer-forward-line 0)
(ibuffer-forward-line (1- target-line-offset))))))
-(defun ibuffer-get-marked-buffers ()
- "Return a list of buffer objects currently marked."
- (delq nil
- (mapcar (lambda (e)
- (when (eq (cdr e) ibuffer-marked-char)
- (car e)))
- (ibuffer-current-state-list))))
+(defun ibuffer-get-marked-buffers (&optional buffer-at-line)
+ "Return a list of buffer objects currently marked.
+If optional arg BUFFER-AT-LINE is non-nil and there are
+no marked buffers, then return a list with the buffer
+at current line, if any."
+ (let ((buffers
+ (delq nil
+ (mapcar (lambda (e)
+ (when (eq (cdr e) ibuffer-marked-char)
+ (car e)))
+ (ibuffer-current-state-list)))))
+ (when (and (null buffers)
+ buffer-at-line
+ (ibuffer-current-buffer))
+ (setq buffers (list (ibuffer-current-buffer)))) buffers))
(defun ibuffer-current-state-list (&optional pos)
"Return a list like (BUF . MARK) of all buffers in an ibuffer.
--
2.9.3
From 2372eec587229008bcb7babaffc383dd750ff8ac Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Wed, 14 Sep 2016 14:14:20 +0900
Subject: [PATCH 2/2] Ibuffer: 'w' and 'B' default to buffer at current
line
* lisp/ibuf-ext.el (ibuffer-copy-buffername-as-kill):
If there are not marked buffers, use buffer at current line
without prompting the user. Use ibuffer-get-marked-buffers
instead of ibuffer-map-marked-lines.
Append to kill ring when last command was a kill-region.
(ibuffer-copy-filename-as-kill): Idem.
Simplify the code.
Use ibuffer-buffer-file-name instead of buffer-file-name to
include buffers in Dired mode.
---
lisp/ibuf-ext.el | 70
+++++++++++++++++++++++---------------------------------
1 file changed, 29 insertions(+), 41 deletions(-)
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index c4e37cb..29a9349 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -1430,37 +1430,27 @@ ibuffer-copy-filename-as-kill
You can then feed the file name(s) to other commands with \\[yank]."
(interactive "p")
- (if (zerop (ibuffer-count-marked-lines))
- (message "No buffers marked; use 'm' to mark a buffer")
- (let ((result "")
- (type (cond ((or (null arg) (zerop arg))
- 'full)
- ((= arg 4)
- 'relative)
- (t
- 'name))))
- (ibuffer-map-marked-lines
- #'(lambda (buf _mark)
- (setq result
- (concat result
- (let ((name (buffer-file-name buf)))
- (cond (name
- (concat
- (pcase type
- (`full
- name)
- (`relative
- (file-relative-name
- name (or ibuffer-default-directory
- default-directory)))
- (_
- (file-name-nondirectory name))) "
"))
- (t "")))))))
- (when (not (zerop (length result)))
- (setq result
- (substring result 0 -1)))
- (kill-new result)
- (message "%s" result))))
+ (let* ((file-names
+ (mapcar
+ (lambda (buf)
+ (let ((name (with-current-buffer buf
+ (ibuffer-buffer-file-name))))
+ (if (null name)
+ ""
+ (cond ((or (null arg) (zerop arg)) name)
+ ((= arg 4)
+ (file-relative-name
+ name (or ibuffer-default-directory
+ default-directory)))
+ (t (file-name-nondirectory name))))))
+ (ibuffer-get-marked-buffers 'buffer-at-line)))
+ (string
+ (mapconcat 'identity (delete "" file-names) " ")))
+ (unless (string= string "")
+ (if (eq last-command 'kill-region)
+ (kill-append string nil)
+ (kill-new string))
+ (message "%s" string))))
;;;###autoload
(defun ibuffer-copy-buffername-as-kill ()
@@ -1468,16 +1458,14 @@ ibuffer-copy-buffername-as-kill
The names are separated by a space.
You can then feed the file name(s) to other commands with \\[yank]."
(interactive)
- (if (zerop (ibuffer-count-marked-lines))
- (message "No buffers marked; use 'm' to mark a buffer")
- (let ((res ""))
- (ibuffer-map-marked-lines
- #'(lambda (buf _mark)
- (setq res (concat res (buffer-name buf) " "))))
- (when (not (zerop (length res)))
- (setq res (substring res 0 -1)))
- (kill-new res)
- (message res))))
+ (let ((string
+ (mapconcat #'buffer-name
+ (ibuffer-get-marked-buffers 'buffer-at-line) " ")))
+ (unless (string= string "")
+ (if (eq last-command 'kill-region)
+ (kill-append string nil)
+ (kill-new string))
+ (message "%s" string))))
(defun ibuffer-mark-on-buffer (func &optional ibuffer-mark-on-buffer-mark
group)
(let ((count
--
2.9.3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.21.5)
of 2016-09-14
Repository revision: 3b9cbacf6110daf7cb2a838e28afef1e4f5ff831
next reply other threads:[~2016-09-14 5:35 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-14 5:35 Tino Calancha [this message]
2016-09-14 6:41 ` Ibuffer: w and B default to buffer at current line John Wiegley
2016-09-14 7:21 ` Tino Calancha
2016-09-14 14:08 ` Drew Adams
2016-09-15 22:05 ` John Wiegley
2016-09-16 6:40 ` Eli Zaretskii
[not found] ` <<83intw5our.fsf@gnu.org>
2016-09-16 14:53 ` Drew Adams
2016-09-17 16:30 ` John Wiegley
2016-09-17 17:21 ` Eli Zaretskii
2016-09-17 21:35 ` John Wiegley
2016-09-17 23:26 ` Drew Adams
2016-09-17 23:51 ` John Wiegley
2016-09-18 1:45 ` Drew Adams
2016-09-18 2:18 ` John Wiegley
2016-09-18 14:26 ` Eli Zaretskii
2016-09-18 19:35 ` John Wiegley
[not found] ` <<83zin630i9.fsf@gnu.org>
2016-09-17 18:47 ` Drew Adams
2016-09-17 19:25 ` Eli Zaretskii
[not found] ` <<83vaxuib1p.fsf@gnu.org>
2016-09-17 19:33 ` Drew Adams
2016-09-18 14:29 ` Eli Zaretskii
[not found] ` <<d33a60f5-b8b6-4637-b3e6-ea1b09d98f85@default>
[not found] ` <<83poo1i8nf.fsf@gnu.org>
2016-09-18 17:55 ` naming functions [was: Ibuffer: w and B default to buffer at current line] Drew Adams
2016-09-18 19:23 ` John Wiegley
2016-09-18 23:24 ` Drew Adams
2016-09-19 16:35 ` Eli Zaretskii
2016-09-17 18:22 ` Ibuffer: w and B default to buffer at current line Tino Calancha
2016-09-26 12:08 ` Tino Calancha
2016-10-03 12:28 ` Tino Calancha
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=alpine.DEB.2.20.1609141431030.19349@calancha-pc \
--to=tino.calancha@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).