dotfiles/emacs-lisp/tempel_templates.org
magic_rb 5b4f5567f2
emacs: fix include-guard template
Signed-off-by: magic_rb <magic_rb@redalder.org>
2024-11-09 22:15:26 +01:00

8.5 KiB

Tempel - Templates

#

Fundamental Mode

  fundamental-mode ;; Available everywhere

  (today (format-time-string "%Y-%m-%d"))
  (heredoc "<<EOF\n" p "EOF\n")

Prog Mode

  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

  latex-mode

  (begin "\\begin{" (s env) "}" > n> r> n>
         "\\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}")

Emacs List Mode

  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> ")")

Nix Mode

  nix-mode

  (resource "resource.\"" p "\".\"" p "\" = {" n> "manifest = {" n> (tempel-retpoint-here) n "};" > n "};" > q)

Text Mode

  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

  rst-mode

  (title (make-string (length title) ?=) n (p "Title: " title) n (make-string (length title) ?=) n)

Java Mode

  java-ts-mode

  (class "public class " (p (file-name-base (or (buffer-file-name) (buffer-name)))) " {" n> r> n "}")

C Mode

  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")) "\"")
  (include-guard
   "#ifndef " (p
  	     (let*
  		 ((project-name (projectile-project-name))
  		  (project-root (projectile-project-root))
  		  (file-name buffer-file-name))
  	       (if (and project-name project-root file-name)
  		   (upcase
  		    (concat
  		     project-name
  		     "_"
  		     (subst-char-in-string ?/ ?_
  					   (file-relative-name
  					    (file-name-sans-extension file-name)
  					    project-root))))
  		   "UNKNOWN"))
  	     name)
   "_H"
   n "#define " name "_H"
   n (tempel-retpoint-here) n "#endif // " name "_H" q
   :post (tempel-retpoint-goto))

Org Mode

  org-mode

  (title "#+title: " p n "#+author: Richard Brežák" n "#+language: en" n n)
  (quote "#+begin_quote" n> r> n> "#+end_quote" n)
  (example "#+begin_example" n> r> n> "#+end_example" n)
  (center "#+begin_center" n> r> n> "#+end_center" n)
  (comment "#+begin_comment" n> r> n> "#+end_comment" n)
  (verse "#+begin_verse" n> r> n> "#+end_verse" n)
  (src "#+begin_src " p n> r> n> "#+end_src" n
       :post (org-edit-src-code))
  (isrc "src_" p "[]{" q "}")
  (export "#+begin_export " p n
          n
          "#+end_export" n
          :post (progn (previous-line) (org-edit-special)))
  (elisp "#+begin_src emacs-lisp" n> r> n "#+end_src" n
         :post (progn (org-edit-src-code)))
  (abs "\\begin{abstract}" n> r> n> "\\end{abstract}" n)
  (align "\\begin{align}" n
         "  " n
         "\\end{align}\n" n
         (tempel-retpoint-here)
         :post (tempel-post-edit-latex t))
  (align* "\\begin{align*}" n
          "  " n
          "\\end{align*}\n" n
          (tempel-retpoint-here)
          :post (tempel-post-edit-latex t))
  (arr "\\begin{array}" n
       n
       "\\end{array}" n
       (tempel-retpoint-here)
       :post (tempel-post-edit-latex t))
  (begin "\\begin{" (p "environment" env) "}"
         n n
         "\\end{" env "}" n
         (tempel-retpoint-here) q
         :post (tempel-post-edit-latex t))
  (bib "\\bibliographystyle{plain}" n "\\bibliography{" s "}" n)
  (dm "\\[" n
      "  ." n
      "\\]" q
      (tempel-retpoint-here)
      :post (tempel-post-edit-latex t))
  (mm "$" p "$ " q
      :post (org-latex-preview))
  (mmc "$\\textcolor{" p "}{" p "}$ " q
       :post (org-latex-preview))
  (item "\\begin{itemize}" n p n "\\end{itemize}" n)
  (it "\\item " r)
  (itd "\\item[" (p "label") "] " r)
  (fig "\\begin{figure}[htbp]" n "\\centering" n p n "\\caption{" p "}" n "\\label{" p "}" n "\\end{figure}" n)
  (minipage "\\begin{minipage}[" (p "htbp") "]{" (p "1.0") (p "\\linewidth") "}" n
            "  " n
            "\\end{minipage}\n" n
            (tempel-retpoint-here)
            :post (tempel-post-edit-latex t))
  (frame "\\begin{frame}{" (p "Frame Title") "}"h n
         "  " n
         "\\end{frame}" n
         (tempel-retpoint-here)
         :post (tempel-post-edit-latex t))
  (package "#+LATEX_HEADER: \\usepackage[" p "]{" p "}" n)
  (ref "\\ref{" p "}")
  (table "\\begin{tabular}{" p "}" n
         "  " n
         "\\end{tabular}" n
         (tempel-retpoint-here)
         :post (tempel-post-edit-latex t))
  (algorithm "\\begin{algorithm}" n
             "  \\DontPrintSemicolon\\;" n
             "  " n
             "\\end{algorithm}" n
             (tempel-retpoint-here)
             :post (tempel-post-edit-latex t))
  (function "\\begin{dummyenv}" n
            "  \\DontPrintSemicolon\\;" n
            "  \\SetKwFunction{" (p "" function) "}{" function "}" n
            "  \\begin{algorithm}" n
            "    \\Fn{\\" function "{" p "}}{"n
            "      " n
            "    }" n
            "  \\end{algorithm}" n
            "\\end{dummyenv}" q n
            (tempel-retpoint-here)
            :post (tempel-post-edit-latex t -3))

  org-mode :condition (org-inside-LaTeX-fragment-p)

  (frac "\\frac{" p "}{" p "}")
  (larrow "\\leftarrow")
  (rarrow "\\rightarrow")
  (bigo "\\mathcal{O}(" p ")")

Haskell Mode

  haskell-mode

  (module
   "module " p n
   "  ( " p n
   "  ) where" q
   )
  (case
      "case " (p "x") " of " n>
      (p "Data") " -> " (p "undefined") n>
      (p "Data") " -> " (p "undefined"))
  ({-} "{- " p " -}")
  (=> (p "Class") " " (p "m") " => ")
  (idata "data " (p "Type" ndata) " = " (s ndata) " " (p "Int") n>
         "deriving (" (p "Show, Eq") ")")
  (newtype "newtype " (p "Type" ndata) " = " (s ndata) " " (p "Int") n>
           "deriving (" (p "Show, Eq") ")")
  (data "data " (p "Type" ndata) " = " (s ndata)  n>
        "{ " (p "field") " :: " (p "Type") n>
        ", " (p "field") " :: " (p "Type") (tempel-retpoint-here) n>
        "}" n>
        "deriving (" (p "Show, Eq") ")")
  (fn (p "f" fname) " :: " (p "a") " -> " (p "b") n
      (s fname) " " (p "x") " = " (p "undefined"))
  (fnc (p "f" fname) " :: " (p "a") " -> " (p "b") n
       (s fname) " " (p "pattern") " = " (p "undefined") n
       (s fname) " " (p "pattern") " = " (p "undefined"))
  ; guarded fn
  (<- (p "x") " <- " (p "undefined"))
  (aeson "instance A.ToJSON " (p "" type) " where" n
         "instance A.FromJSON " type " where" q)
  (testcase "test" (concat (capitalize (substring test-name nil 1)) (substring test-name 1)) " :: Test" n
  	  "test" (concat (capitalize (substring test-name nil 1)) (substring test-name 1)) "= TestLabel \"" (p "name" test-name) "\" $ TestList" n
  	  "  [" n
  	  "  ]" n q)

Java Mode

  java-ts-mode

  (attrinit "this." (s member) " = " member ";" n> q)

Markdown Mode

  markdown-mode
  
  (src "```" p n> q "```" n
       :post (markdown-edit-code-block))