@@ -320,15 +320,23 @@ s-expression, etc.
@cindex reducing boilerplate
We also provide templates for common git commit messages and package
definitions in the @file{etc/snippets} directory. These templates can
-be used with @url{https://joaotavora.github.io/yasnippet/, YASnippet} to
-expand short trigger strings to interactive text snippets. You may want
-to add the snippets directory to the @var{yas-snippet-dirs} variable in
+be used to expand short trigger strings to interactive text snippets. If
+you use @url{https://joaotavora.github.io/yasnippet/, YASnippet}, you
+may want to add the @file{etc/snippets/yas} snippets directory to the
+@var{yas-snippet-dirs} variable. If you use
+@url{https://github.com/minad/tempel/, Tempel}, you may want to add the
+@file{etc/snippets/tempel/*} path to the @var{tempel-path} variable in
Emacs.
@lisp
;; @r{Assuming the Guix checkout is in ~/src/guix.}
+;; @r{Yasnippet}
(with-eval-after-load 'yasnippet
- (add-to-list 'yas-snippet-dirs "~/src/guix/etc/snippets"))
+ (add-to-list 'yas-snippet-dirs "~/src/guix/etc/snippets/yas"))
+;;@r{Tempel}
+(with-eval-after-load 'tempel
+ (add-to-list 'tempel-path
+ "~/src/guix/etc/snippets/tempel/*"))
@end lisp
The commit message snippets depend on @url{https://magit.vc/, Magit} to
new file mode 100644
@@ -0,0 +1,114 @@
+-*- mode: lisp-data -*-
+
+scheme-mode
+
+(package...
+ "(define-public " (s name)
+ n> "(package"
+ n> "(name \"" (s name) "\")"
+ n> "(version \"" p "\")"
+ n> "(source origin...)"
+ n> "(build-system \""
+ (p (completing-read "build-system:"
+ '("android-ndk"
+ "ant"
+ "asdf"
+ "cargo"
+ "chicken"
+ "clojure"
+ "cmake"
+ "copy"
+ "dub"
+ "dune"
+ "emacs"
+ "font"
+ "glib-or-gtk"
+ "gnu"
+ "go"
+ "guile"
+ "haskell"
+ "julia"
+ "linux-module"
+ "maven"
+ "meson"
+ "minetest"
+ "minify"
+ "node"
+ "ocaml"
+ "perl"
+ "python"
+ "qt"
+ "r"
+ "rakudo"
+ "rebar"
+ "renpy"
+ "ruby"
+ "scons"
+ "texlive"
+ "trivial"
+ "waf")
+ nil t) "-build-system")
+ "\")"
+ n> "(home-page \"" p "\")"
+ n> "(synopsis \"" p "\")"
+ n> "(description \"" p "\")"
+ n> "(license " p ")))" n)
+
+(origin...
+ "(origin"
+ n> "(method \""
+ (p (completing-read "method:"
+ '("url-fetch"
+ "url-fetch/tarbomb"
+ "url-fetch/zipbomb"
+ "cvs-fetch"
+ "git-fetch"
+ "hg-fetch"
+ "svn-fetch"
+ "bzr-fetch")
+ nil t) method) "\")"
+ n> "(uri " (cl-case (intern method)
+ ('git-fetch "git-reference...")
+ ('svn-fetch "svn-reference...")
+ ('hg-fetch "hg-reference...")
+ ('cvs-fetch "cvs-reference...")
+ ('bzr-fetch "bzr-reference...")
+ (t "(string-append \"https://"))
+ p
+ (if (equal (substring method 0 9) "url-fetch") "\")")
+ ")"
+ n> (cl-case (intern method)
+ ('git-fetch "(file-name (git-file-name name version))\n")
+ ('hg-fetch "(file-name (hg-file-name name version))\n")
+ ('svn-fetch "(file-name (string-append name \"-\" version \"-checkout\"))\n")
+ ('cvs-fetch "(file-name (string-append name \"-\" version \"-checkout\"))\n")
+ ('bzr-fetch "(file-name (string-append name \"-\" version \"-checkout\"))\n")
+ (t ""))
+ > "(sha256"
+ n> "(base32 \"" p "\")))")
+
+(git-reference...
+ "(git-reference"
+ n> "(url \"" p "\")"
+ n> "(commit \"" p "\"))")
+
+(svn-reference...
+ "(svn-reference"
+ n> "(url \"" p "\")"
+ n> "(revision \"" p "\"))")
+
+(cvs-reference...
+ "(cvs-reference"
+ n> "(root-directory \"" p "\")"
+ n> "(module \"" p "\")"
+ n> "(revision \"" p "\"))")
+
+(hg-reference...
+ "(hg-reference"
+ n> "(url \"" p "\")"
+ n> "(changeset \"" p "\"))")
+
+(bzr-reference...
+ "(bzr-reference"
+ n> "(url \"" p "\")"
+ n> "(revision \"" p "\"))")
new file mode 100644
@@ -0,0 +1,101 @@
+-*- mode: lisp-data -*-
+
+text-mode :when (and (fboundp 'git-commit-mode) (git-commit-mode))
+
+(add\
+ "gnu: Add "
+ (p
+ (with-temp-buffer
+ (magit-git-wash #'magit-diff-wash-diffs
+ "diff" "--staged")
+ (goto-char (point-min))
+ (when (re-search-forward "\\+(define-public \\(\\S-+\\)" nil 'noerror)
+ (match-string-no-properties 1)))
+ var ) "." n n
+ "* " (car (magit-staged-files)) " (" (s var ) "): New variable.")
+
+(remove\
+ "gnu: Remove "
+ (p (with-temp-buffer
+ (magit-git-wash #'magit-diff-wash-diffs
+ "diff" "--staged")
+ (goto-char (point-min))
+ (when (re-search-forward "\\-(define-public \\(\\S-+\\)" nil 'noerror)
+ (match-string-no-properties 1)))
+ var) "." n n
+ "* " (car (magit-staged-files)) " (" (s var) "): Delete variable.")
+
+(rename\
+ "gnu: "
+ (p (with-temp-buffer
+ (magit-git-wash #'magit-diff-wash-diffs
+ "diff" "--staged")
+ (beginning-of-buffer)
+ (when (search-forward "-(define-public " nil 'noerror)
+ (thing-at-point 'sexp 'no-properties)))
+ prev-var)
+ ": Rename package to "
+ (p (with-temp-buffer
+ (magit-git-wash #'magit-diff-wash-diffs
+ "diff" "--staged")
+ (beginning-of-buffer)
+ (when (search-forward "+(define-public " nil 'noerror)
+ (thing-at-point 'sexp 'no-properties)))
+ new-var) "." n n
+ "* " (car (magit-staged-files)) " (" (s prev-var) "): Define in terms of" n
+ "'deprecated-package'." n
+ "(" (s new-var) "): New variable, formerly known as \"" (s prev-var) "\".")
+
+(update\
+ "gnu: "
+ (p (with-temp-buffer
+ (magit-git-wash #'magit-diff-wash-diffs
+ "diff" "--staged")
+ (goto-char (point-min))
+ (when (re-search-forward "^[ ]*(define-public \\(\\S-+\\)" nil 'noerror)
+ (match-string-no-properties 1)))
+ var)
+ ": Update to "
+ (p (with-temp-buffer
+ (magit-git-wash #'magit-diff-wash-diffs
+ "diff" "--staged")
+ (goto-char (point-min))
+ (search-forward "name" nil 'noerror)
+ (search-forward "+" nil 'noerror) ; first change
+ (when (and (search-forward "version " nil 'noerror)
+ (looking-at-p "\""))
+ (let ((end (save-excursion (search-forward "\")" nil 'noerror))))
+ (when end
+ (forward-char)
+ (buffer-substring-no-properties (point) (- end 2))))))
+ version) "." n n
+ "* " (car (magit-staged-files)) " (" (s var) "): Update to " (s version) "."
+ (mapconcat (lambda (file) (concat "* " file)) (cdr (magit-staged-files))) n)
+
+(addcl\
+ "gnu: Add cl-"
+ (p (replace-regexp-in-string
+ "^cl-" "" (with-temp-buffer
+ (magit-git-wash #'magit-diff-wash-diffs
+ "diff" "--staged")
+ (beginning-of-buffer)
+ (when (search-forward "+(define-public " nil 'noerror)
+ (replace-regexp-in-string
+ "^sbcl-" ""
+ (thing-at-point 'sexp 'no-properties)))))
+ var) "." n n
+ "* " (car (magit-staged-files))
+ " (cl-" (s var) ", ecl-" (s var) ", sbcl-" (s var) "): New variables.")
+
+(https\
+ "gnu: "
+ (p (with-temp-buffer
+ (magit-git-wash #'magit-diff-wash-diffs
+ "diff" "--staged")
+ (goto-char (point-min))
+ (when (re-search-forward "^[ ]*(define-public \\(\\S-+\\)" nil 'noerror)
+ (match-string-no-properties 1)))
+ var)
+ ": Use HTTPS home page." n n
+ "* " (car (magit-staged-files)) " (" (s var) ")[home-page]: Use HTTPS." n
+ (mapconcat (lambda (file) (concat "* " file)) (cdr (magit-staged-files))) n)
similarity index 100%
rename from etc/snippets/scheme-mode/guix-bzr-reference
rename to etc/snippets/yas/scheme-mode/guix-bzr-reference
similarity index 100%
rename from etc/snippets/scheme-mode/guix-cvs-reference
rename to etc/snippets/yas/scheme-mode/guix-cvs-reference
similarity index 100%
rename from etc/snippets/scheme-mode/guix-git-reference
rename to etc/snippets/yas/scheme-mode/guix-git-reference
similarity index 100%
rename from etc/snippets/scheme-mode/guix-hg-reference
rename to etc/snippets/yas/scheme-mode/guix-hg-reference
similarity index 100%
rename from etc/snippets/scheme-mode/guix-origin
rename to etc/snippets/yas/scheme-mode/guix-origin
similarity index 100%
rename from etc/snippets/scheme-mode/guix-package
rename to etc/snippets/yas/scheme-mode/guix-package
similarity index 100%
rename from etc/snippets/scheme-mode/guix-svn-reference
rename to etc/snippets/yas/scheme-mode/guix-svn-reference
similarity index 100%
rename from etc/snippets/text-mode/guix-commit-message-add-cl-package
rename to etc/snippets/yas/text-mode/guix-commit-message-add-cl-package
similarity index 100%
rename from etc/snippets/text-mode/guix-commit-message-add-package
rename to etc/snippets/yas/text-mode/guix-commit-message-add-package
similarity index 100%
rename from etc/snippets/text-mode/guix-commit-message-remove-package
rename to etc/snippets/yas/text-mode/guix-commit-message-remove-package
similarity index 100%
rename from etc/snippets/text-mode/guix-commit-message-rename-package
rename to etc/snippets/yas/text-mode/guix-commit-message-rename-package
similarity index 100%
rename from etc/snippets/text-mode/guix-commit-message-update-package
rename to etc/snippets/yas/text-mode/guix-commit-message-update-package
similarity index 100%
rename from etc/snippets/text-mode/guix-commit-message-use-https-home-page
rename to etc/snippets/yas/text-mode/guix-commit-message-use-https-home-page