From: Martin Rudalics Date: Thu, 19 Jan 2012 10:38:31 +0000 (+0100) Subject: Fix handling of persistent window parameters. X-Git-Url: http://git.hcoop.net/bpt/emacs.git/commitdiff_plain/34a02f46dce0136ef10deb0f632330c76babbd9c 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. --- diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 4b9531c0e6..44467d5f51 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,10 @@ +2012-01-19 Martin Rudalics + + * windows.texi (Window Configurations): Rewrite references to + persistent window parameters. + (Window Parameters): Fix description of persistent window + parameters. + 2012-01-16 Juanma Barranquero * windows.texi (Window Parameters): Use @pxref. diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 1bff30e45e..a0f8b61ddf 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -3104,9 +3104,9 @@ window configuration; see @ref{Frame Configurations}. @defun current-window-configuration &optional frame This function returns a new object representing @var{frame}'s current window configuration. The default for @var{frame} is the selected -frame. This function saves copies of window parameters listed by the -variable @code{window-persistent-parameters}, see @ref{Window -Parameters} for details. +frame. The variable @code{window-persistent-parameters} specifies +whether and which window parameters are saved by this function, see +@ref{Window Parameters} for details. @end defun @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 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 argument @var{window} can be any window and defaults to the root window 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 @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 -which window parameters are saved by this function, see @ref{Window -Parameters} for details. +Together, the argument @var{writable} and the variable +@code{window-persistent-parameters} specify which window parameters are +saved by this function, see @ref{Window Parameters} for details. @end defun -The value returned by @code{window-state-get} can be converted, using -one of the functions defined by Desktop Save Mode (@pxref{Desktop Save -Mode}), to an object that can be written to a file. Such objects can be -read back and converted to a Lisp object representing the state of the -window. That Lisp object can be used as argument for the following -function in order to restore the state window in another window. +The value returned by @code{window-state-get} can be used in the same +session to make a clone of a window in another window. It can be also +written to disk and read back in another session. In either case, use +the function described next to restore the state of the window. @defun window-state-put state &optional window ignore 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 parameter within the body of a @code{save-window-excursion}, the 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 -earlier by @code{window-state-get}, the cloned windows come up with no -parameters at all. The following variable allows to override the -standard behavior. +that when you restore via @code{window-state-put} a window state saved +earlier by @code{window-state-get}, all cloned windows have their +parameters reset to @code{nil}. The following variable allows to +override the standard behavior. @defvar window-persistent-parameters 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}. 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 -@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} +This value means the parameter is neither saved by +@code{window-state-get} nor by @code{current-window-configuration}. + +@item @code{t} This value specifies that the parameter is saved by -@code{current-window-configuration} and, provided its @var{ignore} +@code{current-window-configuration} and, provided its @var{writable} argument is @code{nil}, by @code{window-state-get}. -@item @code{t} +@item @code{writable} This means that the parameter is saved unconditionally by both @code{current-window-configuration} and @code{window-state-get}. This value should not be used for parameters whose values do not have a read syntax. Otherwise, invoking @code{window-state-put} in another session may fail with an @code{invalid-read-syntax} error. @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 Some functions, notably @code{delete-window}, diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0fea6a47b0..8fa8031d12 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2012-01-19 Martin Rudalics + + * 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 Eliminate sluggishness and hangs in fontification of "semicolon diff --git a/lisp/window.el b/lisp/window.el index 54e5ec9c74..9122904b0b 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -3568,7 +3568,7 @@ specific buffers." )) ;;; 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'." (let* ((type (cond @@ -3585,29 +3585,22 @@ specific buffers." (normal-height . ,(window-normal-size window)) (normal-width . ,(window-normal-size window t)) (combination-limit . ,(window-combination-limit window)) - ,@(let (list) - ;; Make copies of persistent window parameters whose cdr - ;; is either t or, when IGNORE is non-nil, is either nil - ;; or `state'. - (dolist (pers window-persistent-parameters) - (when (and (consp pers) - (or (eq (cdr pers) t) - (and (memq (cdr pers) '(state nil)) - (not ignore)))) - (let ((par (assq (car pers) (window-parameters window)))) - (setq list (cons (cons (car pers) (when par (cdr par))) - list))))) - ;; Save `clone-of' parameter unless IGNORE or - ;; `window-persistent-parameters' prevail. - (when (and (not (assq 'clone-of (window-parameters window))) - (let ((clone-of - (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))) + ,@(let ((parameters (window-parameters window)) + list) + ;; Make copies of those window parameters whose + ;; persistence property is `writable' if WRITABLE is + ;; non-nil and non-nil if WRITABLE is nil. + (dolist (par parameters) + (let ((pers (cdr (assq (car par) + window-persistent-parameters)))) + (when (and pers (or (not writable) (eq pers 'writable))) + (setq list (cons (cons (car par) (cdr par)) list))))) + ;; Add `clone-of' parameter if necessary. + (let ((pers (cdr (assq 'clone-of + window-persistent-parameters)))) + (when (and pers (or (not writable) (eq pers 'writable)) + (not (assq 'clone-of list))) + (setq list (cons (cons 'clone-of window) list)))) (when list `((parameters . ,list)))) ,@(when buffer @@ -3628,31 +3621,34 @@ specific buffers." (scroll-bars . ,(window-scroll-bars window)) (vscroll . ,(window-vscroll window)) (dedicated . ,(window-dedicated-p window)) - (point . ,(if ignore point (copy-marker point))) - (start . ,(if ignore start (copy-marker start))) + (point . ,(if writable point (copy-marker point))) + (start . ,(if writable start (copy-marker start))) ,@(when mark - `((mark . ,(if ignore + `((mark . ,(if writable mark (copy-marker mark)))))))))))) (tail (when (memq type '(vc hc)) (let (list) (setq window (window-child 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))) (nreverse list))))) (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. WINDOW can be any window and defaults to the root window of the selected frame. -Optional argument IGNORE non-nil means do not use markers for -sampling positions like `window-point' or `window-start' and do -not record parameters unless `window-persistent-parameters' -requests it. IGNORE should be non-nil when the return value -shall be written to a file and read back in another session. +Optional argument WRITABLE non-nil means do not use markers for +sampling `window-point' and `window-start'. Together, WRITABLE +and the variable `window-persistent-parameters' specify which +window parameters are saved by this function. WRITABLE should be +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' 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. ,@(when (window-size-fixed-p window) `((fixed-height . 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 "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)))) (when combination-limit (set-window-combination-limit window combination-limit)) - ;; Assign saved window parameters. If a parameter's value is nil, - ;; don't assign it unless the new window has it set already (which - ;; shouldn't happen unless some `window-configuration-change-hook' - ;; function installed it). + ;; Reset window's parameters and assign saved ones (we might want + ;; a `remove-window-parameters' function here). + (dolist (parameter (window-parameters window)) + (set-window-parameter window (car parameter) nil)) (when parameters (dolist (parameter parameters) - (when (or (cdr parameter) - (window-parameter window (car parameter))) - (set-window-parameter window (car parameter) (cdr parameter))))) + (set-window-parameter window (car parameter) (cdr parameter)))) ;; Process buffer related state. (when state ;; We don't want to raise an error here so we create a buffer if diff --git a/src/ChangeLog b/src/ChangeLog index 3a6e31eede..faaea4057c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2012-01-19 Martin Rudalics + + * window.c (save_window_save, Fcurrent_window_configuration) + (Vwindow_persistent_parameters): Do not use Qstate. Rewrite + doc-strings. + 2012-01-19 Kenichi Handa * character.c (char_width): New function. diff --git a/src/window.c b/src/window.c index 3dc6029d24..324689498a 100644 --- a/src/window.c +++ b/src/window.c @@ -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 Qscroll_up, Qscroll_down, Qscroll_command; 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 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)) { pers = XCAR (tem); - /* Save values for persistent window parameters whose cdr - is either nil or t. */ - if (CONSP (pers) && (NILP (XCDR (pers)) || EQ (XCDR (pers), Qt))) + /* Save values for persistent window parameters. */ + if (CONSP (pers) && !NILP (XCDR (pers))) { par = Fassq (XCAR (pers), w->window_parameters); 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: its value is -not- saved. 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) { register Lisp_Object tem; @@ -6504,7 +6505,6 @@ syms_of_window (void) DEFSYM (Qbelow, "below"); DEFSYM (Qauto_buffer_name, "auto-buffer-name"); DEFSYM (Qclone_of, "clone-of"); - DEFSYM (Qstate, "state"); staticpro (&Vwindow_list); @@ -6616,28 +6616,28 @@ function `set-window-combination-limit'. */); DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters, doc: /* Alist of persistent window parameters. -Parameters in this list are saved by `current-window-configuration' and -`window-state-get' and subsequently restored to their previous values by -`set-window-configuration' and `window-state-put'. +This alist specifies which window parameters shall get saved by +`current-window-configuration' and `window-state-get' and subsequently +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 parameter. The cdr is one of the following: -The symbol `state' means the parameter is saved by `window-state-get' -provided its IGNORE argument is nil. `current-window-configuration' -does not save this parameter. +nil means the parameter is neither saved by `window-state-get' nor by +`current-window-configuration'. -nil means the parameter is saved by `current-window-configuration' and, -provided its IGNORE argument is nil, by `window-state-get'. +t means the parameter is saved by `current-window-configuration' and, +provided its WRITABLE argument is nil, by `window-state-get'. -t means the parameter is saved unconditionally by both -`current-window-configuration' and `window-state-get'. Parameters -without read syntax (like windows or frames) should not use that. +The symbol `writable' means the parameter is saved unconditionally by +both `current-window-configuration' and `window-state-get'. Do not use +this value for parameters without read syntax (like windows or frames). Parameters not saved by `current-window-configuration' or `window-state-get' are left alone by `set-window-configuration' 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 (&Sminibuffer_window);