[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark aa58058ec4 38/67: refactor: add-headlines (W
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark aa58058ec4 38/67: refactor: add-headlines (WIP) |
Date: |
Sat, 22 Jul 2023 06:59:03 -0400 (EDT) |
branch: externals/org-remark
commit aa58058ec496ab521ff74164cb4445a0a40e984c
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
refactor: add-headlines (WIP)
---
org-remark-nov.el | 174 +++++++++++++++++++++++++++++++++++-------------------
1 file changed, 112 insertions(+), 62 deletions(-)
diff --git a/org-remark-nov.el b/org-remark-nov.el
index 07cc8e69e5..002f91a358 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: 24 June 2023
+;; Last modified: 04 July 2023
;;; Commentary:
@@ -33,12 +33,15 @@
;; 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-to-list 'org-remark-notes-headline-functions
+ ;; '(nov-mode . ((1 .
org-remark-nov-highlight-add-book-headline-maybe)
+ ;; (2 .
org-remark-nov-add-source-headline-maybe))))
(add-to-list 'org-remark-notes-headline-functions
- '(nov-mode . ((1 .
org-remark-nov-highlight-add-book-headline-maybe)
- (2 .
org-remark-nov-add-source-headline-maybe)))))
+ '(nov-mode . ((1 .
test/org-remark-nov-highlight-headlines))))
+ )
;; Disable
(remove-hook 'org-remark-source-find-file-name-functions
- #'org-remark-get-epub-filename)
+ #'org-remark-get-epub-source)
(remove-hook 'org-remark-highlight-link-to-source-functions
#'org-remark-nov-link)
(remove-hook 'org-remark-highlight-link-to-source-functions
@@ -84,16 +87,13 @@
(defun org-remark-nov-get-epub-document-title ()
"Return the path of the epub source from which the present session is
initiated."
(when (eq major-mode 'nov-mode)
- (let ((document-info-pair (aref nov-documents nov-documents-index)))
- (concat
- (symbol-name (car document-info-pair)) ;; id
- "/"
- (file-name-base (cdr document-info-pair)))))) ;; temp file
+ (let ((temp-filename (cdr (aref nov-documents nov-documents-index))))
+ (file-name-base temp-filename))))
-(defun org-remark-get-epub-filename ()
- "Return the path of the epub source from which the present session is
initiated."
- (when (eq major-mode 'nov-mode)
- nov-file-name))
+;; (defun org-remark-get-epub-filename ()
+;; "Return the path of the epub source from which the present session is
initiated."
+;; (when (eq major-mode 'nov-mode)
+;; nov-file-name))
(defun org-remark-nov-link (_filname _point)
"Return \"nov:\" link with current point in `nov-mode' buffer.
@@ -105,55 +105,105 @@ buffer."
(when (eq major-mode 'nov-mode)
(org-store-link nil)))
-(defun org-remark-nov-highlight-add-book-headline-maybe (level source-buf
notes-buf)
- "Add a book headline if not present in NOTES-BUF for epub file.
-Return the point of beginning of book headline regardless of it
-being newly added or already present.
-
-LEVEL is the headline level when one is to be added.
-
-SOURCE-BUF is a `nov-mode' buffer visiting a document within an
-epub file.
-
-Assume the current buffer is NOTES-BUF."
- (let (filename title)
- (with-current-buffer source-buf
- ;; The nov variables are only locally set in the source buffer.
- (setq filename nov-file-name
- title (cdr (assoc 'title nov-metadata))))
- ;; Back in the notes buffer, return the point of the beginning of
- ;; the headline
- (with-current-buffer notes-buf
- (or (org-find-property "org-remark-nov-file" filename)
- (progn
- ;; If the book entry does not exist, create one at the bottom of
notes buffer
- (goto-char (point-max))
- ;; Ensure to be in the beginning of line to add a new headline
- (when (eolp) (open-line 1) (forward-line 1) (beginning-of-line))
- (insert-char (string-to-char "*") level)
- ;; Title is assumed to present but the program won't fail even if
it is nil.
- (insert (concat " " title "\n"))
- (org-set-property "org-remark-nov-file" filename)
- (org-back-to-heading) (point))))))
-
-(defun org-remark-nov-add-source-headline-maybe (level source-buf notes-buf)
- "Add a new source headline if not yet present in NOTES-BUF.
-Return the point of beginning of source headline regardless of it
-being newly added or already present.
-
-SOURCE-BUF is the source buffer that contains highlights.
-
-Assume the current buffer is NOTES-BUF."
- (let (source-name title)
- (with-current-buffer source-buf
- (setq source-name (org-remark-get-epub-source))
- (setq title (org-remark-nov-get-epub-document-title)))
- (with-current-buffer notes-buf
- ;; Return the beginning point of the headline. Create if not present
- (or (org-find-property
- org-remark-prop-source-file source-name)
- (org-remark-new-headline
- level title (list org-remark-prop-source-file source-name))))))
+(defun test/org-remark-nov-highlight-headlines (_level source-buf notes-buf)
+ (org-remark-nov-highlight-new-headline-maybe source-buf notes-buf))
+
+(defun org-remark-nov-highlight-new-headline-maybe (source-buf notes-buf)
+ (let* ((headline-1 (list 1
+ (lambda () nov-file-name)
+ (lambda () (cdr (assoc 'title nov-metadata)))
+ "org-remark-nov-file"))
+ (headline-2 (list 2
+ #'org-remark-get-epub-source
+ #'org-remark-nov-get-epub-document-title
+ org-remark-prop-source-file))
+ (headline-constructs (list headline-1 headline-2)))
+ (org-remark-highlight-new-headline-maybe headline-constructs source-buf
notes-buf)))
+
+;; (defun org-remark-highlight-new-headline-maybe (headline-constructs
source-buf notes-buf)
+;; "'((1 filename-fn title-fn prop-to-find)
+;; (2 filename-fn title-fn prop-to-find))"
+;; (dolist (headline headline-constructs point)
+;; (let ((level (nth 0 headline))
+;; (filename-fn (nth 1 headline))
+;; (title-fn (nth 2 headline))
+;; (prop-to-find (nth 3 headline))
+;; (filename nil)
+;; (title nil))
+;; (with-current-buffer source-buf
+;; (setq filename (funcall filename-fn))
+;; (setq title (funcall title-fn)))
+;; (with-current-buffer notes-buf
+;; ;; We need to return the point to outside the dolist loop.
+;; ;; and return from this function.
+;; (setq point
+;; (or (org-find-property
+;; prop-to-find filename)
+;; (org-remark-new-headline
+;; level title (list prop-to-find filename))))))))
+
+(defun org-remark-highlight-new-headline-maybe (headline-constructs source-buf
notes-buf)
+ "'((1 filename-fn title-fn prop-to-find)
+ (2 filename-fn title-fn prop-to-find))"
+ (cl-loop for (level filename-fn title-fn prop-to-find) in headline-constructs
+ ;; This variable "point" is set in order to be returned at
+ ;; the end of the loop.
+ with point = nil
+ do (let (filename title)
+ (with-current-buffer source-buf
+ (setq filename (funcall filename-fn))
+ (setq title (funcall title-fn)))
+ (with-current-buffer notes-buf
+ (setq point
+ (or (org-find-property
+ prop-to-find filename)
+ (org-remark-new-headline
+ level title (list prop-to-find filename))))))
+ ;; Need to return the point at the end of the loop.
+ finally return point))
+
+;; (defun org-remark-nov-highlight-add-book-headline-maybe (level source-buf
notes-buf)
+;; "Add a book headline if not present in NOTES-BUF for epub file.
+;; Return the point of beginning of book headline regardless of it
+;; being newly added or already present.
+
+;; LEVEL is the headline level qwhen one is to be added.
+
+;; SOURCE-BUF is a `nov-mode' buffer visiting a document within an
+;; epub file.
+
+;; Assume the current buffer is NOTES-BUF."
+;; (let (filename title)
+;; (with-current-buffer source-buf
+;; ;; The nov variables are only locally set in the source buffer.
+;; (setq filename nov-file-name)
+;; (setq title (cdr (assoc 'title nov-metadata))))
+;; ;; Back in the notes buffer, return the point of the beginning of
+;; ;; the headline
+;; (with-current-buffer notes-buf
+;; (or (org-find-property
+;; "org-remark-nov-file" filename)
+;; (org-remark-new-headline
+;; level title (list "org-remark-nov-file" filename))))))
+
+;; (defun org-remark-nov-add-source-headline-maybe (level source-buf notes-buf)
+;; "Add a new source headline if not yet present in NOTES-BUF.
+;; Return the point of beginning of source headline regardless of it
+;; being newly added or already present.
+
+;; SOURCE-BUF is the source buffer that contains highlights.
+
+;; Assume the current buffer is NOTES-BUF."
+;; (let (source-name title)
+;; (with-current-buffer source-buf
+;; (setq source-name (org-remark-get-epub-source))
+;; (setq title (org-remark-nov-get-epub-document-title)))
+;; (with-current-buffer notes-buf
+;; ;; Return the beginning point of the headline. Create if not present
+;; (or (org-find-property
+;; org-remark-prop-source-file source-name)
+;; (org-remark-new-headline
+;; level title (list org-remark-prop-source-file source-name))))))
;; navigate from notes to document
(defun test/find-nov-file-buffer ()
- [elpa] externals/org-remark 642d4b489f 13/67: docs: updated NEWS, (continued)
- [elpa] externals/org-remark 642d4b489f 13/67: docs: updated NEWS, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 2a10b3d75a 17/67: refactor: adjust-positions, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 09d95e7519 20/67: Merge branch 'main' into dev/nov.el, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 52bc575bb9 28/67: docs: comments and docstring, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark e10a00b426 35/67: feat: add icon for highlights with annotation body text #64, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 41f90c53a8 59/67: refactor: Add 'org-remark-string=' for highlight-adjust-positions, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 2bd53de493 60/67: refactor: Set fn to hook org-remark-highlights-after-load-functions, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark e1b7a3a1ba 19/67: Merge remote-tracking branch 'sati-bodhi/main' into dev/nov.el, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 090156bed2 21/67: feat: org-remark-nov-mode minor mode, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark ef7e02d542 34/67: fix: annotation body to be nil when no body text, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark aa58058ec4 38/67: refactor: add-headlines (WIP),
ELPA Syncer <=
- [elpa] externals/org-remark c38f46e806 42/67: refactor(highlight-add): remove spurflous/obsolete elements, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark b94c64e381 45/67: feature: Make icons customizable, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark f1ea78bcf1 47/67: refactor: highlight-add, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark f21ab48aad 62/67: refactor: simple name replace org-remark-get-epub-source, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 160de610f8 64/67: fix: make sure new top-level headline is appended, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark fea8103b9b 65/67: fix(legacy): compilation warning #66, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 32149d5135 25/67: fix: Exclude pdfs from default file type #57, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 14996bc1ce 30/67: refactor: notes-set-properties & new-headline, ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 356c87468a 31/67: feature(nov) find-source and link correctly (WIP), ELPA Syncer, 2023/07/22
- [elpa] externals/org-remark 0d4902f9eb 43/67: docs: flymake, ELPA Syncer, 2023/07/22