branch: externals/org-remark commit d606d80a47f9cbbd1619ed795d8de9f8d67f5f33 Author: Noboru Ota <m...@nobiot.com> Commit: Noboru Ota <m...@nobiot.com>
refactor: move highlights-delay-load to org-remark.el --- org-remark-line.el | 27 +++++++++++++++------------ org-remark.el | 33 +++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/org-remark-line.el b/org-remark-line.el index 9bd028d753..25abebd909 100644 --- a/org-remark-line.el +++ b/org-remark-line.el @@ -97,10 +97,12 @@ marginal area does not exist, its width will be returned as nil." ;; (funcall fn)) ;; (setq org-remark-line-delayed-put-overlay-functions nil)) (cl-destructuring-bind (left-width . right-width) (window-margins) + ;; TODO make this part compatible with right margin (if (or (eq left-width nil) (< left-width org-remark-line-minimum-margin-width)) (progn - (setq left-margin-width org-remark-line-minimum-margin-width)) + (setq left-margin-width org-remark-line-minimum-margin-width) + (setq right-margin-width org-remark-line-minimum-margin-width)) (setq left-margin-width left-width) (setq right-margin-width right-width)) (set-window-buffer (get-buffer-window) (current-buffer) 'keep-margins) @@ -147,22 +149,23 @@ Return OV" (org-remark-line-highlight-overlay-put beg end face) ;; window is still not created and assigned to the current buffer. ;; Reload when it is. - (add-hook 'window-state-change-functions #'org-remark-line-reload 95 'local) + ;; (add-hook 'window-state-change-functions #'org-remark-line-reload 95 'local) ;;(push (lambda () ;; (org-remark-line-highlight-overlay-put beg end face)) ;; org-remark-line-delayed-put-overlay-functions) nil)) -(defun org-remark-line-reload (window) - (when (windowp window) - (remove-hook 'window-state-change-functions - #'org-remark-line-reload 'local) - (org-remark-highlights-load))) +;; (defun org-remark-line-reload (window) +;; (when (windowp window) +;; (remove-hook 'window-state-change-functions +;; #'org-remark-line-reload 'local) +;; (org-remark-highlights-load))) (defun org-remark-line-highlight-overlay-put (beg end face &optional string) ;;(when (or (car (window-margins)) (cdr (window-margins))) (let* ((face (or face 'org-remark-line-highlighter)) ;; We need to be sure where the minimum-margin-width is set to the buffer + ;; TODO rigth margin (left-margin (or (car (window-margins)) left-margin-width)) (string (or string (with-temp-buffer ;;(insert-char ?\s spaces) @@ -243,11 +246,11 @@ end of overlay being identical." ;; always follow the point, keeping the original place unless you ;; directly change the notes. That's not really an intutive behaviour, ;; though in some cases, it imay be useful. - (if (not (overlay-start ov)) (delete-overlay ov) - (let* ((ov-start (overlay-start ov)) - (ov-line-bol (org-remark-line-pos-bol ov-start))) - (unless (= ov-start ov-line-bol) - (move-overlay ov ov-line-bol ov-line-bol))))) + ;; (if (not (overlay-start ov)) (delete-overlay ov) + (let* ((ov-start (overlay-start ov)) + (ov-line-bol (org-remark-line-pos-bol ov-start))) + (unless (= ov-start ov-line-bol) + (move-overlay ov ov-line-bol ov-line-bol)))) (defun org-remark-line-icon-overlay-put (ov icon-string) ;; If the icon-string has a display properties, assume it is an icon image diff --git a/org-remark.el b/org-remark.el index 65470522ad..34f7855a33 100644 --- a/org-remark.el +++ b/org-remark.el @@ -862,6 +862,10 @@ round-trip back to the notes file." (if (not filename) (message (format "org-remark: Highlights not saved.\ This buffer (%s) is not supported" (symbol-name major-mode))) + ;; OV may not be created for line-highlights when the user opens + ;; the buffer for the first time, as the window may not have been + ;; created to display the buffer yet. This is necessary for the + ;; margin width to be calculated. (when ov (while properties (let ((prop (pop properties)) @@ -1471,6 +1475,13 @@ highlight is a property list in the following properties: highlights))))) highlights)))))) +(defun org-remark-highlights-delay-load (window) + "Delay load until window for current buffer is created." + (when (windowp window) + (remove-hook 'window-state-change-functions + #'org-remark-highlights-delay-load 'local) + (org-remark-highlights-load))) + ;;;###autoload (defun org-remark-highlights-load (&optional update) "Visit notes file & load the saved highlights onto current buffer. @@ -1479,16 +1490,15 @@ output a message in the echo. Non-nil value for UPDATE is passed for the notes-source sync process." - ;; Some major modes such as nov.el reuse the current buffer, deleting - ;; the buffer content and insert a different file's content. In this - ;; case, obsolete highlight overlays linger when you switch from one - ;; file to another. Thus, in order to update the highlight overlays we - ;; need to begin loading by clearing them first. This way, we avoid - ;; duplicate of the same highlight. (if (not (get-buffer-window)) - ;;(not (or (car (window-margins)) (cdr (window-margins))))) - ;; TODO - (add-hook 'window-state-change-functions #'org-remark-line-reload 95 'local) + (add-hook 'window-state-change-functions + #'org-remark-highlights-delay-load 95 'local) + ;; Some major modes such as nov.el reuse the current buffer, deleting + ;; the buffer content and insert a different file's content. In this + ;; case, obsolete highlight overlays linger when you switch from one + ;; file to another. Thus, in order to update the highlight overlays we + ;; need to begin loading by clearing them first. This way, we avoid + ;; duplicate of the same highlight. (org-remark-highlights-clear) ;; Loop highlights and add them to the current buffer (let (overlays) ;; highlight overlays @@ -1502,10 +1512,9 @@ process." ;; Load highlights with demoted errors -- this makes the loading ;; robust against errors in loading. (dolist (highlight (org-remark-highlights-get notes-buf)) - (push (org-remark-highlight-load highlight) overlays)) + (let ((ov (org-remark-highlight-load highlight))) + (when ov (push ov overlays)))) (unless update (org-remark-notes-setup notes-buf source-buf)) - ;; remove nil - (setq overlays (cl-remove-if nil overlays)) (if overlays (progn (run-hook-with-args 'org-remark-highlights-after-load-functions overlays notes-buf)