diff options
| author | Martin Rudalics | 2011-06-19 11:59:58 +0200 |
|---|---|---|
| committer | Martin Rudalics | 2011-06-19 11:59:58 +0200 |
| commit | fbf5b3ce9d95a61c06ebf09ee58c809469d71387 (patch) | |
| tree | 388f373e544b96a6fe12cd151ca20064f15f5aa0 | |
| parent | 61e6a0aceb7914e50a4e343e50365c939ab00de9 (diff) | |
| download | emacs-fbf5b3ce9d95a61c06ebf09ee58c809469d71387.tar.gz emacs-fbf5b3ce9d95a61c06ebf09ee58c809469d71387.zip | |
Sanitize processing of display specifiers; new option frame-auto-delete.
* window.el (display-buffer-other-window-means-other-frame):
Call display-buffer-normalize-alist.
(display-buffer-normalize-specifiers-1): Rename to
display-buffer-normalize-argument. New argument other-frame.
Rewrite.
(display-buffer-normalize-specifiers-2): Rename to
display-buffer-normalize-options.
(display-buffer-normalize-alist-1): New function.
(display-buffer-normalize-specifiers-3): Rename to
display-buffer-normalize-alist. Call
display-buffer-normalize-alist-1.
(display-buffer-normalize-options-inhibit): New variable.
(display-buffer-normalize-specifiers): Rewrite calling
display-buffer-normalize-alist,
display-buffer-normalize-argument, and
display-buffer-normalize-options. Don't call the latter if
display-buffer-normalize-options-inhibit is non-nil.
(frame-auto-delete): New option.
(window-deletable-p): Use frame-auto-delete.
| -rw-r--r-- | lisp/ChangeLog | 22 | ||||
| -rw-r--r-- | lisp/window.el | 136 |
2 files changed, 120 insertions, 38 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e1a23e53649..281c73528b2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,25 @@ | |||
| 1 | 2011-06-19 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | * window.el (display-buffer-other-window-means-other-frame): | ||
| 4 | Call display-buffer-normalize-alist. | ||
| 5 | (display-buffer-normalize-specifiers-1): Rename to | ||
| 6 | display-buffer-normalize-argument. New argument other-frame. | ||
| 7 | Rewrite. | ||
| 8 | (display-buffer-normalize-specifiers-2): Rename to | ||
| 9 | display-buffer-normalize-options. | ||
| 10 | (display-buffer-normalize-alist-1): New function. | ||
| 11 | (display-buffer-normalize-specifiers-3): Rename to | ||
| 12 | display-buffer-normalize-alist. Call | ||
| 13 | display-buffer-normalize-alist-1. | ||
| 14 | (display-buffer-normalize-options-inhibit): New variable. | ||
| 15 | (display-buffer-normalize-specifiers): Rewrite calling | ||
| 16 | display-buffer-normalize-alist, | ||
| 17 | display-buffer-normalize-argument, and | ||
| 18 | display-buffer-normalize-options. Don't call the latter if | ||
| 19 | display-buffer-normalize-options-inhibit is non-nil. | ||
| 20 | (frame-auto-delete): New option. | ||
| 21 | (window-deletable-p): Use frame-auto-delete. | ||
| 22 | |||
| 1 | 2011-06-18 Chong Yidong <cyd@stupidchicken.com> | 23 | 2011-06-18 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 24 | ||
| 3 | * emacs-lisp/rx.el (rx-constituents): Add support for numbered | 25 | * emacs-lisp/rx.el (rx-constituents): Add support for numbered |
diff --git a/lisp/window.el b/lisp/window.el index 211d8573e0c..454aa6e2941 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -2244,6 +2244,28 @@ and no others." | |||
| 2244 | (next-window base-window (if nomini 'arg) all-frames)))) | 2244 | (next-window base-window (if nomini 'arg) all-frames)))) |
| 2245 | 2245 | ||
| 2246 | ;;; Deleting windows. | 2246 | ;;; Deleting windows. |
| 2247 | (defcustom frame-auto-delete 'automatic | ||
| 2248 | "If non-nil, quitting a window can delete it's frame. | ||
| 2249 | If this variable is nil, functions that quit a window never | ||
| 2250 | delete the associated frame. If this variable equals the symbol | ||
| 2251 | `automatic', a frame is deleted only if it the window is | ||
| 2252 | dedicated or was created by `display-buffer'. If this variable | ||
| 2253 | is t, a frame can be always deleted, even if it was created by | ||
| 2254 | `make-frame-command'. Other values should not be used. | ||
| 2255 | |||
| 2256 | Note that a frame will be effectively deleted if and only if | ||
| 2257 | another frame still exists. | ||
| 2258 | |||
| 2259 | Functions quitting a window and consequently affected by this | ||
| 2260 | variable are `switch-to-prev-buffer', `delete-windows-on', | ||
| 2261 | `replace-buffer-in-windows' and `quit-restore-window'." | ||
| 2262 | :type '(choice | ||
| 2263 | (const :tag "Never" nil) | ||
| 2264 | (const :tag "Automatic" automatic) | ||
| 2265 | (const :tag "Always" t)) | ||
| 2266 | :group 'windows | ||
| 2267 | :group 'frames) | ||
| 2268 | |||
| 2247 | (defun window-deletable-p (&optional window) | 2269 | (defun window-deletable-p (&optional window) |
| 2248 | "Return t if WINDOW can be safely deleted from its frame. | 2270 | "Return t if WINDOW can be safely deleted from its frame. |
| 2249 | Return `frame' if deleting WINDOW should delete its frame | 2271 | Return `frame' if deleting WINDOW should delete its frame |
| @@ -2259,9 +2281,12 @@ instead." | |||
| 2259 | (quit-restore (window-parameter window 'quit-restore))) | 2281 | (quit-restore (window-parameter window 'quit-restore))) |
| 2260 | (cond | 2282 | (cond |
| 2261 | ((frame-root-window-p window) | 2283 | ((frame-root-window-p window) |
| 2262 | (when (and (or dedicated | 2284 | (when (and (or (eq frame-auto-delete t) |
| 2263 | (and (eq (car-safe quit-restore) 'new-frame) | 2285 | (and (eq frame-auto-delete 'automatic) |
| 2264 | (eq (nth 1 quit-restore) (window-buffer window)))) | 2286 | (or dedicated |
| 2287 | (and (eq (car-safe quit-restore) 'new-frame) | ||
| 2288 | (eq (nth 1 quit-restore) | ||
| 2289 | (window-buffer window)))))) | ||
| 2265 | (other-visible-frames-p frame)) | 2290 | (other-visible-frames-p frame)) |
| 2266 | ;; WINDOW is the root window of its frame. Return `frame' but | 2291 | ;; WINDOW is the root window of its frame. Return `frame' but |
| 2267 | ;; only if WINDOW is (1) either dedicated or quit-restore's car | 2292 | ;; only if WINDOW is (1) either dedicated or quit-restore's car |
| @@ -4940,6 +4965,19 @@ SPECIFIERS must be a list of buffer display specifiers." | |||
| 4940 | (set-window-parameter window 'window-slot slot)) | 4965 | (set-window-parameter window 'window-slot slot)) |
| 4941 | (display-buffer-in-window buffer window specifiers))))) | 4966 | (display-buffer-in-window buffer window specifiers))))) |
| 4942 | 4967 | ||
| 4968 | (defun normalize-buffer-to-display (buffer-or-name) | ||
| 4969 | "Normalize BUFFER-OR-NAME argument for buffer display functions. | ||
| 4970 | If BUFFER-OR-NAME is nil, return the curent buffer. Else, if a | ||
| 4971 | buffer specified by BUFFER-OR-NAME exists, return that buffer. | ||
| 4972 | If no such buffer exists, create a buffer with the name | ||
| 4973 | BUFFER-OR-NAME and return that buffer." | ||
| 4974 | (if buffer-or-name | ||
| 4975 | (or (get-buffer buffer-or-name) | ||
| 4976 | (let ((buffer (get-buffer-create buffer-or-name))) | ||
| 4977 | (set-buffer-major-mode buffer) | ||
| 4978 | buffer)) | ||
| 4979 | (current-buffer))) | ||
| 4980 | |||
| 4943 | (defun display-buffer-other-window-means-other-frame (buffer-or-name &optional label) | 4981 | (defun display-buffer-other-window-means-other-frame (buffer-or-name &optional label) |
| 4944 | "Return non-nil if BUFFER shall be preferably displayed in another frame. | 4982 | "Return non-nil if BUFFER shall be preferably displayed in another frame. |
| 4945 | BUFFER must be a live buffer or the name of a live buffer. | 4983 | BUFFER must be a live buffer or the name of a live buffer. |
| @@ -4954,30 +4992,17 @@ Optional argument LABEL is like the same argument of | |||
| 4954 | The calculation of the return value is exclusively based on the | 4992 | The calculation of the return value is exclusively based on the |
| 4955 | user preferences expressed in `display-buffer-alist'." | 4993 | user preferences expressed in `display-buffer-alist'." |
| 4956 | (let* ((buffer (normalize-live-buffer buffer-or-name)) | 4994 | (let* ((buffer (normalize-live-buffer buffer-or-name)) |
| 4957 | (list (display-buffer-normalize-specifiers-3 | 4995 | (list (display-buffer-normalize-alist (buffer-name buffer) label)) |
| 4958 | (buffer-name buffer) label)) | ||
| 4959 | (value (assq 'other-window-means-other-frame | 4996 | (value (assq 'other-window-means-other-frame |
| 4960 | (or (car list) (cdr list))))) | 4997 | (or (car list) (cdr list))))) |
| 4961 | (when value (cdr value)))) | 4998 | (when value (cdr value)))) |
| 4962 | 4999 | ||
| 4963 | (defun normalize-buffer-to-display (buffer-or-name) | 5000 | (defun display-buffer-normalize-argument (buffer-name specifiers label other-frame) |
| 4964 | "Normalize BUFFER-OR-NAME argument for buffer display functions. | 5001 | "Normalize second argument of `display-buffer'. |
| 4965 | If BUFFER-OR-NAME is nil, return the curent buffer. Else, if a | 5002 | BUFFER-NAME is the name of the buffer that shall be displayed, |
| 4966 | buffer specified by BUFFER-OR-NAME exists, return that buffer. | 5003 | SPECIFIERS is the second argument of `display-buffer'. LABEL the |
| 4967 | If no such buffer exists, create a buffer with the name | 5004 | same argument of `display-buffer'. OTHER-FRAME non-nil means use |
| 4968 | BUFFER-OR-NAME and return that buffer." | 5005 | other-frame for other-windo." |
| 4969 | (if buffer-or-name | ||
| 4970 | (or (get-buffer buffer-or-name) | ||
| 4971 | (let ((buffer (get-buffer-create buffer-or-name))) | ||
| 4972 | (set-buffer-major-mode buffer) | ||
| 4973 | buffer)) | ||
| 4974 | (current-buffer))) | ||
| 4975 | |||
| 4976 | (defun display-buffer-normalize-specifiers-1 (specifiers buffer-name label) | ||
| 4977 | "Subroutine of `display-buffer-normalize-specifiers'. | ||
| 4978 | SPECIFIERS is a list of buffer display specfiers. BUFFER-NAME is | ||
| 4979 | the name of the buffer that shall be displayed, LABEL the same | ||
| 4980 | argument of `display-buffer'." | ||
| 4981 | (let (normalized entry) | 5006 | (let (normalized entry) |
| 4982 | (cond | 5007 | (cond |
| 4983 | ((not specifiers) | 5008 | ((not specifiers) |
| @@ -4990,10 +5015,10 @@ argument of `display-buffer'." | |||
| 4990 | (setq normalized (cons specifier normalized))) | 5015 | (setq normalized (cons specifier normalized))) |
| 4991 | ((eq specifier 'other-window) | 5016 | ((eq specifier 'other-window) |
| 4992 | ;; `other-window' must be treated separately. | 5017 | ;; `other-window' must be treated separately. |
| 4993 | (let* ((other-frame (display-buffer-other-window-means-other-frame | 5018 | (let ((entry (assq (if other-frame |
| 4994 | buffer-name label)) | 5019 | 'other-frame |
| 4995 | (entry (assq (if other-frame 'other-frame 'other-window) | 5020 | 'other-window) |
| 4996 | display-buffer-macro-specifiers))) | 5021 | display-buffer-macro-specifiers))) |
| 4997 | (dolist (item (cdr entry)) | 5022 | (dolist (item (cdr entry)) |
| 4998 | (setq normalized (cons item normalized))))) | 5023 | (setq normalized (cons item normalized))))) |
| 4999 | ((symbolp specifier) | 5024 | ((symbolp specifier) |
| @@ -5008,15 +5033,14 @@ argument of `display-buffer'." | |||
| 5008 | ((setq entry (assq specifiers display-buffer-macro-specifiers)) | 5033 | ((setq entry (assq specifiers display-buffer-macro-specifiers)) |
| 5009 | ;; A macro specifier. | 5034 | ;; A macro specifier. |
| 5010 | (cdr entry)) | 5035 | (cdr entry)) |
| 5011 | ((or (display-buffer-other-window-means-other-frame buffer-name label) | 5036 | ((or other-frame (with-no-warnings pop-up-frames)) |
| 5012 | (with-no-warnings pop-up-frames)) | ||
| 5013 | ;; Pop up another frame. | 5037 | ;; Pop up another frame. |
| 5014 | (cdr (assq 'other-frame display-buffer-macro-specifiers))) | 5038 | (cdr (assq 'other-frame display-buffer-macro-specifiers))) |
| 5015 | (t | 5039 | (t |
| 5016 | ;; In any other case pop up a new window. | 5040 | ;; In any other case pop up a new window. |
| 5017 | (cdr (assq 'same-frame-other-window display-buffer-macro-specifiers)))))) | 5041 | (cdr (assq 'same-frame-other-window display-buffer-macro-specifiers)))))) |
| 5018 | 5042 | ||
| 5019 | (defun display-buffer-normalize-specifiers-2 (&optional buffer-or-name) | 5043 | (defun display-buffer-normalize-options (buffer-or-name) |
| 5020 | "Subroutine of `display-buffer-normalize-specifiers'. | 5044 | "Subroutine of `display-buffer-normalize-specifiers'. |
| 5021 | BUFFER-OR-NAME is the buffer to display. This routine provides a | 5045 | BUFFER-OR-NAME is the buffer to display. This routine provides a |
| 5022 | compatibility layer for the now obsolete Emacs 23 buffer display | 5046 | compatibility layer for the now obsolete Emacs 23 buffer display |
| @@ -5127,8 +5151,37 @@ options." | |||
| 5127 | 5151 | ||
| 5128 | specifiers))) | 5152 | specifiers))) |
| 5129 | 5153 | ||
| 5130 | (defun display-buffer-normalize-specifiers-3 (buffer-name label) | 5154 | (defun display-buffer-normalize-alist-1 (specifiers label) |
| 5131 | "Subroutine of `display-buffer-normalize-specifiers'." | 5155 | "Subroutine of `display-buffer-normalize-alist'. |
| 5156 | SPECIFIERS is a list of buffer display specfiers. LABEL is the | ||
| 5157 | same argument of `display-buffer'." | ||
| 5158 | (let (normalized entry) | ||
| 5159 | (cond | ||
| 5160 | ((not specifiers) | ||
| 5161 | nil) | ||
| 5162 | ((listp specifiers) | ||
| 5163 | ;; If SPECIFIERS is a list, we assume it is a list of specifiers. | ||
| 5164 | (dolist (specifier specifiers) | ||
| 5165 | (cond | ||
| 5166 | ((consp specifier) | ||
| 5167 | (setq normalized (cons specifier normalized))) | ||
| 5168 | ((symbolp specifier) | ||
| 5169 | ;; Might be a macro specifier, try to expand it (the cdr is a | ||
| 5170 | ;; list and we have to reverse it later, so do it one at a | ||
| 5171 | ;; time). | ||
| 5172 | (let ((entry (assq specifier display-buffer-macro-specifiers))) | ||
| 5173 | (dolist (item (cdr entry)) | ||
| 5174 | (setq normalized (cons item normalized))))))) | ||
| 5175 | ;; Reverse list. | ||
| 5176 | (nreverse normalized)) | ||
| 5177 | ((setq entry (assq specifiers display-buffer-macro-specifiers)) | ||
| 5178 | ;; A macro specifier. | ||
| 5179 | (cdr entry))))) | ||
| 5180 | |||
| 5181 | (defun display-buffer-normalize-alist (buffer-name label) | ||
| 5182 | "Normalize `display-buffer-alist'. | ||
| 5183 | BUFFER-NAME must be the name of the buffer that shall be displayed. | ||
| 5184 | LABEL the corresponding argument of `display-buffer'." | ||
| 5132 | (let (list-1 list-2) | 5185 | (let (list-1 list-2) |
| 5133 | (dolist (entry display-buffer-alist) | 5186 | (dolist (entry display-buffer-alist) |
| 5134 | (when (and (listp entry) | 5187 | (when (and (listp entry) |
| @@ -5143,10 +5196,10 @@ options." | |||
| 5143 | (string-match-p value buffer-name)) | 5196 | (string-match-p value buffer-name)) |
| 5144 | (and (eq type 'label) (eq value label))) | 5197 | (and (eq type 'label) (eq value label))) |
| 5145 | (throw 'match t))))))) | 5198 | (throw 'match t))))))) |
| 5146 | (let* ((raw (cdr entry)) | 5199 | (let* ((specifiers (cdr entry)) |
| 5147 | (normalized | 5200 | (normalized |
| 5148 | (display-buffer-normalize-specifiers-1 raw buffer-name label))) | 5201 | (display-buffer-normalize-alist-1 specifiers label))) |
| 5149 | (if (assq 'override raw) | 5202 | (if (assq 'override specifiers) |
| 5150 | (setq list-1 | 5203 | (setq list-1 |
| 5151 | (if list-1 | 5204 | (if list-1 |
| 5152 | (append list-1 normalized) | 5205 | (append list-1 normalized) |
| @@ -5158,6 +5211,9 @@ options." | |||
| 5158 | 5211 | ||
| 5159 | (cons list-1 list-2))) | 5212 | (cons list-1 list-2))) |
| 5160 | 5213 | ||
| 5214 | (defvar display-buffer-normalize-options-inhibit nil | ||
| 5215 | "If non-nil, `display-buffer' doesn't process obsolete options.") | ||
| 5216 | |||
| 5161 | (defun display-buffer-normalize-specifiers (buffer-name specifiers label) | 5217 | (defun display-buffer-normalize-specifiers (buffer-name specifiers label) |
| 5162 | "Return normalized specifiers for a buffer matching BUFFER-NAME or LABEL. | 5218 | "Return normalized specifiers for a buffer matching BUFFER-NAME or LABEL. |
| 5163 | BUFFER-NAME must be a string specifying a valid buffer name. | 5219 | BUFFER-NAME must be a string specifying a valid buffer name. |
| @@ -5179,14 +5235,18 @@ specifiers: | |||
| 5179 | component is not set. | 5235 | component is not set. |
| 5180 | 5236 | ||
| 5181 | - `display-buffer-default-specifiers'." | 5237 | - `display-buffer-default-specifiers'." |
| 5182 | (let* ((list (display-buffer-normalize-specifiers-3 buffer-name label))) | 5238 | (let* ((list (display-buffer-normalize-alist buffer-name label)) |
| 5239 | (other-frame (assq 'other-window-means-other-frame | ||
| 5240 | (or (car list) (cdr list))))) | ||
| 5183 | (append | 5241 | (append |
| 5184 | ;; Overriding user specifiers. | 5242 | ;; Overriding user specifiers. |
| 5185 | (car list) | 5243 | (car list) |
| 5186 | ;; Application specifiers. | 5244 | ;; Application specifiers. |
| 5187 | (display-buffer-normalize-specifiers-1 specifiers buffer-name label) | 5245 | (display-buffer-normalize-argument |
| 5246 | buffer-name specifiers label other-frame) | ||
| 5188 | ;; Emacs 23 compatibility specifiers. | 5247 | ;; Emacs 23 compatibility specifiers. |
| 5189 | (display-buffer-normalize-specifiers-2 buffer-name) | 5248 | (unless display-buffer-normalize-options-inhibit |
| 5249 | (display-buffer-normalize-options buffer-name)) | ||
| 5190 | ;; Non-overriding user specifiers. | 5250 | ;; Non-overriding user specifiers. |
| 5191 | (cdr list) | 5251 | (cdr list) |
| 5192 | ;; Default specifiers. | 5252 | ;; Default specifiers. |