commit eb39aa9b3920c7fe5c3cee2631c3f06e41ea2ec7
parent 5a30b7cef81179d101b6895808da1f3b82b5fc33
Author: Vincent Demeester <vincent@sbr.pm>
Date: Thu, 23 Nov 2023 10:05:07 +0100
tools/emacs: add tempel package (for templates)
- Configure tempel
- Add tempel-collection
- Add some custom tempel "expansion", notably for org-mode
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Diffstat:
5 files changed, 149 insertions(+), 3 deletions(-)
diff --git a/tools/emacs/config/config-completion.el b/tools/emacs/config/config-completion.el
@@ -189,5 +189,28 @@ Useful for prompts such as `eval-expression' and `shell-command'."
(setq completion-category-overrides
'((file (styles . (basic partial-completion orderless))))))
+(use-package tempel
+ :bind (("M-+" . tempel-complete) ;; Alternative tempel-expand
+ ("M-*" . tempel-insert))
+ :init
+ (defun tempel-setup-capf ()
+ ;; Add the Tempel Capf to `completion-at-point-functions'.
+ ;; `tempel-expand' only triggers on exact matches. Alternatively use
+ ;; `tempel-complete' if you want to see all matches, but then you
+ ;; should also configure `tempel-trigger-prefix', such that Tempel
+ ;; does not trigger too often when you don't expect it. NOTE: We add
+ ;; `tempel-expand' *before* the main programming mode Capf, such
+ ;; that it will be tried first.
+ (setq-local completion-at-point-functions
+ (cons #'tempel-expand
+ completion-at-point-functions)))
+
+ (add-hook 'conf-mode-hook 'tempel-setup-capf)
+ (add-hook 'prog-mode-hook 'tempel-setup-capf)
+ (add-hook 'text-mode-hook 'tempel-setup-capf))
+
+(use-package tempel-collection
+ :after tempel)
+
(provide 'config-completion)
;;; config-completion.el ends here
diff --git a/tools/emacs/config/config-org.el b/tools/emacs/config/config-org.el
@@ -221,7 +221,23 @@
:no-save t
:immediate-finish nil
:kill-buffer t
- :jump-to-captured t))))
+ :jump-to-captured t)))
+ (defun vde/org-category-from-buffer ()
+ "Get the org category (#+category:) value from the buffer"
+ (cond
+ ((string-match (format "^%s.*$" org-journal-dir) (buffer-file-name))
+ "journal")
+ (t
+ (denote-sluggify (denote--retrieve-title-or-filename (buffer-file-name) 'org))))))
+
+(use-package consult-notes
+ :commands (consult-notes
+ consult-notes-search-in-all-notes
+ consult-notes-denote-mode)
+ :bind (("C-c n F" . consult-notes))
+ :config
+ (when (locate-library "denote")
+ (consult-notes-denote-mode)))
;; (use-package org
;; ;; :ensure org-plus-contrib ;; load from the package instead of internal
diff --git a/tools/emacs/templates b/tools/emacs/templates
@@ -0,0 +1,106 @@
+;; ~/.config/emacs/templates
+
+fundamental-mode ;; Available everywhere
+
+(today (format-time-string "%Y-%m-%d"))
+
+prog-mode
+
+(fixme (if (derived-mode-p 'emacs-lisp-mode) ";; " comment-start) "FIXME ")
+(todo (if (derived-mode-p 'emacs-lisp-mode) ";; " comment-start) "TODO ")
+(bug (if (derived-mode-p 'emacs-lisp-mode) ";; " comment-start) "BUG ")
+(hack (if (derived-mode-p 'emacs-lisp-mode) ";; " comment-start) "HACK ")
+
+lisp-mode emacs-lisp-mode ;; Specify multiple modes
+
+(lambda "(lambda (" p ")" n> r> ")")
+
+emacs-lisp-mode
+
+(autoload ";;;###autoload")
+(pt "(point)")
+(var "(defvar " p "\n \"" p "\")")
+(local "(defvar-local " p "\n \"" p "\")")
+(const "(defconst " p "\n \"" p "\")")
+(custom "(defcustom " p "\n \"" p "\"" n> ":type '" p ")")
+(face "(defface " p " '((t :inherit " p "))\n \"" p "\")")
+(group "(defgroup " p " nil\n \"" p "\"" n> ":group '" p n> ":prefix \"" p "-\")")
+(macro "(defmacro " p " (" p ")\n \"" p "\"" n> r> ")")
+(alias "(defalias '" p " '" p ")")
+(fun "(defun " p " (" p ")\n \"" p "\"" n> r> ")")
+(iflet "(if-let (" p ")" n> r> ")")
+(whenlet "(when-let (" p ")" n> r> ")")
+(whilelet "(while-let (" p ")" n> r> ")")
+(andlet "(and-let* (" p ")" n> r> ")")
+(cond "(cond" n "(" q "))" >)
+(pcase "(pcase " (p "scrutinee") n "(" q "))" >)
+(let "(let (" p ")" n> r> ")")
+(lett "(let* (" p ")" n> r> ")")
+(pcaselet "(pcase-let (" p ")" n> r> ")")
+(pcaselett "(pcase-let* (" p ")" n> r> ")")
+(rec "(letrec (" p ")" n> r> ")")
+(dotimes "(dotimes (" p ")" n> r> ")")
+(dolist "(dolist (" p ")" n> r> ")")
+(loop "(cl-loop for " p " in " p " do" n> r> ")")
+(command "(defun " p " (" p ")\n \"" p "\"" n> "(interactive" p ")" n> r> ")")
+(advice "(defun " (p "adv" name) " (&rest app)" n> p n> "(apply app))" n>
+ "(advice-add #'" (p "fun") " " (p ":around") " #'" (s name) ")")
+(header ";;; " (file-name-nondirectory (or (buffer-file-name) (buffer-name)))
+ " -- " p " -*- lexical-binding: t -*-" n
+ ";;; Commentary:" n ";;; Code:" n n)
+(provide "(provide '" (file-name-base (or (buffer-file-name) (buffer-name))) ")" n
+ ";;; " (file-name-nondirectory (or (buffer-file-name) (buffer-name)))
+ " ends here" n)
+
+eshell-mode
+
+(for "for " (p "i") " in " p " { " q " }")
+(while "while { " p " } { " q " }")
+(until "until { " p " } { " q " }")
+(if "if { " p " } { " q " }")
+(ife "if { " p " } { " p " } { " q " }")
+(unl "unless { " p " } { " q " }")
+(unle "unless { " p " } { " p " } { " q " }")
+
+text-mode
+
+(box "┌─" (make-string (length str) ?─) "─┐" n
+ "│ " (s str) " │" n
+ "└─" (make-string (length str) ?─) "─┘" n)
+(abox "+-" (make-string (length str) ?-) "-+" n
+ "| " (s str) " |" n
+ "+-" (make-string (length str) ?-) "-+" n)
+(cut "--8<---------------cut here---------------start------------->8---" n r n
+ "--8<---------------cut here---------------end--------------->8---" n)
+(rot13 (p "plain text" text) n "----" n (rot13 text))
+(calc (p "taylor(sin(x),x=0,3)" formula) n "----" n (format "%s" (calc-eval formula)))
+
+org-mode
+
+(caption "#+caption: ")
+(drawer ":" p ":" n r ":end:")
+(begin "#+begin_" (s name) n> r> n "#+end_" name)
+(quote "#+begin_quote" n> r> n "#+end_quote")
+(sidenote "#+begin_sidenote" n> r> n "#+end_sidenote")
+(marginnote "#+begin_marginnote" n> r> n "#+end_marginnote")
+(example "#+begin_example" n> r> n "#+end_example")
+(center "#+begin_center" n> r> n "#+end_center")
+(ascii "#+begin_export ascii" n> r> n "#+end_export")
+(html "#+begin_export html" n> r> n "#+end_export")
+(latex "#+begin_export latex" n> r> n "#+end_export")
+(comment "#+begin_comment" n> r> n "#+end_comment")
+(verse "#+begin_verse" n> r> n "#+end_verse")
+(src "#+begin_src " q n r n "#+end_src")
+(gnuplot "#+begin_src gnuplot :var data=" (p "table") " :file " (p "plot.png") n r n "#+end_src" :post (org-edit-src-code))
+(elisp "#+begin_src emacs-lisp" n r n "#+end_src" :post (org-edit-src-code))
+(inlsrc "src_" p "{" q "}")
+(title "#+title: " p n "#+author: Daniel Mendler" n "#+language: en")
+(category "#+category: " (vde/org-category-from-buffer))
+(call & "#+call: " (p "name" name) "(" (s var) "=\"" (s value) "\")")
+(/ "[/]" (org-update-statistics-cookies nil))
+(tsm p " :: " (with-temp-buffer (org-insert-time-stamp (current-time) t t)))
+
+;; Local Variables:
+;; mode: lisp-data
+;; outline-regexp: "[a-z]"
+;; End:
diff --git a/users/vincent/desktop/sway.nix b/users/vincent/desktop/sway.nix
@@ -238,8 +238,8 @@ in
bindsym ${mod}+F10 exec ${pkgs.my.scripts}/bin/shot %d
bindsym ${mod}+Shift+F10 exec ${pkgs.my.scripts}/bin/shotf %d
- bindsym F9 exec ${pkgs.mako}/bin/makoctl mode -s do-not-disturb
- bindsym Shift+F9 exec ${pkgs.mako}/bin/makoctl mode -s default
+ bindsym ${mod}+F9 exec ${pkgs.mako}/bin/makoctl mode -s do-not-disturb
+ bindsym ${mod}+Shift+F9 exec ${pkgs.mako}/bin/makoctl mode -s default
'';
};
programs = {
diff --git a/users/vincent/dev/emacs.nix b/users/vincent/dev/emacs.nix
@@ -130,6 +130,7 @@ let
smartparens
symbol-overlay
tempel
+ tempel-collection
trashed
treesit-auto
try