129 lines
4.8 KiB
Org Mode
129 lines
4.8 KiB
Org Mode
Always restore the previous session when the browser starts.
|
|
|
|
#+begin_src lisp
|
|
(define-configuration browser
|
|
((session-restore-prompt :always-restore)))
|
|
#+end_src
|
|
|
|
Add a function that automatically redirects certain URLs to free alternatives.
|
|
|
|
#+begin_src lisp
|
|
(defun init-redirect-to-alternative (request-data)
|
|
(labels ((log-uri (uri)
|
|
(log:info "Switching to URL: ~a://~a~a"
|
|
(quri:uri-scheme uri)
|
|
(quri:uri-host uri)
|
|
(quri:uri-path uri))))
|
|
(let* ((uri (url request-data))
|
|
(host (quri:uri-host uri)))
|
|
(cond
|
|
((search "blog.bitsrc.io" host)
|
|
(setf (url request-data)
|
|
(progn
|
|
(setf (quri:uri-host uri) "scribe.rip"
|
|
(quri:uri-path uri) (concatenate 'string "/bitsrc" (quri:uri-path uri)))
|
|
(log-uri uri)
|
|
uri)))
|
|
((search "levelup.gitconnected.com" host)
|
|
(setf (url request-data)
|
|
(progn
|
|
(setf (quri:uri-host uri) "scribe.rip"
|
|
(quri:uri-path uri) (concatenate 'string "/gitconnected" (quri:uri-path uri)))
|
|
(log-uri uri)
|
|
uri)))
|
|
((or (search "kevingosse.medium.com" host)
|
|
(search "minidump.net" host))
|
|
(setf (url request-data)
|
|
(progn
|
|
(setf (quri:uri-host uri) "scribe.rip"
|
|
(quri:uri-path uri) (concatenate 'string "/kevingosse" (quri:uri-path uri)))
|
|
(log-uri uri)
|
|
uri)))
|
|
((search "medium.com" host :end2 (length "medium.com"))
|
|
(setf (url request-data)
|
|
(progn
|
|
(setf (quri:uri-host uri) "scribe.rip")
|
|
(log-uri uri)
|
|
uri)))
|
|
((search "twitter.com" host)
|
|
(setf (url request-data)
|
|
(progn
|
|
(setf (quri:uri-host uri) "nitter.net")
|
|
(log-uri uri)
|
|
uri)))
|
|
((search "www.youtube.com" host)
|
|
(setf (url request-data)
|
|
(progn
|
|
(setf (quri:uri-host uri) "redirect.invidious.io")
|
|
(log-uri uri)
|
|
uri))))))
|
|
request-data)
|
|
#+end_src
|
|
|
|
I want the keys to function more like Emacs, so I enable =emacs-mode= for all buffers. I also want my downloads to go to =~/downloads= instead of =~/Downloads=.
|
|
|
|
#+begin_src lisp
|
|
(define-configuration buffer
|
|
((default-modes (append '(emacs-mode) %slot-default%))
|
|
(download-path (make-instance 'data-path :dirname "~/downloads"))
|
|
(request-resource-hook
|
|
(reduce #'hooks:add-hook
|
|
(mapcar #'make-handler-resource (list #'init-redirect-to-alternative))
|
|
:initial-value %slot-default%))
|
|
;; Bind org-capture to `C-c o c', but only in emacs-mode.
|
|
(override-map
|
|
(let ((map (make-keymap "override-map")))
|
|
(define-key map "C-c o c" 'org-capture)))))
|
|
#+end_src
|
|
|
|
Set up capturing URLs with org-capture in Emacs. From https://ag91.github.io/blog/2021/07/09/org-capture-in-nyxt-taking-notes-while-browsing/.
|
|
|
|
#+begin_src lisp
|
|
(defun replace-all (string part replacement &key (test #'char=))
|
|
"Return a new string in which all the occurences of the part is replaced with replacement."
|
|
(with-output-to-string (out)
|
|
(loop with part-length = (length part)
|
|
for old-pos = 0 then (+ pos part-length)
|
|
for pos = (search part string
|
|
:start2 old-pos
|
|
:test test)
|
|
do (write-string string out
|
|
:start old-pos
|
|
:end (or pos (length string)))
|
|
when pos do (write-string replacement out)
|
|
while pos)))
|
|
|
|
(defun eval-in-emacs (&rest s-exps)
|
|
"Evaluate S-EXPS with emacsclient."
|
|
(let ((s-exps-string (replace-all
|
|
(write-to-string
|
|
`(progn ,@s-exps) :case :downcase)
|
|
;; Discard the package prefix.
|
|
"nyxt::" "")))
|
|
(format *error-output* "Sending to Emacs:~%~a~%" s-exps-string)
|
|
(uiop:run-program
|
|
(list "emacsclient" "--eval" s-exps-string))))
|
|
|
|
(define-command-global org-capture ()
|
|
"Org-capture current page."
|
|
(eval-in-emacs
|
|
`(org-link-set-parameters
|
|
"nyxt"
|
|
:store (lambda ()
|
|
(org-store-link-props
|
|
:type "nyxt"
|
|
:link ,(quri:render-uri (url (current-buffer)))
|
|
:description ,(title (current-buffer)))))
|
|
`(org-capture nil "U"))
|
|
(echo "Note stored!"))
|
|
#+end_src
|
|
|
|
Start Swank so I can connect to it through Emacs.
|
|
|
|
#+begin_src lisp
|
|
(defvar *init-swank-started* nil)
|
|
|
|
(unless *init-swank-started*
|
|
(start-swank)
|
|
(setf *init-swank-started* t))
|
|
#+end_src
|