From da468739ff8ed75b6af45d7096cfdd9e8b112968 Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Sun, 24 Mar 2024 09:43:57 +0100 Subject: [PATCH] Add an usage tip stolen from the Consult Wiki --- README.org | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.org b/README.org index 17ae876..3a5d853 100644 --- a/README.org +++ b/README.org @@ -1561,6 +1561,9 @@ Consult usage tips are: consult-mark)}}} or {{{kbd(M-g m)}}}. See [[https://arialdomartini.github.io//emacs-mark-ring][Emacs: Mark Ring]]. 2. {{{kbd(M-x consult-org-heading)}}} or {{{kbd(C-c C-h)}}} is an alternative to {{{kbd(M-x org-goto)}}} or {{{kbd(C-c C-j)}}}. +3. Listing [[lst:find-file-preview]] uses the internal functions + ~consult--file-preview~ and ~consult--read~ to visit files with previewing + during selection. See: [[https://github.com/minad/consult/wiki][Consult Wiki]]. #+attr_latex: :booktabs yes :float table #+caption[Configuration specific key bindings]: @@ -1646,6 +1649,29 @@ Consult usage tips are: (keymap-global-set "M-y" #'consult-yank-pop)) #+end_src +#+caption[Implement =find-file= with previewing before selection]: +#+caption: Implement =find-file= with previewing before selection. +#+name: lst:find-file-preview +#+begin_src emacs-lisp -n :results silent +(defun consult-find-file-preview(cue &optional dir default mustmatch init pred) + (interactive) + (let ((default-directory (or dir default-directory)) + (minibuffer-completing-file-name t)) + (consult--read #'read-file-name-internal :state (consult--file-preview) + :prompt cue :initial init + :require-match mustmatch :predicate pred))) + +(defun toggle-find-file-preview () + "Toggle previewing when calling `find-file'." + (interactive) + (let ((done "Enabled")) + (if (eq read-file-name-function #'read-file-name-default) + (setq read-file-name-function #'consult-find-file-preview) + (setq read-file-name-function #'read-file-name-default + done "Disabled")) + (message "%s `find-file' previewing" done))) +#+end_src + ** [[https://company-mode.github.io/][Company (info)]] :PROPERTIES: :CUSTOM_ID: sec:company-setup