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

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

[elpa] externals/marginalia 7d3f018 024/241: Add annotations for files a


From: Stefan Monnier
Subject: [elpa] externals/marginalia 7d3f018 024/241: Add annotations for files and buffers
Date: Fri, 28 May 2021 20:48:49 -0400 (EDT)

branch: externals/marginalia
commit 7d3f01891d53b071ac70aa58f763442ebf7724cc
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>

    Add annotations for files and buffers
    
    These are not turned on by default.
    
    For files, use size and modification time.
    
    For buffers, modification status, file (if there is one) and major
    mode.
    
    These were imported from embark, per issue #3.
---
 marginalia.el | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/marginalia.el b/marginalia.el
index a977b4c..47ced57 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -202,6 +202,27 @@ determine it."
   (when-let (doc (documentation-property (intern cand) 'group-documentation))
     (marginalia--annotation doc)))
 
+(defun marginalia-annotate-buffer (cand)
+  "Annotate buffer CAND with modification status, file name and major mode."
+  (when-let ((buffer (get-buffer cand)))
+    (marginalia--annotation
+     (format "%s%s (%s)"
+             (if (buffer-modified-p buffer) "*" "")
+             (if-let ((file-name (buffer-file-name buffer)))
+                 (abbreviate-file-name file-name)
+               "")
+             (buffer-local-value 'major-mode buffer)))))
+
+(defun marginalia-annotate-file (cand)
+  "Annotate file CAND with its size and modification time."
+  (when-let ((attributes (file-attributes cand)))
+    (marginalia--annotation
+     (format "%7s %s"
+             (file-size-human-readable (file-attribute-size attributes))
+             (format-time-string
+              "%b %e %k:%M"
+              (file-attribute-modification-time attributes))))))
+
 (defun marginalia-classify-by-command-name ()
   "Lookup category for current command."
   (and marginalia--this-command



reply via email to

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