Skip to content

Instantly share code, notes, and snippets.

@tam17aki
Last active December 21, 2015 19:28
Show Gist options
  • Save tam17aki/6354092 to your computer and use it in GitHub Desktop.
Save tam17aki/6354092 to your computer and use it in GitHub Desktop.
(defun ido-smart-select-text-throw ()
(let ((match (ido-name (car ido-matches))))
(throw 'ido
(setq ido-selected
(if match
(replace-regexp-in-string "/\\'" "" match)
ido-text)
ido-text ido-selected
ido-final-text ido-text))))
(defun ido-smart-select-text ()
"Select the current completed item. Do NOT descend into directories."
(interactive)
(when (and (or (not ido-require-match)
(if (memq ido-require-match
'(confirm confirm-after-completion))
(if (or (eq ido-cur-item 'dir)
(eq last-command this-command))
t
(setq ido-show-confirm-message t)
nil))
(ido-existing-item-p))
(not ido-incomplete-regexp))
(when ido-current-directory
(setq ido-exit 'takeprompt)
(unless (and ido-text (= 0 (length ido-text)))
(ido-smart-select-text-throw))))
(cond ((= 0 (length ido-text))
(ido-smart-select-text-throw))
(t
(exit-minibuffer))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment