Skip to content

Commit

Permalink
Merge pull request weirdNox#32 from org-noter/feature/generalize-file…
Browse files Browse the repository at this point in the history
…-opening-process

Feature/generalize file opening process
  • Loading branch information
dmitrym0 committed Jun 5, 2023
2 parents a274340 + d267c25 commit 1fbf598
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
architecture: 'x64'
- uses: purcell/setup-emacs@master
with:
version: '28.1'
version: '28.2'

- uses: conao3/setup-cask@master
with:
Expand Down
8 changes: 8 additions & 0 deletions org-noter-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ others exist on the current display.'"
:group 'org-noter-insertion
:type 'hook)

(defcustom org-noter-create-session-from-document-hook '(org-noter--create-session-from-document-file-default)
"Hook that is invoked when `org-noter' is invoked from a document."
:group 'org-noter
:type 'hook)

(defcustom org-noter-highlight-selected-text nil
"Highlight selected text when creating notes.
If non-nil, highlight selected-text when creating notes. This
Expand Down Expand Up @@ -1641,6 +1646,9 @@ relative to."
(t (propertize (format " %d notes " number-of-notes) 'face 'org-noter-notes-exist-face))))))

(defun org-noter--check-if-document-is-annotated-on-file (document-path notes-path)
"Check if NOTES-PATH contains any notes that annotate DOCUMENT-PATH.
NOTES-PATH is a path to a notes files.
DOCUMENT-PATH is a path to a document file."
;; NOTE(nox): In order to insert the correct file contents
(let ((buffer (find-buffer-visiting notes-path)))
(when buffer (with-current-buffer buffer (save-buffer)))
Expand Down
2 changes: 1 addition & 1 deletion org-noter-test-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#+TITLE: Test book notes (simple)
* solove-nothing-to-hide
:PROPERTIES:
:NOTER_DOCUMENT: pubs/solove-nothing-to-hide.pdf
:NOTER_DOCUMENT: /tmp/test.pdf
:END:
")

Expand Down
28 changes: 20 additions & 8 deletions org-noter.el
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,39 @@ notes file, even if it finds one."
;; It's not an existing session, create a new session.
(org-noter--create-session ast document-property notes-file-path))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NOTE(nox): Creating the session from the annotated document
;;
;; eg: M-x org-noter from a pdf document
((memq major-mode org-noter-supported-modes)
;; if an org-noter sesseion already exists
(if (org-noter--valid-session org-noter--session)
(progn (org-noter--setup-windows org-noter--session)
(select-frame-set-input-focus (org-noter--session-frame org-noter--session)))
(run-hook-with-args-until-success 'org-noter-create-session-from-document-hook arg buffer-file-name)))))


(defun org-noter--create-session-from-document-file-default (&optional arg document-file-name)
"Create a new org-noter session from an open document file.
This is the default implementation that is called by
`org-noter-create-session-from-document-hook`.
ARG is the prefix argument passed to `org-noter`
DOCUMENT-FILE-NAME is the document filename."
;; NOTE(nox): `buffer-file-truename' is a workaround for modes that delete
;; `buffer-file-name', and may not have the same results
(let* ((buffer-file-name (or (run-hook-with-args-until-success 'org-noter-get-buffer-file-name-hook major-mode)
buffer-file-name))
(document-path (or buffer-file-name buffer-file-truename
;; `document-file-name', and may not have the same results
(let* ((document-file-name (or (run-hook-with-args-until-success 'org-noter-get-buffer-file-name-hook major-mode)
document-file-name))
(document-path (or document-file-name buffer-file-truename
(error "This buffer does not seem to be visiting any file")))
(document-name (file-name-nondirectory document-path))
(document-base (file-name-base document-name))
(document-directory (if buffer-file-name
(file-name-directory buffer-file-name)
(document-directory (if document-file-name
(file-name-directory document-file-name)
(if (file-equal-p document-name buffer-file-truename)
default-directory
(file-name-directory buffer-file-truename))))
;; NOTE(nox): This is the path that is actually going to be used, and should
;; be the same as `buffer-file-name', but is needed for the truename workaround
;; be the same as `document-file-name', but is needed for the truename workaround
(document-used-path (expand-file-name document-name document-directory))

(search-names (remove nil (append org-noter-default-notes-file-names
Expand Down Expand Up @@ -276,7 +288,7 @@ notes file, even if it finds one."
(setq document-location (cons (string-to-number saved-location) 0)))
(let ((org-noter--start-location-override document-location))
(org-noter arg))
(throw 'break t)))))))))))
(throw 'break t))))))))

;;;###autoload
(defun org-noter-start-from-dired ()
Expand Down
11 changes: 11 additions & 0 deletions tests/org-noter-core-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,16 @@



(describe "org-noter basics"
(it "can start org-noter with `org-noter` call"
(with-mock-contents
mock-contents-simple-notes-file
'(lambda ()
;; move to the heading where we're going to invoke org-noter
(search-forward "nothing-to-hide")
(org-noter))))

(it "has org-noter-create-session-from-document hook defined"
(expect org-noter-create-session-from-document-hook :not :to-be nil))
)
)

0 comments on commit 1fbf598

Please sign in to comment.