Fix: (org-ql-view--link-store) Rejection of unlinkable buffers

Also, remove the Org <=9.1.4 compatibility code.  It's not worth it.
I'm probably the only person who needs it, anyway, and I can live with
the double-call until I upgrade my Org version.

Fixes #148.  Thanks to @tpeacock19 for reporting.
This commit is contained in:
Adam Porter 2020-11-12 02:43:08 -06:00
parent 284eda87e5
commit f63012dd5a

View file

@ -647,11 +647,6 @@ protocol. See, e.g. `org-ql-view--link-store'."
:super-groups groups :super-groups groups
:title title))) :title title)))
(defvar org-ql-view--link-store-counter 0
;; TODO: When compatibility with Org <=9.1.4 is dropped, remove this. See
;; <https://github.com/alphapapa/org-ql/issues/147#issuecomment-725835457>.
"Workaround for an idiosyncrasy of `org-store-link' that calls link-storing functions twice.")
(defun org-ql-view--link-store () (defun org-ql-view--link-store ()
"Store a link to the current Org QL view. "Store a link to the current Org QL view.
When opened, the link searches the buffer it's opened from." When opened, the link searches the buffer it's opened from."
@ -659,22 +654,20 @@ When opened, the link searches the buffer it's opened from."
(require 'url-util) (require 'url-util)
(when org-ql-view-query (when org-ql-view-query
;; Only Org QL View buffers should have `org-ql-view-query' set. ;; Only Org QL View buffers should have `org-ql-view-query' set.
(when (or (bufferp org-ql-view-buffers-files)
(cl-some #'bufferp org-ql-view-buffers-files))
;; Buffers are unreadable, so they can't be linked to.
(user-error "Views that search buffers rather than files can't be linked to"))
(cl-incf org-ql-view--link-store-counter) ;; TODO: Remove when not supporting Org<=9.1.4. See other comment.
(cl-flet ((prompt-for (buffers-files) (cl-flet ((prompt-for (buffers-files)
;; HACK: Use counter to avoid prompting the first of the (pcase-exhaustive
;; two times that `org-store-link' calls this function. (completing-read (format "Link to search file containing inserted link or %s? " buffers-files)
;; TODO: Remove the version check when not supporting Org<=9.1.4. See other comment. (list "containing file" buffers-files) nil t)
(when (or (version< "9.1.4" (org-version)) ("containing file" nil)
(cl-evenp org-ql-view--link-store-counter)) (buffers-files (prin1-to-string buffers-files))))
(pcase-exhaustive (string-or-file-buffer-p
(completing-read (format "Link to search file containing inserted link or %s? " buffers-files) (thing) (or (stringp thing)
(list "containing file" buffers-files) nil t) (and (bufferp thing)
("containing file" nil) (buffer-file-name thing)))))
(buffers-files (prin1-to-string buffers-files)))))) (unless (or (string-or-file-buffer-p org-ql-view-buffers-files)
(and (listp org-ql-view-buffers-files)
(cl-every #'string-or-file-buffer-p org-ql-view-buffers-files)))
(user-error "Views that search non-file-backed buffers can't be linked to"))
(let* ((query-string (--if-let (org-ql--query-sexp-to-string org-ql-view-query) (let* ((query-string (--if-let (org-ql--query-sexp-to-string org-ql-view-query)
it (prin1-to-string (org-ql-view--format-query org-ql-view-query)))) it (prin1-to-string (org-ql-view--format-query org-ql-view-query))))
(buffers-files (prompt-for (org-ql-view--contract-buffers-files org-ql-view-buffers-files))) (buffers-files (prompt-for (org-ql-view--contract-buffers-files org-ql-view-buffers-files)))