eaf-interleave: tidy code

master
luhuaei 6 years ago
parent 666fd197f7
commit 49e4b0e161
  1. 154
      app/interleave/eaf-interleave.el

@ -85,7 +85,19 @@ taken as columns."
"Disable narrowing in notes/org buffer." "Disable narrowing in notes/org buffer."
:type 'boolean) :type 'boolean)
;;; Interleave ;; variables
(defvar eaf-interleave-org-buffer nil
"Org notes buffer name.")
(defvar eaf-interleave--window-configuration nil
"Variable to store the window configuration before interleave mode was enabled.")
(defconst eaf-interleave--page-note-prop "interleave_page_note"
"The page note property string.")
(defconst eaf-interleave--url-prop "interleave_url"
"The pdf property string.")
;; Minor mode for the org file buffer containing notes ;; Minor mode for the org file buffer containing notes
(defvar eaf-interleave-mode-map (make-sparse-keymap) (defvar eaf-interleave-mode-map (make-sparse-keymap)
"Keymap while command `eaf-interleave-mode' is active in the org file buffer.") "Keymap while command `eaf-interleave-mode' is active in the org file buffer.")
@ -124,8 +136,6 @@ split horizontally."
(setq eaf-interleave-org-buffer nil) (setq eaf-interleave-org-buffer nil)
)) ))
(defun eaf-interleave--close-all ())
;;; Interleave PDF Mode ;;; Interleave PDF Mode
;; Minor mode for the pdf file buffer associated with the notes ;; Minor mode for the pdf file buffer associated with the notes
(defvar eaf-interleave-pdf-mode-map (make-sparse-keymap) (defvar eaf-interleave-pdf-mode-map (make-sparse-keymap)
@ -137,26 +147,9 @@ split horizontally."
"Interleave view for the pdf." "Interleave view for the pdf."
:keymap eaf-interleave-pdf-mode-map) :keymap eaf-interleave-pdf-mode-map)
;; variables
(defvar eaf-interleave-org-buffer nil
"Org notes buffer name.")
(defvar eaf-interleave--window-configuration nil
"Variable to store the window configuration before interleave mode was enabled.")
(defconst eaf-interleave--page-note-prop "interleave_page_note"
"The page note property string.")
(defconst eaf-interleave--url-prop "interleave_url"
"The pdf property string.")
;; functions
(defun eaf-interleave-add-file-url ()
"Add new url on note if property is none. else modify current url"
(interactive)
(let ((url (read-file-name "Please specify path: " nil nil t)))
(org-entry-put (point) eaf-interleave--url-prop url)))
;;; functions
;; interleave mode
(defun eaf-interleave--select-split-function () (defun eaf-interleave--select-split-function ()
"Determine which split function to use. "Determine which split function to use.
@ -207,44 +200,12 @@ It (possibly) narrows the subtree when found."
(recenter))) (recenter)))
point))) point)))
(defun eaf-interleave-sync-previous-note () (defun eaf-interleave-add-file-url ()
"Move to the previous set of notes. "Add new url on note if property is none. else modify current url"
This show the previous notes and synchronizes the PDF to the right page number."
(interactive)
(eaf-interleave--switch-to-org-buffer)
(widen)
(eaf-interleave--goto-parent-headline eaf-interleave--page-note-prop)
(org-backward-heading-same-level 1)
(eaf-interleave--narrow-to-subtree)
(org-show-subtree)
(org-cycle-hide-drawers t)
(eaf-interleave-sync-current-note))
(defun eaf-interleave-sync-next-note ()
"Move to the next set of notes.
This shows the next notes and synchronizes the PDF to the right page number."
(interactive) (interactive)
(eaf-interleave--switch-to-org-buffer) (let ((url (read-file-name "Please specify path: " nil nil t)))
(widen) (org-entry-put (point) eaf-interleave--url-prop url)))
(org-forward-heading-same-level 1)
(eaf-interleave--narrow-to-subtree)
(org-show-subtree)
(org-cycle-hide-drawers t)
(eaf-interleave-sync-current-note))
(defun eaf-interleave--goto-parent-headline (property)
"Traverse the tree until the parent headline.
Consider a headline with property PROPERTY as parent headline."
(catch 'done
(if (and (eql (org-element-type (org-element-at-point)) 'headline)
(org-entry-get (point) property))
(org-element-at-point)
(condition-case nil
(org-up-element)
('error
(throw 'done nil)))
(eaf-interleave--goto-parent-headline property))))
(defun eaf-interleave--narrow-to-subtree (&optional force) (defun eaf-interleave--narrow-to-subtree (&optional force)
"Narrow buffer to the current subtree. "Narrow buffer to the current subtree.
@ -316,25 +277,6 @@ Return the position of the newly inserted heading."
(org-cycle-hide-drawers t))) (org-cycle-hide-drawers t)))
(eaf-interleave--switch-to-org-buffer t new-note-position))) (eaf-interleave--switch-to-org-buffer t new-note-position)))
(defun eaf-interleave-add-note ()
"Add note for the EAF buffer.
If there are already notes for this url, jump to the notes
buffer."
(interactive)
(cond ((and (derived-mode-p 'eaf-mode)
(equal eaf--buffer-app-name "pdf-viewer"))
(eaf-interleave-pdf-add-note))))
(defun eaf-interleave-pdf-add-note ()
"EAF pdf-viewer-mode add note"
(let* ((page (eaf-interleave--pdf-viewer-current-page eaf--buffer-url))
(position (eaf-interleave--go-to-page-note page)))
(if position
(eaf-interleave--switch-to-org-buffer t position)
(eaf-interleave--create-new-note eaf--buffer-url page)))
)
(defun eaf-interleave-sync-current-note () (defun eaf-interleave-sync-current-note ()
"Sync EAF buffer on current note" "Sync EAF buffer on current note"
(interactive) (interactive)
@ -359,6 +301,64 @@ buffer."
(eaf-interleave--open-pdf pdf-url) (eaf-interleave--open-pdf pdf-url)
))) )))
(defun eaf-interleave-sync-previous-note ()
"Move to the previous set of notes.
This show the previous notes and synchronizes the PDF to the right page number."
(interactive)
(eaf-interleave--switch-to-org-buffer)
(widen)
(eaf-interleave--goto-parent-headline eaf-interleave--page-note-prop)
(org-backward-heading-same-level 1)
(eaf-interleave--narrow-to-subtree)
(org-show-subtree)
(org-cycle-hide-drawers t)
(eaf-interleave-sync-current-note))
(defun eaf-interleave--goto-parent-headline (property)
"Traverse the tree until the parent headline.
Consider a headline with property PROPERTY as parent headline."
(catch 'done
(if (and (eql (org-element-type (org-element-at-point)) 'headline)
(org-entry-get (point) property))
(org-element-at-point)
(condition-case nil
(org-up-element)
('error
(throw 'done nil)))
(eaf-interleave--goto-parent-headline property))))
(defun eaf-interleave-sync-next-note ()
"Move to the next set of notes.
This shows the next notes and synchronizes the PDF to the right page number."
(interactive)
(eaf-interleave--switch-to-org-buffer)
(widen)
(org-forward-heading-same-level 1)
(eaf-interleave--narrow-to-subtree)
(org-show-subtree)
(org-cycle-hide-drawers t)
(eaf-interleave-sync-current-note))
(defun eaf-interleave-add-note ()
"Add note for the EAF buffer.
If there are already notes for this url, jump to the notes
buffer."
(interactive)
(cond ((and (derived-mode-p 'eaf-mode)
(equal eaf--buffer-app-name "pdf-viewer"))
(eaf-interleave-pdf-add-note))))
(defun eaf-interleave-pdf-add-note ()
"EAF pdf-viewer-mode add note"
(let* ((page (eaf-interleave--pdf-viewer-current-page eaf--buffer-url))
(position (eaf-interleave--go-to-page-note page)))
(if position
(eaf-interleave--switch-to-org-buffer t position)
(eaf-interleave--create-new-note eaf--buffer-url page)))
)
;;;###autoload ;;;###autoload
(defun eaf-interleave-open-notes-file-for-pdf () (defun eaf-interleave-open-notes-file-for-pdf ()
"Open the notes org file for the current pdf file if it exists. "Open the notes org file for the current pdf file if it exists.

Loading…
Cancel
Save