From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: Re: Ibuffer: w and B default to buffer at current line Date: Sun, 18 Sep 2016 03:22:09 +0900 (JST) Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1474136660 20744 195.159.176.226 (17 Sep 2016 18:24:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 17 Sep 2016 18:24:20 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: Eli Zaretskii , tino.calancha@gmail.com, drew.adams@oracle.com, Emacs developers To: John Wiegley Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 17 20:24:13 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1blKHc-0004Lx-9B for ged-emacs-devel@m.gmane.org; Sat, 17 Sep 2016 20:24:12 +0200 Original-Received: from localhost ([::1]:47063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blKHZ-0007fR-By for ged-emacs-devel@m.gmane.org; Sat, 17 Sep 2016 14:24:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blKGo-0007ea-Tl for emacs-devel@gnu.org; Sat, 17 Sep 2016 14:23:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1blKGl-0006mo-Kb for emacs-devel@gnu.org; Sat, 17 Sep 2016 14:23:21 -0400 Original-Received: from mail-pf0-f170.google.com ([209.85.192.170]:36685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blKGg-0006lG-F2; Sat, 17 Sep 2016 14:23:14 -0400 Original-Received: by mail-pf0-f170.google.com with SMTP id q2so17209174pfj.3; Sat, 17 Sep 2016 11:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=pNnVQdDMLRRHrgv8mbX3QoGL/Lk0aY1e8Hb0yPEebpE=; b=A+LVjhQbjD3woWumI65e0ao7TKwCHD6+mbtYm73DGDJEyyi+1otUqnKs4T6s0UlUlx 8w012T41xK/2Ubn1x4VQYa0VFU+dghAAovV61exNVjYbcgwqaqodNFWywG5ar/oPl9pl 6nW7XJuw/2ZwSQtuSPQdvy+FQG9452lEyIcuouXN6vmPECAzZ4QaC5SLpwxl6UqUKfwZ M+rwLSbKPHQAqMX6J4Cztk5BABm/YmZxV+YWNIvg7R7+l/qrgZJNq6fxDlOwTwmZonE9 mbclJz7Kgr7Dm6omUTcSMwaoZkoUaNyNHF3n5G5J3b2/yPFoSb5FuEAahfZBlGhFpZbx m7Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=pNnVQdDMLRRHrgv8mbX3QoGL/Lk0aY1e8Hb0yPEebpE=; b=PE+wt1fm2/WZk1onW6B4Gm3L4BMaI2VsJX7O5J7oa7xms7H8hlVaTTABtOu5GB1Gpi hrTSpo2GzBbT3NIJagOONDbLLR2JtuGfsTHuXlKbHoj6sktS/7DM9ODIgGObnptzlNzt cO2qJ1zgkfk4wOK/15TigGsvNn/PgG2vAyNrxfQbYgOJ7ztO/tPquhzQaExn4CPU4qJg v5cMG3NziJji2+c4vLsD4T+lnvZlkCBDs1N6Ofu//MlERORdMeqFrc57XiAXHSfwJITS 2o4XrBlQ6U4kDy0BMHTjX949ogkugDtyC76qzgvrZdkzHFmP5Ix0EmAPeRhhIuL/8AAG zYZg== X-Gm-Message-State: AE9vXwM2RAJfXPKjavsT33IH4tVA42jTmexDqAEns3Ub80RadbYAFl4v4y6GQ26n7JCwwQ== X-Received: by 10.98.33.146 with SMTP id o18mr19657357pfj.177.1474136533495; Sat, 17 Sep 2016 11:22:13 -0700 (PDT) Original-Received: from calancha-pc (57.92.100.220.dy.bbexcite.jp. [220.100.92.57]) by smtp.gmail.com with ESMTPSA id ci9sm20556933pad.34.2016.09.17.11.22.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Sep 2016 11:22:12 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.170 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207497 Archived-At: On Tue, 13 Sep 2016, John Wiegley wrote: >>>>>> "TC" == Tino Calancha writes: > > TC> * lisp/ibuffer.el (ibuffer-get-marked-buffers): > TC> Add an optional parameter BUFFER-AT-LINE: if non-nil and > TC> there are no marked buffers, return the buffer at current line. > > Hi Tino, > > I don't like this part of your proposed change. The name of the function is > `ibuffer-get-marked-buffers'. Adding a new argument to change the meaning of > the function is not a good idea. Hi John, After Drew comments i realized something useful was still missing in my previous patch: a non-zero integer ARG should use the next (or previous if ARG is negative) buffers, regardless if there are marked buffers. That is the behaviour in `dired-copy-filename-as-kill'. I want to support the same in `ibuffer-copy-filename-as-kill' (i-c-f-a-k) and `ibuffer-copy-buffername-as-kill' (i-c-b-a-k). I have prepared to patches `D' and `W': the former follows DWIM, the later follows your suggestion. `D': * 2 files changed, 65 insertions(+), 58 deletions(-) `W': * 2 files changed, 52 insertions(+), 46 deletions(-) I don't have any preference for one or the other. Both provide the same behaviour, so i am fine to push the one that people here prefer. Best regards, Tino ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; patch `D' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From a06c406a5cd7da5c645c5365229144525fe55783 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Sun, 18 Sep 2016 02:40:08 +0900 Subject: [PATCH] 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 point. (ibuffer-get-marked-buffers): Use it. Add argument ARG; if a non-zero integer, return next ARG files. Add argument BUFFER-AT-LINE; if non-nil, and there are no marked files, return the buffer at current line. (ibuffer-do-view-horizontally): Call ibuffer-get-marked-buffers with non-nil second argument. * lisp/ibuf-ext.el (ibuffer-diff-with-file): Idem. (ibuffer-copy-buffername-as-kill): Add argument ARG; if an integer, return next ARG files. Otherwise, return the marked files. 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 | 84 +++++++++++++++++++++++--------------------------------- lisp/ibuffer.el | 39 ++++++++++++++++++++------ 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el index f93957e..ad5298a 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 nil 'buffer-at-line))) (with-current-buffer (get-buffer-create "*Ibuffer Diff*") (setq buffer-read-only nil) (buffer-disable-undo (current-buffer)) @@ -1420,7 +1418,7 @@ ibuffer-diff-with-file ;;;###autoload (defun ibuffer-copy-filename-as-kill (&optional arg) - "Copy filenames of marked buffers into the kill ring. + "Copy filenames of marked (or next ARG) buffers into the kill ring. The names are separated by a space. If a buffer has no filename, it is ignored. @@ -1431,55 +1429,43 @@ ibuffer-copy-filename-as-kill to `ibuffer-default-directory' if non-nil, otherwise `default-directory'. 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)))) + (interactive "P") + (let* ((file-names + (mapcar + (lambda (buf) + (let ((name (with-current-buffer buf + (ibuffer-buffer-file-name)))) + (if (null name) + "" + (cond ((and (integerp arg) (zerop arg)) name) + ((consp arg) + (file-relative-name + name (or ibuffer-default-directory + default-directory))) + (t (file-name-nondirectory name)))))) + (ibuffer-get-marked-buffers arg '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 () - "Copy buffer names of marked buffers into the kill ring. +(defun ibuffer-copy-buffername-as-kill (&optional arg) + "Copy buffer names of marked (or next ARG) 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)))) + (interactive "P") + (let ((string + (mapconcat #'buffer-name + (ibuffer-get-marked-buffers arg '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 diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el index 0336f1d..859b595 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 nil 'buffer-at-line))) (unless (and (eq type 'other-frame) (not ibuffer-expert) (> (length marked-bufs) 3) @@ -2022,13 +2020,36 @@ 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." +;; Return buffers around current line. +(defun ibuffer--near-buffers (n) (delq nil - (mapcar (lambda (e) - (when (eq (cdr e) ibuffer-marked-char) - (car e))) - (ibuffer-current-state-list)))) + (mapcar + (lambda (x) + (car (get-text-property + (line-beginning-position (if (natnump n) x (- (1- x)))) + 'ibuffer-properties))) + (number-sequence 1 (abs n))))) + +(defun ibuffer-get-marked-buffers (&optional arg buffer-at-line) + "Return a list of buffer objects currently marked. +Optional argument ARG, if non-nil, specifies buffers near + point instead of marked buffers. It usually comes from the prefix + argument. + If ARG is an integer, use the next ARG files. +If no files are marked, and BUFFER-AT-LINE is non-nil return the buffer at +current line." + (let ((buffers + (cond ((and (integerp arg) (not (zerop arg))) + (ibuffer--near-buffers arg)) + (t + (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) + (setq buffers (list (ibuffer-current-buffer 'live)))) buffers)) (defun ibuffer-current-state-list (&optional pos) "Return a list like (BUF . MARK) of all buffers in an ibuffer. -- 2.9.3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; patch `W' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 179f608832c2de1fbbba11d4bb1b0c9064d73d2f Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Sun, 18 Sep 2016 02:42:20 +0900 Subject: [PATCH] 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 point. * 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. --- lisp/ibuf-ext.el | 88 +++++++++++++++++++++++++++----------------------------- lisp/ibuffer.el | 10 +++++++ 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/lisp/ibuf-ext.el b/lisp/ibuf-ext.el index f93957e..1918ce8 100644 --- a/lisp/ibuf-ext.el +++ b/lisp/ibuf-ext.el @@ -1420,7 +1420,7 @@ ibuffer-diff-with-file ;;;###autoload (defun ibuffer-copy-filename-as-kill (&optional arg) - "Copy filenames of marked buffers into the kill ring. + "Copy filenames of marked (or next ARG) buffers into the kill ring. The names are separated by a space. If a buffer has no filename, it is ignored. @@ -1431,55 +1431,51 @@ ibuffer-copy-filename-as-kill to `ibuffer-default-directory' if non-nil, otherwise `default-directory'. 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)))) + (interactive "P") + (let* ((buffers (cond ((and (integerp arg) (not (zerop arg))) + (ibuffer--near-buffers arg)) + (t + (or (ibuffer-get-marked-buffers) + (list (ibuffer-current-buffer)))))) + (file-names + (mapcar + (lambda (buf) + (let ((name (with-current-buffer buf + (ibuffer-buffer-file-name)))) + (if (null name) + "" + (cond ((and (integerp arg) (zerop arg)) name) + ((consp arg) + (file-relative-name + name (or ibuffer-default-directory + default-directory))) + (t (file-name-nondirectory name)))))) + buffers)) + (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 () - "Copy buffer names of marked buffers into the kill ring. +(defun ibuffer-copy-buffername-as-kill (&optional arg) + "Copy buffer names of marked (or next ARG) 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)))) + (interactive "P") + (let* ((buffers (cond ((and (integerp arg) (not (zerop arg))) + (ibuffer--near-buffers arg)) + (t + (or (ibuffer-get-marked-buffers) + (list (ibuffer-current-buffer)))))) + (string (mapconcat #'buffer-name buffers " "))) + (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 diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el index 0336f1d..fca8ba3 100644 --- a/lisp/ibuffer.el +++ b/lisp/ibuffer.el @@ -2022,6 +2022,16 @@ ibuffer-map-lines (ibuffer-forward-line 0) (ibuffer-forward-line (1- target-line-offset)))))) +;; Return buffers around current line. +(defun ibuffer--near-buffers (n) + (delq nil + (mapcar + (lambda (x) + (car (get-text-property + (line-beginning-position (if (natnump n) x (- (1- x)))) + 'ibuffer-properties))) + (number-sequence 1 (abs n))))) + (defun ibuffer-get-marked-buffers () "Return a list of buffer objects currently marked." (delq nil -- 2.9.3 In GNU Emacs 25.1.50.1 Repository revision: d7f0daf7ecaa7b138f7c66796e23fa5982b0a8bb