From 421dcf67e559811ca753d5dd2a8e41e9f1763c23 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Fri, 6 Jan 2023 08:47:10 +0100 Subject: [PATCH] Add gist to store the Git revision of the Emacs config in a constant --- gists.org | 23 +++++++++++++++++++ ...tore-configuration-revision-in-constant.el | 18 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 gists/store-configuration-revision-in-constant.el diff --git a/gists.org b/gists.org index 2829cd0..4616eac 100644 --- a/gists.org +++ b/gists.org @@ -361,6 +361,29 @@ Used [[https://github.com/purcell/emacs.d/blob/master/lisp/init-paredit.el][Purc (bind-key (kbd "RET") #'paredit-newline paredit-mode-map))) #+end_src +* Store revision of Emacs configuration in a constant + +#+begin_src elisp :tangle gists/store-configuration-revision-in-constant.el + ;; Store the Git revision of your Emacs configuration at the moment + ;; Emacs started. + + (defconst my/has-git-p (if (executable-find "git") t nil) + "Indicates if git is in your PATH.") + + (defun my/configuration-revision () + "Retrieve the current Git revision of the Emacs configuration." + (when my/has-git-p + (with-temp-buffer + (cd user-emacs-directory) + (when (eql 0 (call-process "git" nil (current-buffer) nil + "describe" "--all" "--long" "--dirty")) + (string-trim (buffer-string)))))) + + (defconst my/configuration-revision + (my/configuration-revision) + "Contains the Git revision of the configuration at the moment Emacs started.") +#+end_src + * Meta ** License diff --git a/gists/store-configuration-revision-in-constant.el b/gists/store-configuration-revision-in-constant.el new file mode 100644 index 0000000..d85af2b --- /dev/null +++ b/gists/store-configuration-revision-in-constant.el @@ -0,0 +1,18 @@ +;; Store the Git revision of your Emacs configuration at the moment +;; Emacs started. + +(defconst my/has-git-p (if (executable-find "git") t nil) + "Indicates if git is in your PATH.") + +(defun my/configuration-revision () + "Retrieve the current Git revision of the Emacs configuration." + (when my/has-git-p + (with-temp-buffer + (cd user-emacs-directory) + (when (eql 0 (call-process "git" nil (current-buffer) nil + "describe" "--all" "--long" "--dirty")) + (string-trim (buffer-string)))))) + +(defconst my/configuration-revision + (my/configuration-revision) + "Contains the Git revision of the configuration at the moment Emacs started.")