summaryrefslogtreecommitdiff
blob: 0aa7cb2d8ca67c520a3190a7be1472708865bec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
diff --git a/popwin.el b/popwin.el
index 22f64f0..a5bafeb 100644
--- a/popwin.el
+++ b/popwin.el
@@ -4,7 +4,7 @@
 
 ;; Author: Tomohiro Matsuyama <tomo@cx4a.org>
 ;; Keywords: convenience
-;; Version: 0.3
+;; Version: 0.4
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -69,7 +69,19 @@
 
 
 
-;;; Common API
+;;; Common
+
+(defmacro popwin:save-selected-window (&rest body)
+  "Evaluate BODY saving the selected window."
+  `(with-selected-window (selected-window) ,@body))
+
+(defun popwin:switch-to-buffer (buffer-or-name &optional norecord)
+  "Call `switch-to-buffer' forcing BUFFER-OF-NAME be displayed in
+the selected window."
+  (with-no-warnings 
+    (if (>= emacs-major-version 24)
+        (switch-to-buffer buffer-or-name norecord t)
+      (switch-to-buffer buffer-or-name norecord))))
 
 (defun popwin:last-selected-window ()
   "Return currently selected window or lastly selected window if
@@ -82,6 +94,12 @@ minibuffer window is selected."
   "Return t if BUFFER might be thought of as a buried buffer."
   (eq (car (last (buffer-list))) buffer))
 
+(defun popwin:called-interactively-p ()
+  (with-no-warnings
+    (if (>= emacs-major-version 23)
+        (called-interactively-p 'any)
+      (called-interactively-p))))
+
 (defvar popwin:empty-buffer nil
   "Marker buffer of indicating a window of the buffer is being a
 popup window.")
@@ -142,7 +160,7 @@ horizontal factor HFACTOR, and vertical factor VFACTOR."
           (cdr node)
         (popwin:adjust-window-edges window edges hfactor vfactor)
         (with-selected-window window
-          (switch-to-buffer buffer t))
+          (popwin:switch-to-buffer buffer t))
         (when selected
           (select-window window)))
     (destructuring-bind (dir edges . windows) node
@@ -221,7 +239,8 @@ window-configuration."
          (root-win (popwin:last-selected-window))
          (hfactor 1)
          (vfactor 1))
-    (delete-other-windows root-win)
+    (popwin:save-selected-window
+     (delete-other-windows root-win))
     (let ((root-width (window-width root-win))
           (root-height (window-height root-win)))
       (when adjust
@@ -238,7 +257,7 @@ window-configuration."
           (popwin:create-popup-window-1 root-win size position)
         ;; Mark popup-win being a popup window.
         (with-selected-window popup-win
-          (switch-to-buffer (popwin:empty-buffer) t))
+          (popwin:switch-to-buffer (popwin:empty-buffer) t))
         (popwin:replicate-window-config master-win root hfactor vfactor)
         (list master-win popup-win)))))
 
@@ -410,7 +429,7 @@ BUFFER."
               popwin:selected-window (selected-window))
         (popwin:start-close-popup-window-timer))))
   (with-selected-window popwin:popup-window
-    (switch-to-buffer buffer))
+    (popwin:switch-to-buffer buffer))
   (setq popwin:popup-buffer buffer
         popwin:popup-window-stuck-p stick)
   (if noselect
@@ -438,6 +457,10 @@ be closed by `popwin:close-popup-window'."
 
 ;;; Special Display
 
+(defmacro popwin:without-special-display (&rest body)
+  "Evaluate BODY without special displaying."
+  `(let (display-buffer-function special-display-function) ,@body))
+
 (defcustom popwin:special-display-config
   '(("*Help*")
     ("*Completions*" :noselect t)
@@ -481,13 +504,19 @@ buffers will be shown at the left of the frame with width 80."
 
 (defun popwin:original-display-buffer (buffer &optional not-this-window)
   "Call `display-buffer' for BUFFER without special displaying."
-  (let (display-buffer-function special-display-function)
-    ;; Close the popup window here so that the popup window won't to
-    ;; be splitted.
-    (when (and (eq (selected-window) popwin:popup-window)
-               (not (same-window-p (buffer-name buffer))))
-      (popwin:close-popup-window))
-    (display-buffer buffer not-this-window)))
+  (popwin:without-special-display
+   ;; Close the popup window here so that the popup window won't to
+   ;; be splitted.
+   (when (and (eq (selected-window) popwin:popup-window)
+              (not (same-window-p (buffer-name buffer))))
+     (popwin:close-popup-window))
+   (if (and (>= emacs-major-version 24)
+            (boundp 'action)
+            (boundp 'frame))
+       ;; Use variables ACTION and FRAME which are formal parameters
+       ;; of DISPLAY-BUFFER.
+       (display-buffer buffer action frame)
+     (display-buffer buffer not-this-window))))
 
 (defun* popwin:display-buffer-1 (buffer-or-name &key default-config-keywords if-buffer-not-found if-config-not-found)
   "Display BUFFER-OR-NAME, if possible, in a popup
@@ -548,9 +577,9 @@ usual. This function can be used as a value of
   (popwin:display-buffer-1
    buffer-or-name
    :if-config-not-found
-   (unless (interactive-p)
-     (lambda (buffer-or-name)
-       (popwin:original-display-buffer buffer-or-name not-this-window)))))
+   (unless (popwin:called-interactively-p)
+     (lambda (buffer)
+       (popwin:original-display-buffer buffer not-this-window)))))
 
 (defun popwin:special-display-popup-window (buffer &rest ignore)
   "The `special-display-function' with a popup window."