From 470675ebf08f2c3b0ea197a5e41dee74371878c3 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 5 Nov 2024 11:22:04 +0000 Subject: [PATCH 01/21] doom config for linux --- config.el | 111 ++++++++++++++++++++++++++++++ custom.el | 20 ++++++ init.el | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++++ packages.el | 50 ++++++++++++++ 4 files changed, 372 insertions(+) create mode 100644 config.el create mode 100644 custom.el create mode 100644 init.el create mode 100644 packages.el diff --git a/config.el b/config.el new file mode 100644 index 0000000..7a4298c --- /dev/null +++ b/config.el @@ -0,0 +1,111 @@ +;;; $DOOMDIR/config.el -*- lexical-binding: t; -*- + +;; Place your private configuration here! Remember, you do not need to run 'doom +;; sync' after modifying this file! + + +;; Some functionality uses this to identify you, e.g. GPG configuration, email +;; clients, file templates and snippets. It is optional. +;; (setq user-full-name "John Doe" +;; user-mail-address "john@doe.com") + +;; Doom exposes five (optional) variables for controlling fonts in Doom: +;; +;; - `doom-font' -- the primary font to use +;; - `doom-variable-pitch-font' -- a non-monospace font (where applicable) +;; - `doom-big-font' -- used for `doom-big-font-mode'; use this for +;; presentations or streaming. +;; - `doom-symbol-font' -- for symbols +;; - `doom-serif-font' -- for the `fixed-pitch-serif' face +;; +;; See 'C-h v doom-font' for documentation and more examples of what they +;; accept. For example: +;; +;;(setq doom-font (font-spec :family "Fira Code" :size 12 :weight 'semi-light) +;; doom-variable-pitch-font (font-spec :family "Fira Sans" :size 13)) +;; +;; If you or Emacs can't find your font, use 'M-x describe-font' to look them +;; up, `M-x eval-region' to execute elisp code, and 'M-x doom/reload-font' to +;; refresh your font settings. If Emacs still can't find your font, it likely +;; wasn't installed correctly. Font issues are rarely Doom issues! + +;; There are two ways to load a theme. Both assume the theme is installed and +;; available. You can either set `doom-theme' or manually load a theme with the +;; `load-theme' function. This is the default: +(setq doom-theme 'doom-one) + +;; This determines the style of line numbers in effect. If set to `nil', line +;; numbers are disabled. For relative line numbers, set this to `relative'. +(setq display-line-numbers-type `relative) + +;; If you use `org' and don't want your org files in the default location below, +;; change `org-directory'. It must be set before org loads! +(setq org-directory "~/Documents/qwan/essays/willem/") +(setq org-roam-directory "~/Documents/qwan/essays/willem/" ) + +;; Speed up clock work, possibly +(setq org-clock-clocked-in-display nil) + + +;; mostalive custom additions to org-roam +(add-load-path! "~/dev/emacs/org-roaming") +(require 'my-org-roam) + +;; Whenever you reconfigure a package, make sure to wrap your config in an +;; `after!' block, otherwise Doom's defaults may override your settings. E.g. +;; +;; (after! PACKAGE +;; (setq x y)) +;; +;; The exceptions to this rule: +;; +;; - Setting file/directory variables (like `org-directory') +;; - Setting variables which explicitly tell you to set them before their +;; package is loaded (see 'C-h v VARIABLE' to look up their documentation). +;; - Setting doom variables (which start with 'doom-' or '+'). +;; +;; Here are some additional functions/macros that will help you configure Doom. +;; +;; - `load!' for loading external *.el files relative to this one +;; - `use-package!' for configuring packages +;; - `after!' for running code after a package has loaded +;; - `add-load-path!' for adding directories to the `load-path', relative to +;; this file. Emacs searches the `load-path' when you load packages with +;; `require' or `use-package'. +;; - `map!' for binding new keys +;; +;; To get information about any of these functions/macros, move the cursor over +;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k'). +;; This will open documentation for it, including demos of how they are used. +;; Alternatively, use `C-h o' to look up a symbol (functions, variables, faces, +;; etc). +;; +;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how +;; they are implemented. +;; embedd llms in emacs. with org-mode support +(use-package ellama + :init + ;; setup key bindings + (setopt ellama-keymap-prefix "C-c e") + ;; language you want ellama to translate to + (setopt ellama-language "Dutch") + ;; could be llm-openai for example + (require 'llm-ollama) + (setopt ellama-provider + (make-llm-ollama + ;; this model should be pulled to use it + ;; value should be the same as you print in terminal during pull + :chat-model "llama3.1:8b-instruct-q8_0" + :embedding-model "nomic-embed-text" + :default-chat-non-standard-params '(("num_ctx" . 8192)))) + ;; Naming new sessions with llm + (setopt ellama-naming-provider + (make-llm-ollama + :chat-model "llama3.1:8b-instruct-q8_0" + :embedding-model "nomic-embed-text" + :default-chat-non-standard-params '(("stop" . ("\n"))))) + (setopt ellama-naming-scheme 'ellama-generate-name-by-llm) + ;; Translation llm provider + (setopt ellama-translation-provider (make-llm-ollama + :chat-model "llama3.1" + :embedding-model "nomic-embed-text"))) diff --git a/custom.el b/custom.el new file mode 100644 index 0000000..89936e5 --- /dev/null +++ b/custom.el @@ -0,0 +1,20 @@ +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(custom-safe-themes + '("d6b934330450d9de1112cbb7617eaf929244d192c4ffb1b9e6b63ad574784aad" default)) + '(package-selected-packages '(ellama)) + '(safe-local-variable-values + '((eval setq-local org-roam-db-location + (expand-file-name "org-roam.db" org-roam-directory)) + (eval setq-local org-roam-directory + (expand-file-name + (locate-dominating-file default-directory ".dir-locals.el")))))) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) diff --git a/init.el b/init.el new file mode 100644 index 0000000..108dd22 --- /dev/null +++ b/init.el @@ -0,0 +1,191 @@ +;;; init.el -*- lexical-binding: t; -*- + +;; This file controls what Doom modules are enabled and what order they load +;; in. Remember to run 'doom sync' after modifying it! + +;; NOTE Press 'SPC h d h' (or 'C-h d h' for non-vim users) to access Doom's +;; documentation. There you'll find a link to Doom's Module Index where all +;; of our modules are listed, including what flags they support. + +;; NOTE Move your cursor over a module's name (or its flags) and press 'K' (or +;; 'C-c c k' for non-vim users) to view its documentation. This works on +;; flags as well (those symbols that start with a plus). +;; +;; Alternatively, press 'gd' (or 'C-c c d') on a module to browse its +;; directory (for easy access to its source code). + +(doom! :input + ;;bidi ; (tfel ot) thgir etirw uoy gnipleh + ;;chinese + ;;japanese + ;;layout ; auie,ctsrnm is the superior home row + + :completion + company ; the ultimate code completion backend + ;;(corfu +orderless) ; complete with cap(f), cape and a flying feather! + ;;helm ; the *other* search engine for love and life + ;;ido ; the other *other* search engine... + ;;ivy ; a search engine for love and life + vertico ; the search engine of the future + + :ui + ;;deft ; notational velocity for Emacs + doom ; what makes DOOM look the way it does + doom-dashboard ; a nifty splash screen for Emacs + ;;doom-quit ; DOOM quit-message prompts when you quit Emacs + ;;(emoji +unicode) ; 🙂 + hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW + ;;indent-guides ; highlighted indent columns + ;;ligatures ; ligatures and symbols to make your code pretty again + ;;minimap ; show a map of the code on the side + modeline ; snazzy, Atom-inspired modeline, plus API + ;;nav-flash ; blink cursor line after big motions + ;;neotree ; a project drawer, like NERDTree for vim + ophints ; highlight the region an operation acts on + (popup +defaults) ; tame sudden yet inevitable temporary windows + ;;tabs ; a tab bar for Emacs + ;;treemacs ; a project drawer, like neotree but cooler + ;;unicode ; extended unicode support for various languages + (vc-gutter +pretty) ; vcs diff in the fringe + vi-tilde-fringe ; fringe tildes to mark beyond EOB + ;;window-select ; visually switch windows + workspaces ; tab emulation, persistence & separate workspaces + ;;zen ; distraction-free coding or writing + + :editor + (evil +everywhere); come to the dark side, we have cookies + file-templates ; auto-snippets for empty files + fold ; (nigh) universal code folding + (format +onsave) ; automated prettiness + ;;god ; run Emacs commands without modifier keys + ;;lispy ; vim for lisp, for people who don't like vim + multiple-cursors ; editing in many places at once + ;;objed ; text object editing for the innocent + ;;parinfer ; turn lisp into python, sort of + ;;rotate-text ; cycle region at point between text candidates + snippets ; my elves. They type so I don't have to + word-wrap ; soft wrapping with language-aware indent + + :emacs + dired ; making dired pretty [functional] + electric ; smarter, keyword-based electric-indent + ;;ibuffer ; interactive buffer management + undo ; persistent, smarter undo for your inevitable mistakes + vc ; version-control and Emacs, sitting in a tree + + :term + ;;eshell ; the elisp shell that works everywhere + ;;shell ; simple shell REPL for Emacs + ;;term ; basic terminal emulator for Emacs + vterm ; the best terminal emulation in Emacs + + :checkers + syntax ; tasing you for every semicolon you forget + ;;(spell +flyspell) ; tasing you for misspelling mispelling + ;;grammar ; tasing grammar mistake every you make + + :tools + ;;ansible + ;;biblio ; Writes a PhD for you (citation needed) + ;;collab ; buffers with friends + ;;debugger ; FIXME stepping through code, to help you add bugs + direnv + docker + ;;editorconfig ; let someone else argue about tabs vs spaces + ;;ein ; tame Jupyter notebooks with emacs + (eval +overlay) ; run code, run (also, repls) + lookup ; navigate your code and its documentation + lsp ; M-x vscode + magit ; a git porcelain for Emacs + ;;make ; run make tasks from Emacs + ;;pass ; password manager for nerds + pdf ; pdf enhancements + ;;prodigy ; FIXME managing external services & code builders + ;;terraform ; infrastructure as code + tmux ; an API for interacting with tmux + tree-sitter ; syntax and parsing, sitting in a tree... + ;;upload ; map local to remote projects via ssh/ftp + + :os + (:if (featurep :system 'macos) macos) ; improve compatibility with macOS + ;;tty ; improve the terminal Emacs experience + + :lang + ;;agda ; types of types of types of types... + ;;beancount ; mind the GAAP + (cc +lsp) ; C > C++ == 1 + ;;clojure ; java with a lisp + ;;common-lisp ; if you've seen one lisp, you've seen them all + ;;coq ; proofs-as-programs + ;;crystal ; ruby at the speed of c + csharp ; unity, .NET, and mono shenanigans + data ; config/data formats + ;;(dart +flutter) ; paint ui and not much else + ;;dhall + elixir ; erlang done right + ;;elm ; care for a cup of TEA? + emacs-lisp ; drown in parentheses + erlang ; an elegant language for a more civilized age + ;;ess ; emacs speaks statistics + ;;factor + ;;faust ; dsp, but you get to keep your soul + ;;fortran ; in FORTRAN, GOD is REAL (unless declared INTEGER) + ;;fsharp ; ML stands for Microsoft's Language + ;;fstar ; (dependent) types and (monadic) effects and Z3 + ;;gdscript ; the language you waited for + ;;(go +lsp) ; the hipster dialect + ;;(graphql +lsp) ; Give queries a REST + (haskell +lsp) ; a language that's lazier than I am + ;;hy ; readability of scheme w/ speed of python + ;;idris ; a language you can depend on + ;;json ; At least it ain't XML + (java +lsp) ; the poster child for carpal tunnel syndrome + javascript ; all(hope(abandon(ye(who(enter(here)))))) + ;;julia ; a better, faster MATLAB + kotlin ; a better, slicker Java(Script) + latex ; writing papers in Emacs has never been so fun + ;;lean ; for folks with too much to prove + ;;ledger ; be audit you can be + ;;lua ; one-based indices? one-based indices + markdown ; writing docs for people to ignore + ;;nim ; python + lisp at the speed of c + ;;nix ; I hereby declare "nix geht mehr!" + ;;ocaml ; an objective camel + (org +roam2) ; organize your plain life in plain text + php ; perl's insecure younger brother + plantuml ; diagrams for confusing people more + purescript ; javascript, but functional + python ; beautiful is better than ugly + ;;qt ; the 'cutest' gui framework ever + ;;racket ; a DSL for DSLs + ;;raku ; the artist formerly known as perl6 + ;;rest ; Emacs as a REST client + ;;rst ; ReST in peace + ;;(ruby +rails) ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"} + ;;(rust +lsp) ; Fe2O3.unwrap().unwrap().unwrap().unwrap() + ;;scala ; java, but good + ;;(scheme +guile) ; a fully conniving family of lisps + sh ; she sells {ba,z,fi}sh shells on the C xor + ;;sml + ;;solidity ; do you need a blockchain? No. + ;;swift ; who asked for emoji variables? + ;;terra ; Earth and Moon in alignment for performance. + ;;web ; the tubes + ;;yaml ; JSON, but readable + ;;zig ; C, but simpler + + :email + ;;(mu4e +org +gmail) + ;;notmuch + ;;(wanderlust +gmail) + + :app + ;;calendar + ;;emms + ;;everywhere ; *leave* Emacs!? You must be joking + ;;irc ; how neckbeards socialize + ;;(rss +org) ; emacs as an RSS reader + + :config + ;;literate + (default +bindings +smartparens)) diff --git a/packages.el b/packages.el new file mode 100644 index 0000000..364e6e9 --- /dev/null +++ b/packages.el @@ -0,0 +1,50 @@ +;; -*- no-byte-compile: t; -*- +;;; $DOOMDIR/packages.el + +;; To install a package with Doom you must declare them here and run 'doom sync' +;; on the command line, then restart Emacs for the changes to take effect -- or +;; use 'M-x doom/reload'. + + +;; To install SOME-PACKAGE from MELPA, ELPA or emacsmirror: +;; (package! some-package) + +;; To install a package directly from a remote git repo, you must specify a +;; `:recipe'. You'll find documentation on what `:recipe' accepts here: +;; https://github.com/radian-software/straight.el#the-recipe-format +;; (package! another-package +;; :recipe (:host github :repo "username/repo")) + +;; If the package you are trying to install does not contain a PACKAGENAME.el +;; file, or is located in a subdirectory of the repo, you'll need to specify +;; `:files' in the `:recipe': +;; (package! this-package +;; :recipe (:host github :repo "username/repo" +;; :files ("some-file.el" "src/lisp/*.el"))) + +;; If you'd like to disable a package included with Doom, you can do so here +;; with the `:disable' property: +;; (package! builtin-package :disable t) + +;; You can override the recipe of a built in package without having to specify +;; all the properties for `:recipe'. These will inherit the rest of its recipe +;; from Doom or MELPA/ELPA/Emacsmirror: +;; (package! builtin-package :recipe (:nonrecursive t)) +;; (package! builtin-package-2 :recipe (:repo "myfork/package")) + +;; Specify a `:branch' to install a package from a particular branch or tag. +;; This is required for some packages whose default branch isn't 'master' (which +;; our package manager can't deal with; see radian-software/straight.el#279) +;; (package! builtin-package :recipe (:branch "develop")) + +;; Use `:pin' to specify a particular commit to install. +;; (package! builtin-package :pin "1a2b3c4d5e") + + +;; Doom's packages are pinned to a specific commit and updated from release to +;; release. The `unpin!' macro allows you to unpin single packages... +;; (unpin! pinned-package) +;; ...or multiple packages +;; (unpin! pinned-package another-pinned-package) +;; ...Or *all* packages (NOT RECOMMENDED; will likely break things) +;; (unpin! t) From a0c892f64588b4bb1db8a0abb3b957c1d44daa75 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Mon, 1 Sep 2025 20:56:32 +0100 Subject: [PATCH 02/21] Enable json and org-pomodoro --- custom.el | 13 ++++++------- init.el | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/custom.el b/custom.el index 89936e5..b0a70c7 100644 --- a/custom.el +++ b/custom.el @@ -3,15 +3,14 @@ ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. - '(custom-safe-themes - '("d6b934330450d9de1112cbb7617eaf929244d192c4ffb1b9e6b63ad574784aad" default)) - '(package-selected-packages '(ellama)) '(safe-local-variable-values - '((eval setq-local org-roam-db-location - (expand-file-name "org-roam.db" org-roam-directory)) + '((haskell-process-use-ghci . t) + (haskell-indent-spaces . 4) + (eval setq-local org-roam-db-location + (expand-file-name "org-roam.db" org-roam-directory)) (eval setq-local org-roam-directory - (expand-file-name - (locate-dominating-file default-directory ".dir-locals.el")))))) + (expand-file-name + (locate-dominating-file default-directory ".dir-locals.el")))))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. diff --git a/init.el b/init.el index 108dd22..e68fb99 100644 --- a/init.el +++ b/init.el @@ -138,7 +138,7 @@ (haskell +lsp) ; a language that's lazier than I am ;;hy ; readability of scheme w/ speed of python ;;idris ; a language you can depend on - ;;json ; At least it ain't XML + json ; At least it ain't XML (java +lsp) ; the poster child for carpal tunnel syndrome javascript ; all(hope(abandon(ye(who(enter(here)))))) ;;julia ; a better, faster MATLAB @@ -151,7 +151,7 @@ ;;nim ; python + lisp at the speed of c ;;nix ; I hereby declare "nix geht mehr!" ;;ocaml ; an objective camel - (org +roam2) ; organize your plain life in plain text + (org +roam2 +pomodoro) ; organize your plain life in plain text php ; perl's insecure younger brother plantuml ; diagrams for confusing people more purescript ; javascript, but functional From 934d5ecd36522e870947e4758f338fb8ab8b51d3 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Wed, 24 Sep 2025 14:17:33 +0100 Subject: [PATCH 03/21] Upgraded doom, implemented some feedback from doom doctor --- config.el | 2 +- custom.el | 4 +--- init.el | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/config.el b/config.el index 7a4298c..ee12de9 100644 --- a/config.el +++ b/config.el @@ -32,7 +32,7 @@ ;; There are two ways to load a theme. Both assume the theme is installed and ;; available. You can either set `doom-theme' or manually load a theme with the ;; `load-theme' function. This is the default: -(setq doom-theme 'doom-one) +(setq doom-theme 'leuven) ;; This determines the style of line numbers in effect. If set to `nil', line ;; numbers are disabled. For relative line numbers, set this to `relative'. diff --git a/custom.el b/custom.el index b0a70c7..3f4ec45 100644 --- a/custom.el +++ b/custom.el @@ -4,9 +4,7 @@ ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(safe-local-variable-values - '((haskell-process-use-ghci . t) - (haskell-indent-spaces . 4) - (eval setq-local org-roam-db-location + '((eval setq-local org-roam-db-location (expand-file-name "org-roam.db" org-roam-directory)) (eval setq-local org-roam-directory (expand-file-name diff --git a/init.el b/init.el index e68fb99..51701a8 100644 --- a/init.el +++ b/init.el @@ -140,7 +140,7 @@ ;;idris ; a language you can depend on json ; At least it ain't XML (java +lsp) ; the poster child for carpal tunnel syndrome - javascript ; all(hope(abandon(ye(who(enter(here)))))) + (javascript +lsp +tree-sitter) ; all(hope(abandon(ye(who(enter(here)))))) ;;julia ; a better, faster MATLAB kotlin ; a better, slicker Java(Script) latex ; writing papers in Emacs has never been so fun @@ -151,7 +151,7 @@ ;;nim ; python + lisp at the speed of c ;;nix ; I hereby declare "nix geht mehr!" ;;ocaml ; an objective camel - (org +roam2 +pomodoro) ; organize your plain life in plain text + (org +roam +pomodoro +dragndrop) ; organize your plain life in plain text php ; perl's insecure younger brother plantuml ; diagrams for confusing people more purescript ; javascript, but functional From 2bd933dced948c01ebc65762906b1746fced64fe Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Fri, 10 Oct 2025 10:21:45 +0100 Subject: [PATCH 04/21] copy snippets from mac --- snippets/elixir-mode/Ecto seed table | 26 +++++++++ snippets/elixir-mode/alter table migration | 9 +++ snippets/elixir-mode/simple form | 15 +++++ snippets/elixir-mode/test module | 15 +++++ snippets/json-mode/AWS CodeBuild json config | 55 +++++++++++++++++++ snippets/json-mode/__code_build.json | 55 +++++++++++++++++++ snippets/markdown-mode/jekyll blog post | 12 ++++ .../jekyll call to action - training | 12 ++++ snippets/org-mode/PlantUML Sequence diagram | 19 +++++++ snippets/org-mode/graphviz_directed_graph | 11 ++++ snippets/org-mode/llm | 10 ++++ .../plantuml class and package diagram | 38 +++++++++++++ snippets/org-mode/plantuml state diagram | 31 +++++++++++ snippets/rustic-mode/builder method | 11 ++++ .../builder method with T Clonable | 11 ++++ snippets/text-mode/newtype | 44 +++++++++++++++ snippets/text-mode/plantuml handwritten | 8 +++ snippets/yaml-mode/___buildspec.yml | 28 ++++++++++ snippets/yaml-mode/aider_config | 7 +++ 19 files changed, 417 insertions(+) create mode 100644 snippets/elixir-mode/Ecto seed table create mode 100644 snippets/elixir-mode/alter table migration create mode 100644 snippets/elixir-mode/simple form create mode 100644 snippets/elixir-mode/test module create mode 100644 snippets/json-mode/AWS CodeBuild json config create mode 100644 snippets/json-mode/__code_build.json create mode 100644 snippets/markdown-mode/jekyll blog post create mode 100644 snippets/markdown-mode/jekyll call to action - training create mode 100644 snippets/org-mode/PlantUML Sequence diagram create mode 100644 snippets/org-mode/graphviz_directed_graph create mode 100644 snippets/org-mode/llm create mode 100644 snippets/org-mode/plantuml class and package diagram create mode 100644 snippets/org-mode/plantuml state diagram create mode 100644 snippets/rustic-mode/builder method create mode 100644 snippets/rustic-mode/builder method with T Clonable create mode 100644 snippets/text-mode/newtype create mode 100644 snippets/text-mode/plantuml handwritten create mode 100644 snippets/yaml-mode/___buildspec.yml create mode 100644 snippets/yaml-mode/aider_config diff --git a/snippets/elixir-mode/Ecto seed table b/snippets/elixir-mode/Ecto seed table new file mode 100644 index 0000000..9072330 --- /dev/null +++ b/snippets/elixir-mode/Ecto seed table @@ -0,0 +1,26 @@ +# key: ecto-seed +# name: Ecto seed table +# -- +alias ${1:App}.${2:Context} + +${3:instance}s = [ + %{name: "Chess", description: "The classic strategy game", sku: 5_678_910, unit_price: 10.00}, + %{ + name: "Tic-Tac-Toe", + description: "The game of Xs and Os", + sku: 11_121_314, + unit_price: 3.00 + }, + %{ + name: "Table tennis", + description: "Bat the ball bck and forth. Don't miss!", + sku: 15_222_324, + unit_price: 12.00 + } +] + +Enum.each($3s, fn $3-> + $2.create_$3($3) +end) + +$0 \ No newline at end of file diff --git a/snippets/elixir-mode/alter table migration b/snippets/elixir-mode/alter table migration new file mode 100644 index 0000000..8748d61 --- /dev/null +++ b/snippets/elixir-mode/alter table migration @@ -0,0 +1,9 @@ +# -*- mode: snippet -*- +# name: alter table migration +# key: alter-table +# -- + +alter table(:$1) do + add :$2, :$3 + $0 +end \ No newline at end of file diff --git a/snippets/elixir-mode/simple form b/snippets/elixir-mode/simple form new file mode 100644 index 0000000..29f686b --- /dev/null +++ b/snippets/elixir-mode/simple form @@ -0,0 +1,15 @@ +# key: simple-form +# name: simple form +# -- + <.simple_form> + :let={f} + for={@$1} + id="$2-form" + phx-change="validate" + phx-submit="save"> + <.input field={@$1[:$3]} type="$4" label="$5" /> + $0 + <:actions> + <.button phx-disable-with="$6...">$7 + + diff --git a/snippets/elixir-mode/test module b/snippets/elixir-mode/test module new file mode 100644 index 0000000..90989b1 --- /dev/null +++ b/snippets/elixir-mode/test module @@ -0,0 +1,15 @@ +# key: test-module +# name: test module +# condition: t +# -- +defmodule $1.$2 do + import $3 + use Pento.DataCase + + describe "$3" do + test "$4" do + $0 + assert false + end + end +end diff --git a/snippets/json-mode/AWS CodeBuild json config b/snippets/json-mode/AWS CodeBuild json config new file mode 100644 index 0000000..91a8b94 --- /dev/null +++ b/snippets/json-mode/AWS CodeBuild json config @@ -0,0 +1,55 @@ +# key: __codebuild.json +# name: AWS CodeBuild json config +# -- +{ + "name": "$1", + "arn": "arn:aws:codebuild:eu-central-1:123456789012:project/$2" + "description": "$3", + "source": { + "type": "CODEPIPELINE", + "insecureSsl": false + }, + "secondarySourceVersions": [], + "artifacts": { + "type": "CODEPIPELINE", + "name": "$4", + "packaging": "NONE", + "encryptionDisabled": false + }, + "cache": { + "type": "NO_CACHE" + }, + "environment": { + "type": "LINUX_CONTAINER", + "image": "aws/codebuild/standard:5.0", + "computeType": "BUILD_GENERAL1_SMALL", + "environmentVariables": [ + { + "name": "AWS_DEFAULT_REGION", + "value": "eu-central-1", + "type": "PLAINTEXT" + } + ], + "privilegedMode": true, + "imagePullCredentialsType": "CODEBUILD" + }, + "serviceRole": "arn:aws:iam::123456789012:role/ExampleCodeBuildServiceRole", + "timeoutInMinutes": 60, + "queuedTimeoutInMinutes": 480, + "encryptionKey": "arn:aws:kms:eu-central-1:123456789012:alias/aws/s3", + "tags": [$5], + "badge": { + "badgeEnabled": false + }, + "logsConfig": { + "cloudWatchLogs": { + "status": "ENABLED" + }, + "s3Logs": { + "status": "DISABLED", + "encryptionDisabled": false + } + }, + "fileSystemLocations": [], + "concurrentBuildLimit": 1 +} \ No newline at end of file diff --git a/snippets/json-mode/__code_build.json b/snippets/json-mode/__code_build.json new file mode 100644 index 0000000..31ddf75 --- /dev/null +++ b/snippets/json-mode/__code_build.json @@ -0,0 +1,55 @@ +# key: __codebuild.json +# name: AWS CodeBuild json config +# -- +{ + "name": "course-vendingmachine-cs", + "arn": "arn:aws:codebuild:eu-central-1:123456789012:project/$1" + "description": "$2", + "source": { + "type": "CODEPIPELINE", + "insecureSsl": false + }, + "secondarySourceVersions": [], + "artifacts": { + "type": "CODEPIPELINE", + "name": "$3", + "packaging": "NONE", + "encryptionDisabled": false + }, + "cache": { + "type": "NO_CACHE" + }, + "environment": { + "type": "LINUX_CONTAINER", + "image": "aws/codebuild/standard:5.0", + "computeType": "BUILD_GENERAL1_SMALL", + "environmentVariables": [ + { + "name": "AWS_DEFAULT_REGION", + "value": "eu-central-1", + "type": "PLAINTEXT" + } + ], + "privilegedMode": true, + "imagePullCredentialsType": "CODEBUILD" + }, + "serviceRole": "arn:aws:iam::123456789012:role/ExampleCodeBuildServiceRole", + "timeoutInMinutes": 60, + "queuedTimeoutInMinutes": 480, + "encryptionKey": "arn:aws:kms:eu-central-1:123456789012:alias/aws/s3", + "tags": [$4], + "badge": { + "badgeEnabled": false + }, + "logsConfig": { + "cloudWatchLogs": { + "status": "ENABLED" + }, + "s3Logs": { + "status": "DISABLED", + "encryptionDisabled": false + } + }, + "fileSystemLocations": [], + "concurrentBuildLimit": 1 +} \ No newline at end of file diff --git a/snippets/markdown-mode/jekyll blog post b/snippets/markdown-mode/jekyll blog post new file mode 100644 index 0000000..eaaa81c --- /dev/null +++ b/snippets/markdown-mode/jekyll blog post @@ -0,0 +1,12 @@ +# -*- mode: snippet -*- +# name: jekyll blog post +# key: jekyll_post +# -- +--- +layout: post +title: $0 +tags: + - $1 +author: Willem van den Ende +image: $2 +--- \ No newline at end of file diff --git a/snippets/markdown-mode/jekyll call to action - training b/snippets/markdown-mode/jekyll call to action - training new file mode 100644 index 0000000..0cfd320 --- /dev/null +++ b/snippets/markdown-mode/jekyll call to action - training @@ -0,0 +1,12 @@ +# -*- mode: snippet -*- +# name: jekyll call to action - training +# key: cta +# -- + diff --git a/snippets/org-mode/PlantUML Sequence diagram b/snippets/org-mode/PlantUML Sequence diagram new file mode 100644 index 0000000..7e8ce57 --- /dev/null +++ b/snippets/org-mode/PlantUML Sequence diagram @@ -0,0 +1,19 @@ +# -*- mode: snippet -*- +# name: PlantUML Sequence diagram +# key: plantuml_sequence +# -- + +#+begin_src plantuml :file $0.png +@startuml +skinparam { + handwritten true + monochrome true +} + +$1 -> Service: message(value) +Service -> Inside +Service --> $1: success(value) +Inside --> Service: success(value) + +@enduml +#+end_src \ No newline at end of file diff --git a/snippets/org-mode/graphviz_directed_graph b/snippets/org-mode/graphviz_directed_graph new file mode 100644 index 0000000..94de1df --- /dev/null +++ b/snippets/org-mode/graphviz_directed_graph @@ -0,0 +1,11 @@ +# key: graphviz +# name: graphviz directed graph +# -- +#+begin_src dot :file ${1:file}.png :cmdline -T${2:png} :exports none :results silent +`%`$0 +digraph G { + a -> b [label=" a to b"] +} +#+end_src + +[[file:$1]] diff --git a/snippets/org-mode/llm b/snippets/org-mode/llm new file mode 100644 index 0000000..72cb95b --- /dev/null +++ b/snippets/org-mode/llm @@ -0,0 +1,10 @@ +# -*- mode: snippet -*- +# name: new llm call in orgmode +# uuid: +# key: llm +# condition: t +# -- + +#+BEGIN_SRC bash :results verbatim +llm prompt -m mlx-community/Qwen2.5-Coder-32B-Instruct-8bit '$0' +#+END_SRC diff --git a/snippets/org-mode/plantuml class and package diagram b/snippets/org-mode/plantuml class and package diagram new file mode 100644 index 0000000..9dca50b --- /dev/null +++ b/snippets/org-mode/plantuml class and package diagram @@ -0,0 +1,38 @@ +# -*- mode: snippet -*- +# name: plantuml class and package diagram +# key: plantuml-package +# -- +#+begin_src plantuml :file vending-domain-package.png +@startuml embedded-machine +skinparam { +handwritten true +monochrome true +} + +package $0 { +together { +class $1 { +$2($3: $4) +} +class Display { +show_message(message: str) +} +} +class Drawer { +deliver() +} +class Button { +push() +} +class CashRegister { +insert(coins: int) +checkout(price: int) +} +Button -> Drawer +Drawer --> CashRegister +Drawer --> Bin +CashRegister --> Display +Bin --> Display +} +@enduml +#+end_src diff --git a/snippets/org-mode/plantuml state diagram b/snippets/org-mode/plantuml state diagram new file mode 100644 index 0000000..be51f4b --- /dev/null +++ b/snippets/org-mode/plantuml state diagram @@ -0,0 +1,31 @@ +# -*- mode: snippet -*- +# name: plantuml state diagram +# key: stateDiagram +# -- +#+begin_src plantuml +@startuml + +[*] --> CheckingValidity +CheckingValidity: is valid [[roam:JSON]] +CheckingValidity --> [*] : fail +CheckingValidity -> ParsingAllFields +state ParsingAllFields { +ParsingFields : type +ParsingFields : attributes +ParsingFields : validations +ParsingFields : messages +ParsingFields : composite +ParsingFields -> ParsingCompositeField : composite +ParsingCompositeField : recursive ParsingFields +ParsingCompositeField : validations of combined part values +ParsingFields -> ParsingField : part +} +ParsingAllFields -> FindingLinks: FormDefinition +ParsingAllFields -> [*] : fail +FindingLinks --> [*]: not found +FindingLinks : conditional show +FindingLinks : none +FindingLinks -> RenderingFields: Enriched FormDefinition +RenderingFields --> [*]: success +@enduml +#+end_src \ No newline at end of file diff --git a/snippets/rustic-mode/builder method b/snippets/rustic-mode/builder method new file mode 100644 index 0000000..e2eb829 --- /dev/null +++ b/snippets/rustic-mode/builder method @@ -0,0 +1,11 @@ +# -*- mode: snippet -*- +# name: builder method +# key: with_attribute_build +# -- + + pub(crate) fn with_${1:attributename}(&mut self, $1: &str) -> &${2:structname} { + self.$1 = $1.to_string(); + return self; + } + +$0 \ No newline at end of file diff --git a/snippets/rustic-mode/builder method with T Clonable b/snippets/rustic-mode/builder method with T Clonable new file mode 100644 index 0000000..926f01a --- /dev/null +++ b/snippets/rustic-mode/builder method with T Clonable @@ -0,0 +1,11 @@ +# -*- mode: snippet -*- +# name: builder method with T Clonable +# key: with_attribute_t_clone +# -- + + pub(crate) fn with_${1:attributename}(&mut self, $1: &${2:Type}) -> &${3:structname} { + self.$1 = $1.clone(); + return self; + } + +$0 \ No newline at end of file diff --git a/snippets/text-mode/newtype b/snippets/text-mode/newtype new file mode 100644 index 0000000..8b72313 --- /dev/null +++ b/snippets/text-mode/newtype @@ -0,0 +1,44 @@ +# key: thenewtype +# name: new purescript newtype in its' own module +# -- +# in 'text-mode' because purescript-mode generates parse error +module ${1:ModulePrefix}.${2:NewTypeName} ( + $2(..) + , aDummy + ) where + +import Data.Firebase.Foreign (class ToFirebaseForeign) +import Data.Foreign (toForeign, readString) +import Data.Foreign.Class (class IsForeign) +import Data.Generic (class Generic, gCompare, gEq, gShow) +import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary) +import Prelude (class Eq, class Ord, class Show, ($),bind, pure) +import UReview.Prelude (readForeign) + +newtype $2 = $2 {${4:fieldName}:: ${5:Type}} + +aDummy :: $2 +aDummy = $2 {$4: "$6"} +derive instance generic$2 :: Generic $2 + +instance show$2 :: Show $2 where + show = gShow + +instance eq$2 :: Eq $2 where + eq = gEq + +instance ord$2 :: Ord $2 where + compare = gCompare + +instance arb$2 :: Arbitrary $2 where + arbitrary = do + $4 <- arbitrary + pure ($2 {$4 }) + +instance isForeign$2 :: IsForeign $2 where + read fo = readForeign fo + +instance toFirebaseForeign$2 :: ToFirebaseForeign $2 + where toFire = ${7:conversionFn} >>> toForeign + +$0 \ No newline at end of file diff --git a/snippets/text-mode/plantuml handwritten b/snippets/text-mode/plantuml handwritten new file mode 100644 index 0000000..8b1af28 --- /dev/null +++ b/snippets/text-mode/plantuml handwritten @@ -0,0 +1,8 @@ +# -*- mode: snippet -*- +# name: plantuml handwritten +# key: handwritten_plantuml +# -- +skinparam { +handwritten true +monochrome true +} diff --git a/snippets/yaml-mode/___buildspec.yml b/snippets/yaml-mode/___buildspec.yml new file mode 100644 index 0000000..e6d9720 --- /dev/null +++ b/snippets/yaml-mode/___buildspec.yml @@ -0,0 +1,28 @@ +# -*- mode: yaml -*- +# name: AWS CodeBuild buildspec +# key: buildspec +# -- + +version: 0.2 + +phases: + pre_build: + commands: + - echo Logging in to Amazon ECR... + - aws --version + - aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.eu-central-1.amazonaws.com + - REPOSITORY_URI=123456789012.dkr.ecr.eu-central-1.amazonaws.com/example/$1 + - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) + - IMAGE_TAG=${COMMIT_HASH:=latest} + build: + commands: + - echo Build started on `date` + - echo Building the Docker image... + - docker build -t $REPOSITORY_URI:latest . + - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG + post_build: + commands: + - echo Build completed on `date` + - echo Pushing the Docker images... + - docker push $REPOSITORY_URI:latest + - docker push $REPOSITORY_URI:$IMAGE_TAG diff --git a/snippets/yaml-mode/aider_config b/snippets/yaml-mode/aider_config new file mode 100644 index 0000000..27458a6 --- /dev/null +++ b/snippets/yaml-mode/aider_config @@ -0,0 +1,7 @@ +# -*- mode: snippet -*- +# name: .aider.conf.yml starting point +# uuid: +# key: aider_config +# condition: t +# -- +read: [CONVENTIONS.md] From e99387c8c49c2c4fc6a3c8bfd3fb80a12a76e68d Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Sun, 9 Nov 2025 16:35:50 +0000 Subject: [PATCH 05/21] llm is a big package to support gptel etc --- init.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index 51701a8..c54a11d 100644 --- a/init.el +++ b/init.el @@ -95,6 +95,7 @@ ;;ein ; tame Jupyter notebooks with emacs (eval +overlay) ; run code, run (also, repls) lookup ; navigate your code and its documentation + llm ; all your robots are belong to us lsp ; M-x vscode magit ; a git porcelain for Emacs ;;make ; run make tasks from Emacs @@ -171,7 +172,7 @@ ;;swift ; who asked for emoji variables? ;;terra ; Earth and Moon in alignment for performance. ;;web ; the tubes - ;;yaml ; JSON, but readable + yaml ; JSON, but readable ;;zig ; C, but simpler :email From 9fd20cb6ee1de91cac75dc4213f0a7e4bc508d6e Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Sun, 9 Nov 2025 16:36:04 +0000 Subject: [PATCH 06/21] change default model to local thinking --- config.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/config.el b/config.el index ee12de9..d6da9d9 100644 --- a/config.el +++ b/config.el @@ -51,6 +51,12 @@ (add-load-path! "~/dev/emacs/org-roaming") (require 'my-org-roam) +(add-load-path! "~/.config/doom/qwan") + +(require 'qwan-blog) +(require 'qwan-refactor) + + ;; Whenever you reconfigure a package, make sure to wrap your config in an ;; `after!' block, otherwise Doom's defaults may override your settings. E.g. ;; @@ -109,3 +115,33 @@ (setopt ellama-translation-provider (make-llm-ollama :chat-model "llama3.1" :embedding-model "nomic-embed-text"))) +;; https://yannesposito.com/posts/0029-ai-assistants-in-doom-emacs-31-on-macos-with-clojure-mcp-server/index.html +;; LLM +(use-package! gptel + :init + ;; declare the default llm configuration + ;; for me this is co-pilot with claude-sonnet-4 + (setq gptel-default-mode 'org-mode ;; I want the llm to reply to me with org-mode format. + gptel-backend (gptel-make-openai "llama.cpp" + :host "localhost:8000" + :protocol "http" + :stream t + :models '(Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf)) + gptel-model 'Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf) + ;; Do not use chatgpt as default. took long to find. + (setq-default gptel-model 'hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL) + (require 'gptel-integrations) ;; <- for mcp + ;; declare another llm configuration, I also use Ollama to easily use multiple smaller models that don't require + ;; max speed or the latest API. + (gptel-make-ollama "Ollama" + :host "localhost:11434" + :stream t + + :models '(hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL + qwen3:0.6B + (qwen3-coder:30b ;Full spec + :description + "qwen3 coder large coding model " + :capabilities (tools media) + :mime-types ("image/jpeg" "image/png" "image/svg"))))) + From 46a8d76abf12ca98f65e7e55a734b8362084caf3 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Sun, 9 Nov 2025 16:36:14 +0000 Subject: [PATCH 07/21] port qwan code from mac --- qwan/qwan-blog.el | 121 ++++++++++++++++++++++++++++++++++++++++++ qwan/qwan-refactor.el | 66 +++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 qwan/qwan-blog.el create mode 100644 qwan/qwan-refactor.el diff --git a/qwan/qwan-blog.el b/qwan/qwan-blog.el new file mode 100644 index 0000000..226e9d7 --- /dev/null +++ b/qwan/qwan-blog.el @@ -0,0 +1,121 @@ +;;; qwan/qwan-blog.el -*- lexical-binding: t; -*- +;;; + +(provide 'qwan-blog) + + +(defun qwan/copy-filename () + "Push the file name of the currently visited buffer to the kill ring. Useful for markdown links" + (interactive) + (unless buffer-file-name + (error "The current buffer doesn't visit a file")) + + (kill-new buffer-file-name) + (message "Copied %s" buffer-file-name)) + +(defun qwan/publish-draft () + "Publish this in the _posts folder" + (interactive) + (let* ((dest-dir "../_posts") + (current-file (buffer-file-name)) + (blogpost-name (file-name-nondirectory current-file)) + (current-date (format-time-string "%Y-%m-%d")) + (new-filename (concat current-date "-" blogpost-name)) + (source-path current-file) + (dest-path (concat dest-dir "/" new-filename))) + (save-buffer) + (rename-file source-path dest-path) + (set-visited-file-name dest-path) + (set-buffer-modified-p nil) + (message "Successfully moved %s to %s" source-path dest-path))) + +;; functions to convert emacs org-roam towards markdown without internal links +(defun qwan/org-replace-link-by-link-description () + "Remove the link part of an org-mode link at point and keep +only the description" + (interactive) + (let ((elem (org-element-context))) + (if (eq (car elem) 'link) + (let* ((content-begin (org-element-property :contents-begin elem)) + (content-end (org-element-property :contents-end elem)) + (link-begin (org-element-property :begin elem)) + (link-end (org-element-property :end elem))) + (if (and content-begin content-end) + (let ((content + (buffer-substring-no-properties + content-begin content-end))) + (delete-region link-begin (- link-end 1)) + (insert content))))))) +(bind-key "C-c r" 'qwan/org-replace-link-by-link-description) + +(defun strip-url (url) + "Remove everything after ? from the url, to hinder tracking." + (replace-regexp-in-string "\\?.*$" "" url)) + +;; TODO define key for this maybe SPC q is available? no, that is quit. +(defun qwan/paste-stripped-url () + "Paste a URL without tracking from the clipboard into the current buffer." + (interactive) + (let ((url (x-get-selection 'CLIPBOARD))) + (when url + (insert (strip-url url))))) + +(defun qwan/org-roam-replace-file-link-by-website-or-description () + "If a linked org-roam file has a website as key, + use that as the link target instead of the filename. + Otherwise, remove the link, and leave just the description. + This may destroy existing links, or change their targets so + use in a copy of buffers you hold dearly as notes" + (interactive) + (let ((elem (org-element-context))) + (if (eq (car elem) 'link) + (let* ((content-begin (org-element-property :contents-begin elem)) + (content-end (org-element-property :contents-end elem)) + (target-type (org-element-property :type elem)) + (target-path (org-element-property :path elem)) + (link-begin (org-element-property :begin elem)) + (link-end (org-element-property :end elem))) + (if (and content-begin + content-end + (string-equal target-type "file") + target-path + link-begin + link-end) + (let ((new-link + (org-roam-description-file-to-org-url + (buffer-substring-no-properties content-begin content-end) + target-path))) + (delete-region link-begin (- link-end 1)) + (insert new-link))))))) +(defun qwan/string-as-markdown-image-link (a-string) + (concat "![alt-text goes here](" a-string ")")) +(defun qwan/image-mode-copy-filename-as-markdown-image-link () + "Push a markdown link to the currently visited image onto the kill ring." + (interactive) + (unless buffer-file-name + (error "The current buffer doesn't visit an image file")) + (let ((markdown-link + (qwan/string-as-markdown-image-link + (qwan/relative-path-to-attachments buffer-file-name)))) + (kill-new markdown-link) + (message "Copied %s" markdown-link))) + +(defun qwan/relative-path-to-attachments (full-path) + (substring full-path (string-search "/attachments" full-path 0))) +(require 'ert) +(ert-deftest relative-path-to-attachments-removes-prefix () + (should + (equal + (qwan/attachments-remove-prefix-path "prefix/attachments") "/attachments"))) +(ert-deftest + relative-path-to-attachments-does-not-remove-prefix-when-no-attachments + () + (should + (equal + (qwan/attachments-remove-prefix-path "prefix/somethingelse") + "prefix/somethingelse"))) +(ert-deftest markdown-link-tokens-should-surround-string () + (should + (equal + (qwan/string-as-markdown-image-link "prefix/image.png") + "![alt-text goes here](prefix/image.png)"))) diff --git a/qwan/qwan-refactor.el b/qwan/qwan-refactor.el new file mode 100644 index 0000000..fac17ba --- /dev/null +++ b/qwan/qwan-refactor.el @@ -0,0 +1,66 @@ + +;;; qwan/qwan-refactor.el -*- lexical-binding: t; -*- +;;; + +(provide 'qwan-refactor) + +(defun qwan-echo (new-name) + (interactive "SRename function to:") + (message "Will rename to %s" new-name)) +;; from @tbf@functional.cafe +(defun movd (from to) + (fset to (symbol-function from)) + (fset from nil) + to) +;; from @tbf@functional.cafe +(defmacro frename (from to) + `(movd ',from ',to)) +(defun qrefactor/rename (new-name) + "Rename function at point. You must modify references yourself" + (interactive "MRename function to:") + (let ((bounds (bounds-of-thing-at-point 'symbol))) + (if bounds + (progn + (let* ((begin (car bounds)) + (end (cdr bounds)) + (old-name (buffer-substring-no-properties begin end)) + (new-function-name (as-function-name new-name))) + (message "Will rename to %s" new-function-name) + ;; should use as-function-name here + (movd (intern old-name) (intern new-function-name)) + (ert-make-test-unbound (intern old-name)) + (delete-region begin end) + (insert new-function-name) + (message "Renamed %s to %s." old-name new-name))) + (message "No symbol under cursor.")))) +(defun qrefactor/remove-test () + "Renmove test at point from memory. + See also ert-delete-test if you want to delete from a list of existing tests." + (interactive) + (let ((bounds (bounds-of-thing-at-point 'symbol))) + (if bounds + (progn + (let* ((begin (car bounds)) + (end (cdr bounds)) + (old-name (buffer-substring-no-properties begin end))) + (ert-make-test-unbound (intern old-name)) + (message "Undefined %s." old-name)))) + (message "No symbol under cursor."))) +;; tests are better than literate programming when you want to triangulate on the same function +;; org only shows the last return value by default, you can return a list of course, but still +(defun as-function-name (candidate-name) + "Take the string and make it suitable to be a function name. + Replaces space with dash and make string all lowercase." + (declare (side-effect-free t)) + (s-join "-" (mapcar 'downcase (split-string candidate-name " " t)))) +;; (s-join "-" (mapcar 'downcase (s-split-words s)))) +(ert-deftest refactor-rename-should-leave-forward-slash () + (should (equal (as-function-name "qwan/echo") "qwan/echo"))) +(ert-deftest refactor-rename-should-replace-space-with-dash () + (should (equal (as-function-name "qwan/echo chamber") "qwan/echo-chamber"))) +(ert-deftest refactor-rename-replaces-uppercase-with-lowercase () + (should (equal (as-function-name "Echo-chamber") "echo-chamber"))) +(ert-deftest refactor-renamed-thrice () + (should (equal 1 1))) +(ert-make-test-unbound 'refactor-rename-test-for-fun) +;; (ert "refactor.*") From 8f3718911383017a17e9da6b043acff8ad1de185 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Mon, 10 Nov 2025 09:09:46 +0000 Subject: [PATCH 08/21] reasoning in separate buffer, ts- and elixir support --- config.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ init.el | 1 + 2 files changed, 46 insertions(+) diff --git a/config.el b/config.el index d6da9d9..c4d7087 100644 --- a/config.el +++ b/config.el @@ -130,6 +130,7 @@ gptel-model 'Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf) ;; Do not use chatgpt as default. took long to find. (setq-default gptel-model 'hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL) + (setq gptel-include-reasoning "*gptel-reasoning*") (require 'gptel-integrations) ;; <- for mcp ;; declare another llm configuration, I also use Ollama to easily use multiple smaller models that don't require ;; max speed or the latest API. @@ -145,3 +146,47 @@ :capabilities (tools media) :mime-types ("image/jpeg" "image/png" "image/svg"))))) + +;; elixir +;; inspiration https://medium.com/@victor.nascimento/elixir-emacs-development-2023-edition-1a6ccc40629 +(use-package + emacs + :ensure nil + :custom + + ;; Should use: + ;; (mapc #'treesit-install-language-grammar (mapcar #'car treesit-language-source-alist)) + ;; at least once per installation or while changing this list + (treesit-language-source-alist + '((heex "https://github.com/phoenixframework/tree-sitter-heex") + (elixir "https://github.com/elixir-lang/tree-sitter-elixir") + (typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src") + (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src"))) + + ;; Install grammars if not present + (dolist (lang '(typescript tsx)) + (unless (treesit-language-available-p lang) + (treesit-install-language-grammar lang))) + (major-mode-remap-alist + '((elixir-mode . elixir-ts-mode))) + ) + +(with-eval-after-load 'eglot + (add-to-list 'eglot-server-programs '(elixir-ts-mode . ("sh" "/Users/willem/.elixir-ls/release/language_server.sh" )))) + +(use-package + elixir-ts-mode + :hook (elixir-ts-mode . eglot-ensure) + (elixir-ts-mode + . + (lambda () + (push '(">=" . ?\u2265) prettify-symbols-alist) + (push '("<=" . ?\u2264) prettify-symbols-alist) + (push '("!=" . ?\u2260) prettify-symbols-alist) + (push '("==" . ?\u2A75) prettify-symbols-alist) + (push '("=~" . ?\u2245) prettify-symbols-alist) + (push '("<-" . ?\u2190) prettify-symbols-alist) + (push '("->" . ?\u2192) prettify-symbols-alist) + (push '("<-" . ?\u2190) prettify-symbols-alist) + (push '("|>" . ?\u25B7) prettify-symbols-alist))) + (before-save . eglot-format)) diff --git a/init.el b/init.el index c54a11d..0cdb9fe 100644 --- a/init.el +++ b/init.el @@ -119,6 +119,7 @@ ;;common-lisp ; if you've seen one lisp, you've seen them all ;;coq ; proofs-as-programs ;;crystal ; ruby at the speed of c + typescript csharp ; unity, .NET, and mono shenanigans data ; config/data formats ;;(dart +flutter) ; paint ui and not much else From 839db3ccdc57d16071bd0b1d150ee3dca449b7b0 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Mon, 1 Dec 2025 21:58:24 +0000 Subject: [PATCH 09/21] set ollama as default, with qwen3:coder --- config.el | 40 ++++++++++++++++++++++------------------ init.el | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/config.el b/config.el index c4d7087..7101c80 100644 --- a/config.el +++ b/config.el @@ -122,29 +122,33 @@ ;; declare the default llm configuration ;; for me this is co-pilot with claude-sonnet-4 (setq gptel-default-mode 'org-mode ;; I want the llm to reply to me with org-mode format. - gptel-backend (gptel-make-openai "llama.cpp" - :host "localhost:8000" - :protocol "http" - :stream t - :models '(Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf)) - gptel-model 'Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf) - ;; Do not use chatgpt as default. took long to find. - (setq-default gptel-model 'hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL) + gptel-backend + (gptel-make-ollama "Ollama" + :host "localhost:11434" + :stream t + + :models '(hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL + qwen3:0.6B + (qwen3-coder:30b ;Full spec + :description + "qwen3 coder large coding model " + :capabilities (tools media) + :mime-types ("image/jpeg" "image/png" "image/svg")))) + gptel-model 'qwen3-coder:30b) + + + (setq gptel-include-reasoning "*gptel-reasoning*") (require 'gptel-integrations) ;; <- for mcp ;; declare another llm configuration, I also use Ollama to easily use multiple smaller models that don't require ;; max speed or the latest API. - (gptel-make-ollama "Ollama" - :host "localhost:11434" + ;; Do not use chatgpt as default. took long to find. + (gptel-make-openai "llama.cpp" + :host "localhost:8000" + :protocol "http" :stream t - - :models '(hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL - qwen3:0.6B - (qwen3-coder:30b ;Full spec - :description - "qwen3 coder large coding model " - :capabilities (tools media) - :mime-types ("image/jpeg" "image/png" "image/svg"))))) + :models '(Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf)) + (set-default gptel-model 'qwen3-coder:30b)) ;; elixir diff --git a/init.el b/init.el index 0cdb9fe..5d66662 100644 --- a/init.el +++ b/init.el @@ -124,7 +124,7 @@ data ; config/data formats ;;(dart +flutter) ; paint ui and not much else ;;dhall - elixir ; erlang done right + (elixir +lsp ) ; erlang done right ;;elm ; care for a cup of TEA? emacs-lisp ; drown in parentheses erlang ; an elegant language for a more civilized age From 673458a4049bbe48f2fb213c8b5898d2c0437ae4 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Sun, 8 Feb 2026 15:26:57 +0000 Subject: [PATCH 10/21] add qwen3 coder next as remote --- config.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config.el b/config.el index 7101c80..c3e7571 100644 --- a/config.el +++ b/config.el @@ -148,6 +148,12 @@ :protocol "http" :stream t :models '(Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf)) + + (gptel-make-openai "llama.cpp on mac" + :host "MacBook-Pro-3.local:8000" + :protocol "http" + :stream t + :models '(Qwen3-Coder-Next-UD-Q4_K_XL)) (set-default gptel-model 'qwen3-coder:30b)) From a1a363f905febd24e6669093855ded4b93f73281 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 5 May 2026 23:02:49 +0100 Subject: [PATCH 11/21] update models --- config.el | 5 +++-- custom.el | 17 ----------------- packages.el | 1 + 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/config.el b/config.el index c3e7571..7c191d9 100644 --- a/config.el +++ b/config.el @@ -129,12 +129,13 @@ :models '(hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL qwen3:0.6B + gpt-oss:20b (qwen3-coder:30b ;Full spec :description "qwen3 coder large coding model " :capabilities (tools media) :mime-types ("image/jpeg" "image/png" "image/svg")))) - gptel-model 'qwen3-coder:30b) + gptel-model 'gpt-oss:20b) @@ -154,7 +155,7 @@ :protocol "http" :stream t :models '(Qwen3-Coder-Next-UD-Q4_K_XL)) - (set-default gptel-model 'qwen3-coder:30b)) + (set-default gptel-model 'Qwen3-Coder-Next-UD-Q4_K_XL)) ;; elixir diff --git a/custom.el b/custom.el index 3f4ec45..e69de29 100644 --- a/custom.el +++ b/custom.el @@ -1,17 +0,0 @@ -(custom-set-variables - ;; custom-set-variables was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(safe-local-variable-values - '((eval setq-local org-roam-db-location - (expand-file-name "org-roam.db" org-roam-directory)) - (eval setq-local org-roam-directory - (expand-file-name - (locate-dominating-file default-directory ".dir-locals.el")))))) -(custom-set-faces - ;; custom-set-faces was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - ) diff --git a/packages.el b/packages.el index 364e6e9..5fc46e4 100644 --- a/packages.el +++ b/packages.el @@ -48,3 +48,4 @@ ;; (unpin! pinned-package another-pinned-package) ;; ...Or *all* packages (NOT RECOMMENDED; will likely break things) ;; (unpin! t) + From 4a27095186252e1812312559aaabdb8a9c51d21d Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Thu, 27 Aug 2026 12:29:54 +0100 Subject: [PATCH 12/21] add brief agent instruction --- AGENTS.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..6f2eacb --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,3 @@ +# Willem's Doom Emacs configuration + +This is a doom emacs configuration. LLM model configurations for GPTEL - Emacs LLM integration are in [config.el](config.el) From a55f4849ae6082c843b526569e925cf9ac20af42 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Thu, 27 Aug 2026 12:30:01 +0100 Subject: [PATCH 13/21] indentation fixed, deleted ellama, add mtplx --- config.el | 34 ++++++---------------------------- custom.el | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/config.el b/config.el index 7c191d9..88f2872 100644 --- a/config.el +++ b/config.el @@ -88,33 +88,6 @@ ;; ;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how ;; they are implemented. -;; embedd llms in emacs. with org-mode support -(use-package ellama - :init - ;; setup key bindings - (setopt ellama-keymap-prefix "C-c e") - ;; language you want ellama to translate to - (setopt ellama-language "Dutch") - ;; could be llm-openai for example - (require 'llm-ollama) - (setopt ellama-provider - (make-llm-ollama - ;; this model should be pulled to use it - ;; value should be the same as you print in terminal during pull - :chat-model "llama3.1:8b-instruct-q8_0" - :embedding-model "nomic-embed-text" - :default-chat-non-standard-params '(("num_ctx" . 8192)))) - ;; Naming new sessions with llm - (setopt ellama-naming-provider - (make-llm-ollama - :chat-model "llama3.1:8b-instruct-q8_0" - :embedding-model "nomic-embed-text" - :default-chat-non-standard-params '(("stop" . ("\n"))))) - (setopt ellama-naming-scheme 'ellama-generate-name-by-llm) - ;; Translation llm provider - (setopt ellama-translation-provider (make-llm-ollama - :chat-model "llama3.1" - :embedding-model "nomic-embed-text"))) ;; https://yannesposito.com/posts/0029-ai-assistants-in-doom-emacs-31-on-macos-with-clojure-mcp-server/index.html ;; LLM (use-package! gptel @@ -155,8 +128,13 @@ :protocol "http" :stream t :models '(Qwen3-Coder-Next-UD-Q4_K_XL)) - (set-default gptel-model 'Qwen3-Coder-Next-UD-Q4_K_XL)) + (gptel-make-openai "MTPLX on mac" + :host "mb:8001" + :protocol "http" + :stream t + :models '(mtplx-qwen38-27b-optimized-speed)) + (set-default gptel-model 'mtplx-qwen38-27b-optimized-speed)) ;; elixir ;; inspiration https://medium.com/@victor.nascimento/elixir-emacs-development-2023-edition-1a6ccc40629 diff --git a/custom.el b/custom.el index e69de29..f48925a 100644 --- a/custom.el +++ b/custom.el @@ -0,0 +1,19 @@ +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(safe-local-variable-values + '((qwan-markdown-attachment-dir . "/Users/willem/dev/elixir/firehose/app/priv/static/images/blog/2026") + (qwan-markdown-attachment-dir . "app/priv/static/images/blog/2026") + (eval setq-local org-roam-db-location + (expand-file-name "org-roam.db" org-roam-directory)) + (eval setq-local org-roam-directory + (expand-file-name + (locate-dominating-file default-directory ".dir-locals.el")))))) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) From 3773aa5dd3707dd8b9fb3ae556f038dd83678590 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 3 Nov 2026 11:57:59 +0000 Subject: [PATCH 14/21] add firehose blog image drop helper --- config.el | 1 + qwan/firehose-blog.el | 369 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 370 insertions(+) create mode 100644 qwan/firehose-blog.el diff --git a/config.el b/config.el index 88f2872..45a73e4 100644 --- a/config.el +++ b/config.el @@ -55,6 +55,7 @@ (require 'qwan-blog) (require 'qwan-refactor) +(require 'firehose-blog) ;; Whenever you reconfigure a package, make sure to wrap your config in an diff --git a/qwan/firehose-blog.el b/qwan/firehose-blog.el new file mode 100644 index 0000000..b91abb2 --- /dev/null +++ b/qwan/firehose-blog.el @@ -0,0 +1,369 @@ +;;; firehose-blog.el --- Blog helpers for the firehose repo -*- lexical-binding: t; -*- + +;;; Commentary: + +;; Drag-and-drop for firehose blog posts (app/priv/blog///*.md): +;; +;; - Dropping an image file copies it into +;; /app/priv/static/images/blog// and inserts +;; `![alt-text goes here](/images/blog//)' at point. +;; The year comes from the post's own directory; clashing names get a +;; _YYYYMMDD_HHMMSS suffix (and a counter if that still clashes). +;; - Dropping any other file opens it, like the default Emacs behaviour. +;; +;; These are the same conventions implemented by scripts/roam-export-blog.el +;; in the firehose repo for the org-roam export flow. +;; +;; All firehose-specific decisions (destination directory and web path) live +;; in `firehose-blog--drop-target'; the DND machinery around it is +;; site-agnostic, so a Jekyll equivalent only needs its own drop-target +;; function. + +;;; Code: + +(require 'dnd) + +(defgroup firehose-blog nil + "Helpers for writing posts in the firehose repo." + :group 'markdown) + +(defcustom firehose-blog-root "~/dev/elixir/firehose" + "Path to the firehose repository root." + :type 'directory) + +(defcustom firehose-blog-image-extensions + '("svg" "png" "jpg" "jpeg" "gif" "webp" "avif") + "Dropped files with these extensions count as images." + :type '(repeat string)) + +(defcustom firehose-blog-alt-text "alt-text goes here" + "Alt text inserted for dropped images; edited in place afterwards." + :type 'string) + +(defun firehose-blog--stamp () + "Timestamp used to uniquify dropped images with clashing names." + (format-time-string "%Y%m%d_%H%M%S")) + +(defun firehose-blog--post-year (post-file) + "Return the year directory of POST-FILE, or the current year. + +Posts live in app/priv/blog///.md; the immediate +parent directory is used as the year when it is four digits." + (let ((parent (car (nreverse (split-string (file-name-directory post-file) + "/" t))))) + (if (and parent (string-match-p "\\`[0-9]\\{4\\}\\'" parent)) + parent + (format-time-string "%Y")))) + +(defun firehose-blog--image-p (file) + "Return non-nil when FILE looks like an image." + (member (downcase (or (file-name-extension file) "")) + firehose-blog-image-extensions)) + +(defun firehose-blog--web-path (year name) + "Return the web path for NAME stored in the images dir of YEAR." + (format "/images/blog/%s/%s" year name)) + +(defun firehose-blog--unique-dest (dir name) + "Return a destination path for NAME in DIR that does not yet exist. + +When NAME already exists in DIR, a _YYYYMMDD_HHMMSS stamp (and, if +that still clashes, a counter) is inserted before the extension." + (let* ((base (file-name-sans-extension name)) + (ext (file-name-extension name)) + (stamp (firehose-blog--stamp)) + (candidate + (lambda (n) + (expand-file-name + (cond + ((zerop n) name) + ((and (= n 1) ext) (format "%s_%s.%s" base stamp ext)) + ((= n 1) (format "%s_%s" base stamp)) + (ext (format "%s_%s_%d.%s" base stamp (1- n) ext)) + (t (format "%s_%s_%d" base stamp (1- n)))) + dir))) + (dest (funcall candidate 0)) + (count 0)) + (while (file-exists-p dest) + (setq count (1+ count) + dest (funcall candidate count))) + dest)) + +(defun firehose-blog--drop-target (source) + "Return (DEST-FILE . WEB-PATH) for dropping image SOURCE. + +Called from a buffer visiting a firehose blog post; the year comes +from the post's own directory. This is the only firehose-specific +function; the DND machinery is site-agnostic so other blogs (e.g. +Jekyll) can supply their own drop-target." + (let* ((year (firehose-blog--post-year (buffer-file-name))) + (dest (firehose-blog--unique-dest + (expand-file-name + (format "app/priv/static/images/blog/%s" year) + firehose-blog-root) + (file-name-nondirectory source)))) + (cons dest (firehose-blog--web-path year (file-name-nondirectory dest))))) + +(defun firehose-blog--drop-image (source) + "Copy image SOURCE into the firehose static images dir and insert a link." + (let* ((target (firehose-blog--drop-target source)) + (dest (car target)) + (web-path (cdr target))) + (make-directory (file-name-directory dest) t) + (copy-file source dest) + (insert (format "![%s](%s)" firehose-blog-alt-text web-path)))) + +(defun firehose-blog-in-post-p () + "Return non-nil when the current buffer visits a firehose blog post." + (and buffer-file-name + (string-prefix-p (expand-file-name "app/priv/blog/" firehose-blog-root) + (expand-file-name buffer-file-name)))) + +(defun firehose-blog--dnd-file-handler (url &optional _action) + "DND handler for firehose blog posts. +Copy images into the static images dir and insert a web-path link; +open any other dropped file. A URI that cannot be resolved to a +local file is reported in *Messages* instead of opening nothing." + (let ((file (dnd-get-local-file-name url t))) + (cond + ((and file (firehose-blog--image-p file)) + (firehose-blog--drop-image file)) + (file (dnd-open-local-file url nil)) + (t (message "firehose-blog: cannot resolve dropped file URI %S" url) + nil)))) + +(defun firehose-blog--enable-dnd () + "Install the firehose DND handler in the current buffer. + +Only active in buffers visiting files under the firehose blog +tree; other markdown buffers keep the default handlers. Idempotent, +so it can be called from both the mode hook and the retrofit sweep." + (when (and (firehose-blog-in-post-p) + (not (rassq 'firehose-blog--dnd-file-handler dnd-protocol-alist))) + (setq-local dnd-protocol-alist + (cons '("^file:" . firehose-blog--dnd-file-handler) + dnd-protocol-alist)))) + +(defun firehose-blog--enable-dnd-in-existing-buffers () + "Install the firehose DND handler in already-open blog buffers. + +Mode hooks never re-run in existing buffers, so a post opened +before this file was loaded keeps the default handlers without +this sweep." + (dolist (buffer (buffer-list)) + (with-current-buffer buffer + (when (derived-mode-p 'markdown-mode) + (firehose-blog--enable-dnd))))) + +;; markdown-mode installs its own buffer-local `dnd-protocol-alist' in the +;; mode body, which runs before mode hooks, so hooking here makes our +;; handler take precedence in firehose posts. The sweep retrofits posts +;; that were already open when this file was loaded. +(with-eval-after-load 'markdown-mode + (add-hook 'markdown-mode-hook #'firehose-blog--enable-dnd) + (firehose-blog--enable-dnd-in-existing-buffers)) + +(defun firehose-blog--dnd-handle-one-url (fn window action url) + "Dispatch FN for a drop in the buffer of the drop WINDOW. + +`dnd-handle-one-url' consults `dnd-protocol-alist' in the current +buffer, which is not necessarily the buffer the file was dropped +on: dropping on a window while another buffer is current runs the +wrong (or no) buffer-local handler. x-dnd.el never switches to +the drop window's buffer (not even `dnd-insert-text'), so force it +here. This repairs buffer-local drop handlers in general -- ours, +markdown-mode's and org-download's alike." + (if (window-live-p window) + (with-current-buffer (window-buffer window) + (funcall fn window action url)) + (funcall fn window action url))) + +(advice-add 'dnd-handle-one-url :around #'firehose-blog--dnd-handle-one-url) + +(provide 'firehose-blog) +;;; firehose-blog.el ends here + +;;; Tests: + +(require 'ert) +(require 'cl-lib) + +(defvar firehose-blog--test-stamp nil + "Test override for `firehose-blog--stamp'.") + +(defun firehose-blog-test--make-repo () + "Create a fake firehose repo tree; return its root." + (let ((root (make-temp-file "firehose-blog-" t))) + (make-directory (expand-file-name "app/priv/blog/engineering/2026" root) t) + root)) + +(defun firehose-blog-test--post (root) + "Return a post path for the fake repo at ROOT." + (expand-file-name "app/priv/blog/engineering/2026/10-20-test-post.md" root)) + +(defun firehose-blog-test--image (name) + "Create an empty image file called NAME in a temp dir; return its path." + (let ((file (expand-file-name name (make-temp-file "firehose-blog-src-" t)))) + (write-region "" nil file) + file)) + +(defmacro firehose-blog-test--with-fixed-stamp (&rest body) + "Run BODY with `firehose-blog--stamp' pinned to a fixed value." + `(cl-letf (((symbol-function 'firehose-blog--stamp) + (lambda () (or firehose-blog--test-stamp "20260101_000000")))) + ,@body)) + +(ert-deftest firehose-blog-post-year-comes-from-post-directory () + (should (equal (firehose-blog--post-year + "/repo/app/priv/blog/engineering/2026/post.md") + "2026"))) + +(ert-deftest firehose-blog-post-year-falls-back-to-current-year () + (should (equal (firehose-blog--post-year "/repo/app/priv/blog/post.md") + (format-time-string "%Y")))) + +(ert-deftest firehose-blog-image-p-recognises-image-extensions () + (should (firehose-blog--image-p "shot.png")) + (should (firehose-blog--image-p "shot.PNG")) + (should (firehose-blog--image-p "diagram.svg")) + (should-not (firehose-blog--image-p "post.md")) + (should-not (firehose-blog--image-p "no-extension"))) + +(ert-deftest firehose-blog-web-path-uses-images-blog-year () + (should (equal (firehose-blog--web-path "2026" "shot.png") + "/images/blog/2026/shot.png"))) + +(ert-deftest firehose-blog-unique-dest-keeps-name-when-free () + (firehose-blog-test--with-fixed-stamp + (let ((dir (make-temp-file "firehose-blog-dst-" t))) + (should (equal (firehose-blog--unique-dest dir "shot.png") + (expand-file-name "shot.png" dir)))))) + +(ert-deftest firehose-blog-unique-dest-stamps-clashing-name () + (firehose-blog-test--with-fixed-stamp + (let ((dir (make-temp-file "firehose-blog-dst-" t))) + (write-region "" nil (expand-file-name "shot.png" dir)) + (should (equal (firehose-blog--unique-dest dir "shot.png") + (expand-file-name "shot_20260101_000000.png" dir)))))) + +(ert-deftest firehose-blog-unique-dest-counts-up-when-still-clashing () + (firehose-blog-test--with-fixed-stamp + (let ((dir (make-temp-file "firehose-blog-dst-" t))) + (write-region "" nil (expand-file-name "shot.png" dir)) + (write-region "" nil (expand-file-name "shot_20260101_000000.png" dir)) + (should (equal (firehose-blog--unique-dest dir "shot.png") + (expand-file-name "shot_20260101_000000_1.png" dir)))))) + +(ert-deftest firehose-blog-drop-image-copies-into-static-and-inserts-web-link () + (let* ((root (firehose-blog-test--make-repo)) + (source (firehose-blog-test--image "shot.png"))) + (let ((firehose-blog-root root)) + (with-current-buffer (find-file-noselect (firehose-blog-test--post root)) + (firehose-blog--drop-image source) + (should (file-exists-p + (expand-file-name + "app/priv/static/images/blog/2026/shot.png" root))) + (should (equal (buffer-string) + "![alt-text goes here](/images/blog/2026/shot.png)")))))) + +(ert-deftest firehose-blog-drop-image-uniquifies-web-path-on-clash () + (let* ((root (firehose-blog-test--make-repo)) + (source (firehose-blog-test--image "shot.png"))) + (let ((firehose-blog-root root)) + (with-current-buffer (find-file-noselect (firehose-blog-test--post root)) + (firehose-blog-test--with-fixed-stamp + (firehose-blog--drop-image source) + (firehose-blog--drop-image source) + (should (file-exists-p + (expand-file-name + "app/priv/static/images/blog/2026/shot.png" root))) + (should (file-exists-p + (expand-file-name + "app/priv/static/images/blog/2026/shot_20260101_000000.png" + root))) + (should (equal (buffer-string) + (concat "![alt-text goes here](/images/blog/2026/shot.png)" + "![alt-text goes here](/images/blog/2026/shot_20260101_000000.png)")))))))) + +(ert-deftest firehose-blog-in-post-p-accepts-blog-files-only () + (let* ((root (firehose-blog-test--make-repo)) + (readme (expand-file-name "README.md" root))) + (write-region "" nil readme) + (let ((firehose-blog-root root)) + (with-current-buffer (find-file-noselect (firehose-blog-test--post root)) + (should (firehose-blog-in-post-p))) + (with-current-buffer (find-file-noselect readme) + (should-not (firehose-blog-in-post-p)))))) + +(ert-deftest firehose-blog-enable-dnd-installs-handler-in-posts-only () + (let* ((root (firehose-blog-test--make-repo)) + (readme (expand-file-name "README.md" root))) + (write-region "" nil readme) + (let ((firehose-blog-root root)) + (with-current-buffer (find-file-noselect (firehose-blog-test--post root)) + (firehose-blog--enable-dnd) + (should (eq (cdr (car dnd-protocol-alist)) + #'firehose-blog--dnd-file-handler))) + (with-current-buffer (find-file-noselect readme) + (let ((before dnd-protocol-alist)) + (firehose-blog--enable-dnd) + (should (equal dnd-protocol-alist before))))))) + +(defun firehose-blog-test--handler-count () + "Count our handler entries in the current buffer's alist." + (let ((n 0)) + (dolist (entry dnd-protocol-alist n) + (when (eq (cdr entry) 'firehose-blog--dnd-file-handler) + (setq n (1+ n)))))) + +(ert-deftest firehose-blog-enable-dnd-is-idempotent () + (let ((root (firehose-blog-test--make-repo))) + (let ((firehose-blog-root root)) + (with-current-buffer (find-file-noselect (firehose-blog-test--post root)) + (firehose-blog--enable-dnd) + (firehose-blog--enable-dnd) + (should (= 1 (firehose-blog-test--handler-count))))))) + +(ert-deftest firehose-blog-enable-dnd-in-existing-buffers-retrofits-posts () + (let* ((root (firehose-blog-test--make-repo)) + (readme (expand-file-name "README.md" root))) + (write-region "" nil readme) + (let ((firehose-blog-root root) + (post-buffer (find-file-noselect (firehose-blog-test--post root))) + (readme-buffer (find-file-noselect readme))) + (cl-letf (((symbol-function 'derived-mode-p) (lambda (&rest _) t))) + (firehose-blog--enable-dnd-in-existing-buffers) + (with-current-buffer post-buffer + (should (eq (cdr (car dnd-protocol-alist)) + 'firehose-blog--dnd-file-handler))) + (with-current-buffer readme-buffer + (should-not (rassq 'firehose-blog--dnd-file-handler + dnd-protocol-alist))))))) + +(ert-deftest firehose-blog-dnd-file-handler-copies-dropped-image () + (let* ((root (firehose-blog-test--make-repo)) + (source (firehose-blog-test--image "shot.png"))) + (let ((firehose-blog-root root)) + (with-current-buffer (find-file-noselect (firehose-blog-test--post root)) + (firehose-blog-test--with-fixed-stamp + (firehose-blog--dnd-file-handler (concat "file://" source)) + (should (equal (buffer-string) + "![alt-text goes here](/images/blog/2026/shot.png)")) + (should (file-exists-p + (expand-file-name + "app/priv/static/images/blog/2026/shot.png" root)))))))) + +(ert-deftest firehose-blog-dnd-file-handler-reports-unresolvable-uri () + (let ((root (firehose-blog-test--make-repo))) + (let ((firehose-blog-root root)) + (with-current-buffer (find-file-noselect (firehose-blog-test--post root)) + (should-not (firehose-blog--dnd-file-handler "file:///does/not/exist.png")) + (should (equal (buffer-string) "")))))) + +(ert-deftest firehose-blog-dnd-advice-passes-through-without-window () + (let ((called nil)) + (cl-letf (((symbol-function 'dnd-handle-one-url) + (lambda (_window _action _url) (setq called t)))) + (firehose-blog--dnd-handle-one-url (lambda (&rest _) (setq called t)) + 'not-a-window 'copy "file:///x.png") + (should called)))) From 56bda55eaa6b70fb6116b5d402941a146eddd78d Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 3 Nov 2026 11:58:06 +0000 Subject: [PATCH 15/21] add api key for MTPLX gptel backend --- config.el | 1 + 1 file changed, 1 insertion(+) diff --git a/config.el b/config.el index 45a73e4..1659fe8 100644 --- a/config.el +++ b/config.el @@ -133,6 +133,7 @@ (gptel-make-openai "MTPLX on mac" :host "mb:8001" :protocol "http" + :key "REDACTED-MTPLX-API-KEY-NOT-A-SECRET" :stream t :models '(mtplx-qwen38-27b-optimized-speed)) (set-default gptel-model 'mtplx-qwen38-27b-optimized-speed)) From 978aa860005e779831825d7d334d207e89b5cdab Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 3 Nov 2026 11:58:12 +0000 Subject: [PATCH 16/21] add whisper stt via lemonade with live dictation --- config.el | 23 +++ lisp/live-dictate.el | 340 +++++++++++++++++++++++++++++++++++++++++++ packages.el | 5 + 3 files changed, 368 insertions(+) create mode 100644 lisp/live-dictate.el diff --git a/config.el b/config.el index 1659fe8..9a01cdb 100644 --- a/config.el +++ b/config.el @@ -138,6 +138,29 @@ :models '(mtplx-qwen38-27b-optimized-speed)) (set-default gptel-model 'mtplx-qwen38-27b-optimized-speed)) +;; Whisper speech-to-text via Lemonade server (OpenAI-compatible API) +(add-load-path! "lisp") +(autoload #'live-dictate "live-dictate" nil t) + +(use-package! whisper + :commands (whisper-run whisper-file whisper-select-language) + :init + (map! :leader + (:prefix ("A" . "+ai") + :desc "Whisper record/transcribe" "w" #'whisper-run + :desc "Whisper transcribe file" "W" #'whisper-file + :desc "Whisper select language" "l" #'whisper-select-language + :desc "Live dictate (streaming)" "d" #'live-dictate)) + :config + (setopt whisper-install-whispercpp nil ; no whisper.cpp needed, remote API only + whisper-server-mode 'openai ; use OpenAI-compatible transcription API + whisper-openai-api-baseurl "http://localhost:13305/" + whisper-openai-api-key "not-needed" ; Lemonade ignores auth, but whisper.el requires a non-nil key + whisper-openai-model "Whisper-Large-v3-Turbo" + whisper-language "en" + whisper-translate nil ; t would POST to /translations instead + whisper-return-cursor 'end)) + ;; elixir ;; inspiration https://medium.com/@victor.nascimento/elixir-emacs-development-2023-edition-1a6ccc40629 (use-package diff --git a/lisp/live-dictate.el b/lisp/live-dictate.el new file mode 100644 index 0000000..7e4add2 --- /dev/null +++ b/lisp/live-dictate.el @@ -0,0 +1,340 @@ +;;; live-dictate.el --- Live dictation via Lemonade realtime WebSocket -*- lexical-binding: t; -*- + +;; Author: Willem (generated with pi) +;; Version: 1.0.0 +;; Package-Requires: ((emacs "27.1") (websocket "1.13")) +;; URL: https://github.com/lemonade-sdk/lemonade + +;;; Commentary: + +;; Live speech-to-text dictation using Lemonade Server's OpenAI +;; Realtime-compatible WebSocket endpoint (/v1/realtime). +;; +;; `live-dictate' toggles dictation in the current buffer: microphone audio +;; is captured with FFmpeg as 16kHz PCM16, streamed to the server over a +;; WebSocket, and interim/final transcripts are inserted at point as you +;; speak. Finalized utterances replace their interim preview. +;; +;; Concurrency note: websocket.el can desync its frame parser if frames are +;; sent from within its own network process filter (or any process filter). +;; All sends are therefore queued to an outbox and flushed from a timer. + +;;; Code: + +(require 'json) +(require 'cl-lib) + +(defgroup live-dictate nil + "Live dictation via Lemonade's realtime transcription WebSocket." + :group 'external) + +(defcustom live-dictate-server-url "http://localhost:13305" + "Base URL of the Lemonade server (WS upgrade happens on /v1/realtime)." + :type 'string + :group 'live-dictate) + +(defcustom live-dictate-model "Whisper-Large-v3-Turbo" + "Realtime transcription model. Must support `realtime-transcription'." + :type 'string + :group 'live-dictate) + +(defcustom live-dictate-follow-cursor t + "Whether point follows the incoming transcription." + :type 'boolean + :group 'live-dictate) + +(defcustom live-dictate-stop-delay 2.0 + "Seconds to wait after committing the buffer before closing the WebSocket." + :type 'number + :group 'live-dictate) + +(defcustom live-dictate-flush-interval 0.1 + "How often to flush queued audio to the WebSocket, in seconds." + :type 'number + :group 'live-dictate) + +(defcustom live-dictate-ffmpeg-input-format + (pcase system-type + ('gnu/linux (if (or (executable-find "pulseaudio") (executable-find "pipewire-pulse")) + "pulse" "alsa")) + ('darwin "avfoundation") + ('windows-nt "dshow") + (_ nil)) + "Value passed to FFmpeg's `-f' flag to record audio." + :type '(choice string (const nil)) + :group 'live-dictate) + +(defcustom live-dictate-ffmpeg-input-device + (pcase system-type + ('gnu/linux "default") + (_ nil)) + "Value passed to FFmpeg's `-i' flag to record audio." + :type '(choice string (const nil)) + :group 'live-dictate) + +(defcustom live-dictate-debug nil + "Verbose logging to *Messages*." + :type 'boolean + :group 'live-dictate) + +(defvar live-dictate--ws nil) +(defvar live-dictate--ffmpeg nil) +(defvar live-dictate--active nil) +(defvar live-dictate--outbox nil) +(defvar live-dictate--flush-timer nil) +(defvar live-dictate--stop-timer nil) +(defvar live-dictate--target-buffer nil) +(defvar live-dictate--marker nil) +(defvar live-dictate--interim-start nil) +(defvar live-dictate--interim-end nil) +(defvar live-dictate--chunk-count 0) +(defvar live-dictate--chunk-bytes 0) +(defvar live-dictate--stderr-buffer " *live-dictate-stderr*") + +(defvar live-dictate--mode-line-indicator + (propertize " 🎙" 'face 'font-lock-warning-face)) + +(defun live-dictate--dbg (fmt &rest args) + (when live-dictate-debug + (message "live-dictate: %s" (apply #'format fmt args)))) + +(defun live-dictate--ws-url () + (format "ws://%s/v1/realtime?model=%s" + (replace-regexp-in-string "^https?://" "" live-dictate-server-url) + (url-hexify-string live-dictate-model))) + +(defun live-dictate--queue-send (payload) + "Queue JSON-able PAYLOAD for sending. Safe from any context." + (push payload live-dictate--outbox)) + +(defun live-dictate--flush-outbox () + "Send all queued payloads. Runs from a timer, never inside process filters." + (when live-dictate--outbox + (if (and live-dictate--ws (websocket-openp live-dictate--ws)) + (let ((queue (nreverse live-dictate--outbox))) + (setq live-dictate--outbox nil) + (live-dictate--dbg "flush: %d payload(s), first is %s" + (length queue) + (alist-get 'type (car queue))) + (catch 'dead + (dolist (payload queue) + (condition-case err + (websocket-send-text live-dictate--ws (json-encode payload)) + (error + (message "live-dictate: send failed: %s" err) + (live-dictate--cleanup) + (throw 'dead nil)))))) + (live-dictate--dbg "flush withheld: %d queued, ws=%s openp=%s status=%s" + (length live-dictate--outbox) + (and live-dictate--ws t) + (and live-dictate--ws (websocket-openp live-dictate--ws)) + (and live-dictate--ws + (process-status (websocket-conn live-dictate--ws))))))) + +(defun live-dictate--mode-line (show) + (when show + (cl-pushnew (list t live-dictate--mode-line-indicator) + global-mode-string :test #'equal)) + (setq global-mode-string + (remove (list t live-dictate--mode-line-indicator) global-mode-string)) + (force-mode-line-update t)) + +(defun live-dictate--clear-interim () + "Drop the interim region markers without touching text." + (setq live-dictate--interim-start nil + live-dictate--interim-end nil)) + +(defun live-dictate--insert (text) + "Insert TEXT into the target buffer at the marker, replacing any interim text." + (when (buffer-live-p live-dictate--target-buffer) + (with-current-buffer live-dictate--target-buffer + (let (inhibit-read-only) + (save-excursion + (cond + ((and live-dictate--interim-start live-dictate--interim-end) + ;; deltas carry the full interim text: replace the whole region + (delete-region live-dictate--interim-start live-dictate--interim-end) + (goto-char live-dictate--interim-start) + (insert text) + (set-marker live-dictate--interim-end (point))) + (t + (goto-char live-dictate--marker) + (setq live-dictate--interim-start (point-marker)) + (insert text) + (setq live-dictate--interim-end (point-marker))))) + (when live-dictate-follow-cursor + (goto-char (marker-position live-dictate--interim-end))))))) + +(defun live-dictate--handle-message (payload) + (let* ((msg (condition-case _ (json-read-from-string payload) + (error nil))) + (type (and msg (alist-get 'type msg)))) + (live-dictate--dbg "<- %s%s" (or type "(unparsed)") + (let ((d (alist-get 'delta msg))) + (if (stringp d) (concat " | " d) ""))) + (pcase type + ("conversation.item.input_audio_transcription.delta" + (let ((delta (alist-get 'delta msg))) + (when (and (stringp delta) (not (equal delta ""))) + (live-dictate--insert delta)))) + ("conversation.item.input_audio_transcription.completed" + (let ((transcript (alist-get 'transcript msg))) + (when (stringp transcript) + ;; replace the interim preview with the final transcript + (live-dictate--insert (string-trim transcript)) + (with-current-buffer live-dictate--target-buffer + (let (inhibit-read-only) + (save-excursion + (goto-char (marker-position live-dictate--interim-end)) + (insert " ") + (set-marker live-dictate--interim-end (point)))) + (set-marker live-dictate--marker (marker-position live-dictate--interim-end)) + (live-dictate--clear-interim))))) + ("error" + (message "live-dictate server error: %s" + (or (alist-get 'message (alist-get 'error msg)) payload))) + (_ nil)))) + +(defun live-dictate--on-message (_ws frame) + (when (eq (websocket-frame-opcode frame) 'text) + (live-dictate--handle-message (websocket-frame-payload frame)))) + +(defun live-dictate--audio-filter (_proc chunk) + "Queue raw PCM16 CHUNK from FFmpeg for sending." + (setq live-dictate--chunk-count (1+ live-dictate--chunk-count) + live-dictate--chunk-bytes (+ live-dictate--chunk-bytes (length chunk))) + (when (zerop (mod live-dictate--chunk-count 100)) + (live-dictate--dbg "audio: %d chunks, %d bytes so far" + live-dictate--chunk-count live-dictate--chunk-bytes)) + (live-dictate--queue-send + `((type . "input_audio_buffer.append") + (audio . ,(base64-encode-string chunk 'nolinebreaks))))) + +(defun live-dictate--on-open (_ws) + (live-dictate--dbg "ws open") + (condition-case err + (progn + (live-dictate--queue-send + `((type . "session.update") + (session . ((model . ,live-dictate-model))))) + ;; start flush timer (sending must not happen inside filter callbacks) + (when live-dictate--flush-timer (cancel-timer live-dictate--flush-timer)) + (setq live-dictate--flush-timer + (run-with-timer live-dictate-flush-interval + live-dictate-flush-interval + #'live-dictate--flush-outbox)) + (unless live-dictate--ffmpeg + (setq live-dictate--ffmpeg + (make-process + :name "live-dictate-ffmpeg" + :command `("ffmpeg" "-nostdin" "-hide_banner" "-loglevel" "error" + "-f" ,live-dictate-ffmpeg-input-format + "-i" ,live-dictate-ffmpeg-input-device + "-ac" "1" "-ar" "16000" "-f" "s16le" "pipe:1") + :connection-type 'pipe + :filter #'live-dictate--audio-filter + :stderr (get-buffer-create live-dictate--stderr-buffer) + :sentinel (lambda (_proc event) + (when (and live-dictate--active + (not (string-prefix-p "finished" event))) + (message "live-dictate: FFmpeg stopped (%s)" + (string-trim event))))))) + (live-dictate--dbg "on-open done")) + (error + (message "live-dictate: ERROR in on-open (was being swallowed): %S" err)))) + +(defun live-dictate--on-close (_ws) + (live-dictate--dbg "ws closed") + (setq live-dictate--ws nil)) + +(defun live-dictate--on-error (_ws _type err) + (message "live-dictate WebSocket error: %s" err) + (live-dictate--cleanup)) + +(defun live-dictate--cleanup () + "Tear down all processes and state." + (setq live-dictate--active nil) ; keep the ffmpeg sentinel quiet + (when live-dictate--stop-timer + (cancel-timer live-dictate--stop-timer) + (setq live-dictate--stop-timer nil)) + (when live-dictate--flush-timer + (cancel-timer live-dictate--flush-timer) + (setq live-dictate--flush-timer nil)) + (when (process-live-p live-dictate--ffmpeg) + (delete-process live-dictate--ffmpeg)) + (setq live-dictate--ffmpeg nil) + (when (and live-dictate--ws (websocket-openp live-dictate--ws)) + (websocket-close live-dictate--ws)) + (setq live-dictate--ws nil + live-dictate--outbox nil) + (live-dictate--clear-interim) + (when (markerp live-dictate--marker) + (set-marker live-dictate--marker nil)) + (setq live-dictate--marker nil + live-dictate--target-buffer nil) + (live-dictate--mode-line nil)) + +(defun live-dictate--load-model () + "Ask the server to load the transcription model, like the official clients do." + (condition-case err + (let ((url-request-method "POST") + (url-request-extra-headers '(("Content-Type" . "application/json"))) + (url-request-data (json-encode `((model_name . ,live-dictate-model))))) + (with-timeout (20 (message "live-dictate: /load preflight timed out, continuing")) + (url-retrieve-synchronously + (concat live-dictate-server-url "/api/v1/load") + nil nil 20) + (live-dictate--dbg "model load preflight done"))) + (error (message "live-dictate: /load preflight failed: %s (continuing)" err)))) + +(defun live-dictate--stop () + "Stop dictation: commit remaining audio, then close." + (setq live-dictate--active nil) ; before killing ffmpeg, so the sentinel stays quiet + (when (process-live-p live-dictate--ffmpeg) + (delete-process live-dictate--ffmpeg)) + (setq live-dictate--ffmpeg nil) + (live-dictate--queue-send '((type . "input_audio_buffer.commit"))) + (live-dictate--flush-outbox) + (setq live-dictate--stop-timer + (run-with-timer live-dictate-stop-delay nil + (lambda () + (live-dictate--cleanup) + (message "live-dictate: stopped"))))) + +;;;###autoload +(defun live-dictate () + "Toggle live dictation in the current buffer. +While active, speech is transcribed continuously via Lemonade's realtime +endpoint and text is inserted at point as it arrives. Run again to stop." + (interactive) + (if live-dictate--active + (live-dictate--stop) + (unless (require 'websocket nil t) + (user-error "live-dictate needs the `websocket' package (run `doom sync')")) + (when live-dictate-debug + (setq websocket-debug t ; frames -> *websocket ...debug* buffer + websocket-callback-debug-on-error t)) ; surface swallowed callback errors + (unless (and live-dictate-ffmpeg-input-format live-dictate-ffmpeg-input-device) + (user-error "live-dictate: set live-dictate-ffmpeg-input-format/-device")) + (unless (executable-find "ffmpeg") + (user-error "live-dictate: FFmpeg not found in PATH")) + (when buffer-read-only + (user-error "Buffer is read-only, can't dictate here")) + (setq live-dictate--active t + live-dictate--target-buffer (current-buffer) + live-dictate--marker (copy-marker (point)) + live-dictate--chunk-count 0 + live-dictate--chunk-bytes 0 + live-dictate--outbox nil) + (live-dictate--mode-line t) + (live-dictate--load-model) + (setq live-dictate--ws + (websocket-open (live-dictate--ws-url) + :on-open #'live-dictate--on-open + :on-message #'live-dictate--on-message + :on-close #'live-dictate--on-close + :on-error #'live-dictate--on-error)) + (message "live-dictate: connecting to %s..." live-dictate-server-url))) + +(provide 'live-dictate) +;;; live-dictate.el ends here diff --git a/packages.el b/packages.el index 5fc46e4..d9da753 100644 --- a/packages.el +++ b/packages.el @@ -49,3 +49,8 @@ ;; ...Or *all* packages (NOT RECOMMENDED; will likely break things) ;; (unpin! t) +(package! whisper + :recipe (:host github :repo "natrys/whisper.el")) + +(package! websocket) + From 7ebcc48e33ef4e3d3171000a623b8b3c873d454e Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 3 Nov 2026 11:58:23 +0000 Subject: [PATCH 17/21] tidy agents.md wording --- AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 6f2eacb..7fe00d3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,3 +1,3 @@ # Willem's Doom Emacs configuration -This is a doom emacs configuration. LLM model configurations for GPTEL - Emacs LLM integration are in [config.el](config.el) +This is a doom emacs configuration. LLM model configurations for GPTEL - Emacs LLM integration are in [config.el](config.el). From a06bb224441f884447bc3095dea571b0594bcd7c Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 3 Nov 2026 12:24:39 +0000 Subject: [PATCH 18/21] chore: adopt mac .gitignore; stop tracking custom.el custom.el is written by Emacs itself (customize-set-variable) and was committed on 2024-07-30 by accident. Upstream mac repo dropped it in e8df0c9; adopting the same rule here so it can never come back. Also ignores config-local.el (per-machine backends/paths, template in config-local.example.el) and stale *.elc. --- .gitignore | 12 ++++++++++++ custom.el | 19 ------------------- 2 files changed, 12 insertions(+), 19 deletions(-) create mode 100644 .gitignore delete mode 100644 custom.el diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..146773b --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/README.tex +custom.el +flycheck* +config-local.el + +# stale byte-compiled files shadow newer sources on load +*.elc + +# pi coding agent: track the dir, but not its local logs +.pi/*.log + +transcripts/ diff --git a/custom.el b/custom.el deleted file mode 100644 index f48925a..0000000 --- a/custom.el +++ /dev/null @@ -1,19 +0,0 @@ -(custom-set-variables - ;; custom-set-variables was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(safe-local-variable-values - '((qwan-markdown-attachment-dir . "/Users/willem/dev/elixir/firehose/app/priv/static/images/blog/2026") - (qwan-markdown-attachment-dir . "app/priv/static/images/blog/2026") - (eval setq-local org-roam-db-location - (expand-file-name "org-roam.db" org-roam-directory)) - (eval setq-local org-roam-directory - (expand-file-name - (locate-dominating-file default-directory ".dir-locals.el")))))) -(custom-set-faces - ;; custom-set-faces was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - ) From a3b0c3d6e28065c4034a09aff7a7452de24000e9 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 3 Nov 2026 12:25:12 +0000 Subject: [PATCH 19/21] refactor: split shared config from OS-specific config Introduces the seam that makes adopting upstream changes safe: config.el holds what every machine shares, and a pcase on `system-type` at the end of it loads exactly one OS file. Leaves are loaded last on purpose, so they can override shared settings such as `gptel-backend'. config-mac.el seeded from mac repo 0789326 and now owned locally config-linux.el new; Linux paths and binaries only config-local.el per-machine, gitignored (template: config-local.example.el) Nothing changes for the current machine. The one line that moved -- the eglot entry pointing elixir-ts-mode at /Users/willem/.elixir-ls/... -- was already dead on Linux; it now lives in config-mac.el, and config-linux.el picks `expert', any elixir-ls on PATH, or nothing at all, in that order. Rationale: upstream already ships this exact layout (236c0e1 "refactor config for multi-machine support"), so adopting it costs nothing and every later upstream hunk then has an obvious correct home -- shared, mac, linux, or not-committed. Verified: parens/strings parse in all five .el files; `load!' arity checked against doom-lib.el (filename &optional path noerror). --- config-linux.el | 28 +++++++ config-mac.el | 219 ++++++++++++++++++++++++++++++++++++++++++++++++ config.el | 22 ++++- 3 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 config-linux.el create mode 100644 config-mac.el diff --git a/config-linux.el b/config-linux.el new file mode 100644 index 0000000..7acd19c --- /dev/null +++ b/config-linux.el @@ -0,0 +1,28 @@ +;;; config-linux.el --- Linux-specific configuration -*- lexical-binding: t; -*- + +;; Loaded from config.el on GNU/Linux machines only; config-mac.el is the +;; macOS counterpart. Anything with a Linux path, a Linux binary, or a +;; backend that only exists on this box belongs here rather than in the +;; shared config.el. +;; +;; Machine-specific settings that should not be committed at all (API keys, +;; checkouts in unusual places) belong in config-local.el, which is +;; gitignored -- see config-local.example.el. + +;; Elixir language server. The shared config.el used to point eglot at a +;; macOS path (/Users/willem/.elixir-ls/...), which was silently dead here. +;; Prefer `expert' if it is installed, else any elixir-ls on PATH, else +;; leave eglot alone rather than configuring a server that cannot start. +(with-eval-after-load 'eglot + (let ((server (cond ((executable-find "expert") + '("expert" "--stdio")) + ((executable-find "language_server.sh") + (list (or (executable-find "bash") "sh") + (executable-find "language_server.sh")))))) + (when server + (setf (alist-get '(elixir-mode elixir-ts-mode heex-ts-mode) + eglot-server-programs + nil nil #'equal) + server)))) + +;;; config-linux.el ends here diff --git a/config-mac.el b/config-mac.el new file mode 100644 index 0000000..14d4ad6 --- /dev/null +++ b/config-mac.el @@ -0,0 +1,219 @@ +;;; config-mac.el --- Mac-specific configuration -*- lexical-binding: t; -*- + +;; Seeded from mac repo 157ed9a, then edited locally. This file is loaded +;; only on darwin (see the dispatch at the end of config.el); it is the +;; home for anything with a macOS path, macOS binary, or macOS-hosted +;; backend. It is no longer a pristine vendor copy -- treat it as ours. + +;; Enable tool use in gptel +(setq gptel-use-tools t) + +;; Always redirect reasoning tokens to a separate buffer +(setq gptel-include-reasoning "*llm-thinking*") + +;;; gptel backend configuration +;; Local llama.cpp server + +(setq gptel-backend (gptel-make-openai "llama.cpp" + :host "localhost:8000" + :protocol "http" + :stream t + :models '(Qwen3.6-27B-Q4_K_M.gguf + Qwen3.6-35B-A3B-MXFP4_MOE.gguf + unsloth/Qwen3-Coder-Next-GGUF:UD-IQ3_XXS + unsloth/Qwen3.5-9B-GGUF:UD-Q4_K_XL + Qwen3-Coder-Next-UD-Q4_K_XL + + ;; GLM models (reasoning handled globally via gptel-include-reasoning) + (GLM-4.7-Flash-Q4_K_M + :description "GLM-4.7-Flash 30B MoE Q4 (17GB)" + :request-params (:max_tokens 8192)) + (GLM-4.7-Flash-UD-Q6_K_XL + :description "GLM-4.7-Flash 30B MoE Q6 XL (26GB)" + :request-params (:max_tokens 8192)))) + gptel-model 'Qwen3.6-35B-A3B-MXFP4_MOE.gguf) + +;; Prevent ChatGPT from being used as default +(setq-default gptel-model 'Qwen3-Coder-30B-A3B-Instruct-Q6_K) + +(setq gptel-backend (gptel-make-openai "mlx-lm" + :host "localhost:8000" + :protocol "http" + :stream t + :models '(mlx-community/Qwen3.6-27B-4bit)) + gptel-model 'mlx-community/Qwen3.6-27B-4bit) + + +(setq gptel-backend (gptel-make-openai "mlx-studio" + :host "localhost:8080" + :protocol "http" + :stream t + :models '(inferencerlabs/Qwen3.5-35B-A3B-MLX-5.5bit)) + gptel-model 'inferencerlabs/Qwen3.5-35B-A3B-MLX-5.5bit) +;; Additional backend: Ollama for smaller models +(gptel-make-ollama "Ollama" + :host "localhost:11434" + :stream t + :models '(qwen2.5-coder:7b + qwen3:0.6B + (qwen2.5-coder:32b + :description "qwen2.5 coder 32b: large coding model" + :capabilities (tools media) + :mime-types ("image/jpeg" "image/png" "image/svg")))) + + +;; Presets (these reference the backends defined above) +(gptel-make-preset 'explain + :system "Explain what this code does to a novice programmer." + :model 'Qwen3-Coder-30B-A3B-Instruct-Q6_K + :backend "llama.cpp") + +(gptel-make-preset 'elixir + :system "You are an expert programmer, specialising in Elixir and TDD, you live in Emacs" + :model 'Qwen3-Coder-30B-A3B-Instruct-Q6_K + :backend "llama.cpp") + +(gptel-make-preset 'elisp + :system "You are an expert programmer, specialising in Emacs Lisp and testing with ERT, you live in Emacs" + :model 'qwen3-coder-80b + :backend "llama.cpp") + +;; GLM-4.7-Flash presets +;; GLM requires explicit stop tokens to prevent infinite generation +;; Fast mode: thinking disabled for quick responses +(gptel-make-preset 'glm-fast + :description "GLM-4.7-Flash without thinking (fast)" + :system "You are a coding agent living in Emacs. Be concise. Code only, minimal explanation. No preamble." + :model 'GLM-4.7-Flash-Q4_K_M + :backend "llama.cpp" + :request-params '(:chat_template_kwargs (:enable_thinking :json-false) + :max_tokens 1024 + :stop ["<|user|>" "<|observation|>" "<|endoftext|>"])) + +;; Thinking mode: reasoning streamed to separate buffer +;; Uses GLM-think backend (DeepSeek parser) for reasoning_content extraction +(gptel-make-preset 'glm-think + :description "GLM-4.7-Flash with thinking (reasoning in side buffer)" + :system "Think briefly. Give a short, direct final answer. No verbose explanations." + :model 'GLM-4.7-Flash-UD-Q6_K_XL + :backend "GLM-think" + :request-params '(:max_tokens 2048 + :stop ["<|user|>" "<|observation|>" "<|endoftext|>"])) + + +(gptel-make-tool + :name "projectile-search" + :function (lambda (pattern) + (require 'projectile) + (projectile-find-file (projectile-guess-project-root)) + (let* ((root (projectile-project-root)) + (default-directory root) + (grep-command (concat "grep -r --exclude-dir={.git,node_modules,vendor} -I '" + pattern + " --include={'*.el','*.py','*.js','*.java','*.c','*.cpp','*.h','*.hs','*.rb','*.go','*.jsx','*.ts','*.tsx','*.scala','*.php','*.sh','*.yaml','*.yml','*.json'}" + )) + (output (shell-command-to-string grep-command))) + (if (string-empty-p output) + (format "No results found for pattern: %s in project %s" pattern (or (projectile-project-name) "current")) + (if (> (length output) 3000) + (concat (substring output 0 3000) "\n... (truncated)") + output)))) + :description "Search the current project using projectile. Sets working directory to project root and searches for a pattern in common source files." + :args (list '(:name "pattern" + :type "string" + :description "Search pattern to find in project files")) + :category "project") + +;; GLM search tool - searches org-roam notes via ripgrep +(gptel-make-tool + :name "search_notes" + :function (lambda (query) + (let* ((roam-dir (expand-file-name "~/MyDocuments/qwan/essays/willem")) + (cmd (format "rg --type org -i -C 1 --max-count 2 --max-filesize 100K %s %s 2>/dev/null | head -100" + (shell-quote-argument query) + (shell-quote-argument roam-dir))) + (output (shell-command-to-string cmd))) + (if (string-empty-p output) + (format "No results found for: %s" query) + (if (> (length output) 3000) + (concat (substring output 0 3000) "\n... (truncated)") + output)))) + :description "Search org-roam notes using ripgrep. Returns matching lines with context from the user's personal knowledge base." + :args (list '(:name "query" + :type "string" + :description "Search term or pattern to find in notes")) + :category "org-roam") + +;; GLM search preset - uses the search_notes tool +(gptel-make-preset 'glm-search + :description "GLM-4.7-Flash with org-roam search" + :system "You are a helpful assistant with access to the user's org-roam knowledge base. Use the search_notes tool to find relevant information before answering. Be concise." + :model 'GLM-4.7-Flash-UD-Q6_K_XL + :backend "llama.cpp" + :tools '("search_notes")) + +(defun gptel-glm-search (query) + "Search org-roam notes using GLM-4.7-Flash with tool calling. +Returns answer with org-roam links to sources." + (interactive "sSearch query: ") + (let* ((script (expand-file-name "~/dev/spikes/llm/llama-metal-openwebui/glm_search.py")) + (buf (get-buffer-create "*glm-search*"))) + (with-current-buffer buf + (erase-buffer) + (org-mode) + (yas-minor-mode -1) ; Disable yasnippet to prevent < triggers + (insert (format "* Query: %s\n\nSearching...\n" query))) + (display-buffer buf) + (redisplay) + ;; Run synchronously to ensure all output captured + (let ((output (shell-command-to-string + (format "python3 %s %s 2>/dev/null" + (shell-quote-argument script) + (shell-quote-argument query))))) + (with-current-buffer buf + (erase-buffer) + (insert (format "* Query: %s\n\n" query)) + ;; Remove everything before ==== line + (let ((clean-output (if (string-match "====\n" output) + (substring output (match-end 0)) + output))) + (insert clean-output)) + (goto-char (point-min)))))) + +;; @glm-search directive - searches org-roam with tool calling +(defun my/gptel-glm-search-run (query) + "Run glm-search script and return results." + (message "Searching org-roam for: %s..." query) + (let* ((script (expand-file-name "~/dev/spikes/llm/llama-metal-openwebui/glm_search.py")) + (output (shell-command-to-string + (format "python3 %s %s 2>/dev/null" + (shell-quote-argument script) + (shell-quote-argument query))))) + (if (string-match "====\n" output) + (substring output (match-end 0)) + output))) + +(defun gptel-glm-search-send () + "Search org-roam using @glm-search or @gptel-search query on current line." + (interactive) + (let ((line (buffer-substring-no-properties + (line-beginning-position) (line-end-position)))) + ;; Accept both @glm-search and @gptel-search patterns + (if (string-match "@\\(?:glm\\|gptel\\)-search\\s-+\\(.+\\)$" line) + (let* ((query (string-trim (match-string 1 line))) + (result (my/gptel-glm-search-run query)) + (yas-was-active (bound-and-true-p yas-minor-mode))) + (when yas-was-active (yas-minor-mode -1)) + (end-of-line) + (insert "\n\n" result) + (when yas-was-active (yas-minor-mode 1))) + (message "No @glm-search or @gptel-search query found on current line")))) + +;; Elixir language server. Moved out of the shared config.el, where this +;; macOS path was hard-coded and therefore dead on any other machine. +(with-eval-after-load 'eglot + (add-to-list 'eglot-server-programs + '(elixir-ts-mode + . ("sh" "/Users/willem/.elixir-ls/release/language_server.sh")))) + +;;; config-mac.el ends here diff --git a/config.el b/config.el index 9a01cdb..f62c536 100644 --- a/config.el +++ b/config.el @@ -185,8 +185,8 @@ '((elixir-mode . elixir-ts-mode))) ) -(with-eval-after-load 'eglot - (add-to-list 'eglot-server-programs '(elixir-ts-mode . ("sh" "/Users/willem/.elixir-ls/release/language_server.sh" )))) +;; The eglot server for elixir-ts-mode is OS-specific; see config-mac.el and +;; config-linux.el. (use-package elixir-ts-mode @@ -204,3 +204,21 @@ (push '("<-" . ?\u2190) prettify-symbols-alist) (push '("|>" . ?\u25B7) prettify-symbols-alist))) (before-save . eglot-format)) + +;;; Machine-specific configuration +;; +;; Everything above is shared by every machine. Anything below is not: the +;; two files below hold paths, binaries and backends that only make sense on +;; one OS. They are loaded last so they can override the shared settings +;; above (e.g. `gptel-backend'). +;; +;; Per-machine secrets and unusual checkout locations go in config-local.el, +;; which is gitignored. Copy config-local.example.el to get started. +(pcase system-type + ('darwin (load! "config-mac.el" doom-user-dir t)) + ('gnu/linux (load! "config-linux.el" doom-user-dir t))) + +(when (file-exists-p (expand-file-name "config-local.el" doom-user-dir)) + (load! "config-local.el" doom-user-dir t)) + +;;; config.el ends here From 4e9170417aae93be3578da79f1241a9f22d4865f Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 3 Nov 2026 12:25:22 +0000 Subject: [PATCH 20/21] vendor: import org-roam blog export and helpers from mac@0789326 New files, no local counterpart, taken verbatim from upstream: qwan/org-roam-export-blog.el org-roam note -> firehose draft / jekyll draft qwan/org-roam-export-blog-test.el 364-line ERT suite for the above qwan/test-fixtures/vault/ vault fixture (notes + .attach tree) mostalive/{my-org-roam,convert-chats-to-org,journelly-convert-entry-to-org-roam}.el config-local.example.el template for gitignored config-local.el elfeed.org, mise.toml feed list; node 24 pin (2ad9dfd) Not imported, deliberately: qwan/qwan-markdown-dnd.el earlier, cruder prototype of the same idea as our firehose-blog.el: copies dropped files to a cwd-relative dir, overwrites on name clash, no year dirs, no tests, and evaluates an ert-deftest at load time (upstream had to disable it in 7153a24/e1d2415). Installing it alongside firehose-blog.el would put two handlers in dnd-protocol-alist for markdown buffers. Ours supersedes it. .devcontainer/, run-container.sh, coe-xx/, .pi/, CLAUDE.md, investigation.md container/game-and-watch/agent scaffolding README.org, AGENTS.md upstream's docs; ours are doom-specific Nothing is wired up yet -- these files are inert until the next commit requires them. Note that mostalive/my-org-roam.el shadows the `my-org-roam' we currently load from ~/dev/emacs/org-roaming, so do not put mostalive/ on the load-path without deciding which one wins. --- config-local.example.el | 72 +++ elfeed.org | 28 + mise.toml | 2 + mostalive/convert-chats-to-org.el | 30 + .../journelly-convert-entry-to-org-roam.el | 97 +++ mostalive/my-org-roam.el | 48 ++ qwan/org-roam-export-blog-test.el | 364 +++++++++++ qwan/org-roam-export-blog.el | 583 ++++++++++++++++++ .../attached-notes.txt | 1 + .../will-it-blend.svg | 1 + qwan/test-fixtures/vault/jev.org | 7 + qwan/test-fixtures/vault/laya.org | 6 + qwan/test-fixtures/vault/note.org | 27 + qwan/test-fixtures/vault/notitle.org | 5 + 14 files changed, 1271 insertions(+) create mode 100644 config-local.example.el create mode 100644 elfeed.org create mode 100644 mise.toml create mode 100644 mostalive/convert-chats-to-org.el create mode 100644 mostalive/journelly-convert-entry-to-org-roam.el create mode 100644 mostalive/my-org-roam.el create mode 100644 qwan/org-roam-export-blog-test.el create mode 100644 qwan/org-roam-export-blog.el create mode 100644 qwan/test-fixtures/vault/.attach/00/000000-0000-0000-0000-000000000001/attached-notes.txt create mode 100644 qwan/test-fixtures/vault/.attach/00/000000-0000-0000-0000-000000000001/will-it-blend.svg create mode 100644 qwan/test-fixtures/vault/jev.org create mode 100644 qwan/test-fixtures/vault/laya.org create mode 100644 qwan/test-fixtures/vault/note.org create mode 100644 qwan/test-fixtures/vault/notitle.org diff --git a/config-local.example.el b/config-local.example.el new file mode 100644 index 0000000..d870ea9 --- /dev/null +++ b/config-local.example.el @@ -0,0 +1,72 @@ +;;; config-local.example.el --- Template for machine-specific config -*- lexical-binding: t; -*- +;; +;; Copy this file to config-local.el and uncomment/modify the section for your setup. +;; config-local.el is gitignored, so each machine can have its own configuration. + +;;; ============================================================================ +;;; OPTION 1: Linux with Ollama (local models) +;;; ============================================================================ + +;; (setq gptel-backend (gptel-make-ollama "Ollama" +;; :host "localhost:11434" +;; :stream t +;; :models '(qwen2.5-coder:7b +;; qwen3:32b +;; llama3.2:latest)) +;; gptel-model 'qwen2.5-coder:7b) +;; +;; (setq-default gptel-model 'qwen2.5-coder:7b) +;; +;; (gptel-make-preset 'explain +;; :system "Explain what this code does to a novice programmer." +;; :model 'qwen2.5-coder:7b +;; :backend "Ollama") + +;;; ============================================================================ +;;; OPTION 2: macOS connecting to remote Linux server +;;; ============================================================================ + +;; (setq gptel-backend (gptel-make-openai "remote-llama" +;; :host "linux-server.local:8000" ; your server's hostname +;; :protocol "http" +;; :stream t +;; :models '(Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf)) +;; gptel-model 'Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf) +;; +;; (setq-default gptel-model 'Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf) +;; +;; (gptel-make-preset 'explain +;; :system "Explain what this code does to a novice programmer." +;; :model 'Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf +;; :backend "remote-llama") + +;;; ============================================================================ +;;; OPTION 3: Linux with local llama.cpp server +;;; ============================================================================ + +;; (setq gptel-backend (gptel-make-openai "llama.cpp" +;; :host "localhost:8000" +;; :protocol "http" +;; :stream t +;; :models '(Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf)) +;; gptel-model 'Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf) +;; +;; (setq-default gptel-model 'Qwen3-30B-A3B-Thinking-2507-Q6_K.gguf) +;; +;; ;; Also add Ollama as secondary backend +;; (gptel-make-ollama "Ollama" +;; :host "localhost:11434" +;; :stream t +;; :models '(qwen2.5-coder:7b qwen3:0.6B)) +;; +;; (gptel-make-preset 'explain +;; :system "Explain what this code does to a novice programmer." +;; :model 'Qwen3-Coder-30B-A3B-Instruct-Q6_K.gguf +;; :backend "llama.cpp") +;; +;; (gptel-make-preset 'elixir +;; :system "You are an expert programmer, specialising in Elixir and TDD, you live in Emacs" +;; :model 'Qwen3-Coder-30B-A3B-Instruct-Q6_K.gguf +;; :backend "llama.cpp") + +;;; config-local.example.el ends here diff --git a/elfeed.org b/elfeed.org new file mode 100644 index 0000000..3d41e26 --- /dev/null +++ b/elfeed.org @@ -0,0 +1,28 @@ +#+title: Elfeed + +* Blogs :elfeed: +** entry-title: \(linux\|linus\|ubuntu\|kde\|gnome\) :linux: +** http://git-annex.branchable.com/design/assistant/blog/index.rss :mustread: +** http://feeds.feedburner.com/InformationIsBeautiful +** [[http://orgmode.org][Org Mode Links supported as well]] +** Software Development :dev: +*** Emacs :emacs:mustread: +**** http://www.terminally-incoherent.com/blog/feed +**** http://nullprogram.com/feed +**** entry-title: \(emacs\|org-mode\) +**** http://planet.emacsen.org/atom.xml +**** [[toobnix:154][EmacsConf]] +*** Web Development :web: +**** http://planet.phpunit.de/atom.xml +**** http://feeds.feedburner.com/symfony/blog +**** http://feeds.feedburner.com/qooxdoo/blog/content +*** Eclipse :eclipse: +**** http://blog.eclipse-tips.com/feeds/posts/default?alt=rss +**** http://ed-merks.blogspot.com/feeds/posts/default + A description of a feed can be written under any headline. + The text will be ignored by elfeed. +**** http://feeds.feedburner.com/eclipselive :ignore: +**** http://www.fosslc.org/drupal/rss.xml :video: +#+link: toobnix https://toobnix.org/feeds/videos.xml?videoChannelId= + +** Willem diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..6ea5a7e --- /dev/null +++ b/mise.toml @@ -0,0 +1,2 @@ +[tools] +node = "24" diff --git a/mostalive/convert-chats-to-org.el b/mostalive/convert-chats-to-org.el new file mode 100644 index 0000000..c212561 --- /dev/null +++ b/mostalive/convert-chats-to-org.el @@ -0,0 +1,30 @@ +;;; mostalive/convert-chats-to-org.el -*- lexical-binding: t; -*- + +(defun chat-remove-hours-ago () + "Format chat messages by adding '|' separator and user names." + (interactive) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "[0-9]+ hours ago" nil t) + (replace-match "")))) + + + +(ert-deftest test-chat-remove-hours-ago () + (should (string= + (with-temp-buffer + (insert "17 hours ago") + (goto-char (point-min)) + (chat-remove-hours-ago) + (buffer-string)) + ""))) + +(ert-deftest test-replace-hours-ago-regexp-in-string () + (should (string= + (replace-regexp-in-string "\n\s+[0-9]+ hours ago\s*\n" + "|" + "\n 11 hours ago \n") + "|"))) + +(ert 'test-replace-hours-ago-regexp-in-string ) +;;(ert 'test-chat-remove-hours-ago ) diff --git a/mostalive/journelly-convert-entry-to-org-roam.el b/mostalive/journelly-convert-entry-to-org-roam.el new file mode 100644 index 0000000..8d454ac --- /dev/null +++ b/mostalive/journelly-convert-entry-to-org-roam.el @@ -0,0 +1,97 @@ +;;; mostalive/convert-journelly-to-org-roam.el -*- lexical-binding: t; -*- +(require 'cl-lib) + +(provide 'journelly-convert-entry-to-org-roam) + +(cl-defstruct journelly-entry + title + content + heading + url) + +(defun journelly-parse-entry (entry-text) + "Parse a journelly entry and return a journelly-entry struct." + (let* ((lines (split-string entry-text "\n" t)) ; t omits null strings + (heading (car lines)) + (url-line (cl-find-if (lambda (l) (string-match-p "https?://" l)) lines)) + (url-pos (cl-position url-line lines :test 'equal)) + ;; Title is the non-empty line before the URL + (title-line (when url-pos + (cl-find-if (lambda (l) (not (string-match-p "^[[:space:]]*$" l))) + (reverse (cl-subseq lines 0 url-pos))))) + ;; Content is everything except heading, title, and URL + (content-lines (cl-remove-if (lambda (l) + (or (equal l heading) + (equal l title-line) + (equal l url-line))) + lines))) + (make-journelly-entry + :title title-line + :content (string-trim (mapconcat 'identity content-lines "\n")) + :heading heading + :url url-line))) + +(defun my/journelly-add-properties (url journelly-heading) + "Add ROAM_REFS and JOURNELLY_TITLE to the current node's property drawer." + (org-with-point-at 1 + (when url + (org-roam-property-add "ROAM_REFS" url)) + (when journelly-heading + (org-roam-property-add "JOURNELLY_TITLE" journelly-heading)))) + + +(defun journelly-convert-entry-to-org-roam () + "Interactive function to convert journelly entry to org-roam. +Opens the capture buffer, adds url as ROAM_REFS +and then lets you review before finalizing." + (interactive) + (let* ((entry-text (if (use-region-p) + (buffer-substring-no-properties (region-beginning) (region-end)) + (buffer-substring-no-properties (point-min) (point-max)))) + (parsed (journelly-parse-entry entry-text)) + (title (journelly-entry-title parsed)) + (content (journelly-entry-content parsed)) + (heading (journelly-entry-heading parsed)) + (url (journelly-entry-url parsed)) + (body (concat (or content "") "\n"))) + (org-roam-capture- + :node (org-roam-node-create :title title) + :props (list :immediate-finish nil + :jump-to-captured t) + :templates `(("d" "default" plain + ,body + :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" + "#+title: ${title}\n\n") + :unnarrowed t))) + (my/journelly-add-properties url heading))) + + +(ert-deftest test-journelly-parse-basic () + (let* ((entry " * [2025-10-08 Wed 22:39] @ - +Paul is #XP +Do software engineering professionals still read? - survey results +https://paulgrenyer.blogspot.com/2025/10/do-software-engineering-professionals.html?m=1") + (parsed (journelly-parse-entry entry))) + (should (equal (journelly-entry-heading parsed) + " * [2025-10-08 Wed 22:39] @ -")) + (should (equal (journelly-entry-title parsed) + "Do software engineering professionals still read? - survey results")) + (should (equal (journelly-entry-url parsed) + "https://paulgrenyer.blogspot.com/2025/10/do-software-engineering-professionals.html?m=1")) + (should (equal (journelly-entry-content parsed) + "Paul is #XP")))) + +(ert-deftest test-journelly-parse-with-extra-text-after-url () + (let* ((entry " * [2025-10-08 Wed 22:39] @ - +Some intro text +Article Title +https://example.com +Some notes after the URL") + (parsed (journelly-parse-entry entry))) + (should (equal (journelly-entry-title parsed) "Article Title")) + (should (equal (journelly-entry-url parsed) "https://example.com")) + (should (string-match-p "Some intro text" (journelly-entry-content parsed))) + (should (string-match-p "Some notes after the URL" (journelly-entry-content parsed))))) + + +;; Run tests manually with: (ert "test-journelly-*") diff --git a/mostalive/my-org-roam.el b/mostalive/my-org-roam.el new file mode 100644 index 0000000..7f98315 --- /dev/null +++ b/mostalive/my-org-roam.el @@ -0,0 +1,48 @@ +;;; mostalive/my-org-roam.el -*- lexical-binding: t; -*- + +(provide 'my-org-roam) +;; Insert a link to a node, don't go to buffer when the node is new. +(defun org-roam-node-insert-immediate (arg &rest args) + (interactive "P") + (let ((args (push arg args)) + (org-roam-capture-templates + (list + (append (car org-roam-capture-templates) '(:immediate-finish t))))) + (apply #'org-roam-node-insert args))) + + +;; make sure that org-timer works and org-pomodoro therefore. Limit the number of agenda files searched +;; plus a utility function for flattening, since that is not part of the standard library of emacs + +(defun org-roam-collect-org-agenda-files () + (interactive) + (setq org-agenda-files (collect-org-agenda-files-))) + +(defun collect-org-agenda-files- () + (seq-map + 'car + (org-roam-db-query + [:select + [file] + :from files + :where (like file "%daily\/2023%") + :order-by (desc file) + :limit 20]))) + +(setq org-agenda-files (collect-org-agenda-files-)) + + +(defun open-today-log () + "Open today's log file in log/YYYY-MM-DD.md format. +Creates the log directory if it doesn't exist." + (interactive) + (let* ((git-root (locate-dominating-file "." ".git")) + (log-dir (concat git-root "log")) + (date-str (format-time-string "%Y-%m-%d"))) + (unless (file-directory-p log-dir) + (make-directory log-dir t)) + (let ((file-name (concat log-dir "/" date-str ".org"))) + (if (file-exists-p file-name) + (find-file file-name) + (progn (find-file file-name) + (insert (format "# %s\n\n" date-str))))))) diff --git a/qwan/org-roam-export-blog-test.el b/qwan/org-roam-export-blog-test.el new file mode 100644 index 0000000..2d80939 --- /dev/null +++ b/qwan/org-roam-export-blog-test.el @@ -0,0 +1,364 @@ +;;; org-roam-export-blog-test.el --- ERT tests for org-roam-export-blog -*- lexical-binding: t; -*- + +;;; Commentary: + +;; Run with: +;; emacs --batch -Q -l org -l ox-md -L ~/.doom.d/qwan \ +;; -l org-roam-export-blog.el -l org-roam-export-blog-test.el \ +;; -f ert-run-tests-batch-and-exit +;; +;; Tests use a fixture vault under test-fixtures/vault and write output into +;; throw-away firehose/jekyll repo skeletons under /tmp. + +;;; Code: + +(require 'ert) +(require 'org-roam-export-blog) + +(defconst roeb-test-dir + (directory-file-name (file-name-directory (or load-file-name default-directory)))) + +(defconst roeb-test-vault (expand-file-name "test-fixtures/vault" roeb-test-dir)) + +(defun roeb-test--file (name) + "Path to fixture file NAME in the test vault." + (expand-file-name name roeb-test-vault)) + +(defun roeb-test--new-firehose-root () + "Create a throw-away firehose repo skeleton and return its root." + (let ((root (make-temp-file "/tmp/roeb-firehose-" t))) + (make-directory (expand-file-name "app/priv/blog/engineering" root) t) + (make-directory (expand-file-name "app/priv/static/images/blog" root) t) + root)) + +(defun roeb-test--new-jekyll-root () + "Create a throw-away jekyll site skeleton and return its root." + (let ((root (make-temp-file "/tmp/roeb-jekyll-" t))) + (make-directory (expand-file-name "_drafts" root) t) + (make-directory (expand-file-name "attachments/blogposts" root) t) + root)) + +(defun roeb-test--setup-org-id () + "Point org-id at a writable temp locations file and index the fixture vault." + (setq org-id-locations-file (make-temp-file "/tmp/roeb-orgid-")) + (setq org-id-locations nil) + (org-id-update-id-locations + (mapcar #'roeb-test--file '("note.org" "jev.org" "laya.org" "notitle.org")) t)) + +(defmacro roeb-test--with-export (firehose-root jekyll-root &rest body) + "Run BODY with the given roots and a pinned export date." + (declare (indent 2)) + `(progn + (roeb-test--setup-org-id) + (let ((org-roam-export-blog-firehose-root ,firehose-root) + (org-roam-export-jekyll-root ,jekyll-root) + (org-roam-export-blog--current-date '("2026" "10" "08"))) + ,@body))) + +(defun roeb-test--filetags-of (filetags-line) + "Write a one-keyword org file to /tmp and return its parsed filetags." + (let ((file (make-temp-file "roeb-filetags-" nil ".org"))) + (unwind-protect + (progn + (with-temp-file file + (insert "#+title: T\n" (or filetags-line "") "\n")) + (org-roam-export-blog--filetags (find-file-noselect file))) + (delete-file file)))) + +;;; Pure helpers + +(ert-deftest org-roam-export-blog/slug () + (should (equal "will-it-blend" (org-roam-export-blog--slug "Will It Blend"))) + (should (equal "improve-diagnostic-in-the-tdd-cycle" + (org-roam-export-blog--slug "Improve Diagnostic in the TDD cycle"))) + (should (equal "v0-2-0-rss-subscribe-links" + (org-roam-export-blog--slug "v0.2.0 — RSS Subscribe Links")))) + +(ert-deftest org-roam-export-blog/truncate-description-short () + (should (equal "Short paragraph." + (org-roam-export-blog--truncate-description "Short paragraph.")))) + +(ert-deftest org-roam-export-blog/truncate-description-at-word-boundary () + (let* ((words (make-list 60 "word")) + (text (string-join words " ")) + (result (org-roam-export-blog--truncate-description text))) + (should (<= (length result) (+ org-roam-export-blog-description-length 1))) + (should (string-suffix-p "…" result)) + (should-not (string-suffix-p " " result)) + (should (string-prefix-p "word word" result)))) + +;;; Filetags + +(ert-deftest org-roam-export-blog/filetags-colon-syntax () + (should (equal '("writing" "blender") + (roeb-test--filetags-of "#+filetags: :writing:blender:")))) + +(ert-deftest org-roam-export-blog/filetags-bracket-syntax () + (should (equal '("writing" "blender") + (roeb-test--filetags-of "#+filetags: [writing blender]")))) + +(ert-deftest org-roam-export-blog/filetags-absent () + (should (null (roeb-test--filetags-of nil)))) + +;;; Targets and configuration + +(ert-deftest org-roam-export-blog/firehose-target-requires-root () + (let ((org-roam-export-blog-firehose-root nil)) + (should-error (org-roam-export-blog--firehose-target) :type 'user-error))) + +(ert-deftest org-roam-export-blog/jekyll-target-requires-root () + (let ((org-roam-export-jekyll-root nil)) + (should-error (org-roam-export-blog--jekyll-target) :type 'user-error))) + +(ert-deftest org-roam-export-blog/target-requires-existing-root () + "A configured but absent root must fail loudly, not create a stray tree." + (let ((org-roam-export-blog-firehose-root "/tmp/roeb-does-not-exist")) + (should-error (org-roam-export-blog--firehose-target) :type 'user-error))) + +;;; Roam ref resolution + +(ert-deftest org-roam-export-blog/roam-refs () + (roeb-test--setup-org-id) + (should (equal "https://example.com/jev" + (org-roam-export-blog--roam-refs (roeb-test--file "jev.org")))) + (should (null (org-roam-export-blog--roam-refs (roeb-test--file "laya.org"))))) + +;;; Aborts + +(ert-deftest org-roam-export-blog/no-title-aborts () + (let ((root (roeb-test--new-firehose-root))) + (roeb-test--with-export root nil + (should-error (org-roam-export-blog--export-file + (org-roam-export-blog--firehose-target) + (roeb-test--file "notitle.org")) + :type 'user-error) + ;; Aborting must not have written any posts. + (should (null + (directory-files-recursively + (expand-file-name "app/priv/blog" root) "\\.md$")))))) + +(ert-deftest org-roam-export-blog/filename-collision-aborts () + (let ((root (roeb-test--new-firehose-root))) + (roeb-test--with-export root nil + ;; Pre-create the exact target file. + (make-directory + (expand-file-name "app/priv/blog/engineering/2026" root) t) + (write-region "" nil + (expand-file-name + "app/priv/blog/engineering/2026/10-08-will-it-blend.md" root)) + (should-error (org-roam-export-blog--export-file + (org-roam-export-blog--firehose-target) + (roeb-test--file "note.org")) + :type 'user-error) + ;; Aborting must not have copied any images (no side effects). + (should (null + (directory-files-recursively + (expand-file-name "app/priv/static/images/blog" root) + ".")))))) + +(ert-deftest org-roam-export-blog/jekyll-filename-collision-aborts () + (let ((root (roeb-test--new-jekyll-root))) + (roeb-test--with-export nil root + ;; Pre-create the exact target file. + (write-region "" nil + (expand-file-name "_drafts/will-it-blend.md" root)) + (should-error (org-roam-export-blog--export-file + (org-roam-export-blog--jekyll-target) + (roeb-test--file "note.org")) + :type 'user-error) + ;; Aborting must not have copied any images (no side effects). + (should (null + (directory-files-recursively + (expand-file-name "attachments" root) + ".")))))) + +;;; Full export: firehose + +(ert-deftest org-roam-export-blog/end-to-end () + (let ((root (roeb-test--new-firehose-root)) + result path body) + (roeb-test--with-export root nil + (setq result (org-roam-export-blog--export-file + (org-roam-export-blog--firehose-target) + (roeb-test--file "note.org")))) + (setq path (car result)) + ;; Written at the agreed path. + (should (equal (expand-file-name + "app/priv/blog/engineering/2026/10-08-will-it-blend.md" root) + path)) + (should (file-exists-p path)) + ;; Image attachment copied into static images with unchanged content. + (let ((image (expand-file-name "app/priv/static/images/blog/2026/will-it-blend.svg" root))) + (should (file-exists-p image)) + (should (equal (with-temp-buffer (insert-file-contents image) (buffer-string)) + (with-temp-buffer + (insert-file-contents (roeb-test--file ".attach/00/000000-0000-0000-0000-000000000001/will-it-blend.svg")) + (buffer-string))))) + (setq body (with-temp-buffer (insert-file-contents path) (buffer-string))) + ;; Frontmatter. + (should (string-match-p "title: \"Will It Blend\"" body)) + (should (string-match-p "author: \"Willem van den Ende\"" body)) + (should (string-match-p "tags: ~w()" body)) + (should (string-match-p + "description: \"Will it Blend was a series of videos promoting a blender brand.\"" + body)) + (should (string-match-p "image: \"/images/blog/2026/will-it-blend.svg\"" body)) + (should (string-match-p "published: false" body)) + ;; Markdown body. + (should (string-match-p "Will it Blend was a series of videos promoting a blender brand." body)) + (should (string-match-p + (regexp-quote "![will-it-blend](/images/blog/2026/will-it-blend.svg)") + body)) + (should (string-match-p (regexp-quote "[Jev](https://example.com/jev)") body)) + (should (string-match-p "Laya popped up" body)) + (should (string-match-p "a missing note vanished" body)) + (should (string-match-p "TODO source needed (LinkedIn)" body)) + (should (string-match-p "^## I learnt this from Julia$" body)) + (should (string-match-p "^> A quoted comment.$" body)) + (should (string-match-p "^```elixir$" body)) + (should (string-match-p (regexp-quote "**bold**") body)) + ;; Org syntax must not leak into the markdown. + (should-not (string-match-p "#\\+begin" body)) + (should-not (string-match-p "attachment:" body)) + (should-not (string-match-p "id:0000" body)) + (should-not (string-match-p "A private comment that must not be exported" body)) + ;; Warnings: dangling ref, ref without ROAM_REFS, ignored non-image + ;; attachment. + (should (= 3 (length (cdr result)))) + (should (cl-some (lambda (w) (string-match-p "00000000-0000-0000-0000-000000009999" w)) + (cdr result))) + (should (cl-some (lambda (w) (string-match-p "00000000-0000-0000-0000-000000000003" w)) + (cdr result))) + (should (cl-some (lambda (w) (string-match-p "attached-notes.txt" w)) + (cdr result))))) + +(ert-deftest org-roam-export-blog/description-truncated-in-frontmatter () + (let* ((root (roeb-test--new-firehose-root)) + (vault (make-temp-file "/tmp/roeb-vault-" t)) + (note (expand-file-name "longpar.org" vault)) + (long-text (string-join (make-list 50 "lorem" ) " "))) + (with-temp-file note + (insert ":PROPERTIES:\n:ID: 00000000-0000-0000-0000-000000000005\n:END:\n" + "#+title: Long Paragraph\n\n" long-text "\n")) + (roeb-test--with-export root nil + (let ((result (org-roam-export-blog--export-file + (org-roam-export-blog--firehose-target) note))) + (let ((body (with-temp-buffer + (insert-file-contents (car result)) + (buffer-string)))) + (string-match "description: \"\\([^\"]*\\)\"" body) + (let ((desc (match-string 1 body))) + (should (<= (length desc) (+ org-roam-export-blog-description-length 1))) + (should (string-suffix-p "…" desc)) + (should (string-prefix-p "lorem lorem" desc)))))))) + +(ert-deftest org-roam-export-blog/elixir-frontmatter-escapes-quotes-once () + "Quotes in title/description must produce valid Elixir string literals. + +Regression test: the old escape-then-%S combination double-escaped, +so a title containing a quote mark came out with literal +backslash-quote sequences in the exported post." + (let* ((root (roeb-test--new-firehose-root)) + (vault (make-temp-file "/tmp/roeb-vault-" t)) + (note (expand-file-name "quoted.org" vault))) + (with-temp-file note + (insert ":PROPERTIES:\n:ID: 00000000-0000-0000-0000-000000000007\n:END:\n" + "#+title: Say \"hi\"\n\n" + "A \"quoted\" remark.\n")) + (roeb-test--with-export root nil + (let* ((result (org-roam-export-blog--export-file + (org-roam-export-blog--firehose-target) note)) + (body (with-temp-buffer + (insert-file-contents (car result)) + (buffer-string)))) + (should (string-match-p (regexp-quote "title: \"Say \\\"hi\\\"\",") body)) + (should (string-match-p (regexp-quote + "description: \"A \\\"quoted\\\" remark.\",") + body)))))) + +;;; Full export: jekyll + +(ert-deftest org-roam-export-blog/jekyll-end-to-end () + (let ((root (roeb-test--new-jekyll-root)) + result path body) + (roeb-test--with-export nil root + (setq result (org-roam-export-blog--export-file + (org-roam-export-blog--jekyll-target) + (roeb-test--file "note.org")))) + (setq path (car result)) + ;; Drafts live in _drafts, without a date prefix. + (should (equal (expand-file-name "_drafts/will-it-blend.md" root) path)) + (should (file-exists-p path)) + ;; Image attachment copied into the site's attachments tree. + (let ((image (expand-file-name "attachments/blogposts/2026/will-it-blend.svg" root))) + (should (file-exists-p image)) + (should (equal (with-temp-buffer (insert-file-contents image) (buffer-string)) + (with-temp-buffer + (insert-file-contents (roeb-test--file ".attach/00/000000-0000-0000-0000-000000000001/will-it-blend.svg")) + (buffer-string))))) + (setq body (with-temp-buffer (insert-file-contents path) (buffer-string))) + ;; YAML frontmatter, tags from #+filetags:. + (should (string-match-p "^---$" body)) + (should (string-match-p "^layout: post$" body)) + (should (string-match-p "^title: \"Will It Blend\"$" body)) + (should (string-match-p "^tags:$" body)) + (should (string-match-p "^ - writing$" body)) + (should (string-match-p "^ - blender$" body)) + (should (string-match-p "^author: \"Willem van den Ende\"$" body)) + (should (string-match-p "^image: /attachments/blogposts/2026/will-it-blend.svg$" body)) + ;; Jekyll posts carry no description key. + (should-not (string-match-p "description:" body)) + ;; Markdown body. + (should (string-match-p + (regexp-quote "![will-it-blend](/attachments/blogposts/2026/will-it-blend.svg)") + body)) + (should (string-match-p (regexp-quote "[Jev](https://example.com/jev)") body)) + (should (string-match-p "Laya popped up" body)) + (should (string-match-p "^## I learnt this from Julia$" body)) + (should (string-match-p "^```elixir$" body)) + ;; Org syntax must not leak into the markdown. + (should-not (string-match-p "#\\+begin" body)) + (should-not (string-match-p "attachment:" body)) + (should-not (string-match-p "id:0000" body)) + ;; Same warnings as the firehose target for the same note. + (should (= 3 (length (cdr result)))))) + +(ert-deftest org-roam-export-blog/jekyll-untagged-note-gets-empty-tags () + (let* ((root (roeb-test--new-jekyll-root)) + (vault (make-temp-file "/tmp/roeb-vault-" t)) + (note (expand-file-name "untagged.org" vault))) + (with-temp-file note + (insert "#+title: Untagged Note\n\nFirst paragraph.\n")) + (roeb-test--with-export nil root + (let* ((result (org-roam-export-blog--export-file + (org-roam-export-blog--jekyll-target) note)) + (body (with-temp-buffer + (insert-file-contents (car result)) + (buffer-string)))) + (should (string-match-p "^tags: \\[\\]$" body)) + (should (string-match-p "^image: $" body)))))) + +(ert-deftest org-roam-export-blog/run-opens-the-generated-post () + (let ((root (roeb-test--new-jekyll-root))) + (roeb-test--with-export nil root + (with-current-buffer (find-file-noselect (roeb-test--file "note.org")) + (org-roam-export-blog--run (org-roam-export-blog--jekyll-target))) + (should (get-file-buffer + (expand-file-name "_drafts/will-it-blend.md" root)))))) + +(ert-deftest org-roam-export-blog/jekyll-frontmatter-shape () + (let ((org-roam-export-blog-author "Willem")) + (should (equal + (concat "---\n" + "layout: post\n" + "title: \"Say \\\"hi\\\"\"\n" + "tags:\n" + " - a\n" + " - b\n" + "author: \"Willem\"\n" + "image: \n" + "---\n") + (org-roam-export-blog--jekyll-frontmatter "Say \"hi\"" nil '("a" "b") nil))))) + +(provide 'org-roam-export-blog-test) +;;; org-roam-export-blog-test.el ends here diff --git a/qwan/org-roam-export-blog.el b/qwan/org-roam-export-blog.el new file mode 100644 index 0000000..c8d1b9b --- /dev/null +++ b/qwan/org-roam-export-blog.el @@ -0,0 +1,583 @@ +;;; org-roam-export-blog.el --- Export org-roam notes as blog posts -*- lexical-binding: t; -*- + +;;; Commentary: + +;; M-x org-roam-export-blog, run from an org-roam note, converts the note to +;; markdown and writes it directly into the firehose repo as a draft post: +;; +;; /app/priv/blog/engineering//-
-.md +;; +;; with `published: false' frontmatter, so the repo's git diff acts as the +;; review mechanism. +;; +;; M-x org-roam-export-jekyll writes the same note as a jekyll draft: +;; +;; /_drafts/.md +;; +;; with YAML frontmatter (layout, title, tags from #+filetags:, author, +;; image), ready to be moved into _posts/ by the usual publishing script. +;; +;; Both targets share one pipeline; each contributes its own frontmatter, +;; post path and image convention: +;; +;; - firehose images are copied into app/priv/static/images/blog// and +;; referenced with the /images/blog/... web path. +;; - jekyll images are copied into attachments/blogposts// and +;; referenced with the /attachments/blogposts/... web path. +;; +;; What happens during export: +;; +;; - `[[id:][text]]' roam refs are resolved via org-id. When the +;; target note carries a :ROAM_REFS: property, the link becomes a +;; markdown link to the first URL; otherwise it degrades to plain text. +;; - `[[attachment:...]]' links are resolved via the org-attach ID scheme +;; (.attach///). Images are copied into the +;; target's image directory; non-image attachments are ignored. +;; - Org syntax is converted to markdown with a derived ox-md backend +;; (fenced code blocks with language, H2 top-level headings, no TOC). +;; - Dropped refs, ignored attachments and unhandled constructs are +;; reported as warnings. +;; - The generated post is opened in another window for review. + +;;; Code: + +(require 'org) +(require 'ox-md) +(require 'org-id) +(require 'cl-lib) + +(defgroup org-roam-export-blog nil + "Export org-roam notes as blog posts (firehose, jekyll)." + :group 'org) + +(defcustom org-roam-export-blog-firehose-root nil + "Path to the firehose repository root, e.g. \"~/dev/elixir/firehose\"." + :type '(choice (const nil) directory)) + +(defcustom org-roam-export-jekyll-root nil + "Path to the jekyll site repository root, e.g. +\"~/MyDocuments/qwan/sites/qwaneu.github.io\"." + :type '(choice (const nil) directory)) + +(defcustom org-roam-export-blog-author "Willem van den Ende" + "Author name written into generated frontmatter." + :type 'string) + +(defcustom org-roam-export-blog-description-length 200 + "Maximum length of the generated description (before the ellipsis)." + :type 'integer) + +(defcustom org-roam-export-blog-image-extensions + '("svg" "png" "jpg" "jpeg" "gif" "webp" "avif") + "Attachment extensions that count as images." + :type '(repeat string)) + +(defvar org-roam-export-blog--current-date nil + "Override for the export date during tests, as a list (YEAR MONTH DAY).") + +;;; Derived markdown backend + +(defun org-roam-export-blog-md-src-block (src-block _contents info) + "Transcode SRC-BLOCK into a fenced markdown code block with language." + (let ((lang (org-element-property :language src-block)) + (value (org-export-format-code-default src-block info))) + (concat "```" (or lang "") "\n" value "```"))) + +(defun org-roam-export-blog-md-link (link desc info) + "Transcode LINK; file links to images become markdown images. + +Everything else is delegated to `org-md-link'." + (let* ((type (org-element-property :type link)) + (path (org-element-property :path link))) + (if (and (equal type "file") (org-roam-export-blog--image-p path)) + (format "![%s](%s)" + (or (and desc (string-trim (substring-no-properties desc))) + (file-name-base path)) + path) + (org-md-link link desc info)))) + +(org-export-define-derived-backend 'org-roam-export-blog-md 'md + :translate-alist '((src-block . org-roam-export-blog-md-src-block) + (link . org-roam-export-blog-md-link))) + +(defconst org-roam-export-blog--export-options + '(:with-toc nil :section-numbers nil :md-toplevel-hlevel 2)) + +;;; Small helpers + +(defun org-roam-export-blog--slug (title) + "Derive a filename slug from TITLE." + (let* ((lower (downcase title)) + (slugged (replace-regexp-in-string "[^a-z0-9]+" "-" lower))) + (replace-regexp-in-string "\\`-+\\|-+\\'" "" slugged))) + +(defun org-roam-export-blog--date-parts () + "Export date as a list of strings (YEAR MONTH DAY)." + (or org-roam-export-blog--current-date + (list (format-time-string "%Y") + (format-time-string "%m") + (format-time-string "%d")))) + +(defun org-roam-export-blog--yaml-string (text) + "Return TEXT as a double-quoted YAML scalar." + (concat "\"" + (replace-regexp-in-string + "\"" "\\\\\"" + (replace-regexp-in-string "\\\\" "\\\\\\\\" text)) + "\"")) + +(defun org-roam-export-blog--yaml-tags (tags) + "Return TAGS as the body of a jekyll frontmatter tags entry." + (if tags + (concat "tags:\n" + (mapconcat (lambda (tag) (format " - %s\n" tag)) tags "")) + "tags: []\n")) + +(defun org-roam-export-blog--truncate-description (text) + "Truncate TEXT to about `org-roam-export-blog-description-length' characters." + (let ((max org-roam-export-blog-description-length)) + (if (<= (length text) max) + text + (let ((cut (cl-position ?\s (substring text 0 max) :from-end t))) + (concat (if cut (substring text 0 cut) (substring text 0 max)) + "…"))))) + +(defun org-roam-export-blog--plain-text (element) + "Return a plain-text approximation of org ELEMENT." + (cond + ((stringp element) element) + ((memq (org-element-type element) '(code verbatim inline-src-block)) + (or (org-element-property :value element) "")) + ((eq (org-element-type element) 'entity) + (or (org-element-property :utf8 element) "")) + (t (mapconcat #'org-roam-export-blog--plain-text (org-element-contents element) "")))) + +;;; Reading the note + +(defun org-roam-export-blog--title (buffer) + "Return the #+TITLE: keyword value in BUFFER, or nil." + (with-current-buffer buffer + (cadr (assoc "TITLE" (org-collect-keywords '("TITLE")))))) + +(defun org-roam-export-blog--filetags (buffer) + "Return the tags of BUFFER's #+filetags: keyword, or nil. + +Accepts both org tag syntaxes: colon style (:a:b:) and bracket +style ([a b])." + (with-current-buffer buffer + (let ((value (cadr (assoc "FILETAGS" (org-collect-keywords '("FILETAGS")))))) + (when value + (let ((trimmed (string-trim value))) + (cond + ((string-prefix-p "[" trimmed) + (split-string + (string-trim-left (string-trim-right trimmed "\\]") "\\[") + "[ \t]+" t)) + (t + (split-string + (string-trim-left (string-trim-right trimmed ":+") ":+") + ":" t)))))))) + +(defun org-roam-export-blog--first-paragraph-text (buffer) + "Return the plain text of the first paragraph in BUFFER." + (with-current-buffer buffer + (let ((para (org-element-map (org-element-parse-buffer) 'paragraph + #'identity nil t))) + (when para + (replace-regexp-in-string + "[ \t\n]+" " " + (string-trim + (substring-no-properties (org-roam-export-blog--plain-text para)))))))) + +(defun org-roam-export-blog--roam-refs (file) + "Return the first :ROAM_REFS: URL of the note in FILE, or nil." + (with-current-buffer (find-file-noselect file) + (org-with-wide-buffer + (goto-char (point-min)) + (let ((value (org-entry-get (point) "ROAM_REFS"))) + (when value (car (split-string value "[ \t]+"))))))) + +(defun org-roam-export-blog--note-title (file) + "Return the #+TITLE: of the note in FILE, or nil." + (org-roam-export-blog--title (find-file-noselect file))) + +;;; Link processing + +(defun org-roam-export-blog--vault-attach-dir (file) + "Return the .attach directory dominating FILE, or nil." + (when-let* ((root (locate-dominating-file file ".attach"))) + (expand-file-name ".attach" root))) + +(defun org-roam-export-blog--image-p (file) + "Return non-nil when FILE looks like an image attachment." + (member (downcase (file-name-extension file)) + org-roam-export-blog-image-extensions)) + +(defun org-roam-export-blog--link-description (link) + "Return the description text of LINK, or nil." + (let ((begin (org-element-property :contents-begin link)) + (end (org-element-property :contents-end link))) + (when (and begin end) + (buffer-substring-no-properties begin end)))) + +(defun org-roam-export-blog--desc-or (desc fallback) + "Return trimmed DESC, or FALLBACK when DESC is nil or empty. + +An empty string is truthy in Elisp, so descriptions must be +treated as absent explicitly." + (let ((trimmed (when desc (string-trim desc)))) + (if (and trimmed (not (string-empty-p trimmed))) + trimmed + fallback))) + +(defun org-roam-export-blog--desc-verbatim-or (desc fallback) + "Return DESC unchanged, or FALLBACK when DESC is nil or blank. + +Used for plain-text replacements: a description like \"Jev \" +may carry the spacing that separated it from surrounding text in +the org source." + (if (and desc (not (string-empty-p (string-trim desc)))) + desc + fallback)) + +(defun org-roam-export-blog--attachment-path (link vault-attach-dir note-id) + "Return the absolute source path of attachment LINK, or nil. + +Handles three shapes: file links already normalized by org to an +absolute path under the vault's .attach directory, plain +attachment: links and fuzzy links carrying an attachment: prefix. +Resolution follows the org-attach ID scheme: +.attach///." + (let* ((type (org-element-property :type link)) + (path (org-element-property :path link)) + (bare (if (and (equal type "fuzzy") + (string-prefix-p "attachment:" path)) + (substring path (length "attachment:")) + path))) + (cond + ((and (equal type "file") (file-name-absolute-p path) + vault-attach-dir + (string-prefix-p vault-attach-dir (expand-file-name path))) + (expand-file-name path)) + ((and vault-attach-dir note-id bare + (>= (length note-id) 2)) + (let ((candidate (expand-file-name + (concat (substring note-id 0 2) + "/" (substring note-id 2) + "/" bare) + vault-attach-dir))) + (when (file-exists-p candidate) candidate))) + (t nil)))) + +(defun org-roam-export-blog--resolve-id (id) + "Return the file containing org ID, or nil." + (ignore-errors (org-id-find id))) + +(defun org-roam-export-blog--link-replacement (link vault-attach-dir note-id target) + "Compute the replacement for LINK. + +TARGET supplies the blog-specific image conventions. Return +(REPLACEMENT WARNINGS IMAGES), where REPLACEMENT is org syntax to +substitute for the link (nil leaves the link alone), WARNINGS is +a list of warning strings and IMAGES is a list of +(SOURCE DEST WEB-PATH) file copies to perform." + (let* ((type (org-element-property :type link)) + (path (org-element-property :path link)) + (desc (org-roam-export-blog--link-description link)) + (replacement nil) + (warnings nil) + (images nil)) + (cond + ;; Roam refs: [[id:uuid][text]] + ((equal type "id") + (let* ((target-file (org-roam-export-blog--resolve-id path)) + (refs (when target-file + (org-roam-export-blog--roam-refs (car target-file))))) + (cond + ((and target-file refs) + (setq replacement (format "[[%s][%s]]" + refs (org-roam-export-blog--desc-or desc refs)))) + (target-file + (setq replacement (org-roam-export-blog--desc-verbatim-or + desc (or (org-roam-export-blog--note-title (car target-file)) + ""))) + (push (format "dropped ref: id %s has no ROAM_REFS, kept plain text %S" + path replacement) + warnings)) + (t + (setq replacement (org-roam-export-blog--desc-verbatim-or desc "")) + (push (format "dropped ref: unresolved id %s, kept plain text %S" + path replacement) + warnings))))) + ;; Attachments (and file links that org normalized from attachments) + ((and vault-attach-dir + (or (member type '("file" "attachment")) + (and (equal type "fuzzy") + (string-prefix-p "attachment:" path)))) + (let ((source (org-roam-export-blog--attachment-path link vault-attach-dir note-id))) + (cond + ((and source (file-exists-p source) (org-roam-export-blog--image-p source)) + (let* ((name (file-name-nondirectory source)) + (year (car (org-roam-export-blog--date-parts))) + (web-path (funcall (plist-get target :image-url) name year)) + (dest (funcall (plist-get target :image-dest) name year))) + (setq images (list (list source dest web-path))) + (setq replacement + (format "[[file:%s][%s]]" web-path + (org-roam-export-blog--desc-or desc + (file-name-base name)))))) + ((and source (file-exists-p source)) + (setq replacement (org-roam-export-blog--desc-verbatim-or desc "")) + (push (format "ignored attachment (not an image): %s" + (file-name-nondirectory source)) + warnings)) + (t + (setq replacement (org-roam-export-blog--desc-verbatim-or desc "")) + (push (format "unhandled link dropped: %s:%s" type path) + warnings))))) + ;; Any other file: link points into the vault, not the blog. + ((equal type "file") + (setq replacement (org-roam-export-blog--desc-verbatim-or desc "")) + (push (format "unhandled link dropped: file:%s" path) warnings)) + ;; Everything else (https, mailto, ...) passes through untouched. + (t nil)) + (list replacement warnings images))) + +(defun org-roam-export-blog--process-links (buffer vault-attach-dir target) + "Rewrite id/attachment/file links in BUFFER's text. + +BUFFER is not modified; a processed copy of its text is returned. +TARGET supplies the blog-specific image conventions. Return +(TEXT WARNINGS IMAGES) where IMAGES is a list of +(SOURCE DEST WEB-PATH) image copies to perform." + (with-current-buffer buffer + (let ((text (buffer-string)) + (note-id (org-entry-get (point-min) "ID")) + (warnings nil) + (all-images nil)) + (let* ((tree (org-element-parse-buffer)) + (replacements + (reverse + (org-element-map tree 'link + (lambda (link) + (let* ((result (org-roam-export-blog--link-replacement + link vault-attach-dir note-id target)) + (replacement (nth 0 result)) + (warns (nth 1 result)) + (images (nth 2 result))) + (setq warnings (append warnings warns) + all-images (append all-images images)) + (when replacement + (list (org-element-property :begin link) + ;; :end includes :post-blank (trailing + ;; whitespace); exclude it from the + ;; replaced region. + (- (org-element-property :end link) + (or (org-element-property :post-blank link) 0)) + replacement)))) + nil nil nil)))) + (dolist (r replacements) + (let ((begin (nth 0 r)) + (end (nth 1 r)) + (replacement (nth 2 r))) + (setq text (concat (substring text 0 (1- begin)) + replacement + (substring text (1- end)))))) + (list text warnings all-images))))) + +;;; Markdown generation + +(defun org-roam-export-blog--to-markdown (text) + "Export org TEXT to markdown with the org-roam-export-blog-md backend." + (with-temp-buffer + (insert text) + (org-mode) + (let ((out (org-export-to-buffer + 'org-roam-export-blog-md "*org-roam-export-blog export*" + nil nil nil nil org-roam-export-blog--export-options))) + (with-current-buffer out (buffer-string))))) + +(defun org-roam-export-blog--cleanup (markdown) + "Collapse runs of blank lines in MARKDOWN." + (replace-regexp-in-string "\n\\(?:[ \t]*\n\\)+\\'" "\n" + (replace-regexp-in-string "\n\\{3,\\}" "\n\n" markdown))) + +;;; Frontmatter + +(defun org-roam-export-blog--firehose-frontmatter (title description _tags image) + "Build the Elixir-term frontmatter for the firehose post. + +TAGS are not used; firehose posts start with an empty tag list." + (concat "%{\n" + (format " title: %S,\n" title) + (format " author: %S,\n" org-roam-export-blog-author) + " tags: ~w(),\n" + (format " description: %S,\n" description) + (format " image: %S,\n" image) + " published: false\n" + "}\n---\n")) + +(defun org-roam-export-blog--jekyll-frontmatter (title _description tags image) + "Build the YAML frontmatter for the jekyll draft. + +DESCRIPTION is not used; jekyll posts carry no description key. +IMAGE is the site-absolute web path of the first image, or nil +for an empty image field." + (concat "---\n" + "layout: post\n" + (format "title: %s\n" (org-roam-export-blog--yaml-string title)) + (org-roam-export-blog--yaml-tags tags) + (format "author: %s\n" + (org-roam-export-blog--yaml-string org-roam-export-blog-author)) + (format "image: %s\n" (or image "")) + "---\n")) + +;;; Targets + +(defun org-roam-export-blog--require-root (root variable) + "Return ROOT expanded; error when unset or not an existing directory. + +VARIABLE is the defcustom symbol the root came from, for the +error message. The existence check keeps a typo or an +uncloned checkout from silently creating a stray export tree." + (unless root + (user-error "org-roam-export-blog: set %s to your blog checkout" variable)) + (setq root (expand-file-name root)) + (unless (file-directory-p root) + (user-error "org-roam-export-blog: %s points at %s, which does not exist" + variable root)) + root) + +(defun org-roam-export-blog--firehose-target () + "Return the firehose export target. + +Errors when `org-roam-export-blog-firehose-root' is unset." + (let ((root (org-roam-export-blog--require-root + org-roam-export-blog-firehose-root + 'org-roam-export-blog-firehose-root))) + (list + :name "firehose" + :post-path (lambda (slug) + (let ((date (org-roam-export-blog--date-parts))) + (expand-file-name + (format "app/priv/blog/engineering/%s/%s-%s-%s.md" + (nth 0 date) (nth 1 date) (nth 2 date) slug) + root))) + :image-dest (lambda (name year) + (expand-file-name + (format "app/priv/static/images/blog/%s/%s" year name) + root)) + :image-url (lambda (name year) + (format "/images/blog/%s/%s" year name)) + :frontmatter #'org-roam-export-blog--firehose-frontmatter))) + +(defun org-roam-export-blog--jekyll-target () + "Return the jekyll export target. + +Errors when `org-roam-export-jekyll-root' is unset." + (let ((root (org-roam-export-blog--require-root + org-roam-export-jekyll-root + 'org-roam-export-jekyll-root))) + (list + :name "jekyll" + :post-path (lambda (slug) + (expand-file-name (format "_drafts/%s.md" slug) root)) + :image-dest (lambda (name year) + (expand-file-name + (format "attachments/blogposts/%s/%s" year name) + root)) + :image-url (lambda (name year) + (format "/attachments/blogposts/%s/%s" year name)) + :frontmatter #'org-roam-export-blog--jekyll-frontmatter))) + +;;; Copying and writing + +(defun org-roam-export-blog--copy-images (images) + "Copy IMAGES (list of SOURCE DEST WEB-PATH), warning on basename clashes." + (let ((copied nil) + (warnings nil)) + (dolist (triple images) + (let ((source (nth 0 triple)) + (dest (nth 1 triple))) + (cond + ((member dest copied) + (push (format "skipped duplicate image copy: %s" + (file-name-nondirectory source)) + warnings)) + (t + (make-directory (file-name-directory dest) t) + (copy-file source dest t) + (push dest copied))))) + (nreverse warnings))) + +;;; The command + +(defun org-roam-export-blog--export-file (target &optional file) + "Export org-roam note FILE to a blog post for TARGET. + +Return (OUTPUT-PATH . WARNINGS). Abort with `user-error' when the +note has no title or the target file already exists." + (setq file (or file (buffer-file-name))) + (unless file + (user-error "org-roam-export-blog: not visiting a file")) + (let* ((buffer (find-file-noselect file)) + (title (org-roam-export-blog--title buffer))) + (unless title + (user-error "org-roam-export-blog: %s has no #+title: keyword, aborting" file)) + (let* ((slug (org-roam-export-blog--slug title)) + (post-path (funcall (plist-get target :post-path) slug))) + (when (file-exists-p post-path) + (user-error "org-roam-export-blog: %s already exists, aborting" post-path)) + (let* ((processed (org-roam-export-blog--process-links + buffer (org-roam-export-blog--vault-attach-dir file) + target)) + (text (nth 0 processed)) + (link-warnings (nth 1 processed)) + (images (nth 2 processed)) + (copy-warnings (org-roam-export-blog--copy-images images)) + (warnings (append (nreverse link-warnings) copy-warnings)) + (image (when images (nth 2 (car images)))) + (tags (org-roam-export-blog--filetags buffer)) + (description (org-roam-export-blog--truncate-description + (org-roam-export-blog--first-paragraph-text buffer))) + (markdown (org-roam-export-blog--cleanup + (org-roam-export-blog--to-markdown text)))) + (make-directory (file-name-directory post-path) t) + (with-temp-file post-path + (insert (funcall (plist-get target :frontmatter) title description tags image) + markdown)) + (cons post-path warnings))))) + +(defun org-roam-export-blog--run (target) + "Export the current note for TARGET and report the result. + +Opens the generated post in another window." + (let* ((result (org-roam-export-blog--export-file target (buffer-file-name))) + (path (car result)) + (warnings (cdr result))) + (message "org-roam-export-blog (%s): wrote %s%s" + (plist-get target :name) path + (if warnings + (format " (%d warning%s)" (length warnings) + (if (= 1 (length warnings)) "" "s")) + "")) + (when warnings + (with-output-to-temp-buffer "*org-roam-export-blog warnings*" + (dolist (w warnings) + (princ (format "%s\n" w))))) + (find-file-other-window path))) + +;;;###autoload +(defun org-roam-export-blog () + "Export the current org-roam note as a firehose blog post." + (interactive) + (org-roam-export-blog--run (org-roam-export-blog--firehose-target))) + +;;;###autoload +(defun org-roam-export-jekyll () + "Export the current org-roam note as a jekyll draft." + (interactive) + (org-roam-export-blog--run (org-roam-export-blog--jekyll-target))) + +(provide 'org-roam-export-blog) +;;; org-roam-export-blog.el ends here diff --git a/qwan/test-fixtures/vault/.attach/00/000000-0000-0000-0000-000000000001/attached-notes.txt b/qwan/test-fixtures/vault/.attach/00/000000-0000-0000-0000-000000000001/attached-notes.txt new file mode 100644 index 0000000..f070a7c --- /dev/null +++ b/qwan/test-fixtures/vault/.attach/00/000000-0000-0000-0000-000000000001/attached-notes.txt @@ -0,0 +1 @@ +some attached notes diff --git a/qwan/test-fixtures/vault/.attach/00/000000-0000-0000-0000-000000000001/will-it-blend.svg b/qwan/test-fixtures/vault/.attach/00/000000-0000-0000-0000-000000000001/will-it-blend.svg new file mode 100644 index 0000000..2b692e1 --- /dev/null +++ b/qwan/test-fixtures/vault/.attach/00/000000-0000-0000-0000-000000000001/will-it-blend.svg @@ -0,0 +1 @@ + diff --git a/qwan/test-fixtures/vault/jev.org b/qwan/test-fixtures/vault/jev.org new file mode 100644 index 0000000..ff7e835 --- /dev/null +++ b/qwan/test-fixtures/vault/jev.org @@ -0,0 +1,7 @@ +:PROPERTIES: +:ID: 00000000-0000-0000-0000-000000000002 +:ROAM_REFS: https://example.com/jev +:END: +#+title: Jev + +Body of Jev. diff --git a/qwan/test-fixtures/vault/laya.org b/qwan/test-fixtures/vault/laya.org new file mode 100644 index 0000000..8e2d126 --- /dev/null +++ b/qwan/test-fixtures/vault/laya.org @@ -0,0 +1,6 @@ +:PROPERTIES: +:ID: 00000000-0000-0000-0000-000000000003 +:END: +#+title: Laya + +Body of Laya. diff --git a/qwan/test-fixtures/vault/note.org b/qwan/test-fixtures/vault/note.org new file mode 100644 index 0000000..0e63a44 --- /dev/null +++ b/qwan/test-fixtures/vault/note.org @@ -0,0 +1,27 @@ +:PROPERTIES: +:ID: 00000000-0000-0000-0000-000000000001 +:END: +#+title: Will It Blend +#+filetags: :writing:blender: + +Will it Blend was a series of videos promoting a blender brand. + +# A private comment that must not be exported. + +[[attachment:will-it-blend.svg]] + +For instance, a day after [[id:00000000-0000-0000-0000-000000000002][Jev]] came out, [[id:00000000-0000-0000-0000-000000000003][Laya]] popped up, and [[id:00000000-0000-0000-0000-000000009999][a missing note]] vanished. TODO source needed (LinkedIn) + +[[attachment:attached-notes.txt]] + +* I learnt this from Julia + +Body text with *bold*. + +#+begin_quote +A quoted comment. +#+end_quote + +#+begin_src elixir +IO.puts("hi") +#+end_src diff --git a/qwan/test-fixtures/vault/notitle.org b/qwan/test-fixtures/vault/notitle.org new file mode 100644 index 0000000..5262118 --- /dev/null +++ b/qwan/test-fixtures/vault/notitle.org @@ -0,0 +1,5 @@ +:PROPERTIES: +:ID: 00000000-0000-0000-0000-000000000004 +:END: + +No title here. From f687a1880613d95882eb8aa6c249c30719e968a2 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 3 Nov 2026 12:25:56 +0000 Subject: [PATCH 21/21] adopt: wire org-roam blog export; move its roots into the OS files config.el require org-roam-export-blog; SPC n r b / SPC n r j config-linux.el firehose ~/dev/elixir/firehose, jekyll ~/Documents/... config-mac.el firehose ~/dev/elixir/firehose, jekyll ~/MyDocuments/... Upstream sets both roots in the shared config.el. That does not survive the trip: the jekyll checkout is ~/MyDocuments/qwan/sites/qwaneu.github.io on macOS and ~/Documents/qwan/sites/qwaneu.github.io here (both verified to exist). So the roots go to the OS files and the shared half holds only the require and the bindings. Paths are home-relative, and config-local.el can override them if a checkout ever moves. Prefix SPC n r was unused in this config, so no rebinding. Verified in a scratch checkout: the imported suite passes 20/20 (emacs -Q --batch -L qwan -l qwan/org-roam-export-blog.el -l qwan/org-roam-export-blog-test.el -f ert-run-tests-batch-and-exit) and the existing firehose-blog suite still passes 16/16. --- config-linux.el | 7 +++++++ config-mac.el | 6 ++++++ config.el | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/config-linux.el b/config-linux.el index 7acd19c..8f996cd 100644 --- a/config-linux.el +++ b/config-linux.el @@ -25,4 +25,11 @@ nil nil #'equal) server)))) +;; Blog export destinations. Upstream keeps these in the shared config.el as +;; ~/MyDocuments/..., which does not exist on this machine; here the jekyll +;; checkout lives under ~/Documents/.... Both are home-relative, so if a +;; checkout ever moves, override it in config-local.el. +(setq org-roam-export-blog-firehose-root "~/dev/elixir/firehose" + org-roam-export-jekyll-root "~/Documents/qwan/sites/qwaneu.github.io") + ;;; config-linux.el ends here diff --git a/config-mac.el b/config-mac.el index 14d4ad6..d548f35 100644 --- a/config-mac.el +++ b/config-mac.el @@ -216,4 +216,10 @@ Returns answer with org-roam links to sources." '(elixir-ts-mode . ("sh" "/Users/willem/.elixir-ls/release/language_server.sh")))) +;; Blog export destinations. Kept in this file rather than in the shared +;; config.el because the jekyll checkout sits under ~/MyDocuments on macOS and +;; under ~/Documents on Linux. Override in config-local.el if it moves. +(setq org-roam-export-blog-firehose-root "~/dev/elixir/firehose" + org-roam-export-jekyll-root "~/MyDocuments/qwan/sites/qwaneu.github.io") + ;;; config-mac.el ends here diff --git a/config.el b/config.el index f62c536..7e074a0 100644 --- a/config.el +++ b/config.el @@ -56,6 +56,14 @@ (require 'qwan-blog) (require 'qwan-refactor) (require 'firehose-blog) +(require 'org-roam-export-blog) + +;; Publishing: export an org-roam note into a blog post. The two candidate +;; destinations live in config-mac.el / config-linux.el, because their paths +;; differ per machine (and neither has anything to do with the OS as such). +(map! :leader + :desc "Export note as firehose blog post" "n r b" #'org-roam-export-blog + :desc "Export note as jekyll draft" "n r j" #'org-roam-export-jekyll) ;; Whenever you reconfigure a package, make sure to wrap your config in an