Use a keymap for the org-ql-view export functionality

This commit is contained in:
Omar Antolín 2023-12-18 13:35:04 -06:00 committed by Adam Porter
parent 121af5c5d5
commit 0552aa8b93

View file

@ -114,6 +114,17 @@ value, or nil."
;;;;; Completing read ;;;;; Completing read
(defun org-ql-export-view ()
"Create `org-ql-view' buffer from current minibuffer org-ql search."
(interactive)
(user-error "Must be run from within an `org-ql-completing-read' session"))
(defvar org-ql-completing-read-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-e") #'org-ql-export-view)
map)
"Keymap active during `org-ql-completing-read' minibuffer sessions.")
;;;###autoload ;;;###autoload
(cl-defun org-ql-completing-read (cl-defun org-ql-completing-read
(buffers-files &key query-prefix query-filter (buffers-files &key query-prefix query-filter
@ -325,20 +336,20 @@ single predicate)."
(selected (selected
(minibuffer-with-setup-hook (minibuffer-with-setup-hook
(lambda () (lambda ()
(let ((map (make-sparse-keymap))) (use-local-map (make-composed-keymap org-ql-completing-read-map (current-local-map))))
(define-key (cl-letf* (((symbol-function 'org-ql-export-view)
map (kbd "C-c C-e") (lambda ()
(lambda () (interactive)
(interactive) (run-at-time 0 nil
(run-at-time 0 nil #'org-ql-search
#'org-ql-search buffers-files
buffers-files (minibuffer-contents-no-properties))
(minibuffer-contents-no-properties)) (if (fboundp 'minibuffer-quit-recursive-edit)
(if (fboundp 'minibuffer-quit-recursive-edit) (minibuffer-quit-recursive-edit)
(minibuffer-quit-recursive-edit) (abort-recursive-edit))))
(abort-recursive-edit)))) ((symbol-function 'embark-export)
(use-local-map (make-composed-keymap map (current-local-map))))) (symbol-function 'org-ql-export-view)))
(completing-read prompt #'collection nil t)))) (completing-read prompt #'collection nil t)))))
;; (debug-message "SELECTED:%S KEYS:%S" selected (hash-table-keys table)) ;; (debug-message "SELECTED:%S KEYS:%S" selected (hash-table-keys table))
(or (gethash selected table) (or (gethash selected table)
;; If there are completions in the table, but none of them exactly match the user input ;; If there are completions in the table, but none of them exactly match the user input