From 7c313fbac259d0603cbeaa8b334c9a5a1cfc98ec Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Wed, 30 Jun 2021 19:24:27 +0300 Subject: [PATCH] selectrum: autoload +selectrum/backward-updir... and make it independent of selectrum --- .../completion/selectrum/autoload/selectrum.el | 18 ++++++++++++++++++ modules/completion/selectrum/config.el | 12 ------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/completion/selectrum/autoload/selectrum.el b/modules/completion/selectrum/autoload/selectrum.el index 1becbb67f..14d4f2a3e 100644 --- a/modules/completion/selectrum/autoload/selectrum.el +++ b/modules/completion/selectrum/autoload/selectrum.el @@ -74,6 +74,24 @@ If ARG (universal argument), include all files, even hidden or compressed ones." (interactive) (consult-line (thing-at-point 'symbol))) +;;;###autoload +(defun +selectrum/backward-updir () + "Delete char before or go up directory for file cagetory selectrum buffers." + (interactive) + (let ((metadata (completion-metadata (minibuffer-contents) + minibuffer-completion-table + minibuffer-completion-predicate))) + (if (and (eq (char-before) ?/) + (eq (completion-metadata-get metadata 'category) 'file)) + (let ((new-path (minibuffer-contents))) + (delete-region (minibuffer-prompt-end) (point-max)) + (insert (abbreviate-file-name + (file-name-directory + (directory-file-name + (expand-file-name new-path)))))) + (call-interactively 'backward-delete-char)))) + + ;;;###autoload (defun +selectrum/embark-export-write () "Export the current selectrum results to a writable buffer if possible. diff --git a/modules/completion/selectrum/config.el b/modules/completion/selectrum/config.el index 72f13adce..107625afe 100644 --- a/modules/completion/selectrum/config.el +++ b/modules/completion/selectrum/config.el @@ -9,18 +9,6 @@ (when (featurep! +prescient) (setq completion-styles '(substring partial-completion))) :config - (defun +selectrum/backward-updir () - "Delete char before or go up directory for file cagetory selectrum buffers." - (interactive) - (if (and (eq (char-before) ?/) - (eq (selectrum--get-meta 'category) 'file)) - (let ((new-path (minibuffer-contents))) - (delete-region (minibuffer-prompt-end) (point-max)) - (insert (abbreviate-file-name - (file-name-directory - (directory-file-name - (expand-file-name new-path)))))) - (call-interactively 'backward-delete-char))) (map! :map selectrum-minibuffer-map [backspace] #'+selectrum/backward-updir))