Skip to content

Commit

Permalink
(feat,fix) save/export scrapper buffers
Browse files Browse the repository at this point in the history
- remap `save-buffer` to new function `orb-pdf-scrapper-save`
- remap `write-file` to new function `orb-pdf-scrapper-save-as`
These functions handle "fileless" Scrapper buffers correctly

- fix a bug where the buffer would master xml file name would after cancelling
- switch to Scrapper buffer when pressing 'n' in prevent-concurrent dialog
  • Loading branch information
myshevchuk committed Dec 9, 2020
1 parent c002d63 commit 1b83f1f
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions orb-pdf-scrapper.el
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@ process."
(defvar orb-pdf-scrapper-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-k" #'orb-pdf-scrapper-kill)
(define-key map [remap save-buffer] #'orb-pdf-scrapper-save)
(define-key map [remap write-file] #'orb-pdf-scrapper-save-as)
map)
"Keymap for `orb-pdf-scrapper-mode' minor mode.
The keymap is updated automatically according to the Orb PDF
Expand Down Expand Up @@ -1067,7 +1069,9 @@ Kill it and start a new one %s? "
(orb--with-message! "Killing current process"
(orb-pdf-scrapper--cleanup))
(orb-pdf-scrapper-run (orb-pdf-scrapper--get :new-key)))
;; Do nothing
;; go to the Scrapper buffer
(pop-to-buffer orb-pdf-scrapper--buffer)
;; reset the concurring flag set by `orb-pdf-scrapper-run'
(orb-pdf-scrapper--put :prevent-concurring nil))
;; Finilize the requested context otherwise
(cl-case callee
Expand Down Expand Up @@ -1114,7 +1118,8 @@ Kill it and start a new one %s? "
(orb-pdf-scrapper-dispatcher 'edit-bib 'continue))
('edit-xml
(when-let ((master-backup (orb-pdf-scrapper--get :master-backup)))
(rename-file master-backup orb-anystyle-parser-training-set t))
(rename-file master-backup orb-anystyle-parser-training-set t)
(setq buffer-file-name nil))
(orb-pdf-scrapper-dispatcher (orb-pdf-scrapper--get :callee) 'continue))
(t
(orb-pdf-scrapper-dispatcher 'error))))
Expand All @@ -1126,6 +1131,35 @@ Kill it and start a new one %s? "
(kill-process process))
(orb-pdf-scrapper-dispatcher 'kill))

(defun orb-pdf-scrapper-save ()
"Save current ORB PDF Scrapper buffer in the respective temp file.
This command shadows `save-buffer' when `orb-pdf-scrapper-mode' is active."
(interactive)
(let ((temp-file
(cl-case (orb-pdf-scrapper--get :caller)
('edit-txt (orb-pdf-scrapper--get :temp-txt))
('edit-bib (orb-pdf-scrapper--get :temp-bib))
('edit-org (orb-pdf-scrapper--get :temp-org))
('edit-xml (orb-pdf-scrapper--get :temp-xml))
(t nil)))) ; fallback flag
(cond
;; ORB PDF Scrapper buffers do not have file names
((and (not buffer-file-name) temp-file)
(write-region (orb-buffer-string) nil temp-file nil -1)
(set-buffer-modified-p nil))
((save-buffer)))))

(defun orb-pdf-scrapper-save-as ()
"Export current ORB PDF Scrapper buffer to a file.
This command shadows `write-file' when `orb-pdf-scrapper-mode' is active."
(interactive)
;; ORB PDF Scrapper buffers do not have file names
(cond
((not buffer-file-name)
(call-interactively #'write-file)
(set-visited-file-name nil)
(rename-buffer orb-pdf-scrapper--buffer))
((call-interactively #'write-file))))

;; * Main functions

Expand Down

0 comments on commit 1b83f1f

Please sign in to comment.