(fix): fix headline completions erroring (#1374)

updates org-roam-with-file to accept nil FILE arg, to operate on current
buffer. Fixes org-roam-link--get-headlines to kill buffer if not
obtaining markers.
This commit is contained in:
Jethro Kuan
2021-01-09 17:49:36 +08:00
committed by GitHub
parent 15d864a500
commit 78a371cdc4
3 changed files with 19 additions and 12 deletions

View File

@ -16,6 +16,7 @@
- [#1346](https://github.com/org-roam/org-roam/pull/1346) prevent malformed path to `org-roam-index-file`
- [#1347](https://github.com/org-roam/org-roam/pull/1347) allow use of `%a` element in regular Org-roam captures
- [#1352](https://github.com/org-roam/org-roam/pull/1352) fixed org-roam-{tag/alias}-{add/delete} altering the original case of the Org property
- [#1374](https://github.com/org-roam/org-roam/pull/1374) fix headline completions erroring out
## 1.2.3 (13-11-2020)

View File

@ -97,7 +97,7 @@ the link."
If FILE, return outline headings for passed FILE instead.
If WITH-MARKER, return a cons cell of (headline . marker).
If USE-STACK, include the parent paths as well."
(org-roam-with-file file 'keep
(org-roam-with-file file (when with-marker 'keep)
(let* ((outline-level-fn outline-level)
(path-separator "/")
(stack-level 0)
@ -128,6 +128,7 @@ If USE-STACK, include the parent paths as well."
name) cands))))
(nreverse cands))))
(defun org-roam-link--get-file-from-title (title &optional no-interactive)
"Return the file path corresponding to TITLE.
When NO-INTERACTIVE, return nil if there are multiple options."
@ -142,8 +143,8 @@ When NO-INTERACTIVE, return nil if there are multiple options."
(completing-read "Select file: " files))))))
(defun org-roam-link--get-id-from-headline (headline &optional file)
"Return (marker . id) correspondng to HEADLINE.
If FILE, get headline from FILE instead.
"Return (marker . id) correspondng to HEADLINE in FILE.
If FILE is nil, get ID from current buffer.
If there is no corresponding headline, return nil."
(save-excursion
(org-roam-with-file file 'keep

View File

@ -52,21 +52,26 @@
(nconc new-lst (list separator it)))
new-lst)))
(defmacro org-roam-with-file (file keep-file-p &rest body)
(defmacro org-roam-with-file (file keep-buf-p &rest body)
"Execute BODY within FILE.
If KEEP-FILE-P or FILE is already visited, do not kill the
buffer."
If FILE is nil, execute BODY in the current buffer.
Kills the buffer if KEEP-BUF-P is nil, and FILE is not yet visited."
(declare (indent 2) (debug t))
`(let* ((existing-buf (find-buffer-visiting ,file))
(buf (or existing-buf (find-file-noselect ,file)))
(keep-buf-p (or existing-buf ,keep-file-p))
`(let* (new-buf
(buf (or (and (not ,file)
(current-buffer)) ;If FILE is nil, use current buffer
(find-buffer-visiting ,file) ; If FILE is already visited, find buffer
(progn
(setq new-buf t)
(find-file-noselect ,file)))) ; Else, visit FILE and return buffer
res)
(with-current-buffer buf
(setq res (progn ,@body))
(unless keep-buf-p
(unless (and new-buf (not ,keep-buf-p))
(save-buffer)))
(unless (and keep-buf-p (find-buffer-visiting ,file))
(kill-buffer (find-buffer-visiting ,file)))
(if (and new-buf (not ,keep-buf-p))
(when (find-buffer-visiting ,file)
(kill-buffer (find-buffer-visiting ,file))))
res))
(defmacro org-roam--with-temp-buffer (file &rest body)