[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark 346fe9cf69 15/16: refactor: separate org-rem
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark 346fe9cf69 15/16: refactor: separate org-remark-icon into its own feature/file |
Date: |
Sat, 29 Jul 2023 18:58:48 -0400 (EDT) |
branch: externals/org-remark
commit 346fe9cf69e3d5b9b287fed41df39298f795bb53
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
refactor: separate org-remark-icon into its own feature/file
To keep the current behaviour, `org-remark-icon-mode` is automaticallly
enabled as part of `org-remark-mode`. It's a local minor mode. If not
required, it can be turned off and revert the buffer to re-load the
highlights; the second time, without icons.
---
org-remark-icon.el | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++
org-remark.el | 108 ++++---------------------------------
2 files changed, 164 insertions(+), 98 deletions(-)
diff --git a/org-remark-icon.el b/org-remark-icon.el
new file mode 100644
index 0000000000..13856b131a
--- /dev/null
+++ b/org-remark-icon.el
@@ -0,0 +1,154 @@
+;;; org-remark-icon.el --- Enable Org-roam to use icons -*- lexical-binding:
t; -*-
+
+;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
+
+;; Author: Noboru Ota <me@nobiot.com>
+;; URL: https://github.com/nobiot/org-remark
+;; Created: 29 July 2023
+;; Last modified: 29 July 2023
+;; Package-Requires: ((emacs "27.1") (org "9.4"))
+;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or (at
+;; your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+(require 'cl-macs)
+
+(defgroup org-remark-icon nil
+ "Highlight and annotate any text files with using Org mode."
+ :group 'org-remark
+ :prefix "org-remark-icon"
+ :link '(url-link :tag "GitHub" "https://github.com/nobiot/org-remark"))
+
+(defcustom org-remark-icon-notes "(*)"
+ "String to be displayed when notes exist for a given highlight.
+
+You can set a function to this user option. In this case, the
+function must take one argument, which is FACE. FACE can be a
+named face (a symbol), or an anonymous face (plist of face
+attributes). The function can ignore them and set its own face
+and/or text-property to the string. This means you can return a
+string with a display property to show an SVG icon instead of the
+underlying string.
+
+Nil means no icon is to be displayed."
+ :safe #'stringp
+ :type '(choice
+ (string "(*)")
+ (function)))
+
+(defcustom org-remark-icon-position-adjusted "(d)"
+ "String to be displayed when a highlight position adjusted.
+
+You can set a function to this user option. In this case, the
+function must take one argument, which is FACE. FACE can be a
+named face (a symbol), or an anonymous face (plist of face
+attributes). The function can ignore them and set its own face
+and/or text-property to the string. This means you can return a
+string with a display property to show an SVG icon instead of the
+underlying string.
+
+Nil means no icon is to be displayed."
+ :safe #'stringp
+ :type '(choice
+ (string "(d)")
+ (function)))
+
+;;;###autoload
+(define-minor-mode org-remark-icon-mode
+ "Enable Org-remark to display icons.
+The icons currently available are defined in `org-remark-icons'."
+ :global nil
+ :group 'org-remark
+ (if org-remark-icon-mode
+ ;; Enable
+ (progn
+ (add-hook 'org-remark-highlights-toggle-hide-functions
#'org-remark-icon-toggle-hide)
+ (add-hook 'org-remark-highlights-toggle-show-functions
#'org-remark-icon-toggle-show)
+ ;; 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))
+ ;; Disable
+ (remove-hook 'org-remark-highlights-toggle-hide-functions
#'org-remark-icon-toggle-hide)
+ (remove-hook 'org-remark-highlights-toggle-show-functions
#'org-remark-icon-toggle-show)
+ (remove-hook 'org-remark-highlights-after-load-functions
+ #'org-remark-highlights-add-icons 80)))
+
+(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-position-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-icon-toggle-hide (highlight)
+ (overlay-put highlight '*org-remark-icons (overlay-get highlight
'after-string))
+ (overlay-put highlight 'after-string nil))
+
+(defun org-remark-icon-toggle-show (highlight)
+ (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)
+ "Add icons to OVERLAYS.
+Each overlay is a highlight."
+ (dolist (ov overlays)
+ (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))))))
+
+(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."
+ (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)))))
+
+(provide 'org-remark-icon)
+;;; org-remark-icon.el ends here
diff --git a/org-remark.el b/org-remark.el
index d5dcea4a81..01f6a8cde9 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -127,48 +127,11 @@ manually or some other function to either the headline or
file."
The current buffer is the note buffer."
:type 'hook)
-(defcustom org-remark-icon-notes "(*)"
- "String to be displayed when notes exist for a given highlight.
-
-You can set a function to this user option. In this case, the
-function must take one argument, which is FACE. FACE can be a
-named face (a symbol), or an anonymous face (plist of face
-attributes). The function can ignore them and set its own face
-and/or text-property to the string. This means you can return a
-string with a display property to show an SVG icon instead of the
-underlying string.
-
-Nil means no icon is to be displayed."
- :safe #'stringp
- :type '(choice
- (string "(*)")
- (function)))
-
-(defcustom org-remark-icon-position-adjusted "(d)"
- "String to be displayed when a highlight position adjusted.
-
-You can set a function to this user option. In this case, the
-function must take one argument, which is FACE. FACE can be a
-named face (a symbol), or an anonymous face (plist of face
-attributes). The function can ignore them and set its own face
-and/or text-property to the string. This means you can return a
-string with a display property to show an SVG icon instead of the
-underlying string.
-
-Nil means no icon is to be displayed."
- :safe #'stringp
- :type '(choice
- (string "(d)")
- (function)))
-
(defcustom org-remark-highlights-after-load-functions
- '(org-remark-highlights-adjust-positions org-remark-highlights-add-icons)
+ '(org-remark-highlights-adjust-positions)
"Abnormal hook run after `org-remark-highlights-load'.
It is run with OVERLAYS and NOTES-BUF as arguments. OVERLAYS are
-highlights. It is run with the source buffer as current buffer.
-
-Add-icons should be the last function because other functions may
-do something relevant for an icon -- e.g. adjust-positon."
+highlights. It is run with the source buffer as current buffer."
:type 'hook)
@@ -324,6 +287,7 @@ recommended to turn it on as part of Emacs initialization.
(cond
(org-remark-mode
;; Activate
+ (org-remark-icon-mode +1) ;; automatically enabled by default
(org-remark-highlights-load)
(add-hook 'after-save-hook #'org-remark-save nil t)
(add-hook 'org-remark-highlight-link-to-source-functions
@@ -335,6 +299,7 @@ recommended to turn it on as part of Emacs initialization.
(dolist (highlight org-remark-highlights)
(delete-overlay highlight)))
(setq org-remark-highlights nil)
+ (org-remark-icon-mode -1)
(remove-hook 'after-save-hook #'org-remark-save t)
(remove-hook 'org-remark-highlight-link-to-source-functions
#'org-remark-highlight-link-to-source-default)
@@ -1463,6 +1428,9 @@ It returns t when sorting is done."
org-remark-highlights))
t))
+(defvar org-remark-highlights-toggle-hide-functions nil)
+(defvar org-remark-highlights-toggle-show-functions nil)
+
(defun org-remark-highlights-hide ()
"Hide highlights.
This function removes the font-lock-face of all the highlights,
@@ -1475,10 +1443,8 @@ state."
;; Faces
(overlay-put highlight '*org-remark-face (overlay-get highlight 'face))
(overlay-put highlight 'face nil)
- ;; Icons
- (overlay-put highlight '*org-remark-icons (overlay-get highlight
'after-string))
- (overlay-put highlight 'after-string nil)
- (overlay-put highlight '*org-remark-hidden t))
+ (overlay-put highlight '*org-remark-hidden t)
+ (run-hook-with-args 'org-remark-highlights-toggle-hide-functions
highlight))
(setq org-remark-highlights-hidden t)))
(defun org-remark-highlights-show ()
@@ -1492,9 +1458,7 @@ the show/hide state."
;; Faces
(overlay-put highlight '*org-remark-hidden nil)
(overlay-put highlight 'face (overlay-get highlight '*org-remark-face))
- ;; Icons
- (overlay-put highlight 'after-string (overlay-get highlight
'*org-remark-icons))
- (overlay-put highlight '*org-remark-icons nil))
+ (run-hook-with-args 'org-remark-highlights-toggle-show-functions
highlight))
(setq org-remark-highlights-hidden nil)))
(defun org-remark-highlights-housekeep ()
@@ -1571,44 +1535,6 @@ 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)
- (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
(defun org-remark-source-get-file-name (filename)
@@ -1657,20 +1583,6 @@ 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-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."
- (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, 2023/07/29
- [elpa] externals/org-remark 346fe9cf69 15/16: refactor: separate org-remark-icon into its own feature/file,
ELPA Syncer <=
- [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
- [elpa] externals/org-remark d73c72cfc3 16/16: docs(info): Add copyright and commentary to source header, ELPA Syncer, 2023/07/29