Skip to content

Instantly share code, notes, and snippets.

@jl2
Created November 11, 2011 19:11
Show Gist options
  • Save jl2/1358912 to your computer and use it in GitHub Desktop.
Save jl2/1358912 to your computer and use it in GitHub Desktop.
Emacs Lisp to search for the current region on DuckDuckGo. To use, type \C-\M-g and enter a bang command or just press enter to search plain duckduckgo
(global-set-key "\C-\M-g" 'ddg-bang-search)
(defun ddg-bang-search (bang)
(interactive "s!")
(let* ((search-query (replace-regexp-in-string " " "+" (buffer-substring-no-properties (region-beginning) (region-end))))
(search-string (if (> (length bang) 0)
(concat "!" bang "+" search-query)
search-query)))
(browse-url (concat "http://duckduckgo.com/?ka=h&kh=1&kj=b2&km=m&ko=1&ks=n&kt=h&ku=-1&kv=1&kw=s&kx=e&ky=b&k1=-1&q=" search-string))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment