From 23a63ba5c46aac401459ff2dde1c45ed73823659 Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Fri, 21 May 2021 13:19:52 +0300 Subject: [PATCH] selectrum: generalize +selectrum/embark-wgrep now tries to open a writable export of the same vein. add exports to `wdired` from `find-file` and `occur-edit` from `consult-line`. --- modules/completion/selectrum/README.org | 4 +++- modules/completion/selectrum/TODO.org | 5 +++-- .../completion/selectrum/autoload/selectrum.el | 18 ++++++++++++------ modules/completion/selectrum/config.el | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/completion/selectrum/README.org b/modules/completion/selectrum/README.org index 6c6f2f272..4ec0d0e3b 100644 --- a/modules/completion/selectrum/README.org +++ b/modules/completion/selectrum/README.org @@ -113,7 +113,7 @@ This module provides some in buffer searching bindings: https://assets.doomemacs.org/completion/selectrum/buffer-search.png -A wgrep buffer can be opened from ~consult-line~ with =C-c C-e= (not yet). +An ~occur-edit~ buffer can be opened from ~consult-line~ with =C-c C-e=. ** Selectrum integration for various completing commands *** General @@ -133,6 +133,8 @@ A wgrep buffer can be opened from ~consult-line~ with =C-c C-e= (not yet). | =SPC b b=, =SPC ,= | Switch to buffer in current workspace | | =SPC b B=, =SPC <= | Switch to buffer | +~find-file~ commands support exported to a =wdired= buffer using =C-c C-e=. + *** Search | Keybind | Description | |-----------+-------------------------------------------| diff --git a/modules/completion/selectrum/TODO.org b/modules/completion/selectrum/TODO.org index 2a157cb0d..236820d7b 100644 --- a/modules/completion/selectrum/TODO.org +++ b/modules/completion/selectrum/TODO.org @@ -18,6 +18,9 @@ Selectrum/Consult don't have a ~swiper-all~ analogue either. Unbound for now. ** TODO orderless style dispatchers Currently the =!= style dispatcher is only as a prefix, due to the abundance of =!= final macros. In my opinion this is useful enough to break consistency. +** TODO =C-c C-e= +on ~consult-line~ this opens a ~occur-edit~ buffer, which is a more natural fit but breaks slightly from the =C-c C-e= = =wgrep= convention. + * PROJ HACKs to be addressed ** ~fboundp~ issues Even if the =ivy= module isn't loaded, it's packages can still get loaded by @@ -62,8 +65,6 @@ is it something the custom search function is doing? does ivy cache stuff? * PROJ Missing Features ** TODO Icons https://github.com/minad/marginalia/issues/59 -** TODO =C-C C-e= wgrep fun -- check if we can add this to ~consult-line~ too ** TODO bibtex-actions improvements? currently =SPC n b= is bound to a function, but =bibtex-actions= doesn't have a main dispatch function like =ivy-bibtex=, rather it has a bunch of different diff --git a/modules/completion/selectrum/autoload/selectrum.el b/modules/completion/selectrum/autoload/selectrum.el index 76891cb10..faacc965d 100644 --- a/modules/completion/selectrum/autoload/selectrum.el +++ b/modules/completion/selectrum/autoload/selectrum.el @@ -75,13 +75,19 @@ If ARG (universal argument), include all files, even hidden or compressed ones." (consult-line (thing-at-point 'symbol))) ;;;###autoload -(defun +selectrum/embark-wgrep () - "Invoke a wgrep buffer on the current selectrum results, if supported." +(defun +selectrum/embark-export-write () + "Export the current selectrum results to a writable buffer if possible. + +Supports exporting consult-grep to wgrep, file to wdeired, and consult-location to occur-edit" (interactive) (require 'wgrep) (pcase-let ((`(,type . ,candidates) (run-hook-with-args-until-success 'embark-candidate-collectors))) - (if (not (eq type 'consult-grep)) - (user-error "embark category %S doesn't support wgrep" type) - (let ((embark-after-export-hook #'wgrep-change-to-wgrep-mode)) - (embark-export))))) + (pcase type + ('consult-grep (let ((embark-after-export-hook #'wgrep-change-to-wgrep-mode)) + (embark-export))) + ('file (let ((embark-after-export-hook #'wdired-change-to-wdired-mode)) + (embark-export))) + ('consult-location (let ((embark-after-export-hook #'occur-edit-mode)) + (embark-export))) + (x (user-error "embark category %S doesn't support writable export" x))))) diff --git a/modules/completion/selectrum/config.el b/modules/completion/selectrum/config.el index f4321e398..d3a12177a 100644 --- a/modules/completion/selectrum/config.el +++ b/modules/completion/selectrum/config.el @@ -31,7 +31,7 @@ (map! :map selectrum-minibuffer-map "C-o" #'embark-act "C-c C-o" #'embark-export - "C-c C-e" #'+selectrum/embark-wgrep + "C-c C-e" #'+selectrum/embark-export-write [backspace] #'+selectrum/backward-updir)) (use-package! selectrum-prescient