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

Re: asynchronous operation [PATCH]



After reviewing the details of the three cases in which emacs-w3m issues
an asych error message, here's a suggested patch that offers a uniform
and clear message, with helpful hints.

Regards,

-- 
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 04:24:54 -0000
@@ -1,3 +1,12 @@
+2018-05-09  Boruch Baum  <boruch_baum@xxxxxxx>
+
+	* w3m.el (w3m--buffer-busy-error): New function for uniform error
+	handling and message presentation.
+
+	* w3m.el (w3m-goto-url): Use the new function
+
+	* w3m-search.el (w3m-search-read-variables): Use the new function
+
 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 04:24:55 -0000
@@ -9640,6 +9684,21 @@
 			       (setq w3m-modeline-title-timer nil))))
 			 (current-buffer)))))))

+(defun w3m--buffer-busy-error ()
+  "Uniform error handling for conition of a busy buffer.
+
+Although operations are asynchronous, it makes sense that only
+one GET operation can be performed at any one time in any single
+buffer, so if the user tries to perform a second operation, a
+helpful message is presented and the operation is aborted."
+  (when w3m-current-process
+    (error "%s"
+      (substitute-command-keys "This buffer is currently busy.
+ `\\<w3m-mode-map>\\[w3m-process-stop]' to abort current operation,
+ `\\<w3m-mode-map>\\[w3m-search-new-session]' to perform a search in a new buffer.
+ `\\<w3m-mode-map>\\[w3m-goto-url-new-session]' to visit a URL in a new buffer."))))
+
+
 ;;;###autoload
 (defun w3m-goto-url (url &optional reload charset post-data referer handler
 			 element no-popup save-pos)
@@ -9675,11 +9734,7 @@
 this will be convenient if a command that calls this function may be
 invoked in other than a w3m-mode buffer."
   (interactive
-   (list (if w3m-current-process
-	     (error "%s"
-		    (substitute-command-keys
-		     "Cannot run two w3m processes simultaneously \
-\(Type `\\<w3m-mode-map>\\[w3m-process-stop]' to stop asynchronous process)"))
+   (list (unless (w3m--buffer-busy-error)
 	   (w3m-input-url "Open URL in current buffer" nil nil nil
 			  'feeling-searchy 'no-initial))
 	 current-prefix-arg
@@ -9750,11 +9805,7 @@
     (unless no-popup
       (w3m-popup-buffer (current-buffer)))
     (w3m-cancel-refresh-timer (current-buffer))
-    (when w3m-current-process
-      (error "%s"
-	     (substitute-command-keys "
-Cannot run two w3m processes simultaneously \
-\(Type `\\<w3m-mode-map>\\[w3m-process-stop]' to stop asynchronous process)")))
+    (w3m--buffer-busy-error)
     (w3m-process-stop (current-buffer))	; Stop all processes retrieving images.
     (w3m-idle-images-show-unqueue (current-buffer))
     ;; Store the current position in the history structure if SAVE-POS
Index: w3m-search.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-search.el,v
retrieving revision 1.85
diff -b -u -w -r1.85 w3m-search.el
--- w3m-search.el	18 Feb 2018 22:54:15 -0000	1.85
+++ w3m-search.el	9 May 2018 04:24:55 -0000
@@ -293,11 +293,7 @@
 WHERE is a string which should have the value \"current\" is the calling
 function intends for the search results to be presented in the current
 buffer, or \"new\" if in a new buffer."
-  (when w3m-current-process
-    (error "%s"
-	   (substitute-command-keys "
-Cannot run two w3m processes simultaneously \
-\(Type `\\<w3m-mode-map>\\[w3m-process-stop]' to stop asynchronous process)")))
+  (w3m--buffer-busy-error)
   (let* ((prompt-prefix (format "Search in %s buffer. " where))
 	 (search-engine
 	  (if current-prefix-arg