From 8e573e1eb80b562ebddf0e9153079adaed4d4f91 Mon Sep 17 00:00:00 2001 From: "Antoine R. Dumont" Date: Sat, 11 Jan 2014 19:16:04 +0100 Subject: [PATCH] Factor the search engine installation to ease the future install of new ones. --- core/prelude-core.el | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/core/prelude-core.el b/core/prelude-core.el index 7ce5060..e40f1f1 100644 --- a/core/prelude-core.el +++ b/core/prelude-core.el @@ -71,21 +71,16 @@ PROMPT sets the `read-string prompt." (buffer-substring (region-beginning) (region-end)) (read-string prompt)))))) -(defun prelude-google () - "Googles a query or region if any." - (interactive) - (prelude-search "http://www.google.com/search?q=" "Google: ")) +(defmacro prelude-install-search-engine (search-engine-name search-engine-url search-engine-prompt) + "Given some information regarding a search engine, install the interactive command to search through them" + `(defun ,(intern (format "prelude-%s" search-engine-name)) () + ,(format "Search %s with a query or region if any." search-engine-name) + (interactive) + (prelude-search ,search-engine-url ,search-engine-prompt))) -(defun prelude-youtube () - "Search YouTube with a query or region if any." - (interactive) - (prelude-search "http://www.youtube.com/results?search_query=" - "Search YouTube: ")) - -(defun prelude-github () - "Search GitHub with a query or region if any." - (interactive) - (prelude-search "https://github.com/search?q=" "Search GitHub: ")) +(prelude-install-search-engine "google" "http://www.google.com/search?q=" "Google: ") +(prelude-install-search-engine "youtube" "http://www.youtube.com/results?search_query=" "Search YouTube: ") +(prelude-install-search-engine "github" "https://github.com/search?q=" "Search GitHub: ") (defun prelude-indent-rigidly-and-copy-to-clipboard (begin end arg) "Indent region between BEGIN and END by ARG columns and copy to clipboard."