Paste number 317863: web search keybindings Pasted by: fiddlerwoaroof When: 4 years, 3 months ago Share: Tweet this! | http://paste.lisp.org/+6T9J Channel: None Paste contents: Raw Source | XML | Display As text/plain image/svg+xml text/html application/xhtml+xml

( provider &rest strings ) :method-combination append :most-specific-last :method :around ( provider &rest r ) declare ignore r string call-next-method apply #' concatenate :method append ( provider &rest r ) declare ignore r list "https://duckduckgo.com/?q=" :method append eql nil provider &rest strings list* car strings cdr strings list "+" string loop for string innconcing :method append eql :google provider &rest strings list* "%21google" list "+" string loop for string in strings nconcing defgeneric get-search-url ( name ddg-shortcut ) ` eql ,name provider &rest strings list* concatenate 'string "%21" ,ddg-shortcut ,ddg-shortcut list "+" string loop for string in strings nconcing defmethod get-search-url append defmacro add-provider ( &body definitions ) ` ( name shortcut ) in definitions collect ` ( add-provider ,name ,shortcut ) loop forincollect ` progn ,@ defmacro add-providers ( add-providers ( :amazon "a" ) ( :php "php" ) ( :python "python" ) ( :stack-overflow "sof" ) ( :lisp "lisp" ) ( :wikipedia "w" ) ) defcommand do-search ( provider search-string ) ( ( :string "Provider: " ) ( :string "Search for: " ) ) "Run a search against a specified provider" or null string check-type provider or null string check-type search-string when and provider search-string let intern string-upcase provider :keyword provider *browser-command* " " substitute #\+ #\space search-string search-string get-search-url provider cat run-shell-command do-search defcommand google ( search-string ) ( ( :string "Search Google for: " ) ) "Search google for a given string" or null string check-type search-string *browser-command* " " :google substitute #\+ #\space search-string search-string get-search-url cat run-shell-command when search-string google ( defcommand search-for-selection ( provider ) ( ( :string "Search Provider?" ) ) "Search for the x selection with provider" ( do-search provider ( get-x-selection ) ) ) defparameter *selection-search-map* nil "selection search map" ( fill-keymap *selection-search-map* ( kbd "g" ) "search-for-selection google" ( kbd "/" ) "search-for-selection google" ( kbd "s-/" ) "search-for-selection google" ( kbd "l" ) "search-for-selection lisp" ) defparameter *search-map* nil "search map" ( fill-keymap *search-map* ( kbd "a" ) "do-search amazon" ( kbd "h" ) "do-search php" ( kbd "p" ) "do-search python" ( kbd "o" ) "do-search stack-overflow" ( kbd "y" ) "do-search youtube" ( kbd "l" ) "do-search lisp" ( kbd "w" ) "do-search wikipedia" ( kbd "d" ) "do-search duckduckgo" ( kbd "g" ) "do-search google" ( kbd "s" ) *selection-search-map* ( kbd "/" ) "do-search google" ( kbd "Return" ) "search-for-selection google" ( kbd "s-/" ) "do-search google" ) ( define-key *top-map* ( kbd "s-/" ) *search-map* ) /s /s