From 494650ecf5903c083c666c085f0dad447911e501 Mon Sep 17 00:00:00 2001 From: "Ian S. Pringle" Date: Sat, 16 Sep 2023 11:57:00 -0500 Subject: [PATCH] feat: added newline command to snippets that require newlines This commit adds the newline (`&`) when it makes sense for a snippet to be written on a newline. For example org src-blocks and headers need to be on their own lines, so if a snippet is called in the middle of a line this will ensure that those snippets are correctly written on the next line. --- templates/emacs-lisp.eld | 2 +- templates/markdown.eld | 16 ++++++------ templates/org.eld | 54 +++++++++++++++++++-------------------- templates/python-base.eld | 2 +- templates/rust.eld | 2 +- templates/sh-base.eld | 2 +- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/templates/emacs-lisp.eld b/templates/emacs-lisp.eld index 5464977..0d2bddc 100644 --- a/templates/emacs-lisp.eld +++ b/templates/emacs-lisp.eld @@ -1,6 +1,6 @@ emacs-lisp-mode -(autoload ";;;###autoload") +(autoload & ";;;###autoload") (pt "(point)") (var "(defvar " p "\n \"" p "\")") (local "(defvar-local " p "\n \"" p "\")") diff --git a/templates/markdown.eld b/templates/markdown.eld index ba320b9..7f4252c 100644 --- a/templates/markdown.eld +++ b/templates/markdown.eld @@ -1,18 +1,18 @@ markdown-mode -(gitcollapse "## " (p "Heading") n n "
" n n +(gitcollapse & "## " (p "Heading") n n "
" n n "" (p "Sub Heading") "" n n (r "Insert Link or comments") n n "
") (bolditalics "***" p "***") (srcblock (call-interactively #'markdown-insert-gfm-code-block)) (src "'" p "'") -(unorderlist "- " (p "First") n> "- " (p "Second") n> "- " (p "Third")) -(orderlist "1. " (p "First") n> "2. " (p "Second") n> "3. " (p "Third")) +(unorderlist & "- " (p "First") n> "- " (p "Second") n> "- " (p "Third")) +(orderlist & "1. " (p "First") n> "2. " (p "Second") n> "3. " (p "Third")) (insertimage (call-interactively #'markdown-insert-image)) (insertlink (call-interactively #'markdown-insert-link)) -(hugotitle "+++" n "title = " (p "title") n "date = " (format-time-string "%Y-%m-%d") n "tags = [ " (p "tag1, tag2 ") "]" n "draft = false" n "+++") -(h1 "# " p " #") -(h2 "## " p " ##") -(h3 "### " p " ###") -(h4 "#### " p " ####") +(hugotitle & "+++" n "title = " (p "title") n "date = " (format-time-string "%Y-%m-%d") n "tags = [ " (p "tag1, tag2 ") "]" n "draft = false" n "+++") +(h1 & "# " p " #") +(h2 & "## " p " ##") +(h3 & "### " p " ###") +(h4 & "#### " p " ####") (inserttable (call-interactively #'markdown-insert-table)) diff --git a/templates/org.eld b/templates/org.eld index 6b437c4..d34681e 100644 --- a/templates/org.eld +++ b/templates/org.eld @@ -1,33 +1,33 @@ org-mode -(ttl "#+title: " p n "#+author: " p n "#+language: " p n n) -(qt "#+begin_quote" n> r> n> "#+end_quote") -(exmpl "#+begin_example" n> r> n> "#+end_example") -(cntr "#+begin_center" n> r> n> "#+end_center") -(comm "#+begin_comment" n> r> n> "#+end_comment") -(vrs "#+begin_verse" n> r> n> "#+end_verse") -(src "#+begin_src " p n> r> n> "#+end_src" :post (org-edit-src-code)) -(rst "#+begin_src restclient" p n> r> n> "#+end_src" :post (org-edit-src-code)) -(elsp "#+begin_src emacs-lisp" n> r> n "#+end_src" :post (org-edit-src-code)) +(ttl & "#+title: " p n "#+author: " p n "#+language: " p n n) +(qt & "#+begin_quote" n> r> n> "#+end_quote") +(exmpl & "#+begin_example" n> r> n> "#+end_example") +(cntr & "#+begin_center" n> r> n> "#+end_center") +(comm & "#+begin_comment" n> r> n> "#+end_comment") +(vrs & "#+begin_verse" n> r> n> "#+end_verse") +(src & "#+begin_src " p n> r> n> "#+end_src" :post (org-edit-src-code)) +(rst & "#+begin_src restclient" p n> r> n> "#+end_src" :post (org-edit-src-code)) +(elsp & "#+begin_src emacs-lisp" n> r> n "#+end_src" :post (org-edit-src-code)) (readonly ":tangle yes :tangle-mode (identity #o444) :mkdirp yes" n) -(oxhugo ":PROPERTIES:" n ":EXPORT_FILE_NAME: " (p "Simple Filename") n ":EXPORT_DATE: " (format-time-string "%Y-%m-%d") n ":EXPORT_HUGO_DRAFT: false" n ":END:") +(oxhugo & ":PROPERTIES:" n ":EXPORT_FILE_NAME: " (p "Simple Filename") n ":EXPORT_DATE: " (format-time-string "%Y-%m-%d") n ":EXPORT_HUGO_DRAFT: false" n ":END:") (readmecollapse "*** " (p "Heading") n "#+HTML:
" (p "sub-heading") " " n (r> "link or any comments") n n "#+HTML:
" n) ;; taken from https://github.com/minad/tempel/blob/5b09f612cfd805dba5e90bf06580583cab045499/README.org#template-file-format -(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") -(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: " p n "#+language: " p n n) +(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") +(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: " p n "#+language: " p n n) diff --git a/templates/python-base.eld b/templates/python-base.eld index 657c653..94bd61f 100644 --- a/templates/python-base.eld +++ b/templates/python-base.eld @@ -1,6 +1,6 @@ python-base-mode (for "for " p " in " p ":" n> q) -(tr "import " p "; " p ".set_trace()" q) +(tr & "import " p "; " p ".set_trace()" q) (ig "# type: ignore" q) diff --git a/templates/rust.eld b/templates/rust.eld index 3520ed2..9e2d846 100644 --- a/templates/rust.eld +++ b/templates/rust.eld @@ -12,7 +12,7 @@ rust-mode rust-ts-mode (crt "extern crate " q ";") -(drv "#[derive(" p ")]" q) +(drv & "#[derive(" p ")]" q) (d "dbg!(" p ")" q) diff --git a/templates/sh-base.eld b/templates/sh-base.eld index e127c2f..0edd0ab 100644 --- a/templates/sh-base.eld +++ b/templates/sh-base.eld @@ -1,6 +1,6 @@ sh-base-mode -(! "#!/usr/bin/env bash" n q) +(! & "#!/usr/bin/env bash" n q) (if "if [ " p " ]" n " then " p n "fi" q)