Add functions to create notes while reading ebooks
This commit is contained in:
parent
cbaeffe3a1
commit
9b147ad6af
1 changed files with 60 additions and 2 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||||
;; Keywords: local
|
;; Keywords: local
|
||||||
;; Version: 2020.0420.220918
|
;; Version: 2020.0511.001009
|
||||||
;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org-plus-contrib org-bullets org-edna diminish all-the-icons)
|
;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org-plus-contrib org-bullets org-edna diminish all-the-icons)
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -231,8 +231,63 @@ _l_: Store link ^^ _j_: Journal entry
|
||||||
("documents/gtd/books.org" :maxlevel . 1)
|
("documents/gtd/books.org" :maxlevel . 1)
|
||||||
("documents/gtd/bookmarks.org" :maxlevel . 2))))
|
("documents/gtd/bookmarks.org" :maxlevel . 2))))
|
||||||
|
|
||||||
|
(defun oni-org-find-heading-in-file (heading file &optional move)
|
||||||
|
"Try to find HEADING somewhere in FILE.
|
||||||
|
This function returns nil if HEADING couldn’t be found, and the
|
||||||
|
position where the chapter starts otherwise. If MOVE is non-nil
|
||||||
|
also move point to the start of the heading."
|
||||||
|
(let ((buffer (find-file-noselect file)))
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(save-excursion
|
||||||
|
(goto-char (point-min))
|
||||||
|
(org-find-exact-headline-in-buffer heading buffer (not move))))))
|
||||||
|
|
||||||
|
(defun oni-org-create-book-heading (book-title file)
|
||||||
|
"Create a new heading for BOOK-TITLE in FILE."
|
||||||
|
(let ((buffer (find-file file)))
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(goto-char (point-max))
|
||||||
|
(insert "\n* " book-title "\n\n "))))
|
||||||
|
|
||||||
|
(defun oni-org-create-chapter-heading (book-title chapter-title file)
|
||||||
|
"Create a new heading under BOOK-TITLE for CHAPTER-TITLE in FILE."
|
||||||
|
(let ((buffer (find-file file)))
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(goto-char (point-min))
|
||||||
|
(goto-char (oni-org-find-heading-in-file book-title file t))
|
||||||
|
(goto-char (org-element-property :end (org-element-at-point)))
|
||||||
|
(unless (= (point) (point-max))
|
||||||
|
(open-line 2))
|
||||||
|
(insert "\n** " chapter-title "\n\n "))))
|
||||||
|
|
||||||
|
(defun oni-org-create-chapter-section (chapter-title file)
|
||||||
|
"Create a new notes section under CHAPTER-TITLE in FILE."
|
||||||
|
(let ((buffer (find-file file)))
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(goto-char (point-min))
|
||||||
|
(goto-char (oni-org-find-heading-in-file chapter-title file t))
|
||||||
|
(goto-char (org-element-property :contents-end (org-element-at-point)))
|
||||||
|
(insert "\n"))))
|
||||||
|
|
||||||
|
(defun oni-org-reading-note ()
|
||||||
|
"Find the org-header associated with the current chapter or page."
|
||||||
|
(let* ((headers (split-string (format-mode-line header-line-format) ":" t " "))
|
||||||
|
(book-name (car headers))
|
||||||
|
(chapter-name (cadr headers))
|
||||||
|
(notes-file (oni-org-expand-to-home "documents/gtd/reading-notes.org"))
|
||||||
|
(chapter-start (oni-org-find-heading-in-file chapter-name notes-file)))
|
||||||
|
(if (not chapter-start)
|
||||||
|
(let ((book-start (oni-org-find-heading-in-file book-name notes-file)))
|
||||||
|
(unless book-start
|
||||||
|
(oni-org-create-book-heading book-name notes-file))
|
||||||
|
(oni-org-create-chapter-heading book-name chapter-name notes-file))
|
||||||
|
(oni-org-create-chapter-section chapter-name notes-file))))
|
||||||
|
|
||||||
|
(setq org-capture-templates-contexts
|
||||||
|
'(("n" ((in-mode . "nov-mode")))))
|
||||||
|
|
||||||
(setq org-capture-templates
|
(setq org-capture-templates
|
||||||
`(("t" "Note" entry
|
`(("t" "Task" entry
|
||||||
(file ,(oni-org-expand-to-home "documents/gtd/inbox.org"))
|
(file ,(oni-org-expand-to-home "documents/gtd/inbox.org"))
|
||||||
"* TODO %i%?\n :PROPERTIES:\n :CREATED: %U\n :END:")
|
"* TODO %i%?\n :PROPERTIES:\n :CREATED: %U\n :END:")
|
||||||
("a" "Appointment" entry
|
("a" "Appointment" entry
|
||||||
|
@ -243,6 +298,9 @@ _l_: Store link ^^ _j_: Journal entry
|
||||||
(file+olp+datetree
|
(file+olp+datetree
|
||||||
,(oni-org-expand-to-home "documents/gtd/journal.org"))
|
,(oni-org-expand-to-home "documents/gtd/journal.org"))
|
||||||
"* %<%H:%M:%S>\n %?")
|
"* %<%H:%M:%S>\n %?")
|
||||||
|
("n" "Reading note" item (function oni-org-reading-note)
|
||||||
|
"%?\n\n#+begin_quote\n%i\n#+end_quote"
|
||||||
|
:empty-lines 1)
|
||||||
("c" "Add to currently clocked item")
|
("c" "Add to currently clocked item")
|
||||||
("ca" "Note" plain
|
("ca" "Note" plain
|
||||||
(clock)
|
(clock)
|
||||||
|
|
Loading…
Reference in a new issue