emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ido.el: swallowing superfluous RET key


From: Karl Chen
Subject: ido.el: swallowing superfluous RET key
Date: 09 Apr 2004 21:02:47 -0700

The behavior for finding files/buffers on TAB without requiring
RET is nice, but I still press RET out of habit, or because I
expect it to be the fist but not unique match.

I've been using the advice code below to swallow unnecessary RETs;
this code could be useful if built-in to ido.el (maybe default off).


(defun kc--key-is-return (key)
  (or (eq key 13)
      (eq key 'return)
      (eq key 'kp-enter)))

;; I'm used to typing TAB-RET to complete a filename, but the RET is
;; unnecessary if unique, with IDO.
(defun kc-ido-absorb-ret ()
  "If the next key is a RET within 1 second, ignore it."

  (with-timeout (1)
    (let ((event (read-event)))
      (if (kc--key-is-return event)
          (message "Swallowed unnecessary RET key")
        (push event unread-command-events)))))

(defun kc-ido-absorb-ret-on-completion ()
  (if (eq this-command 'ido-complete)
      (kc-ido-absorb-ret)))

(defadvice ido-find-file (after kc-ido-absorb-ret-on-completion activate)
  (kc-ido-absorb-ret-on-completion))

(defadvice ido-switch-buffer (after kc-ido-absorb-ret-on-completion activate)
  (kc-ido-absorb-ret-on-completion))


-- 
Karl 2004-04-09 20:58




reply via email to

[Prev in Thread] Current Thread [Next in Thread]