Next: Use PRIN1-TO-STRING instead of manually generated code strings

master
Pierre Neidhardt 2018-12-16 11:43:37 +01:00
parent 1d6b357912
commit 0580104fdb
1 changed files with 23 additions and 31 deletions

View File

@ -12,45 +12,37 @@
(define-key *global-map* (key "M-g") #'go-anchor-new-buffer)
(define-key *global-map* (key "C-M-C") #'kill)
(defun eval-in-emacs (&rest s-exps)
"Evaluate S-EXPS with emacsclient."
(uiop:run-program
(list "emacsclient" "--eval"
;; Discard the package prefix.
(ppcre:regex-replace-all
"next::" (prin1-to-string `(progn ,@s-exps)) ""))))
(define-command org-capture ()
"Org-capture current page."
(buffer-evaluate-javascript
*interface* (active-buffer *interface*)
(ps:ps (+ (ps:chain window location href)
" "
(ps:chain document title)))
(lambda (url-and-title)
(let* ((separation (position #\Space url-and-title))
(title-position (or (and separation (1+ separation)) (length url-and-title)))
(url (subseq url-and-title 0 (or separation (length url-and-title))))
(title (subseq url-and-title title-position)))
(uiop:launch-program (list
"emacsclient"
"--eval"
(format nil "
(progn
(org-link-set-parameters
\"next\"
:store (lambda ()
(org-store-link-props
:type \"next\"
:link \"~a\"
:description \"~a\")))
(org-capture))"
url title)))))))
(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))))
(define-key *global-map* (key "C-M-o") #'org-capture)
(define-command youtube-dl-current-page ()
"Download a video in the currently open buffer."
(with-result (url (buffer-get-url))
(uiop:run-program
(list "emacsclient" "--eval"
(format nil
(if (search "youtu" url)
"(progn (youtube-dl \"~a\") (youtube-dl-list))"
"(ambrevar/youtube-dl-at-point \"~a\")")
url)))))
(eval-in-emacs
(if (search "youtu" url)
`(progn (youtube-dl ,url) (youtube-dl-list))
`(ambrevar/youtube-dl-url ,url)))))
(define-key *global-map* (key "C-M-c d") 'youtube-dl-current-page)
(define-command play-video-in-current-page ()