From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.bugs Subject: bug#10144: 24.0.91; `pop-up-frames' with dedicated windows is broken: `C-x C-f' Date: Mon, 28 Nov 2011 07:30:24 -0800 Message-ID: References: <42F11A5C92E54694A1779211C6EF56FE@us.oracle.com><4ED13A80.70408@gmx.at><4ED213D4.8070400@gmx.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1322494285 12174 80.91.229.12 (28 Nov 2011 15:31:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 28 Nov 2011 15:31:25 +0000 (UTC) Cc: 10144@debbugs.gnu.org To: "'Stefan Monnier'" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Nov 28 16:31:20 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RV3At-0008W2-Gx for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Nov 2011 16:31:19 +0100 Original-Received: from localhost ([::1]:57954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RV3Aq-0001ZV-Er for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Nov 2011 10:31:16 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:46173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RV3Aj-0001Ys-Bq for bug-gnu-emacs@gnu.org; Mon, 28 Nov 2011 10:31:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RV3Ah-0003qA-M1 for bug-gnu-emacs@gnu.org; Mon, 28 Nov 2011 10:31:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41033) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RV3Ah-0003q5-Ef for bug-gnu-emacs@gnu.org; Mon, 28 Nov 2011 10:31:07 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1RV3CX-0005Jv-UV for bug-gnu-emacs@gnu.org; Mon, 28 Nov 2011 10:33:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "Drew Adams" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Nov 2011 15:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10144 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10144-submit@debbugs.gnu.org id=B10144.132249435620419 (code B ref 10144); Mon, 28 Nov 2011 15:33:01 +0000 Original-Received: (at 10144) by debbugs.gnu.org; 28 Nov 2011 15:32:36 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RV3C8-0005JI-0W for submit@debbugs.gnu.org; Mon, 28 Nov 2011 10:32:36 -0500 Original-Received: from rcsinet15.oracle.com ([148.87.113.117]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RV3C6-0005JA-6P for 10144@debbugs.gnu.org; Mon, 28 Nov 2011 10:32:35 -0500 Original-Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pASFUbAU014879 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 28 Nov 2011 15:30:38 GMT Original-Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pASFUaUH008643 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 Nov 2011 15:30:36 GMT Original-Received: from abhmt112.oracle.com (abhmt112.oracle.com [141.146.116.64]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id pASFUUmS029297; Mon, 28 Nov 2011 09:30:31 -0600 Original-Received: from dradamslap1 (/10.159.44.97) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Nov 2011 07:30:30 -0800 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Thread-Index: Acyth3aqwk8wQZV8Qpi45q0TDZH0qgAVJOzw X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-CT-RefId: str=0001.0A090206.4ED3A91E.010A,ss=1,re=0.594,fgs=0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 28 Nov 2011 10:33:01 -0500 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:54364 Archived-At: > > emacs -Q > > C-x d some-dir > > M-x set-variable pop-up-frames t > > (set-window-dedicated-p (selected-window) t) > > RET ; on some file name > > > In Emacs 24 you get the error "Cannot switch...". > > In Emacs-24 and Emacs-21 and Emacs-22. No, only in Emacs 24 - but with my setup only, it seems (see below). With the recipe above, you are right. But with my setup, the original problem I reported occurs only for (recent) Emacs 24. Actually, with only the original recipe I gave, in the older releases *info* is not even shown as a special-display buffer, and its window is not dedicated (why?). So in that regard, that original recipe was also not complete for older versions. With the original recipe, why *info* is not dedicated, in spite of the settings (non-nil `pop-up-frames', `special-display-regexps' matching *info*, *info* removed from `same-window-regexps'), I don't know and don't have time to check now. But in my setup that is what I see in all Emacs versions except 24: the file is simply visited in a separate frame. See below for the likely reason. > > In previous releases the chosen file is visited in another frame. > > You mean in Emacs-23 only. No, I meant in all Emacs versions prior to 24 (with my setup). And in 24 too, back when Martin's code was used. > > Dedicated windows should be primarily about making Emacs > > use a different window/frame. They should not just prevent > > showing the file altogether, by raising an error. > > If the user uses find-file rather than find-file-other-window, she > presumably knows what she's doing. That's why (one reason) the user set `pop-up-frames' to non-nil. ;-) `find-file' in a non-dedicated window should use the same window. In a dedicated window it should (IMO) visit the file somewhere else (another window or, if non-nil `pop-up-frames' then another frame). What's the point of such an error message when Emacs could DTRT and show the user the buffer s?he asked to see? And as Martin pointed out, it is not only about C-x C-f, but `find-file' in general. More generally than that, it is about dedicated windows: trying to reuse a dedicated window should (IMO) just cause another window to be used. What's the point of such an error message? I can imagine that there might be special cases, e.g. the minibuffer, that would be problematic, but in general the buffer should (IMO) be shown, but in another window/frame. And I've had exactly that behavior for decades, with no special-casing and no problems. --- OK, I haven't looked in detail, but I did take a quick look, and it's likely that my setup works the way it does because, for versions < 24, I redefine `switch-to-buffer' so that if the current window is dedicated then another window is used. In Emacs 24 I haven't done that (didn't need to, so far). Here is the code: (if (< emacs-major-version 24) ;; REPLACES ORIGINAL (built-in): ;; 1) Use `read-buffer' in interactive spec. ;; 2) If current window is dedicated, then use another window. ;; NOTE: Emacs versions >= 19.34 signal error if dedicated window, instead ;; of using another one. Don't know what the 19.28 version did. ;; 3) Resize frame to fit sole window if `autofit-frames-flag' ;; (unless BUFFER is already the `current-buffer'). (defun switch-to-buffer (buffer &optional norecord) "Select buffer BUFFER in current window, unless the window is dedicated. If current window is dedicated (`window-dedicated-p'), then another window is used. BUFFER may be a buffer, a string (a buffer name), or nil. If BUFFER is a string that does not identify an existing buffer, then a new buffer with that name is created. If BUFFER is nil, then function `other-buffer' is used to choose a buffer. Optional second arg NORECORD non-nil means do not put BUFFER at the front of the list of recently selected buffers. The buffer switched to is returned. *WARNING*: This is NOT the way to work on another buffer temporarily within a Lisp program! Use `set-buffer' instead, to avoid messing with correspondences between windows and buffers. Resize frame to fit sole window if `autofit-frames-flag' \(unless BUFFER is already the `current-buffer')." (interactive (list (read-buffer "Switch to buffer: " (if (fboundp 'another-buffer) ; In `misc-fns.el'. (another-buffer nil t) (other-buffer (current-buffer)))))) ;; If string arg, convert to a buffer. If nil, use `other-buffer'. (setq buffer (if buffer (get-buffer-create buffer) (other-buffer))) (let ((orig-buf (current-buffer))) (prog1 (if (window-dedicated-p (selected-window)) (switch-to-buffer-other-window buffer) (old-switch-to-buffer buffer norecord)) (and (one-window-p t) (not (eq buffer orig-buf)) ; Don't resize if same buffer. autofit-frames-flag (fit-frame))))) ;; REPLACES ORIGINAL (built-in): ;; ;; Resize frame to fit sole window if `autofit-frames-flag' ;; (unless BUFFER is already the `current-buffer'). ;; (defun switch-to-buffer (buffer-or-name &optional norecord force-same-window) "Switch to buffer BUFFER-OR-NAME in the selected window. Return the buffer switched to. If called interactively, prompt for the buffer name using the minibuffer. The variable `confirm-nonexistent-file-or-buffer' determines whether to request confirmation before creating a new buffer. BUFFER-OR-NAME may be a buffer, a string (a buffer name), or nil. If BUFFER-OR-NAME is a string that does not identify an existing buffer, create a buffer with that name. If BUFFER-OR-NAME is nil, switch to the buffer returned by `other-buffer'. Optional argument NORECORD non-nil means do not put the buffer specified by BUFFER-OR-NAME at the front of the buffer list and do not make the window displaying it the most recently selected one. If FORCE-SAME-WINDOW is non-nil, BUFFER-OR-NAME must be displayed in the selected window. Signal an error if that is impossible (e.g. if the selected window is minibuffer-only). If nil, BUFFER-OR-NAME may be displayed in another window." (interactive (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window)) (let ((orig-buf (current-buffer)) (switch-buf (old-switch-to-buffer buffer-or-name norecord force-same-window))) (when (and (one-window-p t) (not (eq switch-buf orig-buf)) ; Don't resize if same buffer. autofit-frames-flag (fit-frame))) switch-buf))) --- For my part, I will try tweaking my setup to make it work with Emacs 24. But you might also want to consider doing what I do. I think users would prefer to have the buffer shown to them than to just see an error message about window dedication. I can at least testify that that behavior has been natural and helpful to me, for decades now.