[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/kind-icon cfa3d73 38/51: Guard against network or other
From: |
ELPA Syncer |
Subject: |
[elpa] externals/kind-icon cfa3d73 38/51: Guard against network or other icon retrieval issues (text fallback) |
Date: |
Wed, 17 Nov 2021 15:57:46 -0500 (EST) |
branch: externals/kind-icon
commit cfa3d738f9f8f73ff070e6c6a85ddc64cb4af69b
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>
Guard against network or other icon retrieval issues (text fallback)
---
kind-icon.el | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/kind-icon.el b/kind-icon.el
index b431129..488597c 100644
--- a/kind-icon.el
+++ b/kind-icon.el
@@ -178,12 +178,25 @@ See `svg-lib-style-compute-default'."
:type 'plist
:set #'kind-icon--set-default-clear-cache)
+(defun kind-icon--get-icon-safe (icon &optional col bg-col)
+ "Retrieve ICON (a string) from the material database.
+Uses svg-lib, guarding against network errors."
+ (condition-case err
+ (apply #'svg-lib-icon icon nil
+ `(,@kind-icon-default-style
+ ,@(if col `(:foreground ,col))
+ ,@(if bg-col `(:background ,bg-col))))
+ ((error)
+ (warn "Error retrieving icon %s, falling back on short-text\n%s"
+ icon (cdr err))
+ nil)))
+
(defun kind-icon--preview (widget _e)
- (let* ((icon (widget-value widget)))
- (message "%S looks like: %s" icon
- (propertize "**" 'display
- (apply #'svg-lib-icon
- icon nil kind-icon-default-style)))))
+ (let* ((icon-name (widget-value widget)))
+ (message "%S looks like: %s" icon-name
+ (if-let ((icon (kind-icon--get-icon-safe icon-name)))
+ (propertize "??" 'display icon)
+ "??"))))
(defsubst kind-icon--rgb-blend (rgb1 rgb2 frac)
"Return a fractional blend between two colors RGB1 and RGB2.
@@ -240,21 +253,19 @@ background-color."
(pad-right (propertize " " 'display `(space :width (,half))))
(pad-left (propertize " " 'display `(space :width (,(- dfw
half)))))
(disp (if-let ((kind-icon-use-icons)
- (icon (plist-get plist :icon)))
+ (icon-name (plist-get plist :icon))
+ (icon (kind-icon--get-icon-safe icon-name col
bg-col)))
;; icon: always 2x1, half-space on each side
- (propertize (concat
- pad-left
- (propertize "*" ; pretend 2 char-wide
icon is only 1
- 'display (apply
#'svg-lib-icon icon nil
- :foreground
col
- :background
bg-col
-
kind-icon-default-style))
- pad-right) 'face `(:background ,bg-col))
+ (propertize ; pretend it's one char to allow padding
+ (concat pad-left (propertize "*" 'display icon)
pad-right)
+ 'face `(:background ,bg-col))
;; text, 1 or 2 chars, centered with full or half space
on each side
(let* ((txt (truncate-string-to-width (cadr map) 2))
(len (length txt))
(txt-disp (if (eq len 2)
- (concat pad-left (propertize "_"
'display txt) pad-right)
+ (concat pad-left
+ (propertize "_" 'display
txt)
+ pad-right)
(concat " " txt " "))))
(propertize txt-disp 'face
`(:weight bold :foreground ,col
:background ,bg-col))))))
- [elpa] externals/kind-icon eaeea12 12/51: Doc, (continued)
- [elpa] externals/kind-icon eaeea12 12/51: Doc, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 3b0c9c3 11/51: Renamed kind-icon, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 366232c 36/51: Quiet svg-lib-icon warning, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 9a20879 30/51: Use widget-value in customize preview, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 9098597 33/51: Update kinds to match LSP spec, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon fcfe9ea 14/51: kind-icon-formatted: 3 char-width icon/centered 1 or 2 char text, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 8d6fa99 46/51: Update README.md, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon b88e809 48/51: kind-formatter -> margin-formatters, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon f6de892 37/51: Remove add-variable-watcher in favor of custom :set, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 94ff0ac 13/51: customize interface for mappings, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon cfa3d73 38/51: Guard against network or other icon retrieval issues (text fallback),
ELPA Syncer <=
- [elpa] externals/kind-icon ba0f94e 17/51: Re-enable mapping customization preview button, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 0921fe2 35/51: Separate kind-icon--cache, and return ?? when kind missing, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 0d92763 31/51: add kinds constructor, event, reference, typeparameter, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon c69da89 18/51: Updated docs, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 962c209 20/51: Add custom variable watcher for instant updates, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon c0d50c6 40/51: minor reformat, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon be77196 19/51: Update README.md, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon ea06e81 47/51: Update README.md, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon dce91ac 49/51: Update README.md, ELPA Syncer, 2021/11/17
- [elpa] externals/kind-icon 4896e1e 32/51: Switch module & ruler icons, ELPA Syncer, 2021/11/17