[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark eb9741e51f 44/67: refactor: highlights-add-i
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark eb9741e51f 44/67: refactor: highlights-add-icons |
Date: |
Sat, 22 Jul 2023 06:59:03 -0400 (EDT) |
branch: externals/org-remark
commit eb9741e51f28ba7ae158587856831161a2ab3ca0
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
refactor: highlights-add-icons
---
org-remark.el | 95 +++++++++++++++++++++++++++++++++++------------------------
1 file changed, 56 insertions(+), 39 deletions(-)
diff --git a/org-remark.el b/org-remark.el
index 3b87319f93..807c360407 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -6,7 +6,7 @@
;; URL: https://github.com/nobiot/org-remark
;; Version: 1.1.0
;; Created: 22 December 2020
-;; Last modified: 07 July 2023
+;; Last modified: 09 July 2023
;; Package-Requires: ((emacs "27.1") (org "9.4"))
;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp,
@@ -284,6 +284,11 @@ recommended to turn it on as part of Emacs initialization.
(add-hook 'after-save-hook #'org-remark-save nil t)
(add-hook 'org-remark-highlights-after-load-hook
#'org-remark-highlights-adjust-positions)
+ ;; Add-icons should be after all after-load-hook functions because
+ ;; some of them make adjustment that's relevant for an icon --
+ ;; e.g. adjust-positon.
+ (add-hook 'org-remark-highlights-after-load-hook
+ #'org-remark-highlights-add-icons 80)
(add-hook 'org-remark-highlight-link-to-source-functions
#'org-remark-highlight-link-to-source-default 80))
(t
@@ -295,6 +300,8 @@ recommended to turn it on as part of Emacs initialization.
(remove-hook 'after-save-hook #'org-remark-save t)
(remove-hook 'org-remark-highlights-after-load-hook
#'org-remark-highlights-adjust-positions)
+ (remove-hook 'org-remark-highlights-after-load-hook
+ #'org-remark-highlights-add-icons)
(remove-hook 'org-remark-highlight-link-to-source-functions
#'org-remark-highlight-link-to-source-default))))
@@ -844,12 +851,11 @@ buffer is associated. When the source buffer does not
visit a
file (e.g. a website), it is the source buffer's file name
equivalent, such as the URL.
-BEG and END are the range of the highlight being saved. It
-is the highlight overlay's start and end.
+OVERLAY is the highlight being saved.
+
+SOURCE-BUF is the buffer of the source.
-PROPS are the highlight overlay's properties. Not all the
-properties will be added as headline properties. Refer to
-`org-remark-notes-set-properties'.
+NOTES-BUF is the notes buffer for the source.
For the first highlight of the source buffer, this function will
create a new H1 headline for it at the bottom of the marginal
@@ -881,8 +887,7 @@ source with using ORGID.
When the current source buffer is not set up for sync with notes,
this function calls `org-remark-notes-setup' to prepare the notes
buffer for automatic sync."
- (let ((point nil)
- (notes-props nil)
+ (let ((notes-props nil)
;; Does this have to be explicitly in with-current buffer clause?
(headline-constructors (with-current-buffer source-buf
(org-remark-highlight-get-constructors))))
@@ -923,9 +928,15 @@ buffer for automatic sync."
;;; Return notes-props
notes-props))
-(defun org-remark-new-headline (level title props &rest args)
- "
-Return the point of beginning of current heading."
+(defun org-remark-new-headline (level title props)
+ "Add a new headline in the note buffer.
+
+This function assumes that the point is in the notes buffer.
+
+LEVEL is the headline level to be added. TITLE is the headline
+title. PROPS is the alist of properties to be added to the headline.
+
+Return the point of begining of current heading."
;; If file-headline does not exist, create one at the bottom
(org-narrow-to-subtree)
(goto-char (point-max))
@@ -1011,8 +1022,7 @@ Assume the current buffer is the source buffer."
(end (cdr location))
(label (plist-get highlight :label))
(ov nil)
- (props (plist-get highlight :props))
- (highlight-text (plist-get props :original-text)))
+ (props (plist-get highlight :props)))
(let ((fn (intern (concat "org-remark-mark-" label))))
(unless (functionp fn) (setq fn #'org-remark-mark))
(setq ov (funcall fn beg end id :load))
@@ -1030,9 +1040,6 @@ Assume the current buffer is the source buffer."
(overlay-put highlight 'help-echo (plist-get plist :body)))
(overlay-put highlight '*org-remark-note-body
(plist-get plist :body))
- (when (plist-get plist :body)
- (let ((face (overlay-get highlight 'face)))
- (overlay-put highlight 'after-string (propertize "⁽*⁾" 'face face))))
(overlay-put highlight '*org-remark-original-text
(plist-get plist :original-text)))
@@ -1044,8 +1051,8 @@ It is a utility function to take care of both
(delete-overlay overlay))
(defun org-remark-highlight-adjust-position-after-load (highlight text)
- "Adjust the position of highlight after loaded.
-Adjustment is done by TEXT, which should be the original text of the
highlight."
+ "Adjust the position of HIGHLIGHT (an overlay) after loaded.
+It searches for TEXT, which should be the original text of the highlight."
;; Load works. but need one for sync. Need to re-think
;; ' and ’ are different in regex of course.
@@ -1069,15 +1076,16 @@ Adjustment is done by TEXT, which should be the
original text of the highlight."
;; overlay; this way, you don't need to look forward and backward
;; separately.
(when (re-search-forward text paragraph-end :noerror)
- (move-overlay highlight (match-beginning 0) (match-end 0))))
- ;; Even if the new location could not be found, indicate that it is
different to the original
- (let ((afterstring (overlay-get highlight 'after-string)))
- (overlay-put highlight 'after-string
- (concat afterstring
- (propertize "⁽ᵟ⁾" 'face
'org-remark-highlighter-warning)))))))
+ (move-overlay highlight (match-beginning 0) (match-end 0)))
+ ;; Add property to indicate that the position has somehow been
+ ;; adjusted. Even if the new location could not be found,
+ ;; indicate that the fact that string should have moved.
+ (overlay-put highlight '*org-remark-position-adjusted t)))))
(defun org-remark-highlight-link-to-source-default (filename point)
- "Return Org link string for the source when adding a highlight.
+ "Return Org link string for FILENAME & POINT for a highlight.
+POINT is used to compute the line number.
+
Default function for `org-remark-highlight-link-to-source-functions'."
(if buffer-file-name
(let ((line-num (org-current-line point)))
@@ -1327,17 +1335,12 @@ It is run with OVERLAYS and NOTES-BUF as arguments.
OVERLAYS are
highlights. It is run with the source buffer as current buffer.")
(defun org-remark-highlights-load (&optional update)
- "Visit `org-remark-notes-file' & load the saved highlights onto current
buffer.
+ "Visit notes file & load the saved highlights onto current buffer.
If there is no highlights or annotations for current buffer,
output a message in the echo.
-Highlights tracked locally by variable `org-remark-highlights'
-cannot persist when you kill current buffer or quit Emacs. It is
-recommended to set `org-remark-global-tracking-mode' in your
-configuration. It automatically turns on `org-remark-mode'.
-
-Otherwise, do not forget to turn on `org-remark-mode' manually to
-load the highlights"
+Non-nil value for UPDATE is passed for the notes-source sync
+process."
;; Some major modes such as nov.el reuse the buffer for a different
;; "file". In this case, obsolete highlight overlays linger when you
;; switch from one file to another. Thus, we need to begin loading by
@@ -1355,12 +1358,8 @@ load the highlights"
(notes-buf (or (find-buffer-visiting notes-filename)
(find-file-noselect notes-filename)))
(source-buf (current-buffer)))
- (dolist (highlight (org-remark-highlights-get notes-buf) overlays)
- (let* ((location (plist-get highlight :location))
- (beg (car location))
- (end (cdr location))
- (id (plist-get highlight :id)))
- (push (org-remark-highlight-load highlight) overlays)))
+ (dolist (highlight (org-remark-highlights-get notes-buf))
+ (push (org-remark-highlight-load highlight) overlays))
(unless update (org-remark-notes-setup notes-buf source-buf))
(if overlays
(progn (run-hook-with-args 'org-remark-highlights-after-load-hook
@@ -1502,6 +1501,24 @@ mode-specific extensions."
(org-remark-highlight-adjust-position-after-load
ov highlight-text)))))
+(defun org-remark-highlights-add-icons (overlays _notes-buf)
+ "Add icons to highlights."
+ (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 note-body
+ (let ((face (overlay-get ov 'face)))
+ (setq propertized-string (concat propertized-string (propertize
"⁽*⁾" 'face face)))))
+ ;; Even if the new location could not be found, indicate that it is
different to the original
+ (when position-adjusted
+ (setq propertized-string
+ (concat propertized-string
+ (propertize "⁽ᵟ⁾" 'face 'org-remark-highlighter-warning))))
+ (when propertized-string
+ (overlay-put ov 'after-string
+ propertized-string)))))
+
;;;;; Other utilities
(defun org-remark-source-get-file-name (filename)
- [elpa] externals/org-remark 5bd790cf3c 27/67: docs: docstring, (continued)
- [elpa] externals/org-remark 5bd790cf3c 27/67: docs: docstring, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 5ea75070bc 29/67: refactor: move highlights-after-load-hook to org-remark.el, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 2ae9516091 40/67: fix(highlights-get): existence check beg and end, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 612629c366 51/67: docs: NEWS and README, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark e8e0693268 07/67: fix(save): source-setup-done needs to be done in source, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark b35fcfdbe4 16/67: feat: adjust positions after load via new hook, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 32860de66b 24/67: fix: typo in the previous refactor, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark f2a1e9f339 32/67: fix(eww) adjust the arg of fn link-to-source, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark fa81cc764a 36/67: feat(adjust-positions): Add an icon indicating the position adjusted, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 5a0299bdf7 39/67: refactor: (WIP) highlight-new-headline-maybe, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark eb9741e51f 44/67: refactor: highlights-add-icons,
ELPA Syncer <=
- [elpa] externals/org-remark ae220ad29b 50/67: refactor(icon): change default to ascii characters only, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 112bbfa9ba 53/67: docs: Update user manual with new features, etc., ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark d133a32786 58/67: docs: Minor style updates to user manual, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 58feed0c04 54/67: style: lint with flymake, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark e4c42d7fd4 56/67: docs: Fix footnote (remove), ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 536c2cca1e 63/67: fix: add-headline. Location of new highlight notes was wrong, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 883f948bbf 66/67: style: make org-remark-highlight-save obsolete and add alias, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 3216d951fc 09/67: feat: nov.el title and nov-file-name in H1 of the notes, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 81bc062482 10/67: refactor(nov): highlight-save-book-entry, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark eed28d7b8d 26/67: Merge branch 'main' into dev/nov.el, ELPA Syncer, 2023/07/22