Compare commits

...

2 commits

Author SHA1 Message Date
João Távora
0943c81ecd Add new icomplete-force-complete-and-exit-unless-directory command
Useful if you want icomplete to behave a little more like Ido.

(define-key icomplete-minibuffer-map (kbd "RET")
'icomplete-force-complete-and-exit-unless-directory)

* lisp/icomplete.el
  (icomplete-force-complete-and-exit-unless-directory): New command.
2019-02-04 16:06:52 +00:00
João Távora
8c9b9144cf Add new icomplete-force-complete-and-kill command
* lisp/icomplete.el (icomplete-minibuffer-map): Add a new C-k
"filtered" command.
(icomplete-force-complete-and-kill): New command.
2019-02-04 16:06:49 +00:00

View file

@ -149,6 +149,11 @@ icompletion is occurring."
(define-key map [?\C-j] 'icomplete-force-complete-and-exit)
(define-key map [?\C-.] 'icomplete-forward-completions)
(define-key map [?\C-,] 'icomplete-backward-completions)
(define-key map
(kbd "C-k") '(menu-item
"" icomplete-force-complete-and-kill
;; activate binding if at end of input
:filter (lambda (cmd) (and (eobp) cmd))))
map)
"Keymap used by `icomplete-mode' in the minibuffer.")
@ -162,6 +167,51 @@ the default otherwise."
(minibuffer-force-complete-and-exit)
(minibuffer-complete-and-exit)))
(defun icomplete-force-complete-and-exit-unless-directory ()
"Complete minibuffer, don't exit if completing a directory."
(interactive)
(minibuffer-force-complete nil nil 'dont-cycle)
(let* ((meta (cdr (funcall minibuffer-completion-table
nil nil 'metadata)))
(category (cdr (assq 'category meta))))
(unless (and (eq 'file category)
(file-directory-p
(buffer-substring-no-properties (icomplete--field-beg)
(icomplete--field-end))))
(minibuffer-complete-and-exit))))
(defun icomplete-force-complete-and-kill ()
"Complete minibuffer, kill current prospect, don't exit.
Killing the current prospect has different meanings according to
the completion table's `category'. A `file' table will interpret
killing as a request to delete a file whereas a `buffer' table
will interpret it as a request to kill a buffer."
(interactive)
(minibuffer-force-complete nil nil 'dont-cycle)
(let* ((beg (icomplete--field-beg))
(end (icomplete--field-end))
(comp (buffer-substring-no-properties beg end))
(meta (funcall minibuffer-completion-table
nil nil 'metadata))
(meta (and (eq 'metadata (car meta)) (cdr meta)))
(category (cdr (assq 'category meta)))
file buffer)
(cond ((and (eq 'file category)
(file-exists-p
(setq file (expand-file-name comp)))
(yes-or-no-p (format "Delete %s?" file)))
(delete-file file t)
(delete-region beg end)
(insert (file-name-directory file)))
((and (eq 'buffer category)
(buffer-live-p (setq buffer (get-buffer comp)))
;; (yes-or-no-p (format "Kill buffer %s?" buffer))
)
(kill-buffer buffer)
(delete-region beg end)))
;; Clear echo area immediately
(message nil)))
(defun icomplete-force-complete ()
"Complete the icomplete minibuffer."
(interactive)