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

Re: `w3m-input-url' bug



In [emacs-w3m : No.11342] Leo wrote:
[...]
> 1 and 3 are different when point is at a url.

I forgot it, oops.

[...]
> I need a way to stop w3m-input-url from being too smart. So I wonder
> whether extending it like this can be better:

> If pass an empty string "" (or maybe a symbol noguess) as the INITIAL
> arg, that means no initial input. nil means try guessing a value. Same
> logic for DEFAULT arg.

> The prompt part should always show DEFAULT if it is set (might need
> shortening in case of long URLs).

> What do you think?

I feel it reasonable.  How about this one?

--8<---------------cut here---------------start------------->8---
--- w3m.el~	2010-09-06 03:39:33 +0000
+++ w3m.el	2010-09-08 05:36:17 +0000
@@ -4552,14 +4552,19 @@
   "Read a url from the minibuffer, prompting with string PROMPT."
   (let (url)
     (w3m-arrived-setup)
-    (unless default
-      (setq default w3m-home-page))
-    (unless (or initial
-		(not (setq initial (w3m-active-region-or-url-at-point t)))
-		(string-match "[^\000-\177]" initial))
-      (setq initial (w3m-url-decode-string initial w3m-current-coding-system)))
+    (cond ((null initial)
+	   (when (and (setq initial (w3m-active-region-or-url-at-point t))
+		      (not (string-match "[^\000-\177]" initial)))
+	     (setq initial (w3m-url-decode-string initial
+						  w3m-current-coding-system))))
+	  ((string= initial "")
+	   (setq initial nil)))
     (when initial
       (setq initial (w3m-puny-decode-url initial)))
+    (cond ((null default)
+	   (setq default w3m-home-page))
+	  ((string= default "")
+	   (setq default nil)))
     (if (and quick-start
 	     default
 	     (not initial))
@@ -4579,24 +4584,26 @@
 		  (unwind-protect
 		      (completing-read
 		       (if prompt
-			   (if (or initial (not default))
-			       prompt
-			     (when (string-match " *: *\\'" prompt)
-			       (setq prompt (substring prompt 0
-						       (match-beginning 0))))
-			     (concat prompt " (default "
-				     (if (equal default w3m-home-page)
-					 "HOME"
-				       default)
-				     "): "))
-			 (if (or initial (not default))
-			     (if feeling-lucky "URL or Keyword: " "URL: ")
-			   (format "URL %s(default %s): "
-				   (if feeling-lucky "or Keyword " "")
-				   (if (stringp default)
-				       (if (eq default w3m-home-page)
-					   "HOME" default)
-				     (prin1-to-string default)))))
+			   (if default
+			       (progn
+				 (when (string-match " *: *\\'" prompt)
+				   (setq prompt
+					 (substring prompt 0
+						    (match-beginning 0))))
+				 (concat prompt " (default "
+					 (if (equal default w3m-home-page)
+					     "HOME"
+					   default)
+					 "): "))
+			     prompt)
+			 (if default
+			     (format "URL %s(default %s): "
+				     (if feeling-lucky "or Keyword " "")
+				     (if (stringp default)
+					 (if (eq default w3m-home-page)
+					     "HOME" default)
+				       (prin1-to-string default)))
+			   (if feeling-lucky "URL or Keyword: " "URL: ")))
 		       'w3m-url-completion nil nil initial
 		       'w3m-input-url-history)
 		    (define-key minibuffer-local-completion-map " " ofunc))))
--8<---------------cut here---------------end--------------->8---