;; [[file:index.org::*xochitl directory][xochitl directory:1]] (defcustom remarkable-xochitl-directory "~/xochitl" "Directory containing the files from the reMarkable tablet. This should either be a link to the /home/root/.local/share/remarkable/xochitl directory or to a copy of that." :type 'string :group 'reMarkable) ;; xochitl directory:1 ends here ;; [[file:index.org::*rmlist script][rmlist script:1]] (defcustom remarkable-rmlist-script "~/s/remarkable/software/rmlist.sh" "Where the script for listing the files in the xochitl directory is found." :type 'string :group 'reMarkable) ;; rmlist script:1 ends here ;; [[file:index.org::*rmconvert script][rmconvert script:1]] (defcustom remarkable-rmconvert-script "~/s/remarkable/software/rmconvert.sh" "Where the script for converting a reMarkable tablet notebook into a PDF file suitable for viewing on the screen. Also used for creating an annotated version of a PDF document." :type 'string :group 'reMarkable) ;; rmconvert script:1 ends here ;; [[file:index.org::*get the list of documents on the tablet][get the list of documents on the tablet:1]] (defun remarkable--get-documents (dir) (mapcar (lambda (x) (split-string x " ")) (split-string (shell-command-to-string (concat remarkable-rmlist-script " " dir " | sort -k 2 -r")) "\n"))) ;; get the list of documents on the tablet:1 ends here ;; [[file:index.org::*convert selected document to PDF and view][convert selected document to PDF and view:1]] (defun remarkable--convert-document-and-view (uuid) (let* ((uuid (tabulated-list-get-id)) (pdf (concat remarkable-xochitl-directory "/" uuid "_annotated.pdf")) (tmp (concat "/tmp/" uuid "_annotated.pdf"))) (when (or (not (file-exists-p pdf)) (file-newer-than-file-p (concat remarkable-xochitl-directory "/" uuid ".content") pdf)) (message "Converting %s to PDF. Please wait..." uuid) (shell-command (concat "(cd " remarkable-xochitl-directory "; " remarkable-rmconvert-script " " uuid "; " "mv " tmp " " pdf ")")) (message "... conversion complete.") ) (find-file pdf))) ;; convert selected document to PDF and view:1 ends here ;; [[file:index.org::*define a map for local bindings][define a map for local bindings:1]] (defvar remarkable-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "i") '(lambda () (interactive) (message "uuid = %s" (tabulated-list-get-id)))) (define-key map (kbd "v") '(lambda () (interactive) (remarkable--convert-document-and-view (tabulated-list-get-id)))) map)) ;; define a map for local bindings:1 ends here ;; [[file:index.org::*define the derived mode][define the derived mode:1]] (define-derived-mode remarkable-mode tabulated-list-mode "reMarkable" "A mode for viewing documents on the reMarkable tablet." (with-demoted-errors "reMarkable mode error: %s" (let ((columns [("Date" 18 t) ("Document name" 61 t)]) (rows (mapcar (lambda (x) (list (car x) (vconcat (cdr x)))) (remarkable--get-documents remarkable-xochitl-directory)))) (setq tabulated-list-format columns) (setq tabulated-list-entries rows) (tabulated-list-init-header) (tabulated-list-print)))) (provide 'remarkable) ;; define the derived mode:1 ends here ;; [[file:index.org::*define a command to start the mode][define a command to start the mode:1]] (defun remarkable () (interactive) (switch-to-buffer "*reMarkable*") (remarkable-mode) (goto-char (point-min))) ;; define a command to start the mode:1 ends here