From adda08ef4a09ae0370b031eba489199a8ec09eb4 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 31 Jan 2022 00:51:03 -0800 Subject: Add nyxt configuration --- nyxt/.config/nyxt/init.lisp.org | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 nyxt/.config/nyxt/init.lisp.org (limited to 'nyxt') diff --git a/nyxt/.config/nyxt/init.lisp.org b/nyxt/.config/nyxt/init.lisp.org new file mode 100644 index 0000000..33dcf84 --- /dev/null +++ b/nyxt/.config/nyxt/init.lisp.org @@ -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 -- cgit v1.2.3-54-g00ecf