branch: externals/org-remark
commit 4ad2be30e4d5516218a381ce879b1df44d9b9fdc
Author: Noboru Ota <[email protected]>
Commit: Noboru Ota <[email protected]>
fix(icon): the line icon not displaying
---
org-remark-icon.el | 40 ++++++++++++++++++++++++++++------------
org-remark-line.el | 31 ++++++++++++++++++-------------
2 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/org-remark-icon.el b/org-remark-icon.el
index 4e50911ffe..2203f48c5e 100644
--- a/org-remark-icon.el
+++ b/org-remark-icon.el
@@ -85,26 +85,22 @@ The icons currently available are defined in
`org-remark-icons'."
;; Add-icons should be the last function because other functions may do
;; something relevant for an icon -- e.g. adjust-positon."
(add-hook 'org-remark-highlights-after-load-functions
- #'org-remark-highlights-add-icons 80 :local))
+ #'org-remark-highlights-add-icons-maybe 80 :local))
;; Disable
(remove-hook 'org-remark-highlights-toggle-hide-functions
#'org-remark-icon-toggle-hide :local)
(remove-hook 'org-remark-highlights-toggle-show-functions
#'org-remark-icon-toggle-show :local)
(remove-hook 'org-remark-highlights-after-load-functions
- #'org-remark-highlights-add-icons 80 :local)))
+ #'org-remark-highlights-add-icons-maybe :local)))
(defvar org-remark-icons
(list
(list 'notes
- (lambda (ov)
- (and org-remark-icon-notes
- (overlay-get ov '*org-remark-note-body)))
+ #'org-remark-icon-notes-p
nil)
(list 'position-adjusted
- (lambda (ov)
- (and org-remark-icon-position-adjusted
- (overlay-get ov '*org-remark-position-adjusted)))
+ #'org-remark-icon-position-adjusted-p
'org-remark-highlighter-warning))
"List of icons enabled.
It is an alist. Each element is a list of this form:
@@ -121,6 +117,14 @@ 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-icon-notes-p (ov)
+ (and org-remark-icon-notes
+ (overlay-get ov '*org-remark-note-body)))
+
+(defun org-remark-icon-position-adjusted-p (ov)
+ (and org-remark-icon-position-adjusted
+ (overlay-get ov '*org-remark-position-adjusted)))
+
(defun org-remark-icon-toggle-hide (highlight)
(overlay-put highlight '*org-remark-icons (overlay-get highlight
'after-string))
(overlay-put highlight 'after-string nil))
@@ -129,7 +133,7 @@ DEFAULT FACE must be a named face. It is optinal and can be
nil.")
(overlay-put highlight 'after-string (overlay-get highlight
'*org-remark-icons))
(overlay-put highlight '*org-remark-icons nil))
-(defun org-remark-highlights-add-icons (overlays _notes-buf)
+(defun org-remark-highlights-add-icons-maybe (overlays _notes-buf)
"Add icons to OVERLAYS.
Each overlay is a highlight."
(dolist (ov overlays)
@@ -141,9 +145,21 @@ Each overlay is a highlight."
(org-remark-icon-propertize icon-name ov default-face)))))
(let ((icon-string
(mapconcat #'add-icon-maybe org-remark-icons)))
- (when icon-string (org-remark-icon-overlay-put
- ov icon-string
- (overlay-get ov 'org-remark-type)))))))
+ ;; `mapconcat' returns "" when all function calls for SEQUENCE
+ ;; return nil, I guess to guarantee the result is a string
+ (when (and icon-string
+ (not (string= icon-string "")))
+ (org-remark-icon-overlay-put
+ ov icon-string
+ (overlay-get ov 'org-remark-type)))))))
+
+;; (defun org-remark-icon-image-p (icon-string)
+;; "Return t when ICON-STRING contains a display property.
+;; The string may be empty like \"\" but it may have a display
+;; property to display an icon image. In this case, we should not
+;; consider it an empty string. This is important to know when an
+;; image icon is used instead of a string."
+;; (when (get-text-property 0 'display icon-string)))
(cl-defgeneric org-remark-icon-overlay-put (ov icon-string _org-remark-type)
"Default method to deal with icon.
diff --git a/org-remark-line.el b/org-remark-line.el
index 1b4fdcebc0..93b118f857 100644
--- a/org-remark-line.el
+++ b/org-remark-line.el
@@ -98,16 +98,17 @@ by `overlays-in'."
(org-remark-line-highlight-overlay-put ov face) ;; LINE
(overlay-put ov 'insert-in-front-hooks (list
'org-remark-line-highlight-modified)))
-(defun org-remark-line-highlight-overlay-put (ov face)
+(defun org-remark-line-highlight-overlay-put (ov face &optional string)
(let* ((face (or face 'org-remark-line-highlighter))
(left-margin (or (car (window-margins))
;; when nil = no margin, set to 1
(progn (set-window-margins nil 2)
2)))
(spaces (- left-margin 2))
- (string (with-temp-buffer (insert-char ?\s spaces)
- (insert org-remark-line-icon)
- (buffer-string))))
+ (string (or string
+ (with-temp-buffer (insert-char ?\s spaces)
+ (insert org-remark-line-icon)
+ (buffer-string)))))
(overlay-put ov 'before-string (propertize "! " 'display
`((margin left-margin)
,(propertize string 'face
face))))
@@ -160,15 +161,19 @@ end of overlay being identical."
(cl-defmethod org-remark-icon-overlay-put (ov icon-string (org-remark-type
(eql 'line)))
;; If the icon-string has a display properties, assume it is an icon image
(let ((display-prop (get-text-property 0 'display icon-string)))
- (when display-prop
- (let* ((display-prop (list '(margin left-margin) display-prop))
- (icon-string (propertize "* " 'display display-prop))
- (icon-string (propertize icon-string face
'org-remark-line-highligther)))
- (overlay-put ov 'before-string icon-string)))))
-
-;; (defun org-remark-line-inspect-overlay ()
-;; (interactive)
-;; (car (overlays-in (point) (point))))
+ (cond (display-prop
+ (let* ((display-prop (list '(margin left-margin) display-prop))
+ (icon-string (propertize "* " 'display display-prop)))
+ (setq icon-string (propertize icon-string
+ 'face 'org-remark-line-highlighter))
+ (overlay-put ov 'before-string icon-string)))
+ (icon-string
+ (setq icon-string (propertize icon-string
+ 'face 'org-remark-line-highlighter))
+ (org-remark-line-highlight-overlay-put ov
+ 'org-remark-line-highlighter
+ icon-string))
+ (t (ignore)))))
(provide 'org-remark-line)
;;; org-remark-line.el ends here