Files
emacs-config/lisp/init-capture.el
2026-04-06 14:04:32 +02:00

144 lines
4.7 KiB
EmacsLisp

;; (provide 'init-capture)
;; (defvar my/org-capture-title nil)
;; (defun my/org-slugify (s)
;; (replace-regexp-in-string
;; "-+"
;; "-"
;; (replace-regexp-in-string
;; "[^[:alnum:]]+"
;; "-"
;; (downcase (string-trim s)))))
;; ;; Aufgabe (Task) erstellen
;; (defun my/org-capture-new-task ()
;; (interactive)
;; (let ((my/org-capture-title (read-string "Titel: ")))
;; (org-capture nil "n")))
;; (setq org-capture-templates
;; '(("n" "Neue Task-Datei" plain
;; (file
;; (lambda ()
;; (expand-file-name
;; (concat (my/org-slugify my/org-capture-title) ".org")
;; "~/org/todos/")))
;; "#+title: %(or my/org-capture-title \"\")\n\n* TODO %(or my/org-capture-title \"\")\n\n** Kontext\n%?\n\n** Nächste Schritte\n- [ ] \n\n** Notizen\n"
;; :if-new (file+head "%F" "")
;; :unnarrowed t
;; :jump-to-captured t)))
;; (setq org-agenda-files '("~/org/todos/"))
;;; init-capture.el --- Capture-Funktionen für Org -*- lexical-binding: t; -*-
;;; init-capture.el --- Capture-Funktionen -*- lexical-binding: t; -*-
(require 'org)
(require 'org-capture)
(require 'subr-x)
(defvar my/org-capture-title nil)
(defun my/org-slugify (s)
"Wandle S in einen sauberen Dateinamen um."
(let ((s (downcase (string-trim s))))
(setq s (replace-regexp-in-string "ä" "ae" s))
(setq s (replace-regexp-in-string "ö" "oe" s))
(setq s (replace-regexp-in-string "ü" "ue" s))
(setq s (replace-regexp-in-string "ß" "ss" s))
(setq s (replace-regexp-in-string "[^[:alnum:]]+" "-" s))
(setq s (replace-regexp-in-string "-+" "-" s))
(setq s (replace-regexp-in-string "\\`-\\|-\\'" "" s))
s))
(defun my/org-ensure-directory (dir)
(make-directory dir t)
dir)
(defun my/org-task-file-from-title (title)
(expand-file-name
(concat (my/org-slugify title) ".org")
(my/org-ensure-directory "~/org/todos/")))
(defun my/org-doc-file-from-title (title)
(expand-file-name
(concat (my/org-slugify title) ".org")
(my/org-ensure-directory "~/org/docs/")))
(defun my/org-today-file ()
(let* ((date (format-time-string "%Y-%m-%d"))
(year (format-time-string "%Y"))
(dir (expand-file-name year "~/org/notes/")))
(my/org-ensure-directory dir)
(expand-file-name (concat date ".org") dir)))
(defun my/org-open-or-capture (title key file-fn)
(let ((file (funcall file-fn title)))
(if (file-exists-p file)
(find-file file)
(let ((my/org-capture-title title))
(org-capture nil key)))))
;; ===== Commands =====
(defun my/org-capture-new-task ()
(interactive)
(let ((title (read-string "Task-Titel: ")))
(my/org-open-or-capture title "n" #'my/org-task-file-from-title)))
(defun my/org-capture-new-doc ()
(interactive)
(let ((title (read-string "Doku-Titel: ")))
(my/org-open-or-capture title "d" #'my/org-doc-file-from-title)))
(defun my/org-capture-new-kpi ()
(interactive)
(let ((title (read-string "KPI-Titel: ")))
(my/org-open-or-capture title "k" #'my/org-doc-file-from-title)))
(defun my/org-capture-new-note ()
(interactive)
(find-file (my/org-today-file))
(when (= (point-max) 1)
(insert
(format "#+title: Notizen %s\n#+category: Notes\n\n"
(format-time-string "%Y-%m-%d"))))
(goto-char (point-max)))
;; ===== Capture Templates =====
(setq org-capture-templates
'(("n" "Neue Task-Datei" plain
(file
(lambda ()
(my/org-task-file-from-title my/org-capture-title)))
"#+title: %(or my/org-capture-title \"\")\n\n* TODO %(or my/org-capture-title \"\")\n\n** Kontext\n%?\n\n** Nächste Schritte\n- [ ] \n\n** Notizen\n"
:unnarrowed t
:jump-to-captured t)
("d" "Neue Doku-Datei" plain
(file
(lambda ()
(my/org-doc-file-from-title my/org-capture-title)))
"#+title: %(or my/org-capture-title \"\")\n#+category: Docs\n\n:PROPERTIES:\n:ART: Analyse\n:END:\n\n* Überblick\n%?\n\n* Details\n\n* Referenzen\n"
:unnarrowed t
:jump-to-captured t)
;; 👉 HIER ist dein KPI-Template
("k" "KPI-Steckbrief" plain
(file
(lambda ()
(my/org-doc-file-from-title my/org-capture-title)))
"#+title: %(or my/org-capture-title \"\")\n#+category: Docs\n\n:PROPERTIES:\n:ART: KPI-Steckbrief\n:VERANTWORTLICH: %^{Verantwortlich}\n:BEREICH: %^{Bereich}\n:END:\n\n* Definition\n%?\n\n* Berechnung\n#+begin_src sql\n\n#+end_src\n\n* Datenquelle\n\n* Interpretation\n\n* Hinweise\n"
:unnarrowed t
:jump-to-captured t)))
;; ===== Agenda =====
(setq org-agenda-files '("~/org/todos/" "~/org/docs/"))
(provide 'init-capture)
;;; init-capture.el ends here