org-capture: Fix file+olp target with a relative file name

* lisp/org-capture.el (org-capture-expand-file): Expand relative file
  names from `org-directory'
(org-capture-target-buffer): Apply change above.

Reported-by: Allen Li <darkfeline@felesatra.moe>
<http://permalink.gmane.org/gmane.emacs.orgmode/110075>
This commit is contained in:
Nicolas Goaziou 2016-11-06 08:56:22 +01:00
parent c81f9fff3b
commit b89dfaa904
1 changed files with 16 additions and 13 deletions

View File

@ -1007,28 +1007,31 @@ Store them in the capture property list."
:decrypted decrypted-hl-pos))))
(defun org-capture-expand-file (file)
"Expand functions and symbols for FILE.
"Expand functions, symbols and file names for FILE.
When FILE is a function, call it. When it is a form, evaluate
it. When it is a variable, retrieve the value. When it is
a string, return it. However, if it is the empty string, return
`org-default-notes-file' instead."
a string, treat it as a file name, possibly expanding it
according to `org-directory', and return it. If it is the empty
string, however, return `org-default-notes-file'. In any other
case, raise an error."
(cond
((equal file "") org-default-notes-file)
((org-string-nw-p file) file)
((stringp file) (expand-file-name file org-directory))
((functionp file) (funcall file))
((and (symbolp file) (boundp file)) (symbol-value file))
((consp file) (eval file))
(t file)))
(t (error "Invalid file location: %S" file))))
(defun org-capture-target-buffer (file)
"Get a buffer for FILE."
(setq file (org-capture-expand-file file))
(setq file (or (org-string-nw-p file)
org-default-notes-file
(error "No notes file specified, and no default available")))
(or (org-find-base-buffer-visiting file)
(progn (org-capture-put :new-buffer t)
(find-file-noselect (expand-file-name file org-directory)))))
"Get a buffer for FILE.
FILE is a generalized file location, as handled by
`org-capture-expand-file'."
(let ((file (or (org-string-nw-p (org-capture-expand-file file))
org-default-notes-file
(error "No notes file specified, and no default available"))))
(or (org-find-base-buffer-visiting file)
(progn (org-capture-put :new-buffer t)
(find-file-noselect file)))))
(defun org-capture-place-template (&optional inhibit-wconf-store)
"Insert the template at the target location, and display the buffer.