emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/detached 43faf84594 2/2: Add metadata git branch functi


From: ELPA Syncer
Subject: [elpa] externals/detached 43faf84594 2/2: Add metadata git branch function to package
Date: Mon, 23 May 2022 12:57:26 -0400 (EDT)

branch: externals/detached
commit 43faf8459416aaa22738fbafec0f67f210a912fd
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Add metadata git branch function to package
    
    Move the git branch metadata annotator function from the README to
    detached.el.
---
 README.md   | 17 +++--------------
 detached.el |  9 +++++++++
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/README.md b/README.md
index 9f67715964..d70dc5fd2d 100644
--- a/README.md
+++ b/README.md
@@ -257,23 +257,12 @@ Users are encouraged to define the `detached-env` 
variable. It should point to t
 
 ## Metadata annotators
 
-The user can configure any number of annotators to run upon creation of a 
session. Here is an example of an annotator which captures the git branch name, 
if the session is started in a git repository.
+The user can configure any number of annotators to run upon creation of a 
session. The package comes with a function which captures the git branch name, 
if the session is started in a git repository.
 
-``` emacs-lisp
-(defun my/detached--session-git-branch ()
-  "Return current git branch."
-  (let ((git-directory (locate-dominating-file "." ".git")))
-    (when git-directory
-      (let ((args '("name-rev" "--name-only" "HEAD")))
-        (with-temp-buffer
-          (apply #'process-file `("git" nil t nil ,@args))
-          (string-trim (buffer-string)))))))
-```
-
-Next add the annotation function to the `detached-metadata-annotators-alist` 
together with a symbol describing the property.
+This function can be added as an annotation function to the 
`detached-metadata-annotators-alist` together with a symbol describing the 
property.
 
 ``` emacs-lisp
-(setq detached-metadata-annotators-alist '((branch . 
my/detached--session-git-branch))
+(setq detached-metadata-annotators-alist '((branch . 
detached--metadata-git-branch)))
 ```
 
 ## Nonattachable commands
diff --git a/detached.el b/detached.el
index acfdd1f1d0..1598c5578c 100644
--- a/detached.el
+++ b/detached.el
@@ -1292,6 +1292,15 @@ If event is cased by an update to the `detached' 
database, re-initialize
                                     (seq-max)
                                     (min width)))))
 
+(defun detached--metadata-git-branch ()
+  "Return current git branch."
+  (let ((args '("symbolic-ref" "HEAD" "--short")))
+    (with-temp-buffer
+      (apply #'process-file `("git" nil t nil ,@args))
+      (unless (bobp)
+        (goto-char (point-min))
+        (buffer-substring-no-properties (point) (line-end-position))))))
+
 ;;;;; UI
 
 (defun detached--metadata-str (session)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]