GNU bug report logs - #29999
`initial-buffer-choice' function can result in duplicate buffer display

Previous Next

Package: emacs;

Reported by: David Beswick <dlbeswick <at> gmail.com>

Date: Sat, 6 Jan 2018 00:37:02 UTC

Severity: minor

Tags: fixed

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 29999 in the body.
You can then email your comments to 29999 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#29999; Package emacs. (Sat, 06 Jan 2018 00:37:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to David Beswick <dlbeswick <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 06 Jan 2018 00:37:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: David Beswick <dlbeswick <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: `initial-buffer-choice' function can result in duplicate buffer
 display
Date: Sat, 6 Jan 2018 11:36:40 +1100
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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29999; Package emacs. (Tue, 17 Apr 2018 21:56:01 GMT) Full text and rfc822 format available.

Message #8 received at 29999 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: David Beswick <dlbeswick <at> gmail.com>
Cc: 29999 <at> debbugs.gnu.org
Subject: Re: bug#29999: `initial-buffer-choice' function can result in
 duplicate buffer display
Date: Tue, 17 Apr 2018 23:55:47 +0200
David Beswick <dlbeswick <at> gmail.com> writes:

> 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':

Thanks; I've applied your patch to Emacs 27.1.

But a note about the patch: It had been mangled by your mailer (all the
spaces had been turned into non-breaking space), so I had to do it by
hand, but hopefully I got it right.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 17 Apr 2018 21:56:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 29999 <at> debbugs.gnu.org and David Beswick <dlbeswick <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 17 Apr 2018 21:56:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 16 May 2018 11:24:12 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 115 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.