[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark efe2c4d504 13/16: refactor: logic to add an
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark efe2c4d504 13/16: refactor: logic to add an icon |
Date: |
Sat, 29 Jul 2023 18:58:48 -0400 (EDT) |
branch: externals/org-remark
commit efe2c4d504c8235b74af16ab7ff5b0e6719e17a1
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
refactor: logic to add an icon
---
org-remark.el | 65 +++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 24 deletions(-)
diff --git a/org-remark.el b/org-remark.el
index 67529efa9c..d5dcea4a81 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -1571,30 +1571,43 @@ extensions."
(org-remark-highlight-adjust-position-after-load
ov highlight-text)))))
+(defvar org-remark-icons
+ (list
+ (list 'notes
+ (lambda (ov)
+ (overlay-get ov '*org-remark-note-body))
+ nil)
+ (list 'position-adjusted
+ (lambda (ov)
+ (overlay-get ov '*org-remark-position-adjusted))
+ 'org-remark-highlighter-warning))
+ "List of icons enabled.
+It is an alist. Each element is a list of this form:
+ (ICON-NAME PREDICATE DEFAULT-FACE)
+
+ICON-NAME must be a symbol such as 'notes' and 'position-adjusted'.
+They are used as a suffix to be added to 'org-remark-icon-' to
+form a customizing variable such as `org-remark-icon-notes' and
+`org-remark-icon-adjusted'.
+
+PREDICATE must be a function that accepts one argument OV, which
+is the highlight overlay. If PREDICATE returns non-nil, the icon
+for ICON-NAME will be added to the highlight.
+
+DEFAULT FACE must be a named face. It is optinal and can be nil.")
+
(defun org-remark-highlights-add-icons (overlays _notes-buf)
"Add icons to OVERLAYS.
Each overlay is a highlight."
(dolist (ov overlays)
- (let ((propertized-string nil)
- (note-body (overlay-get ov '*org-remark-note-body))
- (position-adjusted (overlay-get ov '*org-remark-position-adjusted)))
- (when (and note-body org-remark-icon-notes)
- (let ((face (overlay-get ov 'face)))
- (setq propertized-string
- (concat propertized-string
- (org-remark-icon-propertize
- org-remark-icon-notes face)))))
- ;; Even if the new location could not be found, indicate that it
- ;; is different to the original
- (when (and position-adjusted org-remark-icon-position-adjusted)
- (setq propertized-string
- (concat propertized-string
- (org-remark-icon-propertize
- org-remark-icon-position-adjusted
- 'org-remark-highlighter-warning))))
- (when propertized-string
- (overlay-put ov 'after-string
- propertized-string)))))
+ (cl-flet ((add-icon-maybe (icon)
+ (cl-destructuring-bind
+ (icon-name pred default-face) icon
+ (when (funcall pred ov)
+ (org-remark-icon-propertize icon-name ov default-face)))))
+ (let ((icon-string
+ (mapconcat #'add-icon-maybe org-remark-icons)))
+ (when icon-string (overlay-put ov 'after-string icon-string))))))
;;;;; Other utilities
@@ -1644,15 +1657,19 @@ Return t if S1 and S2 are an identical string."
(replace-regexp-in-string "[\n ]" "" s1)
(replace-regexp-in-string "[\n ]" "" s2)))
-(defun org-remark-icon-propertize (icon face)
+(defun org-remark-icon-propertize (icon-name highlight default-face)
"Return a propertized string.
ICON can be either a function or string. FACE is either named
face or anonymous. FACE is passed to ICON when it is a function.
In this case, there is no expectation that the function should
use it. It can disregard the FACE."
- (if (functionp icon)
- (funcall icon face)
- (propertize icon 'face face)))
+ (let ((icon (symbol-value (intern (concat "org-remark-icon-"
+ (symbol-name icon-name)))))
+ (highlight-face (overlay-get highlight 'face))
+ (default-face default-face))
+ (if (functionp icon)
+ (funcall icon icon-name highlight-face)
+ (propertize icon 'face (if default-face default-face highlight-face)))))
;;;; Footer
- [elpa] externals/org-remark updated (4c0137d90a -> d73c72cfc3), ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark 430066da54 03/16: fix: headline-add, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark 05d280b5fa 05/16: fix(legacy): compilation warning #66, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark ef14f4e600 02/16: Merge branch 'dev/nov.el' into dev/1.2.0, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark 6333938f12 11/16: feat: Allow function to render icons, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark efe2c4d504 13/16: refactor: logic to add an icon,
ELPA Syncer <=
- [elpa] externals/org-remark 346fe9cf69 15/16: refactor: separate org-remark-icon into its own feature/file, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark ec693af64a 01/16: feat: org-remark-info-mode to support Info-mode #65, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark 87404b78d3 14/16: Merge branch 'main' into dev/1.2.0, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark b44092e6cf 06/16: style: make org-remark-highlight-save obsolete and add alias, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark a0624e2ebc 04/16: fix: make sure new top-level headline is appended, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark c6941579e3 09/16: refactor(nov): nov can defer loading org-remark, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark 6ef0b47bd2 12/16: fix: revert-buffer duplicates highlights, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark c701d9ceaa 07/16: style: silence compiler warning, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark 8ae3c426e0 08/16: fix: default highlighter color for dark theme, ELPA Syncer, 2023/07/29
- [elpa] externals/org-remark 0e05580760 10/16: feat(info): Advice to support rendering Info nodes in same buffer, ELPA Syncer, 2023/07/29