From: Keith David Bershatsky <esq@lawlist.com>
To: martin rudalics <rudalics@gmx.at>
Cc: 15189@debbugs.gnu.org
Subject: bug#15189: 24.3.50; display-buffer does not work well with custom frames.
Date: Mon, 26 Aug 2013 13:15:09 -0700 [thread overview]
Message-ID: <m2a9k41a5u.wl%esq@lawlist.com> (raw)
In-Reply-To: <m2li3pcm1o.wl%esq@lawlist.com>
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
next prev parent reply other threads:[~2013-08-26 20:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-26 0:50 bug#15189: 24.3.50; display-buffer does not work well with custom frames Keith David Bershatsky
2013-08-26 13:06 ` martin rudalics
[not found] ` <4066A3F6-AB96-43EE-B8F4-E3DF2F73CBD2@lawlist.com>
2013-08-26 15:01 ` martin rudalics
[not found] ` <521B6B84.5060106@gmx.at>
[not found] ` <742F02FA-4469-4BCA-94A5-D8A7A679B52B@lawlist.com>
2013-08-26 16:34 ` martin rudalics
2013-08-26 20:15 ` Keith David Bershatsky [this message]
2013-08-27 6:47 ` martin rudalics
2013-08-28 3:59 ` Kevin Rodgers
2013-08-28 16:35 ` Keith David Bershatsky
2013-08-29 0:21 ` Keith David Bershatsky
2013-08-27 22:30 ` Keith David Bershatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2a9k41a5u.wl%esq@lawlist.com \
--to=esq@lawlist.com \
--cc=15189@debbugs.gnu.org \
--cc=rudalics@gmx.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).