From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#15189: 24.3.50; display-buffer does not work well with custom frames. Date: Mon, 26 Aug 2013 13:15:09 -0700 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (generated by - "") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1377548178 21863 80.91.229.3 (26 Aug 2013 20:16:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 26 Aug 2013 20:16:18 +0000 (UTC) Cc: 15189@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 26 22:16:20 2013 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 1VE3D1-0006sM-TH for geb-bug-gnu-emacs@m.gmane.org; Mon, 26 Aug 2013 22:16:20 +0200 Original-Received: from localhost ([::1]:52925 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VE3D1-00010Q-6O for geb-bug-gnu-emacs@m.gmane.org; Mon, 26 Aug 2013 16:16:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VE3Cs-00010I-Qi for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2013 16:16:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VE3Cl-0001Wp-FS for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2013 16:16:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35019) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VE3Cl-0001Wi-5n for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2013 16:16:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VE3Ck-0000c3-FX for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2013 16:16:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 26 Aug 2013 20:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15189 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 15189-submit@debbugs.gnu.org id=B15189.13775481162286 (code B ref 15189); Mon, 26 Aug 2013 20:16:02 +0000 Original-Received: (at 15189) by debbugs.gnu.org; 26 Aug 2013 20:15:16 +0000 Original-Received: from localhost ([127.0.0.1]:57568 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VE3By-0000ak-NR for submit@debbugs.gnu.org; Mon, 26 Aug 2013 16:15:15 -0400 Original-Received: from cobb.liquidweb.com ([50.28.13.150]:54149) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VE3Bv-0000aZ-Ne for 15189@debbugs.gnu.org; Mon, 26 Aug 2013 16:15:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com; s=default; h=Content-Type:MIME-Version:Cc:Subject:To:From:Message-ID:Date; bh=BV0vB33cWEoe+0yEZp34qvDCjr4p6DWpbjrz3U4klHY=; b=BskCt3YsQPHlUFx5XxREbp4yebwfP7CfPWPU/5QT0mQK0bfmMBGDNDaAslW0iJr+IC7UhwJFlZ7TbPyxgQVI0tbr0xKx8gWOGtSMG84oONpZhxdqwAX3HEhfcArwZOVe; Original-Received: from cpe-75-85-5-102.socal.res.rr.com ([75.85.5.102]:52154 helo=MP.local) by cobb.liquidweb.com with esmtp (Exim 4.80.1) (envelope-from ) id 1VE3Br-0006Sa-HA; Mon, 26 Aug 2013 16:15:07 -0400 User-Agent: / () / () APEL/10.8 Emacs/24.3.50 (x86_64-apple-darwin10.8.0) MULE/6.0 (HANACHIRUSATO) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cobb.liquidweb.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-Get-Message-Sender-Via: cobb.liquidweb.com: acl_c_relayhosts_text_entry: lawlist|lawlist.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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:77750 Archived-At: Thank you for the clarification. My goal is to cover the two common types of situations: * File is opened -- creating a new one, or opening one that already exists. * Buffer is created without opening a specific file. It appears that display-buffer-alist ONLY works for some of the no-file buffers, like *Help*. Files that are opened get ignored by the display-buffer-alist. Using your suggestion of find-file-noselect works well with the initial example, and then just adding (switch-to-buffer (get-file-buffer buffer-filename)) to the tail end of the lawlist-display-buffer-function. So, correct please if I wrong, it appears that a different solution is needed for each of the two scenarios. Here is the code that works for display-buffer-alist, but not for actual files being opened. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar system-nofile-regexp nil "Regexps matching `buffer-filename` for frame name `SYSTEM`.") (setq system-nofile-regexp '("\\(\\*Metahelp\\*\\|\\*Help\\*\\)")) (defvar main-nofile-regexp nil "Regexps matching `buffer-filename` for frame name `MAIN`.") (setq main-nofile-regexp '("\\.pdf")) (defvar org-nofile-regexp nil "Regexps matching `buffer-filename` for frame name `ORG`.") (setq org-nofile-regexp '("\\*Org Agenda\\*")) (setq display-buffer-alist `((lawlist-p . (nofile-display-buffer-pop-up-frame)))) (defun lawlist-p (buffer action) (declare (ignore action)) (let ((buffer (get-buffer buffer))) (or (lawlist-regexps-match-p org-nofile-regexp (buffer-name buffer)) (lawlist-regexps-match-p main-nofile-regexp (buffer-name buffer)) (lawlist-regexps-match-p system-nofile-regexp (buffer-name buffer)) ))) (defun nofile-display-buffer-pop-up-frame (buffer alist) (when (lawlist-regexps-match-p org-nofile-regexp (buffer-name buffer)) (if (frame-exists "ORG") (switch-to-frame "ORG") ;; If unnamed frame exists, then take control of it. (catch 'break (dolist (frame (frame-list)) (if (and (not (equal "MAIN" (frame-parameter frame 'name))) (not (equal "SYSTEM" (frame-parameter frame 'name))) (not (equal "ORG" (frame-parameter frame 'name))) (not (equal "WANDERLUST" (frame-parameter frame 'name))) (not (equal "MISCELLANEOUS" (frame-parameter frame 'name))) ) (throw 'break (progn (switch-to-frame (frame-parameter frame 'name)) (set-frame-name "ORG") (toggle-frame-maximized)))))) ;; If dolist found no unnamed frame, then create / name it. (if (not (frame-exists "ORG")) (progn (make-frame) (set-frame-name "ORG") (toggle-frame-maximized))) )) (when (lawlist-regexps-match-p main-nofile-regexp (buffer-name buffer)) (if (frame-exists "MAIN") (switch-to-frame "MAIN") ;; If unnamed frame exists, then take control of it. (catch 'break (dolist (frame (frame-list)) (if (and (not (equal "MAIN" (frame-parameter frame 'name))) (not (equal "SYSTEM" (frame-parameter frame 'name))) (not (equal "ORG" (frame-parameter frame 'name))) (not (equal "WANDERLUST" (frame-parameter frame 'name))) (not (equal "MISCELLANEOUS" (frame-parameter frame 'name))) ) (throw 'break (progn (switch-to-frame (frame-parameter frame 'name)) (set-frame-name "MAIN") (toggle-frame-maximized)))))) ;; If dolist found no unnamed frame, then create / name it. (if (not (frame-exists "MAIN")) (progn (make-frame) (set-frame-name "MAIN") (toggle-frame-maximized))) )) (when (lawlist-regexps-match-p system-nofile-regexp (buffer-name buffer)) (if (frame-exists "SYSTEM") (switch-to-frame "SYSTEM") ;; If unnamed frame exists, then take control of it. (catch 'break (dolist (frame (frame-list)) (if (and (not (equal "MAIN" (frame-parameter frame 'name))) (not (equal "SYSTEM" (frame-parameter frame 'name))) (not (equal "ORG" (frame-parameter frame 'name))) (not (equal "WANDERLUST" (frame-parameter frame 'name))) (not (equal "MISCELLANEOUS" (frame-parameter frame 'name))) ) (throw 'break (progn (switch-to-frame (frame-parameter frame 'name)) (set-frame-name "SYSTEM") (toggle-frame-maximized)))))) ;; If dolist found no unnamed frame, then create / name it. (if (not (frame-exists "SYSTEM")) (progn (make-frame) (set-frame-name "SYSTEM") (toggle-frame-maximized))) )) (when (and (not (lawlist-regexps-match-p org-nofile-regexp (buffer-name buffer))) (not (lawlist-regexps-match-p main-nofile-regexp (buffer-name buffer))) (not (lawlist-regexps-match-p system-nofile-regexp (buffer-name buffer))) ) (if (frame-exists "MISCELLAENOUS") (switch-to-frame "MISCELLAENOUS") ;; If unnamed frame exists, then take control of it. (catch 'break (dolist (frame (frame-list)) (if (and (not (equal "MAIN" (frame-parameter frame 'name))) (not (equal "SYSTEM" (frame-parameter frame 'name))) (not (equal "ORG" (frame-parameter frame 'name))) (not (equal "WANDERLUST" (frame-parameter frame 'name))) (not (equal "MISCELLANEOUS" (frame-parameter frame 'name))) ) (throw 'break (progn (switch-to-frame (frame-parameter frame 'name)) (set-frame-name "MISCELLAENEOUS") (toggle-frame-maximized)))))) ;; If dolist found no unnamed frame, then create / name it. (if (not (frame-exists "MISCELLAENEOUS")) (progn (make-frame) (set-frame-name "MISCELLAENEOUS") (toggle-frame-maximized))))) (if (and (featurep 'init-frames) frame-bufs-mode) (frame-bufs-add-buffer buffer (selected-frame))) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GENERIC FRAME UTILITIES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun frame-exists (frame-name) (not (eq nil (get-frame frame-name)))) (defun get-frame-name (&optional frame) "Return the string that names FRAME (a frame). Default is selected frame." (unless frame (setq frame (selected-frame))) (if (framep frame) (cdr (assq 'name (frame-parameters frame))) (error "Function `get-frame-name': Argument not a frame: `%s'" frame))) (defun get-frame (frame) "Return a frame, if any, named FRAME (a frame or a string). If none, return nil. If FRAME is a frame, it is returned." (cond ((framep frame) frame) ((stringp frame) (catch 'get-a-frame-found (dolist (fr (frame-list)) (when (string= frame (get-frame-name fr)) (throw 'get-a-frame-found fr))) nil)) (t (error "Function `get-frame-name': Arg neither a string nor a frame: `%s'" frame)))) (defun switch-to-frame (frame-name) (let ((frames (frame-list))) (catch 'break (while frames (let ((frame (car frames))) (if (equal (frame-parameter frame 'name) frame-name) (throw 'break (select-frame-set-input-focus frame)) (setq frames (cdr frames)))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; At Mon, 26 Aug 2013 18:34:33 +0200, martin rudalics wrote: > > Please keep 15189@debbugs.gnu.org CCed so others can read your mails > too. > > > Yes, that works now if we also add the following line to the end of > > lawlist-display-buffer-function: (switch-to-buffer (get-file-buffer > > buffer-filename)) > > I'm still not quite sure whether I understand what you want to do. > An idiom like > > (display-buffer > (find-file buffer-filename)) > > is practically always wrong because it usually will (1) display the > buffer via `find-file' which calls `switch-to-buffer' which bypasses > `display-buffer' by calling `set-window-buffer' directly and (2) display > the buffer a second time which might result in reusing the window used > in (1) but may also use another window according to your buffer display > settings. In any case, a doc-string like > > "Locate or create a specific frame, and then open the file." > > is inappropriate because the function nowhere does what you say here. > > > I expected display-buffer to execute the display-buffer-function first > > in time (e.g., before executing find-file), but that is not the case. > > I'm afraid you're confusing things here. `display-buffer' does execute > `display-buffer-function' first but its arguments get evaluated before > its body. This is something you certainly want too because how would > `display-buffer' otherwise know the buffer it is supposed to display? > > > If the purpose of display-buffer is not to execute the > > display-buffer-function first in time (e.g., before executing > > find-file), then I made an erroneous assumption regarding the reason > > for using display-buffer. > > I suppose you made the erroneous assumption that `find-file' does not > display the file's buffer. That's why I suggested to use > `find-file-noselect' instead. Anyway, using `display-buffer-function' > is deprecated since Emacs 24.3 and was hardly used in previous versions. > What you probably want to do is to customize `display-buffer-alist' > instead. > > martin