Fix handling of persistent window parameters.

* window.c (save_window_save, Fcurrent_window_configuration)
(Vwindow_persistent_parameters): Do not use Qstate.  Rewrite
doc-strings.
* window.el (window--state-get-1, window-state-get): Do not use
special state value for window-persistent-parameters.  Rename
argument IGNORE to WRITABLE.  Rewrite doc-string.
(window--state-put-2): Reset all window parameters to nil before
assigning values of persistent parameters.
* windows.texi (Window Configurations): Rewrite references to
persistent window parameters.
(Window Parameters): Fix description of persistent window
parameters.
This commit is contained in:
Martin Rudalics 2012-01-19 11:38:31 +01:00
parent 1259009aa1
commit 34a02f46dc
6 changed files with 100 additions and 94 deletions

View file

@ -1,3 +1,10 @@
2012-01-19 Martin Rudalics <rudalics@gmx.at>
* windows.texi (Window Configurations): Rewrite references to
persistent window parameters.
(Window Parameters): Fix description of persistent window
parameters.
2012-01-16 Juanma Barranquero <lekktu@gmail.com> 2012-01-16 Juanma Barranquero <lekktu@gmail.com>
* windows.texi (Window Parameters): Use @pxref. * windows.texi (Window Parameters): Use @pxref.

View file

@ -3104,9 +3104,9 @@ window configuration; see @ref{Frame Configurations}.
@defun current-window-configuration &optional frame @defun current-window-configuration &optional frame
This function returns a new object representing @var{frame}'s current This function returns a new object representing @var{frame}'s current
window configuration. The default for @var{frame} is the selected window configuration. The default for @var{frame} is the selected
frame. This function saves copies of window parameters listed by the frame. The variable @code{window-persistent-parameters} specifies
variable @code{window-persistent-parameters}, see @ref{Window whether and which window parameters are saved by this function, see
Parameters} for details. @ref{Window Parameters} for details.
@end defun @end defun
@defun set-window-configuration configuration @defun set-window-configuration configuration
@ -3214,27 +3214,25 @@ to clone the state of a frame into an arbitrary live window
(@code{set-window-configuration} effectively clones the windows of a (@code{set-window-configuration} effectively clones the windows of a
frame into the root window of that very frame only). frame into the root window of that very frame only).
@defun window-state-get &optional window ignore @defun window-state-get &optional window writable
This function returns the state of @var{window} as a Lisp object. The This function returns the state of @var{window} as a Lisp object. The
argument @var{window} can be any window and defaults to the root window argument @var{window} can be any window and defaults to the root window
of the selected frame. of the selected frame.
If the optional argument @var{ignore} is non-@code{nil}, this means to If the optional argument @var{writable} is non-@code{nil}, this means to
not use markers for sampling positions like @code{window-point} or not use markers for sampling positions like @code{window-point} or
@code{window-start}. This argument should be non-@code{nil} when the @code{window-start}. This argument should be non-@code{nil} when the
state shall be written on disk and read back in another session. state shall be written to disk and read back in another session.
The variable @code{window-persistent-parameters} specifies whether and Together, the argument @var{writable} and the variable
which window parameters are saved by this function, see @ref{Window @code{window-persistent-parameters} specify which window parameters are
Parameters} for details. saved by this function, see @ref{Window Parameters} for details.
@end defun @end defun
The value returned by @code{window-state-get} can be converted, using The value returned by @code{window-state-get} can be used in the same
one of the functions defined by Desktop Save Mode (@pxref{Desktop Save session to make a clone of a window in another window. It can be also
Mode}), to an object that can be written to a file. Such objects can be written to disk and read back in another session. In either case, use
read back and converted to a Lisp object representing the state of the the function described next to restore the state of the window.
window. That Lisp object can be used as argument for the following
function in order to restore the state window in another window.
@defun window-state-put state &optional window ignore @defun window-state-put state &optional window ignore
This function puts the window state @var{state} into @var{window}. The This function puts the window state @var{state} into @var{window}. The
@ -3281,10 +3279,10 @@ states of windows (@pxref{Window Configurations}) do not care about
window parameters. This means, that when you change the value of a window parameters. This means, that when you change the value of a
parameter within the body of a @code{save-window-excursion}, the parameter within the body of a @code{save-window-excursion}, the
previous value is not restored upon exit of that macro. It also means previous value is not restored upon exit of that macro. It also means
that when you clone via @code{window-state-put} a window state saved that when you restore via @code{window-state-put} a window state saved
earlier by @code{window-state-get}, the cloned windows come up with no earlier by @code{window-state-get}, all cloned windows have their
parameters at all. The following variable allows to override the parameters reset to @code{nil}. The following variable allows to
standard behavior. override the standard behavior.
@defvar window-persistent-parameters @defvar window-persistent-parameters
This variable is an alist specifying which parameters get saved by This variable is an alist specifying which parameters get saved by
@ -3293,32 +3291,25 @@ subsequently restored by @code{set-window-configuration} and
@code{window-state-put}, see @ref{Window Configurations}. @code{window-state-put}, see @ref{Window Configurations}.
The @sc{car} of each entry of this alist is the symbol specifying the The @sc{car} of each entry of this alist is the symbol specifying the
parameter. The @sc{cdr} must be one of the following: parameter. The @sc{cdr} should be one of the following:
@table @asis @table @asis
@item @code{state}
This value means the parameter is saved by @code{window-state-get}
provided its @var{ignore} argument is @code{nil}. The function
@code{current-window-configuration} does not save this parameter.
@item @code{nil} @item @code{nil}
This value specifies that the parameter is saved by This value means the parameter is neither saved by
@code{current-window-configuration} and, provided its @var{ignore} @code{window-state-get} nor by @code{current-window-configuration}.
argument is @code{nil}, by @code{window-state-get}.
@item @code{t} @item @code{t}
This value specifies that the parameter is saved by
@code{current-window-configuration} and, provided its @var{writable}
argument is @code{nil}, by @code{window-state-get}.
@item @code{writable}
This means that the parameter is saved unconditionally by both This means that the parameter is saved unconditionally by both
@code{current-window-configuration} and @code{window-state-get}. This @code{current-window-configuration} and @code{window-state-get}. This
value should not be used for parameters whose values do not have a read value should not be used for parameters whose values do not have a read
syntax. Otherwise, invoking @code{window-state-put} in another session syntax. Otherwise, invoking @code{window-state-put} in another session
may fail with an @code{invalid-read-syntax} error. may fail with an @code{invalid-read-syntax} error.
@end table @end table
Parameters that have been saved are restored to their previous values by
@code{set-window-configuration} respectively are installed by
@code{window-state-put}. Parameters that have not been saved are left
alone by @code{set-window-configuration} respectively are not installed
by @code{window-state-put}.
@end defvar @end defvar
Some functions, notably @code{delete-window}, Some functions, notably @code{delete-window},

View file

@ -1,3 +1,11 @@
2012-01-19 Martin Rudalics <rudalics@gmx.at>
* window.el (window--state-get-1, window-state-get): Do not use
special state value for window-persistent-parameters. Rename
argument IGNORE to WRITABLE. Rewrite doc-string.
(window--state-put-2): Reset all window parameters to nil before
assigning values of persistent parameters.
2012-01-18 Alan Mackenzie <acm@muc.de> 2012-01-18 Alan Mackenzie <acm@muc.de>
Eliminate sluggishness and hangs in fontification of "semicolon Eliminate sluggishness and hangs in fontification of "semicolon

View file

@ -3568,7 +3568,7 @@ specific buffers."
)) ))
;;; Window states, how to get them and how to put them in a window. ;;; Window states, how to get them and how to put them in a window.
(defun window--state-get-1 (window &optional ignore) (defun window--state-get-1 (window &optional writable)
"Helper function for `window-state-get'." "Helper function for `window-state-get'."
(let* ((type (let* ((type
(cond (cond
@ -3585,29 +3585,22 @@ specific buffers."
(normal-height . ,(window-normal-size window)) (normal-height . ,(window-normal-size window))
(normal-width . ,(window-normal-size window t)) (normal-width . ,(window-normal-size window t))
(combination-limit . ,(window-combination-limit window)) (combination-limit . ,(window-combination-limit window))
,@(let (list) ,@(let ((parameters (window-parameters window))
;; Make copies of persistent window parameters whose cdr list)
;; is either t or, when IGNORE is non-nil, is either nil ;; Make copies of those window parameters whose
;; or `state'. ;; persistence property is `writable' if WRITABLE is
(dolist (pers window-persistent-parameters) ;; non-nil and non-nil if WRITABLE is nil.
(when (and (consp pers) (dolist (par parameters)
(or (eq (cdr pers) t) (let ((pers (cdr (assq (car par)
(and (memq (cdr pers) '(state nil)) window-persistent-parameters))))
(not ignore)))) (when (and pers (or (not writable) (eq pers 'writable)))
(let ((par (assq (car pers) (window-parameters window)))) (setq list (cons (cons (car par) (cdr par)) list)))))
(setq list (cons (cons (car pers) (when par (cdr par))) ;; Add `clone-of' parameter if necessary.
list))))) (let ((pers (cdr (assq 'clone-of
;; Save `clone-of' parameter unless IGNORE or window-persistent-parameters))))
;; `window-persistent-parameters' prevail. (when (and pers (or (not writable) (eq pers 'writable))
(when (and (not (assq 'clone-of (window-parameters window))) (not (assq 'clone-of list)))
(let ((clone-of (setq list (cons (cons 'clone-of window) list))))
(assq 'clone-of
window-persistent-parameters)))
(when clone-of
(if ignore
(eq (cdr clone-of) t)
(memq (cdr clone-of) '(state nil))))))
(setq list (cons (cons 'clone-of window) list)))
(when list (when list
`((parameters . ,list)))) `((parameters . ,list))))
,@(when buffer ,@(when buffer
@ -3628,31 +3621,34 @@ specific buffers."
(scroll-bars . ,(window-scroll-bars window)) (scroll-bars . ,(window-scroll-bars window))
(vscroll . ,(window-vscroll window)) (vscroll . ,(window-vscroll window))
(dedicated . ,(window-dedicated-p window)) (dedicated . ,(window-dedicated-p window))
(point . ,(if ignore point (copy-marker point))) (point . ,(if writable point (copy-marker point)))
(start . ,(if ignore start (copy-marker start))) (start . ,(if writable start (copy-marker start)))
,@(when mark ,@(when mark
`((mark . ,(if ignore `((mark . ,(if writable
mark (copy-marker mark)))))))))))) mark (copy-marker mark))))))))))))
(tail (tail
(when (memq type '(vc hc)) (when (memq type '(vc hc))
(let (list) (let (list)
(setq window (window-child window)) (setq window (window-child window))
(while window (while window
(setq list (cons (window--state-get-1 window ignore) list)) (setq list (cons (window--state-get-1 window writable) list))
(setq window (window-right window))) (setq window (window-right window)))
(nreverse list))))) (nreverse list)))))
(append head tail))) (append head tail)))
(defun window-state-get (&optional window ignore) (defun window-state-get (&optional window writable)
"Return state of WINDOW as a Lisp object. "Return state of WINDOW as a Lisp object.
WINDOW can be any window and defaults to the root window of the WINDOW can be any window and defaults to the root window of the
selected frame. selected frame.
Optional argument IGNORE non-nil means do not use markers for Optional argument WRITABLE non-nil means do not use markers for
sampling positions like `window-point' or `window-start' and do sampling `window-point' and `window-start'. Together, WRITABLE
not record parameters unless `window-persistent-parameters' and the variable `window-persistent-parameters' specify which
requests it. IGNORE should be non-nil when the return value window parameters are saved by this function. WRITABLE should be
shall be written to a file and read back in another session. non-nil when the return value shall be written to a file and read
back in another session. Otherwise, an application may run into
an `invalid-read-syntax' error while attempting to read back the
value from file.
The return value can be used as argument for `window-state-put' The return value can be used as argument for `window-state-put'
to put the state recorded here into an arbitrary window. The to put the state recorded here into an arbitrary window. The
@ -3678,7 +3674,7 @@ value can be also stored on disk and read back in a new session."
;; These are probably not needed. ;; These are probably not needed.
,@(when (window-size-fixed-p window) `((fixed-height . t))) ,@(when (window-size-fixed-p window) `((fixed-height . t)))
,@(when (window-size-fixed-p window t) `((fixed-width . t)))) ,@(when (window-size-fixed-p window t) `((fixed-width . t))))
(window--state-get-1 window ignore))) (window--state-get-1 window writable)))
(defvar window-state-put-list nil (defvar window-state-put-list nil
"Helper variable for `window-state-put'.") "Helper variable for `window-state-put'.")
@ -3757,15 +3753,13 @@ value can be also stored on disk and read back in a new session."
(state (cdr (assq 'buffer item)))) (state (cdr (assq 'buffer item))))
(when combination-limit (when combination-limit
(set-window-combination-limit window combination-limit)) (set-window-combination-limit window combination-limit))
;; Assign saved window parameters. If a parameter's value is nil, ;; Reset window's parameters and assign saved ones (we might want
;; don't assign it unless the new window has it set already (which ;; a `remove-window-parameters' function here).
;; shouldn't happen unless some `window-configuration-change-hook' (dolist (parameter (window-parameters window))
;; function installed it). (set-window-parameter window (car parameter) nil))
(when parameters (when parameters
(dolist (parameter parameters) (dolist (parameter parameters)
(when (or (cdr parameter) (set-window-parameter window (car parameter) (cdr parameter))))
(window-parameter window (car parameter)))
(set-window-parameter window (car parameter) (cdr parameter)))))
;; Process buffer related state. ;; Process buffer related state.
(when state (when state
;; We don't want to raise an error here so we create a buffer if ;; We don't want to raise an error here so we create a buffer if

View file

@ -1,3 +1,9 @@
2012-01-19 Martin Rudalics <rudalics@gmx.at>
* window.c (save_window_save, Fcurrent_window_configuration)
(Vwindow_persistent_parameters): Do not use Qstate. Rewrite
doc-strings.
2012-01-19 Kenichi Handa <handa@m17n.org> 2012-01-19 Kenichi Handa <handa@m17n.org>
* character.c (char_width): New function. * character.c (char_width): New function.

View file

@ -57,7 +57,7 @@ static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically; static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically;
static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command; static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command;
static Lisp_Object Qsafe, Qabove, Qbelow; static Lisp_Object Qsafe, Qabove, Qbelow;
static Lisp_Object Qauto_buffer_name, Qclone_of, Qstate; static Lisp_Object Qauto_buffer_name, Qclone_of;
static int displayed_window_lines (struct window *); static int displayed_window_lines (struct window *);
static struct window *decode_window (Lisp_Object); static struct window *decode_window (Lisp_Object);
@ -5889,9 +5889,8 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
tem = XCDR (tem)) tem = XCDR (tem))
{ {
pers = XCAR (tem); pers = XCAR (tem);
/* Save values for persistent window parameters whose cdr /* Save values for persistent window parameters. */
is either nil or t. */ if (CONSP (pers) && !NILP (XCDR (pers)))
if (CONSP (pers) && (NILP (XCDR (pers)) || EQ (XCDR (pers), Qt)))
{ {
par = Fassq (XCAR (pers), w->window_parameters); par = Fassq (XCAR (pers), w->window_parameters);
if (NILP (par)) if (NILP (par))
@ -5966,7 +5965,9 @@ and for each displayed buffer, where display starts, and the positions of
point and mark. An exception is made for point in the current buffer: point and mark. An exception is made for point in the current buffer:
its value is -not- saved. its value is -not- saved.
This also records the currently selected frame, and FRAME's focus This also records the currently selected frame, and FRAME's focus
redirection (see `redirect-frame-focus'). */) redirection (see `redirect-frame-focus'). The variable
`window-persistent-parameters' specifies which window parameters are
saved by this function. */)
(Lisp_Object frame) (Lisp_Object frame)
{ {
register Lisp_Object tem; register Lisp_Object tem;
@ -6504,7 +6505,6 @@ syms_of_window (void)
DEFSYM (Qbelow, "below"); DEFSYM (Qbelow, "below");
DEFSYM (Qauto_buffer_name, "auto-buffer-name"); DEFSYM (Qauto_buffer_name, "auto-buffer-name");
DEFSYM (Qclone_of, "clone-of"); DEFSYM (Qclone_of, "clone-of");
DEFSYM (Qstate, "state");
staticpro (&Vwindow_list); staticpro (&Vwindow_list);
@ -6616,28 +6616,28 @@ function `set-window-combination-limit'. */);
DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters, DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters,
doc: /* Alist of persistent window parameters. doc: /* Alist of persistent window parameters.
Parameters in this list are saved by `current-window-configuration' and This alist specifies which window parameters shall get saved by
`window-state-get' and subsequently restored to their previous values by `current-window-configuration' and `window-state-get' and subsequently
`set-window-configuration' and `window-state-put'. restored to their previous values by `set-window-configuration' and
`window-state-put'.
The car of each entry of this alist is the symbol specifying the The car of each entry of this alist is the symbol specifying the
parameter. The cdr is one of the following: parameter. The cdr is one of the following:
The symbol `state' means the parameter is saved by `window-state-get' nil means the parameter is neither saved by `window-state-get' nor by
provided its IGNORE argument is nil. `current-window-configuration' `current-window-configuration'.
does not save this parameter.
nil means the parameter is saved by `current-window-configuration' and, t means the parameter is saved by `current-window-configuration' and,
provided its IGNORE argument is nil, by `window-state-get'. provided its WRITABLE argument is nil, by `window-state-get'.
t means the parameter is saved unconditionally by both The symbol `writable' means the parameter is saved unconditionally by
`current-window-configuration' and `window-state-get'. Parameters both `current-window-configuration' and `window-state-get'. Do not use
without read syntax (like windows or frames) should not use that. this value for parameters without read syntax (like windows or frames).
Parameters not saved by `current-window-configuration' or Parameters not saved by `current-window-configuration' or
`window-state-get' are left alone by `set-window-configuration' `window-state-get' are left alone by `set-window-configuration'
respectively are not installed by `window-state-put'. */); respectively are not installed by `window-state-put'. */);
Vwindow_persistent_parameters = list1 (Fcons (Qclone_of, Qstate)); Vwindow_persistent_parameters = list1 (Fcons (Qclone_of, Qt));
defsubr (&Sselected_window); defsubr (&Sselected_window);
defsubr (&Sminibuffer_window); defsubr (&Sminibuffer_window);