Files
dotemacs/config.el
T
Willem van den Ende 6c2a08bee5 feat: add markdown drag-and-drop for blog images
- Fix org DND flag: +download-dnd → +dragndrop (was silently no-op)
- New qwan-markdown-dnd.el: handles file drops in markdown buffers
  copies images to configurable attachment dir (default: attachments/)
  inserts markdown image links at point
  per-repo config via .dir-locals.el (qwan-markdown-attachment-dir)
- AGENTS.md: document the new module and DND setup
2026-06-28 13:23:59 +02:00

418 lines
15 KiB
EmacsLisp
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
;;; $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.
(setq
user-full-name "Willem van den Ende"
user-mail-address "redacted@example.invalid")
;; Doom exposes five (optional) variables for controlling fonts in Doom. Here
;; are the three important ones:
;;
;; + `doom-font'
;;j+ `doom-variable-pitch-font'
;; + `doom-big-font' -- used for `doom-big-font-mode'; use this for
;; presentations or streaming.
;;
;; They all accept either a font-spec, font string ("Input Mono-12"), or xlfd
;; font string. You generally only need these two:
;; (setq doom-font (font-spec :family "monospace" :size 12 :weight 'semi-light)
;; doom-variable-pitch-font (font-spec :family "sans" :size 13))
;; 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 'leuven)
;; prevent emacs from asking about variables on startup
(setq-default enable-local-variables t)
;; general editor customizations
(setq display-line-numbers-type 'relative)
(setq linum-format "%3d \u2502'")
;; org-mode customizations
(setq org-superstar-headline-bullets-list '("⁖" "◉" "○" "✸" "✿"))
(setq org-startup-with-inline-images t)
;; org-roam customizations
;; 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 "~/MyDocuments/qwan/essays/willem")
(setq org-roam-directory "~/MyDocuments/qwan/essays/willem")
; (define-key org-roam-mode-map [mouse-1] #'org-roam-visit-thing)
(require 'org-roam)
(setq mastodon-instance-url "https://mastodon.social"
mastodon-active-user "mostalive")
;; 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" "~/.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))
;;(add-hook 'after-init-hook #'global-mise-mode)
;; fix pdflatex for pdf export (macOS-specific path)
(when (eq system-type 'darwin)
(setenv "PATH" (concat (getenv "PATH") ":/Library/TeX/texbin")))
;; html export configuration, assuming use in a CMS or static site gerator that
;; takes care of the layout
;; https://stackoverflow.com/questions/47508315/emacs-org-mode-export-to-html-without-syntax-highlighting
(setq org-html-htmlize-output-type `nil)
(setq org-html-preamble `nil)
(setq org-html-postamble `nil)
;; LaTEX export that does not look like an academic paper
;; source: https://so.nwalsh.com/2020/01/05-latex
;; utf-8 supported by the following lines
(setq org-latex-compiler "xelatex")
(setq org-latex-pdf-process
(list
(concat
"latexmk -"
org-latex-compiler
" -recorder -synctex=1 -bibtex-cond %b")))
;; syntax highlighting for source code
(setq org-latex-src-block-backend t)
;; stuff taken care of by the classes that come in the next step can be set to nil.
(setq org-latex-default-packages-alist
'(("" "graphicx" t)
("" "grffile" t)
("" "longtable" nil)
("" "wrapfig" nil)
("" "rotating" nil)
("normalem" "ulem" t)
("" "amsmath" t)
("" "textcomp" t)
("" "amssymb" t)
("" "capt-of" nil)
("" "hyperref" nil)))
;; lots of latex
(setq org-latex-classes
'(("article"
"\\RequirePackage{fix-cm}
\\PassOptionsToPackage{svgnames}{xcolor}
\\documentclass[11pt]{article}
\\usepackage{fontspec}
\\setmainfont{ETBembo RomanOSF}
\\setsansfont[Scale=MatchLowercase]{Raleway}
\\setmonofont[Scale=MatchLowercase]{Fira Code}
\\usepackage{sectsty}
\\allsectionsfont{\\sffamily}
\\usepackage{enumitem}
\\setlist[description]{style=unboxed,font=\\sffamily\\bfseries}
\\usepackage{listings}
\\lstset{frame=single,aboveskip=1em,
framesep=.5em,backgroundcolor=\\color{AliceBlue},
rulecolor=\\color{LightSteelBlue},framerule=1pt}
\\usepackage{xcolor}
\\newcommand\\basicdefault[1]{\\scriptsize\\color{Black}\\ttfamily#1}
\\lstset{basicstyle=\\basicdefault{\\spaceskip1em}}
\\lstset{literate=
{§}{{\\S}}1
{©}{{\\raisebox{.125ex}{\\copyright}\\enspace}}1
{«}{{\\guillemotleft}}1
{»}{{\\guillemotright}}1
{Á}{{\\'A}}1
{Ä}{{\\\"A}}1
{É}{{\\'E}}1
{Í}{{\\'I}}1
{Ó}{{\\'O}}1
{Ö}{{\\\"O}}1
{Ú}{{\\'U}}1
{Ü}{{\\\"U}}1
{ß}{{\\ss}}2
{à}{{\\`a}}1
{á}{{\\'a}}1
{ä}{{\\\"a}}1
{é}{{\\'e}}1
{í}{{\\'i}}1
{ó}{{\\'o}}1
{ö}{{\\\"o}}1
{ú}{{\\'u}}1
{ü}{{\\\"u}}1
{¹}{{\\textsuperscript1}}1
{²}{{\\textsuperscript2}}1
{³}{{\\textsuperscript3}}1
{ı}{{\\i}}1
{—}{{---}}1
{’}{{'}}1
{…}{{\\dots}}1
{⮠}{{$\\hookleftarrow$}}1
{␣}{{\\textvisiblespace}}1,
keywordstyle=\\color{DarkGreen}\\bfseries,
identifierstyle=\\color{DarkRed},
commentstyle=\\color{Gray}\\upshape,
stringstyle=\\color{DarkBlue}\\upshape,
emphstyle=\\color{Chocolate}\\upshape,
showstringspaces=false,
columns=fullflexible,
keepspaces=true}
\\usepackage[a4paper,margin=1in,left=1.5in]{geometry}
\\usepackage{parskip}
\\makeatletter
\\renewcommand{\\maketitle}{%
\\begingroup\\parindent0pt
\\sffamily
\\Huge{\\bfseries\\@title}\\par\\bigskip
\\LARGE{\\bfseries\\@author}\\par\\medskip
\\normalsize\\@date\\par\\bigskip
\\endgroup\\@afterindentfalse\\@afterheading}
\\makeatother
[DEFAULT-PACKAGES]
\\hypersetup{linkcolor=Blue,urlcolor=DarkBlue,
citecolor=DarkRed,colorlinks=true}
\\AtBeginDocument{\\renewcommand{\\UrlFont}{\\ttfamily}}
[PACKAGES]
[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
("report"
"\\documentclass[11pt]{report}"
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
("book"
"\\documentclass[11pt]{book}"
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
;; make screenshot and paste
;; https://zzamboni.org/post/how-to-insert-screenshots-in-org-documents-on-macos/
;; 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)
;; Here are some additional functions/macros that could 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.
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.
;; configure git-delta
(after! magit (magit-delta-mode +1))
;; HACK: disable diff-hl in magit - it appears to work ok inside files, but not in magit
;; Why? diff-hl-magit-post-refresh appears to be 'null' for some reason
;; When? after stage, unstage or commit an error appears in messages.
(after!
(magit) (remove-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh))
;; from hlissner https://github.com/hlissner/.doom.d/blob/2529bcd46c5aad0cbe796793e5c08e1faf5ba272/config.el#L59-L65
;; disable auto-complete
(after! company (setq company-idle-delay nil))
;; HACK show small snippets for backlinks preview in roam-buffer
;; there is currently a problem in org-mode that shows an error
;; org-element--cache: Unregistered buffer modifications detected. Resetting. but this also happens without this function, it appears to be an interaction between org-roam and changes in orgmode.
(defun qwan/brief-preview ()
(let* ((elem (org-element-context))
(parent (org-element-property :parent elem)))
;; TODO: alt for non-paragraph elements
(string-trim-right
(buffer-substring-no-properties
(org-element-property :begin parent)
(org-element-property :end parent)))))
(setq org-roam-preview-function #'qwan/brief-preview)
;; evil mode settings for frictionless editing
;; cursor moved back to ?beginning of line? too often
;; https://evil.readthedocs.io/en/latest/settings.html under 'cursor movement'
;; Not setting these two leads to missing space when adding links with org-roam.
;; white-space at EOL is removed automatically by something else so does not bother us here.
(setq evil-move-cursor-back nil)
(setq evil-move-beyond-eol t)
;; to enable multiple org-roam dirs
;; https://github.com/org-roam/org-roam/issues/1527
(setq-default enable-local-variables t)
;; two functions from:
;; https://zzamboni.org/post/my-emacs-configuration-with-commentary/#reformatting-an-org-buffer
(defun zz/org-reformat-buffer ()
(interactive)
(when (y-or-n-p "Really format current buffer? ")
(let ((document (org-element-interpret-data (org-element-parse-buffer))))
(erase-buffer)
(insert document)
(goto-char (point-min)))))
(defun afs/org-remove-link ()
"Replace an org link by its description or if empty its address"
(interactive)
(if (org-in-regexp org-link-bracket-re 1)
(let ((remove (list (match-beginning 0) (match-end 0)))
(description
(if (match-end 3)
(match-string-no-properties 3)
(match-string-no-properties 1))))
(apply 'delete-region remove)
(insert description))))
;; craft of emacs
(add-load-path! "~/.doom.d/coe-xx")
(require 'coe-xx)
(require 'coe-demo)
(add-load-path! "~/.doom.d/mostalive")
(require 'my-org-roam)
(require 'journelly-convert-entry-to-org-roam)
(add-load-path! "~/.doom.d/qwan")
(require 'qwan-blog)
(require 'qwan-refactor)
(require 'qwan-markdown-dnd)
;; Elfeed RSS configuration
;; Feeds are defined in org-directory (same as org-roam-directory)
(setq rmh-elfeed-org-files (list "elfeed.org"))
(after! elfeed
(setq elfeed-search-filter "@1-week-ago +unread"))
;; Custom elfeed: link type to open entries in elfeed
(after! org
(org-link-set-parameters
"elfeed"
:follow (lambda (path)
(require 'elfeed)
(let* ((id (read path))
(entry (elfeed-db-get-entry id)))
(if entry
(progn
(elfeed-show-entry entry)
(switch-to-buffer "*elfeed-entry*"))
(message "Entry not found in elfeed database: %s" path))))
:store (lambda ()
(when (eq major-mode 'elfeed-show-mode)
(let ((entry elfeed-show-entry))
(org-link-store-props
:type "elfeed"
:link (format "elfeed:%s" (prin1-to-string (elfeed-entry-id entry)))
:description (elfeed-entry-title entry)))))))
(map! :leader
:desc "Elfeed RSS reader"
"o e" (cmd! (elfeed)))
;; Capture elfeed entry to org-roam with ROAM_REFS and elfeed link
(defun my/elfeed-entry-to-org-roam ()
"Capture current elfeed entry to org-roam with ROAM_REFS and elfeed link."
(interactive)
(let* ((entry (or elfeed-show-entry
(elfeed-search-selected :single)))
(title (elfeed-entry-title entry))
(url (elfeed-entry-link entry))
(date (format-time-string "%Y-%m-%d" (elfeed-entry-date entry)))
(elfeed-id (prin1-to-string (elfeed-entry-id entry))))
(org-roam-capture-
:keys "e"
:node (org-roam-node-create :title title)
:templates
`(("e" "elfeed" plain "%?"
:target (file+head
"%<%Y%m%d%H%M%S>-${slug}.org"
,(concat ":PROPERTIES:\n"
":ROAM_REFS: " url "\n"
":END:\n"
"#+title: ${title}\n"
"#+date: " date "\n\n"
"[[elfeed:" elfeed-id "][View in Elfeed]]\n\n"))
:unnarrowed t)))))
(map! :after elfeed
:map elfeed-show-mode-map
:n "C" #'my/elfeed-entry-to-org-roam
:map elfeed-search-mode-map
:n "C" #'my/elfeed-entry-to-org-roam)
;; LLM configuration with gptel
;; Machine-specific backends are configured in config-local.el
;; This file contains shared settings only
(use-package! gptel
:init
(setq gptel-default-mode 'org-mode) ;; LLM replies in org-mode format
(require 'gptel-integrations)) ;; <- for mcp
;; emacs mode for pi
(use-package! pi-coding-agent
:commands pi
:init (defalias 'pi 'pi-coding-agent)
:custom pi-coding-agent-executable '("devcontainer" "exec" "pi"))
;; Load machine-specific configuration (gptel backends, etc.)
(load! "config-mac.el" doom-user-dir t)
;; org-roam v1 port to v2, insert node without opening buffer
(map!
:leader
:desc
"Insert node immediate, don't open buffer on new node"
"n r I"
#'org-roam-node-insert-immediate)
(after! flycheck
(setq flycheck-haskell-ghc-executable "cabal")
(setq flycheck-haskell-runghc-executable "cabal"))
;; Use aspell for spell checking (hunspell has no dictionaries installed)
(setq ispell-program-name "aspell")