Skip to content

Commit

Permalink
Use a keymap for the org-ql-view export functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
oantolin committed Dec 18, 2023
1 parent 2dad3d2 commit 0fd7045
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions org-ql-completing-read.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ For an experience like `org-rifle', use a newline."

;;;;; 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
(cl-defun org-ql-completing-read (buffers-files &key query-prefix query-filter
(prompt "Find entry: "))
Expand Down Expand Up @@ -268,20 +279,20 @@ single predicate)."
(selected
(minibuffer-with-setup-hook
(lambda ()
(let ((map (make-sparse-keymap)))
(define-key
map (kbd "C-c C-e")
(lambda ()
(interactive)
(run-at-time 0 nil
#'org-ql-search
buffers-files
(minibuffer-contents-no-properties))
(if (fboundp 'minibuffer-quit-recursive-edit)
(minibuffer-quit-recursive-edit)
(abort-recursive-edit))))
(use-local-map (make-composed-keymap map (current-local-map)))))
(completing-read prompt #'collection nil t))))
(use-local-map (make-composed-keymap org-ql-completing-read-map (current-local-map))))
(cl-letf* (((symbol-function 'org-ql-export-view)
(lambda ()
(interactive)
(run-at-time 0 nil
#'org-ql-search
buffers-files
(minibuffer-contents-no-properties))
(if (fboundp 'minibuffer-quit-recursive-edit)
(minibuffer-quit-recursive-edit)
(abort-recursive-edit))))
((symbol-function 'embark-export)
(symbol-function 'org-ql-export-view)))
(completing-read prompt #'collection nil t)))))
;; (debug-message "SELECTED:%S KEYS:%S" selected (hash-table-keys table))
(or (gethash selected table)
;; If there are completions in the table, but none of them exactly match the user input
Expand Down

0 comments on commit 0fd7045

Please sign in to comment.