next: Update config to 1.3.3.

master
Pierre Neidhardt 2019-10-02 16:31:34 +02:00
parent 79e0d99399
commit 452b545573
1 changed files with 150 additions and 88 deletions

View File

@ -1,9 +1,56 @@
(in-package :next)
(in-package :next-user)
;; Use development platform port.
(setf (get-default 'port 'path)
(setf +platform-port-command+
"~/common-lisp/next/ports/gtk-webkit/next-gtk-webkit")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun eval-in-emacs (&rest s-exps)
"Evaluate S-exps with `emacsclient'."
(let ((s-exps-string (str:replace-all
;; Discard the package prefix.
"next::" ""
(write-to-string
`(progn ,@s-exps) :case :downcase))))
(log:debug "Sending to Emacs: ~a" s-exps-string)
(ignore-errors (uiop:run-program
(list "emacsclient" "--eval" s-exps-string)))))
(defvar *my-keymap* (make-keymap)
"Keymap for `my-mode'.")
(define-command org-capture (&optional (buffer (current-buffer)))
"Org-capture current page."
(eval-in-emacs
`(org-link-set-parameters
"next"
:store (lambda ()
(org-store-link-props
:type "next"
:link ,(url buffer)
:description ,(title buffer))))
`(org-capture)))
(define-key :keymap *my-keymap* "C-M-o" #'org-capture)
(define-command youtube-dl-current-page (&optional (buffer (current-buffer)))
"Download a video in the currently open buffer."
(eval-in-emacs
(if (search "youtu" (url buffer))
`(progn (youtube-dl ,(url buffer)) (youtube-dl-list))
`(ambrevar/youtube-dl-url ,(url buffer)))))
(define-key :keymap *my-keymap* "C-M-c d" 'youtube-dl-current-page)
(define-command play-video-in-current-page (&optional (buffer (current-buffer)))
"Play video in the currently open buffer."
(uiop:run-program (list "mpv" (url buffer))))
(define-key :keymap *my-keymap* "C-M-c v" #'play-video-in-current-page)
(define-mode my-mode ()
"Dummy mode for the custom key bindings in `*my-keymap*'."
((keymap-schemes :initform (list :emacs-map *my-keymap*
:vi-normal *my-keymap*))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar +youtube-dl-command+ "youtube-dl"
"Path to the 'youtube-dl' program.")
@ -18,8 +65,6 @@ Videos are downloaded with `+youtube-dl-command+'."
(uiop:launch-program (list +youtube-dl-command+ url "-o" "/tmp/videos/%(title)s.%(ext)s"))))
url)
;; (add-to-default-list #'auto-yt-dl-handler 'buffer 'load-hook)
(defun old-reddit-handler (url)
(let* ((uri (quri:uri url)))
(if (search "www.reddit" (quri:uri-host uri))
@ -29,14 +74,6 @@ Videos are downloaded with `+youtube-dl-command+'."
(log:info "Switching to old Reddit: ~a" new-url)
new-url))
url)))
(add-to-default-list #'old-reddit-handler 'buffer 'load-hook)
(defun blocker-hook (url)
(match (quri:uri-host (quri:uri url))
("www.imdb.com" (next/blocker-mode:blocker-mode :activate t)))
url)
(add-to-default-list #'blocker-hook 'buffer 'load-hook)
(defvar *my-unproxied-domains*
'("jit.si"
@ -51,88 +88,113 @@ Videos are downloaded with `+youtube-dl-command+'."
(not (member-string domain *my-unproxied-domains*)))))
url)
(add-to-default-list #'auto-proxy-handler 'buffer 'load-hook)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setf (get-default 'remote-interface 'download-directory)
"~/temp")
(defvar *my-blocked-hosts*
(next/blocker-mode:make-hostlist
:hosts '("platform.twitter.com"
"syndication.twitter.com"
"m.media-amazon.com")))
(add-to-default-list 'vi-normal-mode 'buffer 'default-modes)
(add-to-default-list 'proxy-mode 'buffer 'default-modes)
(add-to-default-list 'blocker-mode 'buffer 'default-modes)
(defun set-buffer-cookies-path (buffer)
(declare (ignore buffer))
;; (setf (cookies-path buffer) #P"")
)
;; TODO: Fetch from Emacs' engine.el automatically?
(nconc (get-default 'remote-interface '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")))
(defun my-buffer-defaults (buffer)
(add-to-default-list
(next/blocker-mode:make-hostlist
:hosts '("platform.twitter.com"
"syndication.twitter.com"
"m.media-amazon.com"))
'next/blocker-mode:blocker-mode 'next/blocker-mode:hostlists)
(setf (zoom-ratio-default buffer) 1.0)
(unzoom-page :buffer buffer) ; Needed for non-web-mode buffers.
(defun eval-in-emacs (&rest s-exps)
"Evaluate S-exps with `emacsclient'."
(let ((s-exps-string (str:replace-all
;; Discard the package prefix.
"next::" ""
(write-to-string
`(progn ,@s-exps) :case :downcase))))
(log:debug "Sending to Emacs: ~a" s-exps-string)
(ignore-errors (uiop:run-program
(list "emacsclient" "--eval" s-exps-string)))))
(dolist (mode '(vi-normal-mode proxy-mode my-mode))
(pushnew mode (default-modes buffer)))
;; TODO: Pros and cons of the following approach to mode init?
;; The problem with DEFAULT-MODES is that it does not allow for configuring
;; the modes.
(next/blocker-mode:blocker-mode
:hostlists (list *my-blocked-hosts* next/blocker-mode:*default-host-list*)
:buffer buffer)
(dolist (handler (list #'old-reddit-handler #'auto-proxy-handler))
(hooks:add-to-hook (hooks:object-hook buffer 'load-hook)
handler)))
(define-command org-capture (&optional (buffer (current-buffer)))
"Org-capture current page."
(eval-in-emacs
`(org-link-set-parameters
"next"
:store (lambda ()
(org-store-link-props
:type "next"
:link ,(url buffer)
:description ,(title buffer))))
`(org-capture)))
(defun my-window-defaults (window)
(setf (minibuffer-open-height window) 200))
(define-key "C-M-o" #'org-capture)
(define-key :scheme :vi-normal
"C-M-o" #'org-capture)
(defun my-minibuffer-defaults (minibuffer)
(setf
(minibuffer-line-height minibuffer) "1.0em"
(minibuffer-font-size minibuffer) "1.0em"))
(define-command youtube-dl-current-page (&optional (buffer (current-buffer)))
"Download a video in the currently open buffer."
(eval-in-emacs
(if (search "youtu" (url buffer))
`(progn (youtube-dl ,(url buffer)) (youtube-dl-list))
`(ambrevar/youtube-dl-url ,(url buffer)))))
(define-key "C-M-c d" 'youtube-dl-current-page)
(defun my-interface-defaults ()
;; TODO: Fetch from Emacs' engine.el automatically?
(setf (search-engines *interface*)
(append
'(("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"))
(search-engines *interface*)))
(setf (download-directory *interface*) "~/temp")
;; (setf (history-path *interface*) "/home/ambrevar/temp/next/history.lisp")
(hooks:add-to-hook (hooks:object-hook *interface* 'buffer-before-make-hook)
#'set-buffer-cookies-path)
(hooks:add-to-hook (hooks:object-hook *interface* 'buffer-make-hook)
#'my-buffer-defaults)
(hooks:add-to-hook (hooks:object-hook *interface* 'minibuffer-make-hook)
#'my-minibuffer-defaults)
(hooks:add-to-hook (hooks:object-hook *interface* 'window-make-hook)
#'my-window-defaults))
(define-command play-video-in-current-page (&optional (buffer (current-buffer)))
"Play video in the currently open buffer."
(uiop:run-program (list "mpv" (url buffer))))
(define-key "C-M-c v" 'play-video-in-current-page)
(hooks:add-to-hook '*after-init-hook* #'my-interface-defaults)
(defmethod deserialize-bookmarks (stream)
"This version of deserialize-bookmarks is compatibly with Ambrevar's EWW
format."
(handler-case
(let ((*standard-input* stream))
(let ((entries (read stream)))
(mapcar (lambda (entry)
(when (getf entry :date)
(setf (getf entry :date)
(local-time:parse-timestring (getf entry :date))))
(when (getf entry :time)
(let ((timestamp (asctime->timestamp (getf entry :time))))
(when timestamp
(setf (getf entry :date) timestamp)))
(remf entry :time))
(when (getf entry :search)
(setf (getf entry :search-url) (getf entry :search))
(remf entry :search))
(when (getf entry :mark)
(setf (getf entry :shortcut) (getf entry :mark))
(remf entry :mark))
(apply #'make-instance 'bookmark-entry
entry))
entries)))
(error (c)
(log:error "Error during bookmark deserialization: ~a" c)
nil)))