*** /usr/local/src/xemacs-21.5.28/lisp/window-xemacs.el Tue Oct 31 09:16:29 2006 --- ./window-xemacs.el Sun Mar 16 09:40:36 2008 *************** *** 35,40 **** --- 35,51 ---- ;;; Code: + ;; Protect two crucial functions from the impact of advice + ;; (Any others need to be treated similarly?) + ;; ht@inf.ed.ac.uk Sun Mar 16 09:27:35 2008 + + (unless (fboundp 'orig-split-window) + (fset 'orig-split-window (symbol-function 'split-window))) + + (unless (fboundp 'orig-delete-window) + (fset 'orig-delete-window (symbol-function 'delete-window))) + + (defgroup windows nil "Windows within a frame." :group 'environment) *************** *** 124,130 **** pixel-left pixel-top pixel-right pixel-bottom hscroll modeline-hscroll dedicatedp ! first-hchild first-vchild next-child) (defstruct window-configuration frame --- 135,142 ---- pixel-left pixel-top pixel-right pixel-bottom hscroll modeline-hscroll dedicatedp ! first-hchild first-vchild next-child ! window) (defstruct window-configuration frame *************** *** 256,261 **** --- 268,274 ---- (bottom (nth 3 edges))) (let ((saved-window (make-saved-window +:window window :currentp (eq window (selected-window (window-frame window))) :minibufferp (eq window (minibuffer-window (window-frame window))) :minibuffer-scrollp (eq window minibuffer-scroll-window) *************** *** 287,296 **** --- 300,334 ---- (copy-marker (mark-marker t buffer))))) saved-window)))) + (defmacro save-window-excursion/mapping (&rest body) + "Execute BODY, preserving window sizes and contents. + Restores which buffer appears in which window, where display starts, + as well as the current buffer. + Does not restore the value of point in current buffer. + On non-error return, value is cons of BODY value and list of + remapped windows (see set-window-configuration/mapping for + more on remapping)." + (let ((window-config (gensym 'window-config)) + (res (gensym 'res))) + `(let ((,window-config (current-window-configuration)) + ,res) + (unwind-protect + (setq ,res (progn ,@body)) + (setq ,res (cons ,res (set-window-configuration/mapping ,window-config)))) + ,res))) + (defun set-window-configuration (configuration) "Set the configuration of windows and buffers as specified by CONFIGURATION. CONFIGURATION must be a value previously returned by `current-window-configuration'." + (set-window-configuration/mapping configuration) + nil) + + (defun set-window-configuration/mapping (configuration) + "As set-window-configuration, but returns an a-list mapping + dead windows to their replacements. This allows you to work + around the fact that s-w-c no longer (as of xemacs 21.5) preserves + window identity." (let ((frame (window-configuration-frame configuration))) (if (and (frame-live-p frame) (not (window-configuration-equal configuration *************** *** 298,304 **** (really-set-window-configuration frame configuration)))) (defun really-set-window-configuration (frame configuration) ! "Set the window configuration CONFIGURATION on live frame FRAME." ;; avoid potential temporary problems (setq window-min-width 0) (setq window-min-height 0) --- 336,343 ---- (really-set-window-configuration frame configuration)))) (defun really-set-window-configuration (frame configuration) ! "Set the window configuration CONFIGURATION on live frame FRAME. ! Value is a-list mapping dead windows to their replacements." ;; avoid potential temporary problems (setq window-min-width 0) (setq window-min-height 0) *************** *** 318,324 **** (set-frame-property frame 'top top)))) ;; these may have changed because of the delete ! (let ((root-window (frame-root-window frame))) (enlarge-window-pixels (- (window-configuration-minibuffer-pixel-height configuration) (window-pixel-height (minibuffer-window frame))) --- 357,364 ---- (set-frame-property frame 'top top)))) ;; these may have changed because of the delete ! (let ((root-window (frame-root-window frame)) ! rsw-res) (enlarge-window-pixels (- (window-configuration-minibuffer-pixel-height configuration) (window-pixel-height (minibuffer-window frame))) *************** *** 336,342 **** (window-configuration-saved-root-window configuration) 'vertical) (if window-configuration-current-window ! (select-window window-configuration-current-window)))) (setq window-min-width (window-configuration-min-width configuration)) (setq window-min-height (window-configuration-min-height configuration)) --- 376,382 ---- (window-configuration-saved-root-window configuration) 'vertical) (if window-configuration-current-window ! (select-window window-configuration-current-window))) (setq window-min-width (window-configuration-min-width configuration)) (setq window-min-height (window-configuration-min-height configuration)) *************** *** 344,350 **** (let ((buffer (window-configuration-current-buffer configuration))) (if (buffer-live-p buffer) (set-buffer buffer) ! (set-buffer (car (buffer-list)))))) (defun set-window-configuration-frame-size (configuration) "Restore the frame size of a window configuration." --- 384,391 ---- (let ((buffer (window-configuration-current-buffer configuration))) (if (buffer-live-p buffer) (set-buffer buffer) ! (set-buffer (car (buffer-list))))) ! rsw-res)) (defun set-window-configuration-frame-size (configuration) "Restore the frame size of a window configuration." *************** *** 370,376 **** (while window (if (window-live-p window) (let ((next (window-next-child window))) ! (delete-window window) (setq window next))))) (cond ((window-first-hchild window) --- 411,417 ---- (while window (if (window-live-p window) (let ((next (window-next-child window))) ! (orig-delete-window window) (setq window next))))) (cond ((window-first-hchild window) *************** *** 384,392 **** (not (saved-window-minibufferp (saved-window-next-child saved-window))) (progn (cond ((eq direction 'vertical) ! (split-window window nil nil)) ((eq direction 'horizontal) ! (split-window window nil t))) (restore-saved-window configuration (window-next-child window) (saved-window-next-child saved-window) --- 425,433 ---- (not (saved-window-minibufferp (saved-window-next-child saved-window))) (progn (cond ((eq direction 'vertical) ! (orig-split-window window nil nil)) ((eq direction 'horizontal) ! (orig-split-window window nil t))) (restore-saved-window configuration (window-next-child window) (saved-window-next-child saved-window) *************** *** 402,408 **** window (saved-window-first-vchild saved-window) 'vertical)) ! (if (not (saved-window-minibufferp saved-window)) (restore-saved-window-parameters configuration window saved-window))) --- 443,451 ---- window (saved-window-first-vchild saved-window) 'vertical)) ! (if (not (eq window (saved-window-window saved-window))) ! (setq rsw-res (cons (cons (saved-window-window saved-window) window) ! rsw-res))) (if (not (saved-window-minibufferp saved-window)) (restore-saved-window-parameters configuration window saved-window))) *************** *** 933,939 **** split-width-threshold) (and (window-leftmost-p window) (window-rightmost-p window)))) ! (setq window (split-window window)) (let (upper other) (setq window (get-lru-window target-frame)) ;; If the LRU window is selected, and big enough, --- 976,982 ---- split-width-threshold) (and (window-leftmost-p window) (window-rightmost-p window)))) ! (setq window (orig-split-window window)) (let (upper other) (setq window (get-lru-window target-frame)) ;; If the LRU window is selected, and big enough, *************** *** 945,951 **** (not (window-parent window))) (>= (window-height window) (* 2 window-min-height))) ! (setq window (split-window window))) ;; If get-lru-window returned nil, try other approaches. ;; Try visible frames first. (or window --- 988,994 ---- (not (window-parent window))) (>= (window-height window) (* 2 window-min-height))) ! (setq window (orig-split-window window))) ;; If get-lru-window returned nil, try other approaches. ;; Try visible frames first. (or window