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