branch: externals/org-remark
commit 193fe279ea3c7943cd441e41f5ccf55db8d35e2c
Author: Noboru Ota <m...@nobiot.com>
Commit: Noboru Ota <m...@nobiot.com>

    feat(line):add line-number as a property to the highlight headline
    
    This commit also adds the facility (abnormal hook) for future
    extensions.
---
 org-remark-line.el | 13 ++++++++++++-
 org-remark.el      | 23 ++++++++++++++++++++---
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/org-remark-line.el b/org-remark-line.el
index 9d8403de56..ff57efa8fe 100644
--- a/org-remark-line.el
+++ b/org-remark-line.el
@@ -5,7 +5,7 @@
 ;; Author: Noboru Ota <m...@nobiot.com>
 ;; URL: https://github.com/nobiot/org-remark
 ;; Created: 01 August 2023
-;; Last modified: 19 August 2023
+;; Last modified: 20 August 2023
 ;; Package-Requires: ((emacs "27.1") (org "9.4"))
 ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp
 
@@ -130,6 +130,8 @@ in cons cell (or nil) before function
         ;; Need to reload to cater to margin changes done by `olivetti'.
         (add-hook 'window-size-change-functions
                   #'org-remark-line-highlights-redraw 96 :local)
+        (add-hook 'org-remark-highlight-other-props-functions
+                  #'org-remark-line-prop-line-number-get)
         (org-remark-line-set-window-margins))
     ;; Disable
     (remove-hook 'org-remark-find-dwim-functions #'org-remark-line-find :local)
@@ -137,6 +139,8 @@ in cons cell (or nil) before function
                  #'org-remark-line-set-window-margins :local)
     (remove-hook 'window-size-change-functions
                  #'org-remark-line-highlights-redraw :local)
+    (remove-hook 'org-remark-highlight-other-props-functions
+                 #'org-remark-line-prop-line-number-get)
     (when org-remark-line-margins-set-p
       (setq left-margin-width (car org-remark-line-margins-original))
       (setq right-margin-width (cdr org-remark-line-margins-original))
@@ -210,6 +214,13 @@ by `overlays-in'."
          (highlights (overlays-in bol bol)))
     (seq-find #'org-remark-line-highlight-p highlights)))
 
+(defun org-remark-line-prop-line-number-get (highlight)
+  "Return the line number for HIGHLIGHT overlay.
+This happens only when HIGHLIGHT is a line-highlight."
+  (when (org-remark-line-highlight-p highlight)
+    (list 'org-remark-line-number
+          (number-to-string (org-current-line (overlay-start highlight))))))
+
 (cl-defmethod org-remark-beg-end ((_org-remark-type (eql 'line)))
     (let ((bol (org-remark-line-pos-bol (point))))
       (list bol bol)))
diff --git a/org-remark.el b/org-remark.el
index 03d0228e83..75ff21e08a 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: 18 August 2023
+;; Last modified: 20 August 2023
 ;; Package-Requires: ((emacs "27.1") (org "9.4"))
 ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp,
 
@@ -1056,6 +1056,21 @@ buffer for automatic sync."
    "\n" " "
    (buffer-substring-no-properties (overlay-start ov) (overlay-end ov))))
 
+(defvar org-remark-highlight-other-props-functions nil
+  "Abnormal hook to be run when adding or updating headline.
+It is called with one argument HIGHLIGHT, which is the overlay
+that represents the current highlight being worked on. The
+function is run with source buffer as the current buffer.")
+
+(defun org-remark-highlight-collect-other-props (highlight)
+  "
+Assume to be run in the source buffer."
+  (let ((props nil))
+    (dolist (fn org-remark-highlight-other-props-functions props)
+      (let ((plist (funcall fn highlight)))
+        (when plist
+          (setq props (append props plist)))))))
+
 (defun org-remark-highlight-add-or-update-highlight-headline (highlight 
source-buf notes-buf)
   "Add a new HIGHLIGHT headlne to the NOTES-BUF or update it.
 Return notes-props as a property list.
@@ -1079,11 +1094,13 @@ beginning of source-headline, which should be one level 
up."
                       (org-remark-source-find-file-name))
             link (run-hook-with-args-until-success
                   'org-remark-highlight-link-to-source-functions filename beg)
-            orgid (org-remark-highlight-get-org-id beg))
+            orgid (org-remark-highlight-get-org-id beg)
+            other-props (org-remark-highlight-collect-other-props highlight))
       ;; TODO ugly to add the beg end after setq above
       (plist-put props org-remark-prop-source-beg (number-to-string beg))
       (plist-put props org-remark-prop-source-end (number-to-string end))
-      (when link (plist-put props "org-remark-link" link)))
+      (when link (plist-put props "org-remark-link" link))
+      (when other-props (setq props (append props other-props))))
     ;;; Make it explicit that we are now in the notes-buf, though it is
     ;;; functionally redundant.
     (with-current-buffer notes-buf

Reply via email to