[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

[BUG] session popup window [PATCH INCLUDED]



The attached patch fixes a bug in the creation of the session pop-up
window, which had been destroying the window orientation of the current
frame. It copies its behavior from the similar popup window function for
the list of buffers. It also respects the users declared preference for
displaying popup windows horizontally or vertically.

1] Description of the bug

   From any emacs frame, `C-x 3' to split the frame into two windows. In
   one, open a emacs-w3m buffer, press `t' (w3m-select-buffer) and then
   `q'. You should have been presented with a popup buffer, and after
   quitting, the frame should revert to its original orientation of two
   windows side-by-side.

   Now try the same thing with w3m-session-select. Press `M-s', and then
   `q'. My experience is that the non-emacs-w3m window has been
   destroyed.

2] Description of the patch.

   It occurred to me that all w3m popup buffers could/should share the
   same logic for many features. In this case, w3m-select-buffer was
   functioning better, so I shamelessly created a new function based
   upon a snippet from it, and used that new function as common code for
   both popup buffers.

   This method had additional benefits, in that it gives
   w3m-session-select features it didn't have before. w3m-select-buffer
   allows the user to control whether the popup buffer displays below or
   beside the main buffer, so this patch adds the feature. It also means
   that both popups use the same algorithm for determining the window
   size: function w3m-select-buffer-window-size.


-- 
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0
Index: ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/ChangeLog,v
retrieving revision 1.3665
diff -b -u -w -r1.3665 ChangeLog
--- ChangeLog	2 May 2018 05:38:10 -0000	1.3665
+++ ChangeLog	9 May 2018 07:11:31 -0000
@@ -1,3 +1,12 @@
+2018-05-09  Boruch Baum  <boruch_baum@xxxxxxx>
+
+	* w3m.el (w3m--setup-popup-window): new function.
+	(w3m-select-buffer): Use the new function.
+	(w3m-select-buffer-horizontal-window): Update documentation.
+
+	* w3m-session.el (w3m-session-select): Use the new function, thus
+	fixing a display bug, and making popup windows consistent.
+
 2018-05-02  Katsumi Yamaoka  <yamaoka@xxxxxxx>

 	* w3m-image.el (w3m-favicon-usable-p): Relax the criterion.
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1708
diff -b -u -w -r1.1708 w3m.el
--- w3m.el	5 Apr 2018 05:20:01 -0000	1.1708
+++ w3m.el	9 May 2018 07:11:32 -0000
@@ -10946,7 +10996,7 @@

 ;;; Interactive select buffer.
 (defcustom w3m-select-buffer-horizontal-window t
-  "*Non-nil means split windows horizontally to open the selection window."
+  "*Non-nil means split windows horizontally to open selection pop-up windows."
   :group 'w3m
   :type 'boolean)

@@ -10975,36 +11025,47 @@
 	 (window-width))
        (or w3m-fill-column -1))))

-(defun w3m-select-buffer (&optional toggle nomsg)
-  "Pop to the emacs-w3m buffers selection window up.
-It provides the feature for switching emacs-w3m buffers using the
-buffer list.  The following command keys are available:
+(defun w3m--setup-popup-window (toggle buffer-name nomsg)
+  "Create a generic w3m popup window and its buffer.

-\\{w3m-select-buffer-mode-map}"
-  (interactive "P")
+TOGGLE toggles the position of the window between being below or
+beside the main window."
+  (let ((selected-window (selected-window))
+        (current-buffer (current-buffer)))
   (when toggle
     (setq w3m-select-buffer-horizontal-window
 	  (not w3m-select-buffer-horizontal-window))
-    (when (get-buffer-window w3m-select-buffer-name)
-      (delete-windows-on w3m-select-buffer-name)))
+     (when (get-buffer-window buffer-name)
+       (delete-windows-on buffer-name)))
   (unless (or (eq major-mode 'w3m-mode)
 	      (eq major-mode 'w3m-select-buffer-mode))
     (let ((buffer (w3m-alive-p t)))
       (if buffer
 	  (w3m-popup-buffer buffer)
 	(w3m-goto-url (or w3m-home-page "about:")))))
-  (let ((selected-window (selected-window))
-	(current-buffer (current-buffer)))
-    (set-buffer (w3m-get-buffer-create w3m-select-buffer-name))
+   (set-buffer (w3m-get-buffer-create buffer-name))
     (unless (eq nomsg 'update)
       (setq w3m-select-buffer-window selected-window))
-    (let ((w (or (get-buffer-window w3m-select-buffer-name)
+   (let ((w (or (get-buffer-window buffer-name)
 		 (split-window selected-window
 			       (w3m-select-buffer-window-size)
 			       w3m-select-buffer-horizontal-window))))
       (set-window-buffer w (current-buffer))
-      (select-window w))
-    (w3m-select-buffer-generate-contents current-buffer))
+     (select-window w))))
+
+(defun w3m-select-buffer (&optional toggle nomsg)
+  "Pop-up an emacs-w3m buffers selection window.
+
+Allows convenient switching between emacs-w3m buffers. With the
+prefix-argument, toggles the position of the popup window between
+being below or beside the main window.
+
+The following command keys are available:
+
+\\{w3m-select-buffer-mode-map}"
+  (interactive "P")
+  (w3m--setup-popup-window toggle w3m-select-buffer-name nomsg)
+  (w3m-select-buffer-generate-contents (current-buffer))
   (w3m-select-buffer-mode)
   (or nomsg (w3m-message w3m-select-buffer-message)))

Index: w3m-session.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-session.el,v
retrieving revision 1.45
diff -b -u -w -r1.45 w3m-session.el
--- w3m-session.el	18 Feb 2018 23:38:58 -0000	1.45
+++ w3m-session.el	9 May 2018 07:11:32 -0000
@@ -741,39 +732,22 @@
 			   (- (line-number-at-pos (point-max)) 4)))))))

 ;;;###autoload
-(defun w3m-session-select (&optional n)
+(defun w3m-session-select (&optional n toggle nomsg)
   "Select session from session list.
-Position point at N-th session if N is given."
-  (interactive)
+Position point at N-th session if N is given.  With the
+prefix-argument, toggles the position of the popup window between
+being below or beside the main window."
+  (interactive (list nil current-prefix-arg nil))
   (w3m-session-ignore-errors
    (let ((sessions (w3m-load-list w3m-session-file))
 	 (showbuf " *w3m-session select*")
 	 window)
      (if sessions
-	 (let ((wheight (max (+ (length sessions) 5) window-min-height))
-	       last-window)
-	   (setq last-window (previous-window
-			      (w3m-static-if (fboundp 'frame-highest-window)
-				  (frame-highest-window)
-				(frame-first-window))))
-	   (while (minibuffer-window-active-p last-window)
-	     (setq last-window (previous-window last-window)))
-	   (while (and
-		   (not (one-window-p))
-		   (or (< (window-width last-window)
-			  (frame-width))
-		       (< (window-height last-window)
-			  (+ wheight window-min-height))))
-	     (setq window last-window)
-	     (setq last-window (previous-window window))
-	     (delete-window window))
-	   (select-window (split-window last-window))
-	   (condition-case nil
-	       (shrink-window (- (window-height) wheight))
-	     (error nil))
-	   (switch-to-buffer (w3m-get-buffer-create showbuf))
+       (progn
+         (w3m--setup-popup-window toggle showbuf nomsg)
 	   (w3m-session-select-mode sessions)
 	   (when n (w3m-session-select-next n)))
+      ;else, ie. (not sessions)
        (when (setq showbuf (get-buffer showbuf))
 	 (when (setq window (prog1 (get-buffer-window showbuf t)
 			      (kill-buffer showbuf)))