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: Ibuffer: w and B default to buffer at current line Date: Wed, 14 Sep 2016 14:35:12 +0900 (JST) Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-812021647-1473831315=:19349" X-Trace: blaine.gmane.org 1473831916 4606 195.159.176.226 (14 Sep 2016 05:45:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Sep 2016 05:45:16 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: tino.calancha@gmail.com To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 14 07:45:12 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 1bk30R-0000gD-F4 for ged-emacs-devel@m.gmane.org; Wed, 14 Sep 2016 07:45:11 +0200 Original-Received: from localhost ([::1]:53196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bk30P-0004ty-Gv for ged-emacs-devel@m.gmane.org; Wed, 14 Sep 2016 01:45:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bk2rt-00072D-2V for emacs-devel@gnu.org; Wed, 14 Sep 2016 01:36:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bk2ro-0003lB-Si for emacs-devel@gnu.org; Wed, 14 Sep 2016 01:36:20 -0400 Original-Received: from mail-pa0-f52.google.com ([209.85.220.52]:35692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bk2ro-0003kz-Jh for emacs-devel@gnu.org; Wed, 14 Sep 2016 01:36:16 -0400 Original-Received: by mail-pa0-f52.google.com with SMTP id b2so1808694pat.2 for ; Tue, 13 Sep 2016 22:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:date:to:cc:subject:message-id:user-agent:mime-version; bh=cFL85XRWtI/J5W6OnI28LeMB4ncu8ARdpRHwTavnqGs=; b=i6i5n8Xp3XFbOISyPbXje1jw4mPH8wqyIzp+SiDMXEsB6rclruFRJvHg79TvywVdno M0lkKipsY4HskeTclReXurK6XR5ScFS7xynSThUaRi3U7G+6VV3y7+BwHTh0o59kEbdP XUQ7gw9UnZnBbCOZPfW+wTFaRG2PL8k8zxlJiWmu22xEo00crOPR5iGDqgshaRDZPF5A zYmuQN9YhlpIdVBKnieB/+789BQMVLbccGm7Q2/TNeODRJmRBmYC/Y1U0BCniMOYpMFZ LDfjXvSWszVW/axnoJekSNWmOOOgNN+oTST8maGSxmAVwUJlnN4J4zYJqYxxvDhY4J9m 3Fig== 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:message-id:user-agent :mime-version; bh=cFL85XRWtI/J5W6OnI28LeMB4ncu8ARdpRHwTavnqGs=; b=JJT5UZyXsltXap86flnCdb+j1ZvaVhVcactRJg/vPkKs0sIWTo3O3oM/vjJa6P9bKp vw2kr/LFCDrX3au9M25HrAML4H+WSOXPDioTMFqI43pXrO/+Dwp7+/IeSZO8tjZIPYyq pSvLjn5DWJXnMn7Wcwztu453NOUlpQpaM4XjwEg2B06nZlMb6COgzTZhM0JcbDdYD9+w b8MchPpytyEyFMrFK2kqux5UVofPddNRNA/9CHzW0SbQwR3N++5gxphlKU7mtcUZ9M74 Nszdu2yuN3hKr9tDVqWvKcka5SO0MRAbQI75al2xiMXBW9HYwdyypGA/zni6pEQ/tJrD bBrQ== X-Gm-Message-State: AE9vXwNvUBO+i4TdQrL7JvgBjD6od6Ur57Ry9YAJ2p3PfnEGe0o+xj6dRctJfGKj8CEqqQ== X-Received: by 10.66.245.177 with SMTP id xp17mr1267834pac.118.1473831315894; Tue, 13 Sep 2016 22:35:15 -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 y2sm2079498pan.31.2016.09.13.22.35.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Sep 2016 22:35:15 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.52 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:207427 Archived-At: --8323329-812021647-1473831315=:19349 Content-Type: text/plain; format=flowed; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT 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 --8323329-812021647-1473831315=:19349--