From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.bugs Subject: bug#11556: 24.0.97; Strange behaviour of bury-buffer after desktop-read Date: Sun, 27 May 2012 15:20:00 +0200 Message-ID: <4FC22A00.3030608@gmx.at> References: <4FBF47E7.1000300@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080500040206030308060403" X-Trace: dough.gmane.org 1338124861 26355 80.91.229.3 (27 May 2012 13:21:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 27 May 2012 13:21:01 +0000 (UTC) Cc: 11556@debbugs.gnu.org To: Tobias Bading Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun May 27 15:21:00 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SYdOz-00047b-AQ for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 May 2012 15:20:57 +0200 Original-Received: from localhost ([::1]:43277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYdOz-00049A-0J for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 May 2012 09:20:57 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:51760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYdOv-00048z-4r for bug-gnu-emacs@gnu.org; Sun, 27 May 2012 09:20:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SYdOs-0000O3-Pc for bug-gnu-emacs@gnu.org; Sun, 27 May 2012 09:20:52 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SYdOs-0000Nx-Lc for bug-gnu-emacs@gnu.org; Sun, 27 May 2012 09:20:50 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SYdQ2-0005ZQ-0z for bug-gnu-emacs@gnu.org; Sun, 27 May 2012 09:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: martin rudalics Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 27 May 2012 13:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11556 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11556-submit@debbugs.gnu.org id=B11556.133812487421357 (code B ref 11556); Sun, 27 May 2012 13:22:01 +0000 Original-Received: (at 11556) by debbugs.gnu.org; 27 May 2012 13:21:14 +0000 Original-Received: from localhost ([127.0.0.1]:45346 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SYdPF-0005YP-II for submit@debbugs.gnu.org; Sun, 27 May 2012 09:21:14 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.22]:54184) by debbugs.gnu.org with smtp (Exim 4.72) (envelope-from ) id 1SYdPC-0005YC-Vw for 11556@debbugs.gnu.org; Sun, 27 May 2012 09:21:12 -0400 Original-Received: (qmail invoked by alias); 27 May 2012 13:19:52 -0000 Original-Received: from 62-47-61-97.adsl.highway.telekom.at (EHLO [62.47.61.97]) [62.47.61.97] by mail.gmx.net (mp024) with SMTP; 27 May 2012 15:19:52 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX181uFpEN/Q1IEj0YDncmxuDnYDQs4eW6jhmNlA9/i PoGC3B14IftIme In-Reply-To: <4FBF47E7.1000300@web.de> X-Y-GMX-Trusted: 0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:60396 Archived-At: This is a multi-part message in MIME format. --------------080500040206030308060403 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > I recently switched from Emacs 23 to the current version on the emacs-24 > branch (r108014) and bumped into a strange behaviour of bury-buffer at > the start of a session. I'm using desktop.el and (global-set-key "\C-xy" > 'bury-buffer) in .emacs (because I have a bad memory and like to bury > stuff ;-). Every time I start Emacs, I see the correct buffer, i.e. the > one I used before I closed Emacs previously. This is accomplished by this form (switch-to-buffer (car (buffer-list))) in `desktop-read'. > I edit that buffer a bit > and bury it. In my case, bury-buffer switches to the wrong buffer. > Instead of switching to the buffer next in line (so to speak), > bury-buffer switches to what seems to be the last buffer in the list of > all buffers. > > Here's a little example in form of a "emacs -Q" recipe: > 3 C-x C-s 3 RET > C-x b 2 RET > 2 C-x C-s 2 RET > C-x b 1 RET > 1 C-x C-s 1 RET > M-x desktop-save > > This should leave you with with three saved buffers in the order 1-2-3 > and a desktop file. C-x C-b should be able to confirm the buffer order. > > Now close Emacs, start a fresh one and M-x desktop-read your desktop > file. You should see buffer 1. So far, so good. Now M-x bury-buffer. I'd > expect to see buffer 2 now, instead Emacs switched to buffer 3. If you > C-x C-b now, you'll see that the buffer list says that buffer 2 is up > front, although you're staring at buffer 3. This bug hits you only at > the very beginning of a session. I can continue to bury buffers using > C-x y and end up with buffers apparently from the end of the buffer > list, instead of from the top. What happens is this: The buffer section of .emacs.desktop lists buffers "in same order as in buffer list". Processing these in your case means processing 1 then 2 then 3. `desktop-restore-file-buffer', which is implicitly called in this process, switches to 1, 2 and 3 in this order in the selected window. This means that the last buffer shown in the window is 3. After that, the above mentioned `switch-to-buffer' from `desktop-read' switches to buffer 1. Burying that buffer shows the last buffer shown in the selected window which is 3 and not 2 as expected. > But some actions fix this, like switching > a buffer once using C-x b. Afterwards the bug is nowhere to be found. Since the corruption happens once only when processing .emacs.desktop. > The last few days I started work with a strange > I-could-swear-that-wasnt-the-file-I-was-working-on-yesterday-before-I-went-home > feeling :-D. Any ideas on how to get rid of that feeling are very > welcome :-). The bug is obviously a regression with respect to Emacs 23.1 so we should fix it. One possible approach is to remove the buffer switching done in `desktop-restore-file-buffer' which apparently should have the sole reason to affect the buffer list while somehow preserving the history of buffers that have been shown before calling `desktop-read'. But I'm completely ignorant of desktop's handling of the buffer list which involves some 14 calls to `bury-buffer' for restoring just three buffers here. If someone competent in this area could tell us how to simplify this, I'd be all ears. Eventually, we should handle this when restoring the windows from the previous session but the question remains how to handle previously shown buffers correctly when doing `desktop-read' in the middle of a session. Meanwhile I can offer the attached brute force fix which kills the individual history of all windows but should leave the buffer lists in place. Note that I have to manually bury the *Messages* buffer because it's in the way as well when burying buffer 1. All this is very ugly but I can't think of a better fix without a rather complete rewrite of desktop's handling of the buffer lists. martin --------------080500040206030308060403 Content-Type: text/plain; name="desktop.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="desktop.diff" *** lisp/desktop.el 2012-05-13 03:05:06 +0000 --- lisp/desktop.el 2012-05-27 10:52:53 +0000 *************** *** 1020,1025 **** --- 1020,1037 ---- (format ", %d to restore lazily" (length desktop-buffer-args-list)) "")) + ;; Bury the *Messages* buffer to not reshow it when burying + ;; the buffer we switched to above. + (when (buffer-live-p (get-buffer "*Messages*")) + (bury-buffer "*Messages*")) + ;; Clear all windows' previous and next buffers, these have + ;; been corrupted by the `switch-to-buffer' calls in + ;; `desktop-restore-file-buffer' (bug#1156). This is a + ;; brute force fix and should be replaced by a more subtle + ;; strategy eventually. + (walk-window-tree (lambda (window) + (set-window-prev-buffers window nil) + (set-window-next-buffers window nil))) t)) ;; No desktop file found. (desktop-clear) --------------080500040206030308060403--