[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
w3m-session retain cursor positions [PATCH]
- From: Boruch Baum <boruch_baum@xxxxxxx>
- Date: Thu, 7 Dec 2017 00:29:56 -0500
- X-ml-name: emacs-w3m
- X-mail-count: 12832
Within the session-session minibuffer (M-x w3m-session-select, bound by
default to M-s), when one performs a rename or a delete, the cursor
(point) would jump to the first entry of the minibuffer.
This patch fixes that.
Also, while I was 'in the neighborhood', I performed edits on some of
the code to (hopefully) simplify / clean-up. In my testing, it doesn't
seem to have introduced any trouble.
Two of the notable cleanups were: an unnecessary throw/catch idiom; and
a deprecated use of an argument in a read function.
For your consideration ...
--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0
Index: w3m-session.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-session.el,v
retrieving revision 1.38
diff -u -w -B -r1.38 w3m-session.el
--- w3m-session.el 17 Aug 2017 01:49:09 -0000 1.38
+++ w3m-session.el 7 Dec 2017 05:22:05 -0000
@@ -633,7 +633,8 @@
(sessions w3m-session-select-sessions))
(w3m-session-select-quit)
(w3m-session-rename sessions num)
- (w3m-session-select)))
+ (w3m-session-select)
+ (forward-line num)))
(defun w3m-session-select-delete ()
"Delete the session."
@@ -645,7 +646,8 @@
(sessions w3m-session-select-sessions))
(w3m-session-select-quit)
(w3m-session-delete sessions num)
- (w3m-session-select))))
+ (w3m-session-select)
+ (forward-line num))))
;;;###autoload
(defun w3m-session-select ()
@@ -711,55 +713,47 @@
(defun w3m-session-rename (sessions num)
(if (consp num)
- (message "This command can execute in Main session area")
- (let ((prompt "New session title: ")
- (overwrite nil)
- tmp title otitle)
- (setq tmp (nth num sessions))
- (setq otitle (car tmp))
- (setq title otitle)
- (catch 'loop
- (while t
- (setq title (read-from-minibuffer prompt otitle))
+ (message "This command must be run from the `w3m-session-select' minibuffer.")
+ ; OK, but why do we allow `w3m-session-delete' to run otherwise?
+ (let* ((default-prompt "Enter new session title (C-g to abort): ")
+ (prompt default-prompt)
+ overwrite
+ title
+ (tmp (nth num sessions))
+ (otitle (car tmp)))
+ (while (not title)
+ (setq title (read-from-minibuffer prompt nil nil nil nil otitle))
(cond
((string= title "")
- nil)
+ (setq title nil
+ prompt default-prompt))
((string= title otitle)
- (when (y-or-n-p
- (format "\"%s\" is same as original title. Do not rename? "
- title))
- (throw 'loop t)))
+ (setq prompt (concat title " is same as original title (C-g to abort): ")
+ title nil))
((assoc title sessions)
- (when (y-or-n-p (format "\"%s\" is exist. Overwrite? " title))
- (setq overwrite t)
- (throw 'loop t)))
- (t
- (throw 'loop t)))
- (setq prompt "Again New session title: ")))
- (when overwrite
- (setq sessions (delete (assoc title sessions) sessions)))
- (unless (string= title otitle)
- (setq sessions (delete tmp sessions))
+ (if (not (y-or-n-p (format "\"%s\" exists. Overwrite? " title)))
+ (setq prompt default-prompt
+ title nil))
+ (setq sessions (delete (assoc title sessions) sessions))
+ (setq num (seq-position sessions (assoc otitle sessions))))))
+ ; in this case, wrapper must decrement its copy of num
(setcar tmp title)
- (setq sessions (cons tmp sessions))
- (w3m-save-list w3m-session-file sessions)))))
+ (setcar (nthcdr num sessions) tmp)
+ (w3m-save-list w3m-session-file sessions))))
(defun w3m-session-delete (sessions num)
- (let (tmp)
(if (consp num)
(let ((item (nth 2 (nth (car num) sessions))))
(setq tmp (delete (nth (cdr num) item)
item))
(setf (nth 2 (nth (car num) sessions))
tmp))
- (setq tmp (nth num sessions))
- (setq sessions (delete tmp sessions)))
+ (setq sessions (delete (nth num sessions) sessions)))
(if sessions
(w3m-save-list w3m-session-file sessions)
(let ((file (expand-file-name w3m-session-file)))
- (when (and (file-exists-p file)
- (file-writable-p file))
- (delete-file file))))))
+ (when (and (file-exists-p file) (file-writable-p file))
+ (delete-file file)))))
(defvar w3m-session-menu-items
`([,(w3m-make-menu-item "新しいセッションを作る..."
Index: ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/ChangeLog,v
retrieving revision 1.3631
diff -u -w -B -r1.3631 ChangeLog
--- ChangeLog 4 Dec 2017 22:45:30 -0000 1.3631
+++ ChangeLog 7 Dec 2017 05:22:09 -0000
@@ -1,3 +1,10 @@
+2017-12-07 Boruch Baum <boruch_baum@xxxxxxx>
+
+ * w3m-session.el (w3m-session-select-delete)
+ (w3m-session-select-rename): Retain cursor position after completion.
+ * w3m-session.el (w3m-session-select-delete)
+ (w3m-session--rename): simplify code.
+
2017-12-04 Katsumi Yamaoka <yamaoka@xxxxxxx>
* w3m-filter.el (w3m-filter-add-name-anchors): Relax regexp