aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTino Calancha2016-10-03 21:16:00 +0900
committerTino Calancha2016-10-03 21:16:00 +0900
commita7e9d1cce3f935dbe9f242f0bf2dbf34f5919952 (patch)
tree93bb7cf3489fab90f3e03852d03a311a707c0796
parent3b6eb9489d03e5ecc60e487e8eb340e34942825c (diff)
downloademacs-a7e9d1cce3f935dbe9f242f0bf2dbf34f5919952.tar.gz
emacs-a7e9d1cce3f935dbe9f242f0bf2dbf34f5919952.zip
Ibuffer: 'w' and 'B' default to buffer at current line
See discussion in: https://lists.gnu.org/archive/html/emacs-devel/2016-09/msg00384.html * lisp/ibuffer.el (ibuffer--near-buffers): New defun; return buffers near current line. * lisp/ibuf-ext.el (ibuffer-copy-buffername-as-kill): Use it. Add argument ARG; if a non-zero integer, return next ARG buffers. Otherwise return the marked buffers. If there are not marked buffers, return 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.
-rw-r--r--lisp/ibuf-ext.el88
-rw-r--r--lisp/ibuffer.el10
2 files changed, 52 insertions, 46 deletions
diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el
index f93957ecb78..1918ce8c5b6 100644
--- a/lisp/ibuf-ext.el
+++ b/lisp/ibuf-ext.el
@@ -1420,7 +1420,7 @@ This requires the external program \"diff\" to be in your `exec-path'."
1420 1420
1421;;;###autoload 1421;;;###autoload
1422(defun ibuffer-copy-filename-as-kill (&optional arg) 1422(defun ibuffer-copy-filename-as-kill (&optional arg)
1423 "Copy filenames of marked buffers into the kill ring. 1423 "Copy filenames of marked (or next ARG) buffers into the kill ring.
1424 1424
1425The names are separated by a space. 1425The names are separated by a space.
1426If a buffer has no filename, it is ignored. 1426If a buffer has no filename, it is ignored.
@@ -1431,55 +1431,51 @@ With \\[universal-argument], use the filename of each marked file relative
1431to `ibuffer-default-directory' if non-nil, otherwise `default-directory'. 1431to `ibuffer-default-directory' if non-nil, otherwise `default-directory'.
1432 1432
1433You can then feed the file name(s) to other commands with \\[yank]." 1433You can then feed the file name(s) to other commands with \\[yank]."
1434 (interactive "p") 1434 (interactive "P")
1435 (if (zerop (ibuffer-count-marked-lines)) 1435 (let* ((buffers (cond ((and (integerp arg) (not (zerop arg)))
1436 (message "No buffers marked; use 'm' to mark a buffer") 1436 (ibuffer--near-buffers arg))
1437 (let ((result "") 1437 (t
1438 (type (cond ((or (null arg) (zerop arg)) 1438 (or (ibuffer-get-marked-buffers)
1439 'full) 1439 (list (ibuffer-current-buffer))))))
1440 ((= arg 4) 1440 (file-names
1441 'relative) 1441 (mapcar
1442 (t 1442 (lambda (buf)
1443 'name)))) 1443 (let ((name (with-current-buffer buf
1444 (ibuffer-map-marked-lines 1444 (ibuffer-buffer-file-name))))
1445 #'(lambda (buf _mark) 1445 (if (null name)
1446 (setq result 1446 ""
1447 (concat result 1447 (cond ((and (integerp arg) (zerop arg)) name)
1448 (let ((name (buffer-file-name buf))) 1448 ((consp arg)
1449 (cond (name 1449 (file-relative-name
1450 (concat 1450 name (or ibuffer-default-directory
1451 (pcase type 1451 default-directory)))
1452 (`full 1452 (t (file-name-nondirectory name))))))
1453 name) 1453 buffers))
1454 (`relative 1454 (string
1455 (file-relative-name 1455 (mapconcat 'identity (delete "" file-names) " ")))
1456 name (or ibuffer-default-directory 1456 (unless (string= string "")
1457 default-directory))) 1457 (if (eq last-command 'kill-region)
1458 (_ 1458 (kill-append string nil)
1459 (file-name-nondirectory name))) " ")) 1459 (kill-new string))
1460 (t ""))))))) 1460 (message "%s" string))))
1461 (when (not (zerop (length result)))
1462 (setq result
1463 (substring result 0 -1)))
1464 (kill-new result)
1465 (message "%s" result))))
1466 1461
1467;;;###autoload 1462;;;###autoload
1468(defun ibuffer-copy-buffername-as-kill () 1463(defun ibuffer-copy-buffername-as-kill (&optional arg)
1469 "Copy buffer names of marked buffers into the kill ring. 1464 "Copy buffer names of marked (or next ARG) buffers into the kill ring.
1470The names are separated by a space. 1465The names are separated by a space.
1471You can then feed the file name(s) to other commands with \\[yank]." 1466You can then feed the file name(s) to other commands with \\[yank]."
1472 (interactive) 1467 (interactive "P")
1473 (if (zerop (ibuffer-count-marked-lines)) 1468 (let* ((buffers (cond ((and (integerp arg) (not (zerop arg)))
1474 (message "No buffers marked; use 'm' to mark a buffer") 1469 (ibuffer--near-buffers arg))
1475 (let ((res "")) 1470 (t
1476 (ibuffer-map-marked-lines 1471 (or (ibuffer-get-marked-buffers)
1477 #'(lambda (buf _mark) 1472 (list (ibuffer-current-buffer))))))
1478 (setq res (concat res (buffer-name buf) " ")))) 1473 (string (mapconcat #'buffer-name buffers " ")))
1479 (when (not (zerop (length res))) 1474 (unless (string= string "")
1480 (setq res (substring res 0 -1))) 1475 (if (eq last-command 'kill-region)
1481 (kill-new res) 1476 (kill-append string nil)
1482 (message res)))) 1477 (kill-new string))
1478 (message "%s" string))))
1483 1479
1484(defun ibuffer-mark-on-buffer (func &optional ibuffer-mark-on-buffer-mark group) 1480(defun ibuffer-mark-on-buffer (func &optional ibuffer-mark-on-buffer-mark group)
1485 (let ((count 1481 (let ((count
diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index e9655358c26..9becfc9fc78 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -2022,6 +2022,16 @@ the buffer object itself and the current mark symbol."
2022 (ibuffer-forward-line 0) 2022 (ibuffer-forward-line 0)
2023 (ibuffer-forward-line (1- target-line-offset)))))) 2023 (ibuffer-forward-line (1- target-line-offset))))))
2024 2024
2025;; Return buffers around current line.
2026(defun ibuffer--near-buffers (n)
2027 (delq nil
2028 (mapcar
2029 (lambda (x)
2030 (car (get-text-property
2031 (line-beginning-position (if (natnump n) x (- (1- x))))
2032 'ibuffer-properties)))
2033 (number-sequence 1 (abs n)))))
2034
2025(defun ibuffer-get-marked-buffers () 2035(defun ibuffer-get-marked-buffers ()
2026 "Return a list of buffer objects currently marked." 2036 "Return a list of buffer objects currently marked."
2027 (delq nil 2037 (delq nil