summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-02-03 00:34:27 -0500
committerKyle Meyer <kyle@kyleam.com>2014-02-03 00:50:18 -0500
commitba4e43b1c4693635d83072d9e67f4eb4ea7f76d7 (patch)
treee9f3cb6d4b18bc1fd80f833cec5ff75a1d8188a1
parentd90c0d8417fcc8dc93a5745825be7af3fec8e905 (diff)
downloadbog-ba4e43b1c4693635d83072d9e67f4eb4ea7f76d7.tar.gz
Add function rename staged PDF
-rw-r--r--bog.el38
1 files changed, 38 insertions, 0 deletions
diff --git a/bog.el b/bog.el
index aa52749..6eb3b27 100644
--- a/bog.el
+++ b/bog.el
@@ -50,6 +50,14 @@
:group 'bog
:type 'string)
+(defcustom bog-pdf-directory-stage
+ (expand-file-name "pdf-stage" bog-notes-directory)
+ "The name of the directory to search for new PDFs in.
+`bog-rename-staged-pdf-to-citekey' will search here for files to
+rename."
+ :group 'bog
+ :type 'string)
+
(defcustom bog-read-file-name 'read-file-name
"A function that will be used to promtp for file name.
The function should accept one arguments, a string to use for the
@@ -153,6 +161,36 @@ first parent heading that matches `bog-citekey-format'."
(error "%s does not exist" pdf-file))
(start-process "bog-pdf" nil bog-pdf-opener pdf-file)))
+;;;###autoload
+(defun bog-rename-staged-pdf-to-citekey ()
+ "Rename PDF in `bog-pdf-directory-stage' to `bog-pdf-directory'/<citekey>.pdf.
+The citekey will be taken from the text under point if it matches
+`bog-citekey-format' or from the first parent heading that
+matches `bog-citekey-format'."
+ (interactive)
+ (bog-citekey-action 'bog-rename-staged-pdf
+ nil
+ nil))
+
+(defun bog-rename-staged-pdf (citekey)
+ (let* ((pdf-file (bog-citekey-as-pdf citekey))
+ (choices
+ (file-expand-wildcards
+ (concat (file-name-as-directory bog-pdf-directory-stage) "*.pdf")))
+ (num-choices (length choices))
+ staged-pdf)
+ (cond
+ ((= 0 num-choices)
+ (setq staged-pdf (funcall bog-read-file-name
+ "Select PDF file to rename: ")))
+ ((= 1 num-choices)
+ (setq staged-pdf (car choices)))
+ (t
+ (setq staged-pdf (funcall bog-completing-read
+ "Select PDF file to rename: " choices))))
+ (rename-file staged-pdf pdf-file)
+ (message "Renamed %s to %s." staged-pdf pdf-file)))
+
(defun bog-citekey-as-pdf (citekey)
(expand-file-name (concat citekey ".pdf") bog-pdf-directory))