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

Editing non-local files [PATCH]



The current behavior of w3m-edit-url only allows editing a local file.
The attached patch adds the ability to edit any url displayed in the
emacs-w3m buffer. If the url is not a local file, the user is prompted
for a lcoation in which to save it before editing.

The patch also modifies a few docstrings and user-prompts, mainly to use
the term 'buffer' instead of 'session'.

For your consideration.


-- 
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1693
diff -u -w -B -r1.1693 w3m.el
--- w3m.el	3 Dec 2017 22:50:45 -0000	1.1693
+++ w3m.el	8 Dec 2017 13:20:29 -0000
@@ -7173,7 +7173,7 @@
   "Display the page pointed to by the link under point.
 If ARG is the number 2 or the list of the number 16 (you may produce
 this by typing `C-u' twice) or NEW-SESSION is non-nil and the link is
-an anchor, this function makes a copy of the current session in
+an anchor, this function makes a copy of the current buffer in
 advance.  Otherwise, if ARG is non-nil, it forces to reload the url at
 point."
   (interactive (if (member current-prefix-arg '(2 (16)))
@@ -7612,7 +7612,7 @@
 		      (w3m-highlight-current-anchor-1 seq))))))))
 
 (defun w3m-edit-url (url)
-  "Edit the page pointed by URL."
+  "Edit the source code of URL."
   (interactive (list (w3m-input-url)))
   (when (string-match "\\`about://\\(?:header\\|source\\)/" url)
     (setq url (substring url (match-end 0))))
@@ -7623,17 +7623,19 @@
 	(throw 'found (funcall (cdr pair) url))))
     (funcall w3m-edit-function
 	     (or (w3m-url-to-file-name url)
+             (call-interactively 'w3m-save-buffer)
 		 (error "URL:%s is not a local file" url)))))
 
 (defun w3m-edit-current-url ()
-  "Edit this viewing page."
+  "Edit the source code of the file that the current
+emacs-w3m buffer is viewing."
   (interactive)
   (if w3m-current-url
       (w3m-edit-url w3m-current-url)
     (w3m-message "No URL")))
 
 (defun w3m-edit-this-url ()
-  "Edit the page linked from the anchor under the cursor."
+  "Edit the source code of the file linked from the anchor at point."
   (interactive)
   (let ((url (w3m-url-valid (w3m-anchor))))
     (if url
@@ -9555,7 +9557,10 @@
 ;;;###autoload
 (defun w3m-goto-url (url &optional reload charset post-data referer handler
 			 element no-popup save-pos)
-  "Visit World Wide Web pages.  This is the primitive function of `w3m'.
+  "Visit World Wide Web pages in the current buffer.
+
+This is the primitive function of `w3m'.
+
 If the second argument RELOAD is non-nil, reload a content of URL.
 Except that if it is 'redisplay, re-display the page without reloading.
 The third argument CHARSET specifies a charset to be used for decoding
@@ -9588,7 +9597,7 @@
 	     (error "%s"
 		    (substitute-command-keys "Cannot run two w3m processes simultaneously \
 \(Type `\\<w3m-mode-map>\\[w3m-process-stop]' to stop asynchronous process)"))
-	   (w3m-input-url nil nil nil nil 'feeling-searchy 'no-initial))
+	   (w3m-input-url "Open URL in current buffer" nil nil nil 'feeling-searchy 'no-initial))
 	 current-prefix-arg
 	 (w3m-static-if (fboundp 'universal-coding-system-argument)
 	     coding-system-for-read)))
@@ -9927,12 +9936,13 @@
 ;;;###autoload
 (defun w3m-goto-url-new-session (url &optional reload charset post-data
 				     referer)
-  "Visit World Wide Web pages in a new session.
-If you invoke this command in the emacs-w3m buffer, the new session
-will be created by copying the current session.  Otherwise, the new
-session will start afresh."
+  "Visit World Wide Web pages in a new buffer.
+
+If you invoke this command in the emacs-w3m buffer, the new buffer
+will be created by copying the current buffer.  Otherwise, the new
+buffer will start afresh."
   (interactive
-   (list (w3m-input-url nil nil
+   (list (w3m-input-url "Open URL in new buffer" nil
 			(or (w3m-active-region-or-url-at-point)
 			    w3m-new-session-url)
 			nil 'feeling-searchy 'no-initial)
@@ -10163,8 +10173,8 @@
 whether this command should pop to a window or a frame up for the
 session.
 
-When emacs-w3m sessions have already been opened, this command will
-pop to the existing window or frame up, but if `w3m-quick-start' is
+When an emacs-w3m session has already been opened, this command will
+pop to an existing window or frame, but if `w3m-quick-start' is
 nil, \(default t), you will be prompted for a URL (which defaults to
 `popup' meaning to pop to an existing emacs-w3m buffer up).
 
@@ -10369,7 +10379,8 @@
 				(substring w3m-current-url (match-end 0)))))
 	 (t
 	  (w3m-goto-url  (concat "about://source/" w3m-current-url))))
-	(w3m-history-restore-position))
+	(w3m-history-restore-position)
+     t) ; <-- an improvement, but wrong if the above failed (BORUCH)
     (w3m-message "Can't view page source")))
 
 (defun w3m-make-separator ()
Index: w3m-bookmark.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-bookmark.el,v
retrieving revision 1.57
diff -u -w -B -r1.57 w3m-bookmark.el
--- w3m-bookmark.el	28 Jun 2017 00:53:11 -0000	1.57
+++ w3m-bookmark.el	8 Dec 2017 13:20:29 -0000
@@ -359,7 +359,7 @@
 
 ;;;###autoload
 (defun w3m-bookmark-view (&optional reload)
-  "Display the bookmark."
+  "Display the bookmark list in the current buffer."
   (interactive "P")
   (if (file-exists-p w3m-bookmark-file)
       (progn
@@ -370,7 +370,7 @@
 
 ;;;###autoload
 (defun w3m-bookmark-view-new-session (&optional reload)
-  "Display the bookmark on a new session."
+  "Display the bookmark list in a new buffer."
   (interactive "P")
   (if (not (eq major-mode 'w3m-mode))
       (message "This command can be used in w3m mode only")
Index: w3m-save.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-save.el,v
retrieving revision 1.10
diff -u -w -B -r1.10 w3m-save.el
--- w3m-save.el	4 Jan 2017 23:55:59 -0000	1.10
+++ w3m-save.el	8 Dec 2017 13:20:29 -0000
@@ -80,8 +80,11 @@
 		       (make-temp-name "w3m-")))
 	     (case-fold-search t))
 	 (setq name (w3m-replace-in-string name "[\C-@- \"*/:<>?\|]+" "_"))
-	 (list (read-file-name
-		"Save this page to: "
+	 (list
+       (read-file-name
+         (if (not w3m-save-buffer-html-only)
+           "Save this page (with images) to: "
+          "Save this page (html only) to: ")
 		(file-name-as-directory w3m-save-buffer-directory)
 		name nil (concat name ".html"))
 	       current-prefix-arg))
@@ -228,7 +231,7 @@
      (prog1
 	 (cadar w3m-history)
        (w3m-history-push (w3m-expand-file-name-as-url name)
-			 (list :title (or w3m-current-title "<no-title>")))))))
+			 (list :title (or w3m-current-title "<no-title>"))))) name))
 
 (provide 'w3m-save)
 
Index: w3m-search.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-search.el,v
retrieving revision 1.83
diff -u -w -B -r1.83 w3m-search.el
--- w3m-search.el	8 Dec 2017 00:01:57 -0000	1.83
+++ w3m-search.el	8 Dec 2017 13:20:29 -0000
@@ -284,14 +284,16 @@
 		   prompt)
 		 initial history default)))
 
-(defun w3m-search-read-variables (session)
-  "Ask for a search engine and words to query and return them as a list."
+(defun w3m-search-read-variables (where)
+  "Ask for a search engine and words to query and return them as a list.
+
+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)")))
-  (let* ((prompt-prefix (format "Search in %s session. " session))
+  (let* ((prompt-prefix (format "Search in %s buffer. " where))
 	 (search-engine
 	  (if current-prefix-arg
 	      (let ((default (or (car w3m-search-engine-history)
@@ -327,6 +329,9 @@
 ;;;###autoload
 (defun w3m-search (search-engine query)
   "Search QUERY using SEARCH-ENGINE.
+
+Search results will appear in the current buffer.
+
 When called interactively with a prefix argument, you can choose one of
 the search engines defined in `w3m-search-engine-alist'.  Otherwise use
 `w3m-search-default-engine'.
@@ -337,7 +342,7 @@
 
 ;;;###autoload
 (defun w3m-search-new-session (search-engine query)
-  "Like `w3m-search', but do the search in a new session."
+  "Like `w3m-search', but do the search in a new buffer."
   (interactive (w3m-search-read-variables "new"))
   (w3m-search-do-search 'w3m-goto-url-new-session search-engine query))
 
Index: ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/ChangeLog,v
retrieving revision 1.3635
diff -u -w -B -r1.3635 ChangeLog
--- ChangeLog	8 Dec 2017 00:01:56 -0000	1.3635
+++ ChangeLog	8 Dec 2017 13:20:31 -0000
@@ -1,8 +1,27 @@
+2017-12-08  Boruch Baum  <boruch_baum@xxxxxxx>
+
+	* w3m.el (w3m-edit-url, w3m-edit-current-url, w3m-edit-this-url):
+	Enable editing non-local files. In such cases, the user is prompted to
+	save the emacs-w3m buffer locally, prior to beginning the editing
+	session. Edit docstring.
+	(w3m-goto-url, w3m-goto-url-new-session): Clarify in docstring
+	and in input prompt whether the action is to happen in the current or
+	in a new buffer.
+	* w3m-save.el (w3m-save-buffer): function returns the saved file name.
+	* w3m-bookmark.el (w3m-bookmark-view-new-session): Add to docstring
+	whether the bookmark list will be presented in the current or in a new
+	buffer.
+	* w3m-search.el (w3m-search-read-variables): Add to docstring
+	information on new arg, rename arg to `where', change terminology from
+	`session' to `buffer'.
+	(w3m-search, w3m-search-new-session): Add to docstring whether results
+	will be repesented in the current or in a new buffer.
+
 2017-12-07  Boruch Baum  <boruch_baum@xxxxxxx>
 
 	* w3m-search.el (w3m-search, w3m-search-new-session)
 	(w3m-search-read-variables): Provide visual feedback for whether search
-	will be in new or current session.
+	will be in new or current session  ([emacs-w3m:12837]).
 
 2017-12-07  Katsumi Yamaoka  <yamaoka@xxxxxxx>