eww.el: If given a non-domain text, search for the term
authorIvan Kanis <ivan@kanis.fr>
Sun, 23 Jun 2013 18:22:28 +0000 (20:22 +0200)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Sun, 23 Jun 2013 18:22:28 +0000 (20:22 +0200)
* net/eww.el (eww-search-prefix): New variable.
(eww): Use it.

lisp/ChangeLog
lisp/net/eww.el

index 1c4846e..521827c 100644 (file)
@@ -1,3 +1,8 @@
+2013-06-23  Ivan Kanis  <ivan@kanis.fr>
+
+       * net/eww.el (eww-search-prefix): New variable.
+       (eww): Use it.
+
 2013-06-23  Juanma Barranquero  <lekktu@gmail.com>
 
        * emacs-lisp/tabulated-list.el (tabulated-list-init-header):
index ad19758..eb1b0a2 100644 (file)
   "Header line format.
 - %t is replaced by the title.
 - %u is replaced by the URL."
+  :version "24.4"
+  :group 'eww
+  :type 'string)
+
+(defcustom eww-search-prefix "https://duckduckgo.com/html/?q="
+  "Prefix URL to search engine"
+  :version "24.4"
   :group 'eww
   :type 'string)
 
 
 ;;;###autoload
 (defun eww (url)
-  "Fetch URL and render the page."
-  (interactive "sUrl: ")
-  (unless (string-match-p "\\`[a-zA-Z][-a-zA-Z0-9+.]*://" url)
-    (setq url (concat "http://" url)))
+  "Fetch URL and render the page.
+If the input doesn't look like an URL or a domain name, the
+word(s) will be searched for via `eww-search-prefix'."
+  (interactive "sEnter URL or keywords: ")
+  (if (and (= (length (split-string url)) 1)
+           (> (length (split-string url "\\.")) 1))
+      (unless (string-match-p "\\`[a-zA-Z][-a-zA-Z0-9+.]*://" url)
+        (setq url (concat "http://" url)))
+    (setq url (concat eww-search-prefix
+                      (replace-regexp-in-string " " "+" url))))
   (url-retrieve url 'eww-render (list url)))
 
 ;;;###autoload