From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: David Beswick Newsgroups: gmane.emacs.bugs Subject: bug#29999: `initial-buffer-choice' function can result in duplicate buffer display Date: Sat, 6 Jan 2018 11:36:40 +1100 Message-ID: <5594011c-2604-8cc1-036e-8f828aaf73c8@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1515198929 4988 195.159.176.226 (6 Jan 2018 00:35:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 6 Jan 2018 00:35:29 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 To: 29999@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 06 01:35:24 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1eXcS8-0000Aj-A4 for geb-bug-gnu-emacs@m.gmane.org; Sat, 06 Jan 2018 01:35:12 +0100 Original-Received: from localhost ([::1]:38361 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXcU5-00061s-No for geb-bug-gnu-emacs@m.gmane.org; Fri, 05 Jan 2018 19:37:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXcTz-00061M-2x for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2018 19:37:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXcTv-0000xE-0P for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2018 19:37:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56988) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eXcTu-0000wl-MX for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2018 19:37:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eXcTu-0004YA-Eu for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2018 19:37:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: David Beswick Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Jan 2018 00:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 29999 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.151519902117482 (code B ref -1); Sat, 06 Jan 2018 00:37:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jan 2018 00:37:01 +0000 Original-Received: from localhost ([127.0.0.1]:37436 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXcTt-0004Xt-Ck for submit@debbugs.gnu.org; Fri, 05 Jan 2018 19:37:01 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:50770) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXcTr-0004Xg-Hg for submit@debbugs.gnu.org; Fri, 05 Jan 2018 19:36:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXcTk-0000nm-Ve for submit@debbugs.gnu.org; Fri, 05 Jan 2018 19:36:54 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:44818) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eXcTk-0000nB-Ob for submit@debbugs.gnu.org; Fri, 05 Jan 2018 19:36:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41734) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXcTj-0005vd-9S for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2018 19:36:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXcTf-0000f3-1E for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2018 19:36:51 -0500 Original-Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:41324) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eXcTe-0000dU-Jp for bug-gnu-emacs@gnu.org; Fri, 05 Jan 2018 19:36:46 -0500 Original-Received: by mail-pl0-x244.google.com with SMTP id g2so4031970pli.8 for ; Fri, 05 Jan 2018 16:36:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=GXgO9ZQlE1S8ouMcDOV+zWaV3WwhD2Y3HE9+nBmJduY=; b=gE98z4kDVc8KtnqjRNVEYcR1IXFNZz6EL3UpOSxuZdslUpZykDCFdJz58lXYZ//Fp2 nhRgKFIe6FqoExKKL4XqJiM4tgOQY/ccyYfibMIvAqhnEBq2GbVXawgTcSnwP1i31Ym1 7FuFrV66KiWktzueT5+TerRrFQuCA93Nwk1I9WIqkwv90lI/2AJ6O7nAP+jTx4C7ZPFX 19C+l6iaIVI3l8UEdNVHIRUfHTU0EiwPKKPAinAb1wI56XOQSbwxTHDrGWoAHwFk0Avz VznAsWyWO6yc95f0xP1eAhhiZjzZg9PmMzM9ROczUFdDtMCWwyEPge6bzuJqo07yLYIq s9xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=GXgO9ZQlE1S8ouMcDOV+zWaV3WwhD2Y3HE9+nBmJduY=; b=iooKtCUATzLzKKOD4cmi4gd5K7Gg+ObwYge7bpSOsoWYkZMhAcB7JHg1bpTeoa6o3y sOg2GtmfZDIQFTJwAu33EjNGngsP/0avrqeqHMIXrs4OYEt+qlnmgwui34h9aIJjHHkr R7sjIINdvBQWqLdGCYszGDRn04YQ7giMo/h3DIpZnhVuBQvPBGddlT85hOll5UDssyjm C0OG0O5c8cFjFPc4/fG+Upw1v3JNCiyP8Ff/JiYBifPINvQuWahmXC/ZwhZEDq9zRckq 6qsvR0TNibr6QTlLDSnIXozA/TBDxsBuep/Z7SzHLGwUR5KfWcu3WyHt8JhV/vbF5Int XlkQ== X-Gm-Message-State: AKGB3mLHeAPBqKRTJaXFRvl9/yVJG161fv5e0KEWCAg3Ixhyo+hk+mZJ xVQrDB+mfauOg/CVeGxN7oKEdg== X-Google-Smtp-Source: ACJfBosNgx5sYgXRkWxzkrJ1dkolSFRWJPWkxr/ofCtIBht9AZQMqx8ljZMLwmUPV1Qf2H1Vp3FVyQ== X-Received: by 10.84.252.10 with SMTP id x10mr4601187pll.289.1515199004655; Fri, 05 Jan 2018 16:36:44 -0800 (PST) Original-Received: from [192.168.178.61] (210-84-53-66.dyn.iinet.net.au. [210.84.53.66]) by smtp.googlemail.com with ESMTPSA id l80sm13989564pfk.67.2018.01.05.16.36.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jan 2018 16:36:43 -0800 (PST) Content-Language: en-AU X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:141821 Archived-At: Hello, just a minor bug relating to the behaviour of startup.el's `command-line-1' and the `initial-buffer-choice' variable. When an `initial-buffer-choice' function returns the head of the `displayable-buffers' list in `command-line-1' then Emacs starts with that same buffer visited in two windows. I would expect it should only be shown in a single window. To be concrete, I ran into this behavior as on startup I wanted to display a particular buffer that I create except when a file is given on the command line. In that case I want to visit the given file instead. The behavior can be reproduced by creating a file `bug-init.el': (require 'seq) (setq initial-buffer-choice       (lambda () (seq-some (lambda (b)                              (with-current-buffer b                                (and buffer-file-name b)))                            (buffer-list)))) And then running this command: $ emacs -Q -l bug-init.el bug-init.el On startup, bug-init.el will be visited in two different windows. My fix: ---  lisp/startup.el | 9 +++++++--  1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lisp/startup.el b/lisp/startup.el index 2855e7c31c..cef9108cdf 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -2486,7 +2486,12 @@ command-line-1           (insert (substitute-command-keys initial-scratch-message))           (set-buffer-modified-p nil)))) -    ;; Prepend `initial-buffer-choice' to `displayable-buffers'. +    ;; Prepend `initial-buffer-choice' to `displayable-buffers'. If +    ;; the buffer is already a member of that list then shift the +    ;; buffer to the head of the list. The shift behavior is intended +    ;; to prevent the same buffer being displayed in two windows when +    ;; an `initial-buffer-choice' function happens to return the head +    ;; of `displayable-buffers'.      (when initial-buffer-choice        (let ((buf               (cond ((stringp initial-buffer-choice) @@ -2499,7 +2504,7 @@ command-line-1                      (error "initial-buffer-choice must be a string, a function, or t.")))))          (unless (buffer-live-p buf)            (error "initial-buffer-choice is not a live buffer.")) -        (setq displayable-buffers (cons buf displayable-buffers)))) +        (setq displayable-buffers (cons buf (delq buf displayable-buffers)))))      ;; Display the first two buffers in `displayable-buffers'. If      ;; `initial-buffer-choice' is non-nil, its buffer will be the -- 2.14.1