Change/Fix: (org-ql-select) Warn instead of erroring on bad files

This helps prevent unexpected errors from making it impossible to
search, and displaying the messages in the warnings buffer makes them
more noticeable and readable for the user.
This commit is contained in:
Adam Porter 2022-06-25 10:54:38 -05:00
parent 5768c685ad
commit bbd164c6ae

View file

@ -362,18 +362,18 @@ each priority the newest items would appear first."
(function (funcall buffers-or-files)) (function (funcall buffers-or-files))
(list buffers-or-files) (list buffers-or-files)
(otherwise (list buffers-or-files))) (otherwise (list buffers-or-files)))
(--map (cl-etypecase it (--map (cl-etypecase it
;; NOTE: This etypecase is essential to opening links safely, ;; NOTE: This etypecase is essential to opening links safely,
;; as it rejects, e.g. lambdas in the buffers-files argument. ;; as it rejects, e.g. lambdas in the buffers-files argument.
(buffer it) (buffer it)
(string (or (find-buffer-visiting it) (string (or (find-buffer-visiting it)
(when (file-readable-p it) (when (file-readable-p it)
;; It feels unintuitive that `find-file-noselect' returns ;; It feels unintuitive that `find-file-noselect' returns
;; a buffer if the filename doesn't exist. ;; a buffer if the filename doesn't exist.
(find-file-noselect it)) (find-file-noselect it))
(user-error "Can't open file: %s" it))))) (display-warning 'org-ql-select (format "Can't open file: %s" it) :error)))))
;; Ignore special/hidden buffers. ;; Ignore special/hidden buffers.
(--remove (string-prefix-p " " (buffer-name it))))) (--remove (string-prefix-p " " (buffer-name it)))))
(query (org-ql--normalize-query query)) (query (org-ql--normalize-query query))
((&plist :query :preamble :preamble-case-fold) (org-ql--query-preamble query)) ((&plist :query :preamble :preamble-case-fold) (org-ql--query-preamble query))
(predicate (org-ql--query-predicate query)) (predicate (org-ql--query-predicate query))
@ -409,12 +409,12 @@ each priority the newest items would appear first."
(fset name fn))) (fset name fn)))
;; Run query on buffers. ;; Run query on buffers.
(->> buffers (->> buffers
(--map (with-current-buffer it (--map (with-current-buffer it
(unless (derived-mode-p 'org-mode) (unless (derived-mode-p 'org-mode)
(user-error "Not an Org buffer: %s" (buffer-name))) (display-warning 'org-ql-select (format "Not an Org buffer: %s" (buffer-name)) :error))
(org-ql--select-cached :query query :preamble preamble :preamble-case-fold preamble-case-fold (org-ql--select-cached :query query :preamble preamble :preamble-case-fold preamble-case-fold
:predicate predicate :action action :narrow narrow))) :predicate predicate :action action :narrow narrow)))
(-flatten-n 1))) (-flatten-n 1)))
(--each orig-fns (--each orig-fns
;; Restore original function mappings. ;; Restore original function mappings.
(-let (((&plist :name :fn) it)) (-let (((&plist :name :fn) it))