summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-12-30 18:03:55 -0500
committerKyle Meyer <kyle@kyleam.com>2015-12-30 18:03:55 -0500
commitdf93878aa8c590579774593b747a5000cbb35c42 (patch)
treea0eb54777c67b573933fca7e693e135b6033777a
parentea99bc6b8108bd3b2ff767541fa264db4dbf04a5 (diff)
downloadbog-df93878aa8c590579774593b747a5000cbb35c42.tar.gz
Add command to rename existing citekey file
-rw-r--r--NEWS3
-rw-r--r--bog.el29
2 files changed, 30 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index d55a33c..3cc18af 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@
** New features
+- New command ~bog-rename-citekey-file~ updates the name of an
+ existing citekey file.
+
- New option ~bog-combined-bib-ignore-not-found~ controls whether
~bog-create-combined-bib~ prompts to continue when a citekey's bib
file is missing. With a prefix argument to
diff --git a/bog.el b/bog.el
index d5882bd..64b5ab9 100644
--- a/bog.el
+++ b/bog.el
@@ -625,8 +625,33 @@ If the citekey prompt is slow to appear, consider enabling the
(org-icompleting-read "Select file to rename: "
staged-file-names)
bog-stage-directory))))
- (message "Renamed %s to %s" staged-file
- (funcall bog-file-renaming-func staged-file citekey))))
+ (bog--rename-file-to-citekey staged-file citekey)))
+
+;;;###autoload
+(defun bog-rename-citekey-file (&optional no-context)
+ "Associate a citekey file with a new citekey.
+
+This allows you to update a file's name if you change the
+citekey.
+
+The new citekey is taken from the text under point if it matches
+`bog-citekey-format' or from the current tree.
+
+With prefix argument NO-CONTEXT, prompt with citekeys present in
+any note file. Do the same if locating a citekey from context
+fails."
+ (interactive "P")
+ (let ((file-paths (mapcar (lambda (path)
+ (cons (file-name-nondirectory path) path))
+ (bog-all-citekey-files))))
+ (bog--rename-file-to-citekey
+ (cdr (assoc-string (org-icompleting-read "Rename file: " file-paths)
+ file-paths))
+ (bog-citekey-from-surroundings-or-all no-context))))
+
+(defun bog--rename-file-to-citekey (file citekey)
+ (message "Renamed %s to %s" file
+ (funcall bog-file-renaming-func file citekey)))
(defun bog-file-ask-on-conflict (staged-file citekey)
"Rename citekey file, prompting for a new name if it already exists.