adding tempel

This commit is contained in:
Chris Cochrun 2022-03-08 10:57:16 -06:00
parent 11c902c909
commit 5493170045
3 changed files with 183 additions and 6 deletions

View file

@ -15,6 +15,7 @@
- [[#better-ui][Better UI]]
- [[#completion][Completion]]
- [[#yasnippet][YASnippet]]
- [[#tempel][Tempel]]
- [[#projectile][Projectile]]
- [[#httpd][HTTPD]]
- [[#navigation][Navigation]]
@ -755,6 +756,15 @@ Marginalia makes for some great decoration to our minibuffer completion items. W
#+end_src
Along with Marginalia, let's add in icons.
#+begin_src emacs-lisp
(use-package all-the-icons-completion
:after vertico
:config
(all-the-icons-completion-mode))
#+end_src
*** Embark
Embark or do something.
#+BEGIN_SRC emacs-lisp
@ -954,6 +964,38 @@ YASnippet is a templating system. It's powerful.
(yas-global-mode 1))
#+end_src
** Tempel
Tempel is another templating system. Also perhaps even more powerful with it's elisp way of creating snippets, but elisp is tougher to work around. But, I'll give it a try.
#+BEGIN_SRC emacs-lisp
(use-package tempel
:bind (("M-+" . tempel-complete) ;; Alternative tempel-expand
("M-*" . tempel-insert)
("C-M-<return>" . tempel-done))
:init
;; Setup completion at point
(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 Tempel will probably 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-complete
completion-at-point-functions)))
(add-hook 'prog-mode-hook 'tempel-setup-capf)
(add-hook 'text-mode-hook 'tempel-setup-capf)
;; Optionally make the Tempel templates available to Abbrev,
;; either locally or globally. `expand-abbrev' is bound to C-x '.
;; (add-hook 'prog-mode-hook #'tempel-abbrev-mode)
;; (tempel-global-abbrev-mode)
)
#+END_SRC
** Projectile
I'm going to use projectile to keep my projects inline.
#+begin_src emacs-lisp
@ -2294,13 +2336,14 @@ Let's use pdf-tools for a lot better interaction with pdfs.
#+begin_src emacs-lisp
(use-package pdf-tools
:straight (:host github
:repo "flatwhatson/pdf-tools"
:branch "fix-macros")
:repo "flatwhatson/pdf-tools"
:branch "fix-macros")
:defer 1
:config
(pdf-tools-install)
(custom-set-variables '(pdf-misc-print-program "/usr/bin/lpr")
'(pdf-misc-print-program-args (quote ("-o media=Letter" "-o fitplot")))))
'(pdf-misc-print-program-args (quote ("-o media=Letter" "-o fitplot"))))
(add-hook 'pdf-view-mode 'pdf-view-fit-page-to-window))
#+end_src
** EPUB

57
init.el
View file

@ -408,6 +408,11 @@
:config
(setq marginalia--cache-size 60000))
(use-package all-the-icons-completion
:after vertico
:config
(all-the-icons-completion-mode))
(use-package embark
:ensure t
:general
@ -569,6 +574,34 @@ targets."
(setq yas-snippet-dirs (list (expand-file-name "yasnippets/" user-emacs-directory)))
(yas-global-mode 1))
(use-package tempel
:bind (("M-+" . tempel-complete) ;; Alternative tempel-expand
("M-*" . tempel-insert)
("C-M-<return>" . tempel-done))
:init
;; Setup completion at point
(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 Tempel will probably 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-complete
completion-at-point-functions)))
(add-hook 'prog-mode-hook 'tempel-setup-capf)
(add-hook 'text-mode-hook 'tempel-setup-capf)
;; Optionally make the Tempel templates available to Abbrev,
;; either locally or globally. `expand-abbrev' is bound to C-x '.
;; (add-hook 'prog-mode-hook #'tempel-abbrev-mode)
;; (tempel-global-abbrev-mode)
)
(use-package projectile
:defer t
:general
@ -1681,13 +1714,14 @@ If on a:
(use-package pdf-tools
:straight (:host github
:repo "flatwhatson/pdf-tools"
:branch "fix-macros")
:repo "flatwhatson/pdf-tools"
:branch "fix-macros")
:defer 1
:config
(pdf-tools-install)
(custom-set-variables '(pdf-misc-print-program "/usr/bin/lpr")
'(pdf-misc-print-program-args (quote ("-o media=Letter" "-o fitplot")))))
'(pdf-misc-print-program-args (quote ("-o media=Letter" "-o fitplot"))))
(add-hook 'pdf-view-mode 'pdf-view-fit-page-to-window))
(use-package nov
:mode ("\\.epub\\'" . nov-mode)
@ -1950,3 +1984,20 @@ interfere with the default `bongo-playlist-buffer'."
gcmh-verbose nil))
(setq warning-suppress-types '((comp)))
(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.
'(pdf-misc-print-program "/usr/bin/lpr" t)
'(pdf-misc-print-program-args '("-o media=Letter" "-o fitplot") t)
'(safe-local-variable-values
'((projectile-project-compilation-cmd . "cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -B build/ . && make --dir build/")
(projectile-project-compilation-cmd . "cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -B buld/ . && make --dir build/")
(projectile-project-run-cmd . "./build/bin/presenter"))))
(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.
)

83
templates Normal file
View file

@ -0,0 +1,83 @@
;; -*- mode: lisp -*
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 ")
latex-mode
(begin "\\begin{" (s env) "}" > n> r> "\\end{" (s env) "}")
(frac "\\frac{" p "}{" p "}")
(enumerate "\\begin{enumerate}\n\\item " r> n> "\\end{enumerate}")
(itemize "\\begin{itemize}\n\\item " r> n> "\\end{itemize}")
lisp-mode emacs-lisp-mode ;; Specify multiple modes
(lambda "(lambda (" p ")" n> r> ")")
emacs-lisp-mode
(lambda "(lambda (" p ")" n> r> ")")
(var "(defvar " 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> ")")
(fun "(defun " p " (" p ")\n \"" p "\"" n> r> ")")
(let "(let (" p ")" n> r> ")")
(star "(let* (" p ")" n> r> ")")
(rec "(letrec (" p ")" n> r> ")")
(command "(defun " p " (" p ")\n \"" p "\"" n> "(interactive)" n> r> ")")
eshell-mode
(for "for " (p "i") " in " p " { " p " }")
(while "while { " p " } { " p " }")
(until "until { " p " } { " p " }")
(if "if { " p " } { " p " }")
(if-else "if { " p " } { " p " } { " p " }")
(unless "unless { " p " } { " p " }")
(unless-else "unless { " p " } { " p " } { " p " }")
text-mode
(cut "--8<---------------cut here---------------start------------->8---" n r n
"--8<---------------cut here---------------end--------------->8---" n)
(asciibox "+-" (make-string (length str) ?-) "-+" n
"| " (s str) " |" n
"+-" (make-string (length str) ?-) "-+" 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)))
rst-mode
(title (make-string (length title) ?=) n (p "Title: " title) n (make-string (length title) ?=) n)
java-mode
(class "public class " (p (file-name-base (or (buffer-file-name) (buffer-name)))) " {" n> r> n "}")
c-mode :condition (re-search-backward "^\\w*$" (line-beginning-position) 'noerror)
(inc "#include <" (p (concat (file-name-base (or (buffer-file-name) (buffer-name))) ".h")) ">")
(incc "#include \"" (p (concat (file-name-base (or (buffer-file-name) (buffer-name))) ".h")) "\"")
org-mode
(title "#+title: " p n "#+author: Chris Cochrun" n n)
(quote "#+begin_quote" n> r> n> "#+end_quote")
(example "#+begin_example" n> r> n> "#+end_example")
(center "#+begin_center" n> r> n> "#+end_center")
(comment "#+begin_comment" n> r> n> "#+end_comment")
(verse "#+begin_verse" n> r> n> "#+end_verse")
(src "#+begin_src " p n> r> n> "#+end_src")
(elisp "#+begin_src emacs-lisp" n> r> n "#+end_src"
:post (progn (tempel-done) (org-edit-src-code)))