Add tempel and templates file back

Add additional license-templates and gitignore-templates packages

Fix setting python apheleia formatters
This commit is contained in:
Evie Litherland-Smith 2024-05-26 11:04:42 +01:00
parent a90f5dc23e
commit d0e6cfa652
4 changed files with 243 additions and 1 deletions

1
.gitignore vendored
View file

@ -69,3 +69,4 @@ flycheck_*.el
# bookmarks # bookmarks
/bookmarks /bookmarks
/image-dired/ /image-dired/
/request/

47
init.el
View file

@ -284,6 +284,40 @@
:after (embark consult) :after (embark consult)
:hook (embark-collect-mode . consult-preview-at-point-mode)) :hook (embark-collect-mode . consult-preview-at-point-mode))
(use-package tempel
:custom
(tempel-trigger-prefix "<")
:bind (("M-+" . tempel-complete)
("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)
;; 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)
(global-tempel-abbrev-mode))
(use-package license-templates
:defer t)
(use-package gitignore-templates
:defer t)
;; Scratch buffer shortcut ;; Scratch buffer shortcut
(keymap-global-set "C-c w x" #'scratch-buffer) (keymap-global-set "C-c w x" #'scratch-buffer)
@ -294,6 +328,14 @@
(find-file (locate-user-emacs-file "init.el"))) (find-file (locate-user-emacs-file "init.el")))
(keymap-global-set "C-c w e" #'my/open-init-file) (keymap-global-set "C-c w e" #'my/open-init-file)
;; Tempel template file shortcut
(defun my/open-template-file ()
"Open `tempel' template file."
(interactive)
(require 'tempel)
(find-file tempel-path))
(keymap-global-set "C-c w t" #'my/open-template-file)
;; Org directory shortcut ;; Org directory shortcut
(defun my/open-org-directory () (defun my/open-org-directory ()
"Open base `org-mode' directory in Dired." "Open base `org-mode' directory in Dired."
@ -890,6 +932,7 @@
(setq-local completion-at-point-functions (setq-local completion-at-point-functions
(list (cape-capf-super (list (cape-capf-super
#'eglot-completion-at-point #'eglot-completion-at-point
#'tempel-expand
#'cape-file)))) #'cape-file))))
(add-hook 'eglot-managed-mode-hook #'my/eglot-capf))) (add-hook 'eglot-managed-mode-hook #'my/eglot-capf)))
@ -902,7 +945,9 @@
(add-to-list 'apheleia-formatters '(alejandra . ("alejandra"))) (add-to-list 'apheleia-formatters '(alejandra . ("alejandra")))
(add-to-list 'apheleia-formatters '(isort . ("isort" "--profile" "black" "-"))) (add-to-list 'apheleia-formatters '(isort . ("isort" "--profile" "black" "-")))
(add-to-list 'apheleia-mode-alist '(nix-mode . alejandra)) (add-to-list 'apheleia-mode-alist '(nix-mode . alejandra))
(add-to-list 'apheleia-mode-alist '(python-base-mode . (ruff isort)))) (add-to-list 'apheleia-mode-alist '(python-base-mode . (ruff isort)))
(add-to-list 'apheleia-mode-alist '(python-mode . (ruff isort)))
(add-to-list 'apheleia-mode-alist '(python-ts-mode . (ruff isort))))
(use-package flymake (use-package flymake
:bind (("C-c C-." . flymake-goto-next-error) :bind (("C-c C-." . flymake-goto-next-error)

View file

@ -12,6 +12,8 @@
all-the-icons nerd-icons nerd-icons-completion nerd-icons-corfu nerd-icons-dired nerd-icons-ibuffer doom-modeline diminish ligature page-break-lines helpful which-key ace-window link-hint diff-hl all-the-icons nerd-icons nerd-icons-completion nerd-icons-corfu nerd-icons-dired nerd-icons-ibuffer doom-modeline diminish ligature page-break-lines helpful which-key ace-window link-hint diff-hl
;; Completion ;; Completion
cape consult consult-eglot consult-flyspell corfu corfu-terminal embark embark-consult marginalia orderless vertico cape consult consult-eglot consult-flyspell corfu corfu-terminal embark embark-consult marginalia orderless vertico
;; Templates
tempel license-templates gitignore-templates
;; spell-checking ;; spell-checking
flyspell-correct flyspell-correct
;; password-store ;; password-store

194
templates Normal file
View file

@ -0,0 +1,194 @@
;; ~/.config/emacs/templates
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
(abstract "\\begin{abstract}\n" r> n> "\\end{abstract}")
(align "\\begin{align}\n" r> n> "\\end{align}")
(alignn "\\begin{align*}\n" r> n> "\\end{align*}")
(gather "\\begin{gather}\n" r> n> "\\end{gather}")
(gatherr "\\begin{gather*}\n" r> n> "\\end{gather*}")
(appendix "\\begin{appendix}\n" r> n> "\\end{appendix}")
(begin "\\begin{" (s env) "}" r> n> "\\end{" (s env) "}")
(center "\\begin{center}\n" r> n> "\\end{center}")
(displaymath "\\begin{displaymath}\n" r> n> "\\end{displaymath}")
(document "\\begin{document}\n" r> n> "\\end{document}")
(enumerate "\\begin{enumerate}\n\\item " r> n> "\\end{enumerate}")
(equation "\\begin{equation}" r> n> "\\end{equation}")
(flushleft "\\begin{flushleft}" r> n> "\\end{flushleft}")
(flushright "\\begin{flushright}" r> n> "\\end{flushright}")
(frac "\\frac{" p "}{" q "}")
(fussypar "\\begin{fussypar}" r> n> "\\end{fussypar}")
(itemize "\\begin{itemize}\n\\item " r> n> "\\end{itemize}")
(letter "\\begin{letter}\n" r> n> "\\end{letter}")
(math "\\begin{math}\n" r> n> "\\end{math}")
(minipage "\\begin{minipage}[t]{0.5\linewidth}\n" r> n> "\\end{minipage}")
(quotation "\\begin{quotation}\n" r> n> "\\end{quotation}")
(quote "\\begin{quote}\n" r> n> "\\end{quote}")
(sloppypar "\\begin{sloppypar}\n" r> n> "\\end{sloppypar}")
(theindex "\\begin{theindex}\n" r> n> "\\end{theindex}")
(trivlist "\\begin{trivlist}\n" r> n> "\\end{trivlist}")
(verbatim "\\begin{verbatim}\n" r> n> "\\end{verbatim}")
(verbatimm "\\begin{verbatim*}\n" r> n> "\\end{verbatim*}")
texinfo-mode
(defmac "@defmac " p n> r> "@end defmac")
(defun "@defun " p n> r> "@end defun")
(defvar "@defvar " p n> r> "@end defvar")
(example "@example " p n> r> "@end example")
(lisp "@lisp " p n> r> "@end lisp")
(bullet "@itemize @bullet{}" n> r> "@end itemize")
(code "@code{" p "}")
(var "@var{" p "}")
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)
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
(title "#+title: " p n "#+author: " p n "#+email: " p n "#+language: en")
(babel "#+property: header-args:emacs-lisp :tangle yes :mkdirp yes :results output silent")
(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 "}")
nix-mode
(buildphase > "buildPhase= ''" n (p "Build Instructions") n " '';")
(checkPhase > "checkPhase= ''" n (p "") n " '';")
(configurephase > "configurePhase= ''" n (p "") n " '';")
(fixupphase > "fixupPhase= ''" n (p "") n " '';")
(distphase > "distPhase= ''" n (p "") n " '';")
(patchphase > "patchPhase= ''" n (p "") n " '';")
(unpackphase > "unpackPhase= ''" n (p "") n " '';")
(installCheckPhasephase > "installCheckPhasePhase= ''" n (p "") n " '';")
(installphase > "installphase= ''" n p " mkdir -p $out/bin" n> "for f in $(find . -executable -type f);" n> "do" n> "cp $f $out/bin" n> "done}" n> " '';")
(gitpackage "{ lib" n ", stdenv" n ", fetchFromGitHub" n ", " (p "inputs") n ", " (p "inputs") n "}:" n n>
"stdenv.mkDerivation rec {" n> "pname = \"" (p "" pkgn nil) "\";" n> "version = \"" p "\";" n n>
"src = fetchFromGitHub {" n> "owner = \"" (p "" own) "\";" n> "repo = \"" (s pkgn) "\";" n>
"rev = \"" "v${version}" "\";" n> "sha256 = \"" "${lib.fakeSha256}" "\";" n> "};" n n>
"nativeBuildInputs = [ " (p "makeWrapper") " ];" n n> "BuildInputs = [ " (p) " ];" n n>
"meta = with lib; {" n>
"homepage = \"" "https://github.com/" (s own) "/" (s pkgn) "\";" n>
"description = \"" (p) "\";" n>
"license = licenses." (p (completing-read "License: " '("agpl3" "asl20" "bsd1" "bsd2" "bsd3" "free" "gpl2" "gpl2Only" "gpl2Plus" "gpl3" "gpl3Only" "gpl3Plus" "isc" "lgpl21Only" "lgpl21Plus" "lgpl2Only" "lgpl2Plus" "lgpl3" "lgpl3Only" "mit" "mpl20" "ofl" "unfree"))) ";" n>
"maintainers = with maintainers; [ " (s own) " ];" n>
"platforms = platforms."
(p (completing-read "Platform: " '("all" "allBut" "arm" "cygwin" "darwin" "freebsd" "gnu" "i686" "illumos" "linux" "mesaPlatforms" "mips" "netbsd" "none" "openbsd" "unix" "x86"))) ";" n> q "};" n> "}"
)
(pythonshell "with import " (p "<nixpkgs>") " {};"
n> "mkShellNoCC {"
n> "packages = ["
n> "(" (p "python3") ".withPackages"
n> "(ps: with ps; ["(p "python-lsp-server isort mypy") "]))"
n> q
n> "];"
n> "}")
(poetryshell "# See https://github.com/nix-community/poetry2nix/blob/master/docs/edgecases.md#cases"
n "# for edgecases like setuptools not found"
n "with import " (p "<nixpkgs>") " {};"
n "with (builtins.getFlake \"github:nix-community/poetry2nix\").lib.mkPoetry2Nix {inherit pkgs;};"
n> "(mkPoetryEnv rec {"
n> "projectDir = ./.;"
n> "preferWheels = true;"
n> "extras = [\"*\"];"
n> "editablePackageSources = {" (p "package") "=projectDir;};"
n> "extraPackages = ps: with ps; [" (p "python-lsp-server isort mypy") " " q "];"
n> "})"
n> ".env")
(poetryoverride "overrides = defaultPoetryOverrides.extend"
n> "(self: super: {"
n> (s package) " ="
n> "super." package ".overridePythonAttrs"
n> "(old: {"
n> "buildInputs = (old.buildInputs or []) ++ [super." (p "setuptools" ) "];"
n> "});"
n> "});")
python-base-mode
(main "def main(" (p "*args, **kwargs") ") -> " (p "None") ":"
n> q "return"
n
n "if __name__ == \"__main__\":"
n> "main()")
(args "def parse_arguments() -> argparse.Namespace:"
n> "parser = argparse.ArgumentParser(description=\"" p "\")"
n> p
n> "return parser.parse_args()")
(logg "logger = logging.getLogger(__name__)")
(nimp "raise NotImplementedError")
;; Local Variables:
;; mode: lisp-data
;; outline-regexp: "[a-z]"
;; End: