ambevar-dotfiles/.config/next/init.lisp

116 lines
3.9 KiB
Common Lisp
Raw Normal View History

2018-12-02 20:32:28 +01:00
(in-package :next)
2018-12-10 12:53:58 +01:00
;; Use development platform port.
(setf (get-default 'port 'path)
"~/common-lisp/next/ports/gtk-webkit/next-gtk-webkit")
2018-12-10 12:53:58 +01:00
2019-06-24 10:05:50 +02:00
(setf (get-default 'remote-interface 'download-directory)
"~/temp")
2019-06-10 11:21:15 +02:00
(add-to-default-list 'vi-normal-mode 'buffer 'default-modes)
;; ;; (setf (cdr (last (eval (get-default 'window 'search-engines))))
;; ;; '(("yt" . "https://www.youtube.com/results?search_query=~a")))
(nconc (get-default 'window 'search-engines)
2019-06-04 08:12:05 +02:00
'(("q" . "http://quickdocs.org/search?q=~a")
("yt" . "https://www.youtube.com/results?search_query=~a")))
(add-to-default-list
(make-instance 'hostlist
:hosts '("platform.twitter.com"
"syndication.twitter.com"
"m.media-amazon.com"))
'blocker-mode 'hostlists)
(defun eval-in-emacs (&rest s-exps)
"Evaluate S-exps with `emacsclient'."
2018-12-17 10:41:44 +01:00
(let ((s-exps-string (cl-strings:replace-all
(write-to-string
`(progn ,@s-exps) :case :downcase)
;; Discard the package prefix.
"next::" "")))
2019-06-10 11:21:15 +02:00
(log:debug "Sending to Emacs: ~a" s-exps-string)
(ignore-errors (uiop:run-program
(list "emacsclient" "--eval" s-exps-string)))))
2018-12-10 12:54:56 +01:00
(define-command org-capture ()
"Org-capture current page."
(with-result* ((url (buffer-get-url))
(title (buffer-get-title)))
(eval-in-emacs
`(org-link-set-parameters
"next"
:store (lambda ()
(org-store-link-props
:type "next"
:link ,url
:description ,title)))
`(org-capture))))
2018-12-10 12:54:56 +01:00
2019-06-10 11:21:15 +02:00
(define-key "C-M-o" #'org-capture)
(define-key :scheme :vi-normal
"C-M-o" #'org-capture)
2018-12-10 13:43:52 +01:00
(define-command youtube-dl-current-page ()
"Download a video in the currently open buffer."
(with-result (url (buffer-get-url))
(eval-in-emacs
(if (search "youtu" url)
`(progn (youtube-dl ,url) (youtube-dl-list))
`(ambrevar/youtube-dl-url ,url)))))
2019-06-10 11:21:15 +02:00
(define-key "C-M-c d" 'youtube-dl-current-page)
(define-command play-video-in-current-page ()
"Play video in the currently open buffer."
(with-result (url (buffer-get-url))
(uiop:run-program (list "mpv" url))))
2019-06-10 11:21:15 +02:00
(define-key "C-M-c v" 'play-video-in-current-page)
2019-06-26 14:07:06 +02:00
2019-07-29 18:25:22 +02:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2019-06-26 14:07:06 +02:00
(define-mode shell-mode ()
"A basic shell prompt."
2019-07-29 18:25:22 +02:00
((keymap-schemes
2019-06-26 14:07:06 +02:00
:initform
(let ((map (make-keymap)))
(define-key :keymap map
"c" 'run-shell-command
"k" 'clear-shell)
2019-07-29 18:25:22 +02:00
(list :emacs map
:vi-normal map)))))
2019-06-26 14:07:06 +02:00
(define-parenscript clear-shell-output ()
(setf (ps:chain document body inner-h-t-m-l) ""))
(define-command clear-shell (shell-mode)
"Clear the output in the shell buffer."
(rpc-buffer-evaluate-javascript
*interface* (active-buffer *interface*)
(clear-shell-output)))
(define-parenscript append-output (output)
(setf (ps:chain document body inner-h-t-m-l)
(ps:chain document body inner-h-t-m-l
(concat (ps:lisp
(format nil "<pre><code>~a</code></pre><br/>" output))))))
(define-command run-shell-command (shell-mode)
"Run a shell command."
(with-result
(input (read-from-minibuffer
(minibuffer *interface*)
2019-07-29 18:25:22 +02:00
:input-prompt "Run in shell:"))
2019-06-26 14:07:06 +02:00
(rpc-buffer-evaluate-javascript
*interface* (active-buffer *interface*)
(append-output
:output
(uiop:run-program input :force-shell t :output :string)))))
(define-command shell ()
"Open a shell buffer."
2019-08-18 15:57:22 +02:00
(set-active-buffer *interface*
(make-buffer :name "*shell*"
:default-modes (cons 'shell-mode
(get-default 'buffer 'default-modes)))))
2019-06-26 14:07:06 +02:00
(define-key "C-x s" #'shell)