From 6dfc32441d3dc274aa347eb490deb52306b91813 Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Sat, 1 May 2021 13:58:02 +0300 Subject: [PATCH] selectrum: improve file category commands... now when pressing backspace on `/`, the input will go up one directory. --- modules/completion/selectrum/TODO.org | 3 --- modules/completion/selectrum/config.el | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/completion/selectrum/TODO.org b/modules/completion/selectrum/TODO.org index 0e1f6ca5c..555635ac0 100644 --- a/modules/completion/selectrum/TODO.org +++ b/modules/completion/selectrum/TODO.org @@ -17,9 +17,6 @@ gets us close but moves the cursor to the new screen which is undesirable. * PROJ List of things needed for Ivy parity ** TODO Icons https://github.com/minad/marginalia/issues/59 -** TODO make backspace work in filepath searching -In ivy, backspace on =/foo/bar/!= (where =!= is the cursor) leads to =/foo/!= -In selectrum, it leads to =/foo/bar!= ** TODO =SPC s B= ** TODO modules to look over - lookup diff --git a/modules/completion/selectrum/config.el b/modules/completion/selectrum/config.el index e48e37004..3e7ec61b5 100644 --- a/modules/completion/selectrum/config.el +++ b/modules/completion/selectrum/config.el @@ -14,9 +14,24 @@ (defadvice! +selectrum-refresh-on-cycle (&rest _) :after 'marginalia-cycle (when (bound-and-true-p selectrum-mode) (selectrum-exhibit))) + + (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 - "C-o" #'embark-act - "C-c C-o" #'embark-export)) + "C-o" #'embark-act + "C-c C-o" #'embark-export + [backspace] #'+selectrum/backward-updir)) (use-package! selectrum-prescient :when (featurep! +prescient)