summaryrefslogtreecommitdiff
path: root/helm-net.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2015-08-20 15:36:13 +0200
committerThierry Volpiatto <thierry.volpiatto@gmail.com>2015-08-20 15:36:13 +0200
commit325b7ed8dea1241f413626af532c38a5a8a14a28 (patch)
treeae9b2653dbd517d3a678ce59cb0d88190d74df80 /helm-net.el
parent959dfbffd7efd1ed401e04b082858f32e9dca0a8 (diff)
Simplify url query - drop yahoo suggest.
* helm-net.el (helm-net--url-retrieve-sync): New. (helm-google-suggest-fetch): Do it. (helm-wikipedia-suggest-fetch): Do it. (helm-wikipedia-fetch-summary): Do it.
Diffstat (limited to 'helm-net.el')
-rw-r--r--helm-net.el118
1 files changed, 26 insertions, 92 deletions
diff --git a/helm-net.el b/helm-net.el
index 652d8294..f965f981 100644
--- a/helm-net.el
+++ b/helm-net.el
@@ -65,18 +65,6 @@ Otherwise `url-retrieve-synchronously' is used."
:type 'boolean
:group 'helm-net)
-(defcustom helm-yahoo-suggest-url
- "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=Generic&query="
- "Url used for looking up Yahoo suggestions."
- :type 'string
- :group 'helm-net)
-
-(defcustom helm-yahoo-suggest-search-url
- "http://search.yahoo.com/search?&ei=UTF-8&fr&h=c&p=%s"
- "Url used for Yahoo searching."
- :type 'string
- :group 'helm-net)
-
(defcustom helm-surfraw-duckduckgo-url
"https://duckduckgo.com/lite/?q=%s&kp=1"
"The duckduckgo url.
@@ -171,22 +159,16 @@ This is a format string, don't forget the `%s'."
candidate))))
"List of additional actions for suggest sources.")
-
-;;; Google Suggestions
-;;
-;;
-(defun helm-google-suggest-fetch (input)
- "Fetch suggestions for INPUT from XML buffer."
- (let ((request (concat helm-google-suggest-url
- (url-hexify-string input)))
- (fetch #'(lambda ()
- (cl-loop
- with result-alist = (xml-get-children
- (car (xml-parse-region
- (point-min) (point-max)))
- 'CompleteSuggestion)
- for i in result-alist collect
- (cdr (cl-caadr (assoc 'suggestion i)))))))
+(defun helm-net--url-retrieve-sync (request &optional parser)
+ (let ((fetch (or parser
+ (lambda ()
+ (cl-loop
+ with result-alist = (xml-get-children
+ (car (xml-parse-region
+ (point-min) (point-max)))
+ 'CompleteSuggestion)
+ for i in result-alist collect
+ (cdr (cl-caadr (assoc 'suggestion i))))))))
(if helm-google-suggest-use-curl-p
(with-temp-buffer
(call-process "curl" nil t nil request)
@@ -195,6 +177,16 @@ This is a format string, don't forget the `%s'."
(url-retrieve-synchronously request)
(funcall fetch)))))
+
+;;; Google Suggestions
+;;
+;;
+(defun helm-google-suggest-fetch (input)
+ "Fetch suggestions for INPUT from XML buffer."
+ (let ((request (concat helm-google-suggest-url
+ (url-hexify-string input))))
+ (helm-net--url-retrieve-sync request)))
+
(defun helm-google-suggest-set-candidates (&optional request-prefix)
"Set candidates with result and number of google results found."
(let ((suggestions (helm-google-suggest-fetch
@@ -252,47 +244,6 @@ This is a format string, don't forget the `%s'."
"Try to emacs lisp complete with google suggestions."
(helm-google-suggest-set-candidates "emacs lisp"))
-
-;;; Yahoo suggestions
-;;
-;;
-(defun helm-yahoo-suggest-fetch (input)
- "Fetch Yahoo suggestions for INPUT from XML buffer.
-Return an alist with elements like (data . number_results)."
- (let ((request (concat helm-yahoo-suggest-url
- (url-hexify-string input))))
- (with-current-buffer
- (url-retrieve-synchronously request)
- (cl-loop with result-alist =
- (xml-get-children
- (car (xml-parse-region
- (point-min) (point-max)))
- 'Result)
- for i in result-alist
- collect (cl-caddr i)))))
-
-(defun helm-yahoo-suggest-set-candidates ()
- "Set candidates with Yahoo results found."
- (let ((suggestions (helm-yahoo-suggest-fetch helm-input)))
- (or suggestions
- (append
- suggestions
- (list (cons (concat "Search for " "'" helm-input "'" " on Yahoo")
- helm-input))))))
-
-(defun helm-yahoo-suggest-action (candidate)
- "Default action to jump to a Yahoo suggested candidate."
- (helm-browse-url (format helm-yahoo-suggest-search-url
- (url-hexify-string candidate))))
-
-(defvar helm-source-yahoo-suggest
- `((name . "Yahoo Suggest")
- (candidates . helm-yahoo-suggest-set-candidates)
- (action . (("Yahoo Search" . helm-yahoo-suggest-action)))
- (volatile)
- (keymap . ,helm-map)
- (requires-pattern . 3)))
-
;;; Wikipedia suggestions
;;
;;
@@ -302,13 +253,8 @@ Return an alist with elements like (data . number_results)."
(require 'json)
(let ((request (concat helm-wikipedia-suggest-url
(url-hexify-string helm-pattern))))
- (if helm-google-suggest-use-curl-p
- (with-temp-buffer
- (call-process "curl" nil t nil request)
- (helm-wikipedia--parse-buffer))
- (with-current-buffer
- (url-retrieve-synchronously request)
- (helm-wikipedia--parse-buffer)))))
+ (helm-net--url-retrieve-sync
+ request #'helm-wikipedia--parse-buffer)))
(defun helm-wikipedia--parse-buffer ()
(goto-char (point-min))
@@ -353,17 +299,11 @@ Return an alist with elements like (data . number_results)."
(display-buffer buf)
(message mess)))))
-
(defun helm-wikipedia-fetch-summary (input)
- (let* ((request (concat helm-wikipedia-summary-url (url-hexify-string input))))
- (if helm-google-suggest-use-curl-p
- (with-temp-buffer
- (call-process "curl" nil t nil request)
- (helm-wikipedia--parse-summary))
- (with-current-buffer
- (url-retrieve-synchronously request)
- (helm-wikipedia--parse-summary)))))
-
+ (let* ((request (concat helm-wikipedia-summary-url
+ (url-hexify-string input))))
+ (helm-net--url-retrieve-sync
+ request #'helm-wikipedia--parse-summary)))
(defun helm-wikipedia--parse-summary ()
(goto-char (point-min))
@@ -540,12 +480,6 @@ Return an alist with elements like (data . number_results)."
(helm-other-buffer 'helm-source-google-suggest "*helm google*"))
;;;###autoload
-(defun helm-yahoo-suggest ()
- "Preconfigured `helm' for Yahoo searching with Yahoo suggest."
- (interactive)
- (helm-other-buffer 'helm-source-yahoo-suggest "*helm yahoo*"))
-
-;;;###autoload
(defun helm-wikipedia-suggest ()
"Preconfigured `helm' for Wikipedia lookup with Wikipedia suggest."
(interactive)