[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/marginalia 14dce57 062/241: scale field widths such tha
From: |
Stefan Monnier |
Subject: |
[elpa] externals/marginalia 14dce57 062/241: scale field widths such that annotations look better on smaller windows |
Date: |
Fri, 28 May 2021 20:48:57 -0400 (EDT) |
branch: externals/marginalia
commit 14dce57bafcf6fc0984c717c1d6a9ac995b252fd
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
scale field widths such that annotations look better on smaller windows
---
marginalia.el | 41 +++++++++++++++++------------------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/marginalia.el b/marginalia.el
index af8474e..2cac877 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -94,23 +94,10 @@
"Face used to highlight file owners in `marginalia-mode'."
:group 'marginalia)
-(defcustom marginalia-separator " "
- "Field separator."
- :type 'string
- :group 'marginalia)
-
-(defcustom marginalia-documentation-width 80
- "Width of documentation string."
- :type 'integer
- :group 'marginalia)
+(defcustom marginalia-truncate-width 80
+ "Maximum truncation width of annotation fields.
-(defcustom marginalia-file-name-width 80
- "Width of file name."
- :type 'integer
- :group 'marginalia)
-
-(defcustom marginalia-variable-width 30
- "Width of variable value annotation string."
+This value is adjusted in the `minibuffer-setup-hook' depending on the
`window-width'."
:type 'integer
:group 'marginalia)
@@ -202,6 +189,9 @@ determine it."
;;;; Marginalia mode
+(defvar marginalia--separator " "
+ "Field separator.")
+
(defvar marginalia--this-command nil
"Last command symbol saved in order to allow annotations.")
@@ -238,14 +228,14 @@ WIDTH is the format width. This can be specified as
alternative to FORMAT."
(defmacro marginalia--fields (&rest fields)
"Format annotation FIELDS as a string with separators in between."
`(marginalia--align (concat ,@(cdr (mapcan (lambda (field)
- (list 'marginalia-separator
`(marginalia--field ,@field)))
+ (list 'marginalia--separator
`(marginalia--field ,@field)))
fields)))))
(defun marginalia--documentation (str)
"Format documentation string STR."
(when str
(marginalia--fields
- (str :truncate marginalia-documentation-width :face
'marginalia-documentation))))
+ (str :truncate marginalia-truncate-width :face
'marginalia-documentation))))
(defvar-local marginalia-annotate-command-binding--hash nil
"Hash table storing the keybinding of every command.
@@ -287,8 +277,8 @@ This hash table is needed to speed up
`marginalia-annotate-command-binding'.")
(when-let (doc (documentation-property sym 'variable-documentation))
(marginalia--fields
((if (boundp sym) (symbol-value sym) 'unbound)
- :truncate marginalia-variable-width :format "%S" :face
'marginalia-variable)
- (doc :truncate marginalia-documentation-width :face
'marginalia-documentation)))))
+ :truncate (/ marginalia-truncate-width 2) :format "%S" :face
'marginalia-variable)
+ (doc :truncate marginalia-truncate-width :face
'marginalia-documentation)))))
(defun marginalia-annotate-face (cand)
"Annotate face CAND with documentation string and face example."
@@ -296,7 +286,7 @@ This hash table is needed to speed up
`marginalia-annotate-command-binding'.")
(when-let (doc (documentation-property sym 'face-documentation))
(marginalia--fields
("abcdefghijklmNOPQRSTUVWXYZ" :face sym)
- (doc :truncate marginalia-documentation-width :face
'marginalia-documentation)))))
+ (doc :truncate marginalia-truncate-width :face
'marginalia-documentation)))))
(defun marginalia-annotate-package (cand)
"Annotate package CAND with its description summary."
@@ -311,7 +301,7 @@ This hash table is needed to speed up
`marginalia-annotate-command-binding'.")
((if (package-installed-p desc)
"installed"
(package-desc-archive desc)) :width 9 :face 'marginalia-archive)
- ((package-desc-summary desc) :truncate marginalia-documentation-width
:face 'marginalia-documentation))))
+ ((package-desc-summary desc) :truncate marginalia-truncate-width :face
'marginalia-documentation))))
(defun marginalia-annotate-customize-group (cand)
"Annotate customization group CAND with its documentation string."
@@ -327,7 +317,7 @@ This hash table is needed to speed up
`marginalia-annotate-command-binding'.")
((buffer-local-value 'major-mode buffer) :width 30 :face 'marginalia-mode)
((if-let (file (buffer-file-name buffer))
(abbreviate-file-name file) "")
- :truncate marginalia-file-name-width
+ :truncate marginalia-truncate-width
:face 'marginalia-file-name))))
;; At some point we might want to revisit how this function is implemented.
Maybe we come up with a
@@ -424,7 +414,10 @@ PROP is the property which is looked up."
(defun marginalia--minibuffer-setup ()
"Setup minibuffer for `marginalia-mode'.
Remember `this-command' for annotation."
- (setq-local marginalia--this-command this-command))
+ (let ((w (window-width)))
+ (setq-local marginalia-truncate-width (min (/ w 2)
marginalia-truncate-width))
+ (setq-local marginalia--separator (if (> w 100) " " " "))
+ (setq-local marginalia--this-command this-command)))
;;;###autoload
(define-minor-mode marginalia-mode
- [elpa] externals/marginalia 59d65af 018/241: Add basic classifiers: orginal category, symbols, by words in prompt, (continued)
- [elpa] externals/marginalia 59d65af 018/241: Add basic classifiers: orginal category, symbols, by words in prompt, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 0f1e763 025/241: rename some variables for consistency, update readme, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia cd95c65 028/241: buffer annotation: add read-only status, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 675e680 036/241: improve annotator defcustoms, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 8be2daf 046/241: marginalia-annotate-file: remove unnecessary offset which only costs space for no reason, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia c8c3f87 045/241: Rename toggle -> cycle, improve documenation, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 1269445 049/241: marginalia-annotate-command-binding: cache key binding, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 376ccc5 048/241: Revert "fix marginalia--full-candidate for selectrum", Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia ccefc57 052/241: marginalia-annotate-command-binding: add comment, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 597186d 065/241: add marginalia-annotate-minor-mode, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 14dce57 062/241: scale field widths such that annotations look better on smaller windows,
Stefan Monnier <=
- [elpa] externals/marginalia 7d3719d 074/241: Fix advice skipping regexp for older Emacsen, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 5373a26 076/241: add marginalia-modified face, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia c0460b6 085/241: classify environment variable, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 9d2f319 080/241: marginalia-annotate-variable: add modification indicator, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 9f1b63b 086/241: add symbol class characters from Emacs 28, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 74603c0 091/241: use mapatoms to fix the harmless unused variable warning, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 88ba686 090/241: remove unnecessary :group specification, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 6cd9768 098/241: minor optimization to marginalia--function-doc, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 4ac0f1f 096/241: rename variable, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia ed02f22 099/241: marginalia--align: only align text if non-empty, Stefan Monnier, 2021/05/28