From df93878aa8c590579774593b747a5000cbb35c42 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Wed, 30 Dec 2015 18:03:55 -0500 Subject: Add command to rename existing citekey file --- NEWS | 3 +++ bog.el | 29 +++++++++++++++++++++++++++-- 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. -- cgit v1.2.3