Next: Fetch search engines from Emacs Engine.

master
Pierre Neidhardt 2020-04-08 15:41:14 +02:00
parent dff4a1e139
commit fbc093b730
1 changed files with 32 additions and 29 deletions

View File

@ -133,44 +133,47 @@ Videos are downloaded with `+youtube-dl-command+'."
(setf *buffer-class* 'my-buffer)
(defmacro with-maybe-gpg-file ((stream filespec) &body body)
"Evaluate BODY with STREAM bound to FILESPEC.
FILESPEC may be a GPG-encrypted file."
`(let ((clear-data (handler-case
(with-output-to-string (out)
(uiop:run-program (list "gpg" "-d" ,filespec) :output out))
(error ()
(alexandria:read-file-into-string ,filespec)))))
(with-input-from-string (,stream clear-data)
,@body)))
(defun format-c->lisp (s)
"Incomplete substitution of C format string to Lisp format string.
Recognized formats:
- %%
- %s"
(str:join "%" (mapcar (lambda (s) (str:replace-all "%s" "~a" s))
(str:split "%%" s))))
(defun read-emacs-engines (stream)
"Return a list of (NAME URL SHORTCUT)."
(loop for object = (read stream nil :eof)
until (eq object :eof)
when (eq (car object) 'defengine)
collect (list ;; (nth 1 object) ; No need for name?
(getf (nthcdr 3 object) :keybinding)
(format-c->lisp (nth 2 object)))))
(defvar my-search-engines
'(("aa" . "https://aur.archlinux.org/packages.php?O=0&K=~a&do_Search=Go")
("ap" . "https://www.archlinux.org/packages/?sort=&q=~a&maintainer=&flagged=")
("aw" . "https://wiki.archlinux.org/index.php?search=~a")
("ctan" . "http://www.ctan.org/search?phrase=~a")
("dd" . "http://devdocs.io/#q=~a")
("dg" . "https://duckduckgo.com/?q=~a")
("eb" . "https://debbugs.gnu.org/cgi/pkgreport.cgi?package=emacs;include=subject%3A~a;repeatmerged=on;archive=both")
("ed" . "https://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-devel&submit=Search&query=~a")
("ee" . "https://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emms-help&submit=Search!&query=~a")
("ge" . "https://wiki.gentoo.org/index.php?title=Special%3ASearch&search=~a&go=Go")
("gh" . "https://github.com/search?ref=simplesearch&q=~a")
("gr" . "https://www.goodreads.com/search?q=~a")
("gm" . "https://maps.google.com/maps?q=~a")
("gud" . "https://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=guix-devel&submit=Search&query=~a")
("guh" . "https://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=help-guix&submit=Search!&query=~a")
("gup" . "https://guix-hpc.bordeaux.inria.fr/package/~a")
("i" . "http://www.imdb.com/find?q=~a&s=all")
("mba" . "http://musicbrainz.org/search?query=~a&type=artist&method=indexed")
("mbr" . "http://musicbrainz.org/search?query=~a&type=release&method=indexed")
("osm" . "https://www.openstreetmap.org/search?query=~a")
("q" . "http://quickdocs.org/search?q=~a")
("s" . "http://stackoverflow.com/search?q=~a")
("wp" . "http://www.wikipedia.org/search-redirect.php?language=en&go=Go&search=~a")
("wb" . "http://en.wikibooks.org/wiki/Special:Search?search=~a")
("wk" . "http://en.wiktionary.org/wiki/Special:Search?search=~a")
("wa" . "http://www.winehq.org/search/?q=~a")
("yt" . "https://www.youtube.com/results?search_query=~a")))
(loop for file in '("~/.emacs.d/lisp/init-engine.el"
"~/personal/bookmarks/engines.el")
append (with-maybe-gpg-file (s file)
(read-emacs-engines s))))
(if (find-class 'remote-interface nil)
(defclass my-remote-interface (remote-interface)
;; TODO: Fetch from Emacs' engine.el automatically?
((search-engines :initform
(append
my-search-engines
(get-default 'remote-interface 'search-engines)))))
(defclass my-browser (gtk-browser)
;; TODO: Fetch from Emacs' engine.el automatically?
((search-engines :initform
(append
my-search-engines