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

Re: [BUGFIX] w3m-session-delete [PATCH]



In [emacs-w3m:12849]
On Thu, 14 Dec 2017 01:35:02 -0500, Boruch Baum wrote:
> Oh, I hadn't paid attention to that. Yes, your patch is better, but it
> doesn't handle the case of deleting the final session on the list - in
> that case the cursor jumps back to the first item.

OK, I fixed it in the new patch (attached).

> Also, at around line 723 your patch reverts a change I made...

> -       (setq title (read-from-minibuffer prompt nil nil nil nil otitle))
> +       (setq title (read-from-minibuffer prompt otitle))

> The reason I made the change was because of something I read in the
> current docstring for function `read-from-minibuffer':

>   The optional second arg INITIAL-CONTENTS is an obsolete alternative to
>   DEFAULT-VALUE.  It normally should be nil in new code, except when
>   HIST is a cons.  It is discussed in more detail below.

> When the documentation says 'obsolete', I'm not sure what they mean, and
> what the future consequences of retaining the behavior will be, but for
> now the behavior is identical, so it isn't so important.

Yes, I did read it but didn't follow.  But I found `M-n' brings
the initial string, so I decided to following the convention. :)

* w3m-session.el (w3m-session-save): Update selection buffer.
(w3m-session-select-rename, w3m-session-select-delete):
Make the selected session highlighted after renaming or deletion.
(w3m-session-select): Allow specifying the session number.
--- w3m-session.el~	2017-12-07 06:36:37.848393500 +0000
+++ w3m-session.el	2017-12-14 07:48:09.584233100 +0000
@@ -247,7 +247,10 @@
        (w3m-save-list w3m-session-file sessions)
        (if (= len 1)
 	   (message "%s: 1 session save...done" title)
-	 (message "%s: %d sessions save...done" title len))))))
+	 (message "%s: %d sessions save...done" title len))
+       (when (and (setq buf (get-buffer " *w3m-session select*"))
+		  (get-buffer-window buf 'visible))
+	 (save-selected-window (w3m-session-select)))))))
 
 (defun w3m-session-automatic-save ()
   "Save list of displayed session automatically."
@@ -631,10 +634,8 @@
   (let ((num (get-text-property
 	      (point) 'w3m-session-number))
 	(sessions w3m-session-select-sessions))
-    (w3m-session-select-quit)
     (w3m-session-rename sessions num)
-    (w3m-session-select)
-    (forward-line num)))
+    (w3m-session-select num)))
 
 (defun w3m-session-select-delete ()
   "Delete the session."
@@ -644,14 +645,13 @@
     (let ((num (get-text-property
 		(point) 'w3m-session-number))
 	  (sessions w3m-session-select-sessions))
-      (w3m-session-select-quit)
       (w3m-session-delete sessions num)
-      (w3m-session-select)
-      (forward-line num))))
+      (w3m-session-select (min num (1- (length sessions)))))))
 
 ;;;###autoload
-(defun w3m-session-select ()
-  "Select session from session list."
+(defun w3m-session-select (&optional n)
+  "Select session from session list.
+Position point at N-th session if N is given."
   (interactive)
   (w3m-session-ignore-errors
    (let* ((sessions (w3m-load-list w3m-session-file))
@@ -680,7 +680,8 @@
        (error nil))
      (switch-to-buffer showbuf)
      (setq w3m-session-select-wincfg wincfg)
-     (w3m-session-select-mode sessions))))
+     (w3m-session-select-mode sessions)
+     (when n (w3m-session-select-next n)))))
 
 (defun w3m-session-goto-session (session)
   "Goto URLs."