Here’s a cool hack I use to optimize my docs searching.
Let’s start off with DuckDuckGo search engine.
By itself it’s a pretty powerful tool thanks to its numerous features like the !bang syntax. For example searching for:
!cpp std::string::clear
…takes me exactly where I want.
Let’s use it to our advantage, shall we?
StumpWM is a tailing window manager that allows you to define system-wide key bindings that work and feel pretty much like Emacs ones. Combining that with DuckDuckGo’es !bang syntax makes you just a few clicks away from anything out there:
(defcommand duckduckgo (phrase) ((:string "Search: ")) "Searches for something on DuckDuckGo." (run-shell-command (concatenate 'string *your-fav-webbrowser* " http://duckduckgo.com/?q=" (substitute #\+ #\Space phrase)))) (define-key *root-map* (kbd "d") "duckduckgo")
Now, if you want to find out if I used substitute correctly all you have to do is:
C-t d !lisp substitute
…what will take you directly there. Turns out I did.
But wait, there’s more!
You can wrap this code in a simple macro and use it with any site or search engine you wish:
(defmacro make-search (name prefix) `(defcommand ,name (phrase) ((:string ,(format nil "~A search: " name))) ,(format nil "Searches for something on ~A." name) (run-shell-command (concatenate 'string *your-fav-webbrowser* " " ,prefix (substitute #\+ #\Space phrase))))) (make-search duckduckgo "http://www.duckduckgo.com/?q=") (define-key *root-map* (kbd "d") "duckduckgo") (make-search wikipedia "http://en.wikipedia.org/") (define-key *root-map* (kbd "w") "wikipedia")
…and even search directly in your favourite online source:
(make-search texqa "http://www.duckduckgo.com/?q=!tex+") (define-key *root-map* (kbd "T") "texqa")
Neat.