Skip to content

Instantly share code, notes, and snippets.

@ctanis
Created August 10, 2013 19:15
Show Gist options
  • Save ctanis/6201749 to your computer and use it in GitHub Desktop.
Save ctanis/6201749 to your computer and use it in GitHub Desktop.
a dinky little elisp function for searching duckduckgo with (optionally) the region contents (optionally enclosed in quotes) with no active region, it just sends the minibuffer contents. with an active region, it concats the minibuffer contents with the region contents. with a prefix argument, the region contents are enclosed in quotes.
(defun ddg-search (prefix str)
(interactive "P\nMSearch term: ")
(let ((arg
(if (region-active-p)
(concat str (if prefix " \"" " ")
(buffer-substring (region-beginning) (region-end))
(if prefix "\""))
str)))
(browse-url (concat "https://duckduckgo.com/?q=" (url-hexify-string arg)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment