Add nyxt configuration

This commit is contained in:
Tom Willemse 2022-01-31 00:51:03 -08:00
parent 9b7417f6c6
commit adda08ef4a
2 changed files with 71 additions and 1 deletions

View file

@ -1,4 +1,4 @@
MODULES=xmodmap emacs xdg shepherd dunst zsh mcron mbsync
MODULES=xmodmap emacs xdg shepherd dunst zsh mcron mbsync nyxt
STOW = stow
EMACS = emacs
@ -120,6 +120,10 @@ mbsync: mbsync/.config/cron/mbsync.guile
zsh: zsh/.profile zsh/.zshrc zsh/.zsh/functions/unzip.zwc \
zsh/.zsh/functions/x-yank.zwc zsh/.zsh/functions/x-copy-region-as-kill.zwc
## Nyxt
nyxt: nyxt/.config/nyxt/init.lisp
## Helper
%.el: %.org

View file

@ -0,0 +1,66 @@
Always restore the previous session when the browser starts.
#+begin_src lisp
(define-configuration browser
((session-restore-prompt :always-restore)))
#+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"))
;; 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
(start-swank)
#+end_src