[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark b35fcfdbe4 16/67: feat: adjust positions aft
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark b35fcfdbe4 16/67: feat: adjust positions after load via new hook |
Date: |
Sat, 22 Jul 2023 06:59:00 -0400 (EDT) |
branch: externals/org-remark
commit b35fcfdbe46fb86a8ebd8b43e3df99ca0c2bdff4
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
feat: adjust positions after load via new hook
---
adjust-highlights.el | 17 +++++++++++++
org-remark-nov.el | 9 ++++++-
org-remark.el | 70 +++++++++++++++++++++++++++++++++++-----------------
3 files changed, 72 insertions(+), 24 deletions(-)
diff --git a/adjust-highlights.el b/adjust-highlights.el
new file mode 100644
index 0000000000..3f55b5ccae
--- /dev/null
+++ b/adjust-highlights.el
@@ -0,0 +1,17 @@
+;; This is probably not very good for text that you change; and change the
highlights.
+;; if you change it, this will bring it back to the "original".
+(defun test/move-highlight (highlight text)
+ (let* ((beg (overlay-start highlight))
+ (end (overlay-end highlight))
+ (paragraph-beg)(paragraph-end)
+ ;; Cater to the case when the text is divided by a \n
+ ;; The regexp must look for space or \n
+ (text (replace-regexp-in-string " " "\[ \n\]" text)))
+ (org-with-wide-buffer
+ (unless (string= (buffer-substring beg end) text)
+ (goto-char beg) (backward-paragraph 2) (setq paragraph-beg (point))
+ (goto-char beg) (forward-paragraph 2) (setq paragraph-end (point))
+ (goto-char (point-min))
+ (when (or (re-search-forward text paragraph-end :noerror)
+ (re-search-backward text paragraph-beg :noerror))
+ (move-overlay highlight (match-beginning 0) (match-end 0)))))))
diff --git a/org-remark-nov.el b/org-remark-nov.el
index e265bbb48f..322a13ed90 100644
--- a/org-remark-nov.el
+++ b/org-remark-nov.el
@@ -2,7 +2,7 @@
;; URL: https://github.com/nobiot/org-remark
;; Created: 9 January 2023
-;; Last modified: 11 January 2023
+;; Last modified: 12 January 2023
;;; Commentary:
@@ -22,6 +22,8 @@
;; displayed get removed; the ones for the new document need to be
;; loaded document after `nov-mode' renders the new document.
(add-hook 'nov-post-html-render-hook #'org-remark-highlights-load)
+(add-hook 'org-remark-highlights-after-load-hook
+ #'org-remark-nov-highlight-adjust-positions)
(add-to-list 'org-remark-notes-headline-functions
'(nov-mode . ((1 . org-remark-nov-highlight-add-book-headline-maybe)
(2 . org-remark-highlight-add-source-headline-maybe))))
@@ -75,5 +77,10 @@ Assume the current buffer is NOTES-BUF."
(org-set-property "org-remark-nov-file" filename)
(org-back-to-heading) (point))))))
+(defun org-remark-nov-highlight-adjust-positions (overlays _notes-buf)
+ (dolist (ov overlays)
+ (let ((highlight-text (overlay-get ov '*org-remark-original-text)))
+ (when highlight-text (test/move-highlight ov highlight-text)))))
+
(provide 'org-remark-nov)
;;; org-remark-nov.el ends here
diff --git a/org-remark.el b/org-remark.el
index 6a9b5a8a6c..419572777e 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -6,7 +6,7 @@
;; URL: https://github.com/nobiot/org-remark
;; Version: 1.0.5
;; Created: 22 December 2020
-;; Last modified: 11 January 2023
+;; Last modified: 13 January 2023
;; Package-Requires: ((emacs "27.1") (org "9.4"))
;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp,
@@ -753,12 +753,8 @@ round-trip back to the notes file."
;; Get props for create and change modes
(notes-props
(org-remark-highlight-add ov source-buf notes-buf)))
- ;; TODO generalize putting props to highlight overlay
(when notes-props
- (unless (overlay-get ov 'help-echo)
- (overlay-put ov 'help-echo (plist-get notes-props :body)))
- (overlay-put ov '*org-remark-note-body
- (plist-get notes-props :body)))
+ (org-remark-highlight-put-props ov notes-props))
;; Save the notes buffer when not loading
(unless (eq notes-buf (current-buffer))
(with-current-buffer notes-buf (save-buffer))))))
@@ -945,7 +941,7 @@ beginning of source-headline, which should be one level up."
(level (1+ (org-current-level))))
(if highlight-headline
(progn
- (goto-char id-headline)
+ (goto-char highlight-headline)
;; Update the existing headline and position properties
;; Don't update the headline text when it already exists
;; Let the user decide how to manage the headlines
@@ -961,13 +957,21 @@ beginning of source-headline, which should be one level
up."
;; Add a properties
(insert (concat (insert-char (string-to-char "*") level)
" " text "\n"))
+ ;; org-remark-original-text should be added onlyy when this
+ ;; headline is created. No update afterwards
+ (plist-put props "org-remark-original-text" text)
(org-remark-notes-set-properties beg end props)
(when (and orgid org-remark-use-org-id)
(insert (concat "[[id:" orgid "]" "[" title "]]"))))
- (list :body (org-remark-notes-get-body))))))
+ (list :body (org-remark-notes-get-body)
+ :original-text text)))))
(defun org-remark-highlight-load (highlight)
"Load a single HIGHLIGHT to the source buffer.
+
+Return highlight overlay that has been loaded on the source
+buffer.
+
Assume the current buffer is the source buffer."
(let* ((id (plist-get highlight :id))
(location (plist-get highlight :location))
@@ -975,18 +979,27 @@ Assume the current buffer is the source buffer."
(end (cdr location))
(label (plist-get highlight :label))
(ov nil)
- (props (plist-get highlight :props)))
+ (props (plist-get highlight :props))
+ (highlight-text (plist-get props :original-text)))
(let ((fn (intern (concat "org-remark-mark-" label))))
(unless (functionp fn) (setq fn #'org-remark-mark))
(setq ov (funcall fn beg end id :load))
- ;; TODO Generalize the part that updates properties.
- ;; :body should not be the fixed property.
- ;; '(:text (val . fn) :prop1 (val . fn) :prop2 (val .fn))
- ;; (dolist list)
- (unless (overlay-get ov 'help-echo)
- (overlay-put ov 'help-echo (plist-get props :body)))
- (overlay-put ov '*org-remark-note-body
- (plist-get props :body)))))
+ (org-remark-highlight-put-props ov props)
+ ;; Return highlight overlay
+ ov)))
+
+(defun org-remark-highlight-put-props (highlight plist)
+ "Put PLIST from notes Org props to HIGHLIGHT overlay properties."
+ ;; TODO Generalize the part that updates properties.
+ ;; :body should not be the fixed property.
+ ;; '(:text (val . fn) :prop1 (val . fn) :prop2 (val .fn))
+ ;; (dolist list)
+ (unless (overlay-get highlight 'help-echo)
+ (overlay-put highlight 'help-echo (plist-get plist :body)))
+ (overlay-put highlight '*org-remark-note-body
+ (plist-get plist :body))
+ (overlay-put highlight '*org-remark-original-text
+ (plist-get plist :original-text)))
(defun org-remark-highlight-clear (overlay)
"Clear a single highlight OVERLAY.
@@ -1244,14 +1257,22 @@ highlight is a property list in the following
properties:
(end (string-to-number
(org-entry-get (point)
org-remark-prop-source-end)))
- (text (org-remark-notes-get-body)))
+ (body (org-remark-notes-get-body)))
(push (list :id id
:location (cons beg end)
:label (org-entry-get (point)
"org-remark-label")
- :props (list :body text))
+ :props (list
+ :original-text
+ (org-entry-get (point)
"org-remark-original-text")
+ :body body))
highlights))))
highlights))))))
+(defvar org-remark-highlights-after-load-hook nil
+ "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.")
+
(defun org-remark-highlights-load ()
"Visit `org-remark-notes-file' & load the saved highlights onto current
buffer.
If there is no highlights or annotations for current buffer,
@@ -1266,10 +1287,13 @@ Otherwise, do not forget to turn on `org-remark-mode'
manually to
load the highlights"
;; Loop highlights and add them to the current buffer
(let ((notes-buf (find-file-noselect (org-remark-notes-get-file-name)))
- (source-buf (current-buffer)))
- (dolist (highlight (org-remark-highlights-get notes-buf))
- (org-remark-highlight-load highlight))
- (org-remark-notes-setup notes-buf source-buf))
+ (source-buf (current-buffer))
+ (overlays)) ;; highlight overlays
+ (dolist (highlight (org-remark-highlights-get notes-buf) overlays)
+ (push (org-remark-highlight-load highlight) overlays))
+ (org-remark-notes-setup notes-buf source-buf)
+ (run-hook-with-args 'org-remark-highlights-after-load-hook
+ overlays notes-buf))
t)
(defun org-remark-highlights-get-positions (&optional reverse)
- [elpa] externals/org-remark 3c25682d1d 14/67: fix: typo in regression issue, (continued)
- [elpa] externals/org-remark 3c25682d1d 14/67: fix: typo in regression issue, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 97c5f1c8e0 15/67: fix: missing defvar org-remark-source-find-file-name-functions, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark ba8e3433e0 18/67: feat: test/find-nov-file-buffer, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 9f95c8a6f9 22/67: refactor: adjust-positions and sync, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 7bf6359fae 23/67: refactor: remove org-remark-notes-update-source, ELPA Syncer, 2023/07/22
- [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 <=
- [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, 2023/07/22
- [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