aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-08-12 18:52:33 -0400
committerStefan Monnier2012-08-12 18:52:33 -0400
commit1439443be63a2b0d796df8ebca882cdaecb7269f (patch)
tree288bff90b49fb823e73413a64023894e079a39b7
parent0d9e2599ec037fe0582c36ea5e965cd6fa65d9dc (diff)
downloademacs-1439443be63a2b0d796df8ebca882cdaecb7269f.tar.gz
emacs-1439443be63a2b0d796df8ebca882cdaecb7269f.zip
* lisp/subr.el (internal--before-with-seleted-window)
(internal--after-with-seleted-window): New functions. (with-selected-window): Use them, to replace dependency on tty-top-frame.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/subr.el53
2 files changed, 34 insertions, 25 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6f54b9f7c0e..d57c3f8b61a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12012-08-12 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * subr.el (internal--before-with-seleted-window)
4 (internal--after-with-seleted-window): New functions.
5 (with-selected-window): Use them, to replace dependency on tty-top-frame.
6
12012-08-12 Nobuyoshi Nakada <nobu@ruby-lang.org> 72012-08-12 Nobuyoshi Nakada <nobu@ruby-lang.org>
2 8
3 * progmodes/ruby-mode.el (ruby-mode-map): Remove unnecessary 9 * progmodes/ruby-mode.el (ruby-mode-map): Remove unnecessary
diff --git a/lisp/subr.el b/lisp/subr.el
index 860d1b2a108..34c0a780930 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3023,6 +3023,30 @@ also `with-temp-buffer'."
3023 (set-buffer ,buffer-or-name) 3023 (set-buffer ,buffer-or-name)
3024 ,@body)) 3024 ,@body))
3025 3025
3026(defun internal--before-with-seleted-window (window)
3027 (let ((other-frame (window-frame window)))
3028 (list window (selected-window)
3029 ;; Selecting a window on another frame also changes that
3030 ;; frame's frame-selected-window. We must save&restore it.
3031 (unless (eq (selected-frame) other-frame)
3032 (frame-selected-window other-frame))
3033 ;; Also remember the top-frame if on ttys.
3034 (unless (eq (selected-frame) other-frame)
3035 (tty-top-frame other-frame)))))
3036
3037(defun internal--after-with-seleted-window (state)
3038 ;; First reset frame-selected-window.
3039 (when (window-live-p (nth 2 state))
3040 ;; We don't use set-frame-selected-window because it does not
3041 ;; pass the `norecord' argument to Fselect_window.
3042 (select-window (nth 2 state) 'norecord)
3043 (and (frame-live-p (nth 3 state))
3044 (not (eq (tty-top-frame) (nth 3 state)))
3045 (select-frame (nth 3 state) 'norecord)))
3046 ;; Then reset the actual selected-window.
3047 (when (window-live-p (nth 2 state))
3048 (select-window (nth 2 state) 'norecord)))
3049
3026(defmacro with-selected-window (window &rest body) 3050(defmacro with-selected-window (window &rest body)
3027 "Execute the forms in BODY with WINDOW as the selected window. 3051 "Execute the forms in BODY with WINDOW as the selected window.
3028The value returned is the value of the last form in BODY. 3052The value returned is the value of the last form in BODY.
@@ -3040,34 +3064,13 @@ current buffer, since otherwise its normal operation could
3040potentially make a different buffer current. It does not alter 3064potentially make a different buffer current. It does not alter
3041the buffer list ordering." 3065the buffer list ordering."
3042 (declare (indent 1) (debug t)) 3066 (declare (indent 1) (debug t))
3043 ;; Most of this code is a copy of save-selected-window. 3067 `(let ((save-selected-window--state
3044 `(let* ((save-selected-window-destination ,window) 3068 (internal--before-with-seleted-window ,window)))
3045 (save-selected-window-frame
3046 (window-frame save-selected-window-destination))
3047 (save-selected-window-window (selected-window))
3048 ;; Selecting a window on another frame also changes that
3049 ;; frame's frame-selected-window. We must save&restore it.
3050 (save-selected-window-other-frame
3051 (unless (eq (selected-frame) save-selected-window-frame)
3052 (frame-selected-window save-selected-window-frame)))
3053 (save-selected-window-top-frame
3054 (unless (eq (selected-frame) save-selected-window-frame)
3055 (tty-top-frame save-selected-window-frame))))
3056 (save-current-buffer 3069 (save-current-buffer
3057 (unwind-protect 3070 (unwind-protect
3058 (progn (select-window save-selected-window-destination 'norecord) 3071 (progn (select-window (car save-selected-window--state) 'norecord)
3059 ,@body) 3072 ,@body)
3060 ;; First reset frame-selected-window. 3073 (internal--before-with-seleted-window save-selected-window--state)))))
3061 (when (window-live-p save-selected-window-other-frame)
3062 ;; We don't use set-frame-selected-window because it does not
3063 ;; pass the `norecord' argument to Fselect_window.
3064 (select-window save-selected-window-other-frame 'norecord)
3065 (and (frame-live-p save-selected-window-top-frame)
3066 (not (eq (tty-top-frame) save-selected-window-top-frame))
3067 (select-frame save-selected-window-top-frame 'norecord)))
3068 ;; Then reset the actual selected-window.
3069 (when (window-live-p save-selected-window-window)
3070 (select-window save-selected-window-window 'norecord))))))
3071 3074
3072(defmacro with-selected-frame (frame &rest body) 3075(defmacro with-selected-frame (frame &rest body)
3073 "Execute the forms in BODY with FRAME as the selected frame. 3076 "Execute the forms in BODY with FRAME as the selected frame.