Created
April 2, 2012 14:47
-
-
Save mikeivanov/2283997 to your computer and use it in GitHub Desktop.
Duckduckgo the term under cursor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun search-selection-or-symbol (arg) | |
(interactive "p") | |
(unless (and (local-variable-p 'search-prefix-default) | |
search-prefix-default) | |
(let* ((mode (symbol-name major-mode)) | |
(name (replace-regexp-in-string "-mode$" "" mode)) | |
(prefix (replace-regexp-in-string "-" " " name))) | |
(set (make-local-variable 'search-prefix-default) prefix))) | |
(let* ((prefix (if (= arg 1) | |
search-prefix-default | |
(setq search-prefix-default | |
(read-from-minibuffer "Set prefix: " | |
search-prefix-default)))) | |
(query (read-from-minibuffer | |
"Search for: " (concat | |
(if prefix (format "%s " prefix) "") | |
(substring-no-properties | |
(or (if (region-active-p) | |
(buffer-substring (region-beginning) | |
(region-end)) | |
(thing-at-point 'symbol)) | |
""))))) | |
(url (format "https://duckduckgo.com/?q=%s" | |
(url-hexify-string query)))) | |
(message "Searching %s" query) | |
(browse-url url))) | |
(global-set-key (kbd "s-/") 'search-selection-or-symbol) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment