[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark 9f95c8a6f9 22/67: refactor: adjust-positions
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark 9f95c8a6f9 22/67: refactor: adjust-positions and sync |
Date: |
Sat, 22 Jul 2023 06:59:01 -0400 (EDT) |
branch: externals/org-remark
commit 9f95c8a6f95b54b84786cd41946a3208476ee6f0
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
refactor: adjust-positions and sync
---
org-remark.el | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 46 insertions(+), 3 deletions(-)
diff --git a/org-remark.el b/org-remark.el
index f9b1f98383..6e194bf759 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -1008,6 +1008,34 @@ It is a utility function to take care of both
(setq org-remark-highlights (delete overlay org-remark-highlights))
(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."
+ ;; Load works. but need one for sync. Need to re-think
+ ;; ' and ’ are different in regex of course.
+
+ ;; 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".
+ (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)
+ ;; Look at one paragraph ahead as it is possible that the
+ ;; position has been displaced across a paragraph
+ (goto-char beg) (backward-paragraph 2) (setq paragraph-beg (point))
+ (goto-char beg) (forward-paragraph 2) (setq paragraph-end (point))
+ (goto-char paragraph-beg)
+ ;; Search from the beginning of the previous paragraph to the end
+ ;; of next paragraph relative to the begining 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)))))))
+
;;;;; org-remark-notes
;; Private functions that work on marginal notes buffer (notes
@@ -1176,9 +1204,10 @@ base-buffer of the notes and not to the indirect buffer."
"Update SOURCE-BUFFER with marginal notes properties.
This function assumes the current buffer is one visiting the
notes file (indrect or base)."
- (let ((notes-buf (current-buffer)))
+ (let ((notes-buf (current-buffer))
+ (overlays)) ;; highlight overlays
(with-current-buffer source-buffer
- (dolist (highlight (org-remark-highlights-get notes-buf))
+ (dolist (highlight (org-remark-highlights-get notes-buf) overlays)
(let* ((location (plist-get highlight :location))
(beg (car location))
(end (cdr location))
@@ -1194,7 +1223,12 @@ notes file (indrect or base)."
;; completely new location where the old location does not
;; overlap with the new location at all.
(when ov (org-remark-highlight-clear ov))
- (org-remark-highlight-load highlight))))))
+ (push (org-remark-highlight-load highlight) overlays)))
+ ;; TODO This function is pretty much the same as
+ ;; `org-remark-highlights-load'. Refactor into one?
+ (run-hook-with-args 'org-remark-highlights-after-load-hook
+ overlays notes-buf))
+ t))
(defun org-remark-notes-sync-with-source ()
"Update sources from the current notes buffer.
@@ -1414,6 +1448,15 @@ Case 2. The overlay points to no buffer
(setq org-remark-highlights (delete ov org-remark-highlights))))
t)
+(defun org-remark-highlights-adjust-positions (overlays _notes-buf)
+ "
+Meant to be set to `org-remark-highlights-after-load-hook' by
+mode-specific extensions."
+ (dolist (ov overlays)
+ (let ((highlight-text (overlay-get ov '*org-remark-original-text)))
+ (when highlight-text (org-remark-highlight-adjust-position-after-load
+ ov highlight-text)))))
+
;;;;; Other utilities
(defun org-remark-source-get-file-name (filename)
- [elpa] externals/org-remark 883d0018fe 08/67: fix(save): source-setup-done needs to be done in source, (continued)
- [elpa] externals/org-remark 883d0018fe 08/67: fix(save): source-setup-done needs to be done in source, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 02f2ca5c7c 12/67: fix: Text cut off if the highlight spans across two lines #56, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark a2fcae8d5b 03/67: refactor(mark): save notes buf only when create/change, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark b2e0b37247 04/67: refactor(save): -highlight-save function, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 3f71f58603 05/67: feat: dynamic notes headline level - WIP with test code, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark b2d2d432dd 06/67: feat(save): per-mode options for -notes-create-entry-functions WIP, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 8e067b1813 11/67: refactor(save): -highlight-save -> -highlight-add, ELPA Syncer, 2023/07/22
- [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 <=
- [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, 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