From 56c8551219ecace0157ce813733adf8eecb38c32 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Fri, 8 Jul 2016 17:22:56 +0900 Subject: [PATCH] Copy buffer names to kill ring * ibuf-ext.el (ibuffer-copy-buffername-as-kill): New command. * lisp/ibuffer (ibuffer-mode-map): Bound it to 'B'. ;* etc/NEWS: Add entry for this new feature. --- etc/NEWS | 4 ++++ lisp/ibuf-ext.el | 17 +++++++++++++++++ lisp/ibuffer.el | 1 + 3 files changed, 22 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index f9fbe03e08..54b62f02ee 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -198,6 +198,10 @@ same as in modes where the character is not whitespace. ** Ibuffer +--- +*** A new command 'ibuffer-copy-buffername-as-kill'; bound +to 'B'. + --- *** New command 'ibuffer-change-marks'; bound to '* c'. diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el index 2444dac580..6102e1f740 100644 --- a/lisp/ibuf-ext.el +++ b/lisp/ibuf-ext.el @@ -1462,6 +1462,23 @@ You can then feed the file name(s) to other commands with \\[yank]." (kill-new result) (message "%s" result)))) +;;;###autoload +(defun ibuffer-copy-buffername-as-kill () + "Copy buffer names of marked buffers into the kill ring. +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)))) + (defun ibuffer-mark-on-buffer (func &optional ibuffer-mark-on-buffer-mark group) (let ((count (ibuffer-map-lines diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el index fde17573dd..37f72bc1aa 100644 --- a/lisp/ibuffer.el +++ b/lisp/ibuffer.el @@ -586,6 +586,7 @@ directory, like `default-directory'." (define-key map (kbd "k") 'ibuffer-do-kill-lines) (define-key map (kbd "w") 'ibuffer-copy-filename-as-kill) + (define-key map (kbd "B") 'ibuffer-copy-buffername-as-kill) (define-key map (kbd "RET") 'ibuffer-visit-buffer) (define-key map (kbd "e") 'ibuffer-visit-buffer) -- 2.39.2