-
Notifications
You must be signed in to change notification settings - Fork 33
Ido, icomplete(fido) emulation
Clemens Radermacher edited this page Jan 25, 2021
·
2 revisions
You can use the following, see here for more info:
(defun selectrum-fido-backward-updir ()
"Delete char before or go up directory, like `ido-mode'."
(interactive)
(if (and (eq (char-before) ?/)
(eq (selectrum--get-meta 'category) 'file))
(save-excursion
(goto-char (1- (point)))
(when (search-backward "/" (point-min) t)
(delete-region (1+ (point)) (point-max))))
(call-interactively 'backward-delete-char)))
(defun selectrum-fido-delete-char ()
"Delete char or maybe call `dired', like `ido-mode'."
(interactive)
(let ((end (point-max)))
(if (or (< (point) end) (not (eq (selectrum--get-meta 'category) 'file)))
(call-interactively 'delete-char)
(dired (file-name-directory (minibuffer-contents)))
(exit-minibuffer))))
(defun selectrum-fido-ret ()
"Exit minibuffer or enter directory, like `ido-mode'."
(interactive)
(let* ((dir (and (eq (selectrum--get-meta 'category) 'file)
(file-name-directory (minibuffer-contents))))
(current (selectrum-get-current-candidate))
(probe (and dir current
(expand-file-name (directory-file-name current) dir))))
(cond ((and probe (file-directory-p probe) (not (string= current "./")))
(selectrum-insert-current-candidate))
(t
(selectrum-select-current-candidate)))))
(define-key selectrum-minibuffer-map (kbd "RET") 'selectrum-fido-ret)
(define-key selectrum-minibuffer-map (kbd "DEL") 'selectrum-fido-backward-updir)
(define-key selectrum-minibuffer-map (kbd "C-d") 'selectrum-fido-delete-char)
Ido like horizontal display:
(setq-default selectrum-display-style '(horizontal))