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

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

[elpa] externals/marginalia 27cd29d 101/241: add buffer size annotation,


From: Stefan Monnier
Subject: [elpa] externals/marginalia 27cd29d 101/241: add buffer size annotation, fix #29
Date: Fri, 28 May 2021 20:49:05 -0400 (EDT)

branch: externals/marginalia
commit 27cd29d8564c3577acd4d71faaa31da0cd79aaef
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    add buffer size annotation, fix #29
---
 marginalia.el | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/marginalia.el b/marginalia.el
index e99595e..7c17376 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -470,10 +470,21 @@ Similar to `marginalia-annotate-symbol', but does not 
show symbol class."
   "Annotate coding system CAND with its description."
   (marginalia--documentation (coding-system-doc-string (intern cand))))
 
+(defun marginalia--buffer-bytes (buf)
+  "Return byte size of BUF."
+  (with-current-buffer buf
+    (position-bytes (let ((max (point-max)))
+                      (if (= (buffer-size) (- max (point-min)))
+                          max ;; Buffer not narrowed
+                        (save-restriction
+                          (widen)
+                          (point-max)))))))
+
 (defun marginalia-annotate-buffer (cand)
   "Annotate buffer CAND with modification status, file name and major mode."
   (when-let (buffer (get-buffer cand))
     (marginalia--fields
+     ((file-size-human-readable (marginalia--buffer-bytes buffer)) :width 7 
:face 'marginalia-size)
      ((concat
        (if (buffer-modified-p buffer) "*" " ")
        (if (buffer-local-value 'buffer-read-only buffer) "%" " "))
@@ -528,7 +539,7 @@ using `minibuffer-force-complete' on the candidate CAND."
        (file-attribute-modification-time attributes)) :face 
'marginalia-date))))
 
 (defun marginalia-annotate-project-file (cand)
-  "Annotate file CAND with its size, modification time and other attributes."  
+  "Annotate file CAND with its size, modification time and other attributes."
   (when-let ((project (project-current))
              (root (project-root project))
              (file (expand-file-name cand root)))



reply via email to

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