浏览代码

Many bugfixes

Ryan C. Thompson 10 年之前
父节点
当前提交
7239d809fc
共有 2 个文件被更改,包括 73 次插入53 次删除
  1. 25 17
      ido-completing-read+.el
  2. 48 36
      ido-ubiquitous.el

+ 25 - 17
ido-completing-read+.el

@@ -43,6 +43,28 @@
 
 (require 'ido)
 
+;;; Debug messages
+
+(defvar ido-cr+-debug-mode)
+
+;; Defined as a macro for efficiency (args are not evaluated unless
+;; debug mode is on)
+(defmacro ido-cr+--debug-message (format-string &rest args)
+  `(when ido-cr+-debug-mode
+     (message (concat "ido-completing-read+: " ,format-string) ,@args)))
+
+(defun ido-cr+--explain-fallback (arg)
+  ;; This function accepts a string, or an ido-cr+-fallback
+  ;; signal.
+  (when ido-cr+-debug-mode
+    (when (and (listp arg)
+               (eq (car arg) 'ido-cr+-fallback))
+      (setq arg (cdr arg)))
+    (ido-cr+--debug-message "Falling back to `%s' because %s."
+                                   ido-cr+-fallback-function arg)))
+
+;;; Core code
+
 (defvar ido-cr+-enable-next-call nil
   "If non-nil, then the next call to `ido-completing-read' is by `ido-completing-read+'.")
 (defvar ido-cr+-enable-this-call nil
@@ -224,8 +246,10 @@ advice completely replaces `ido-completing-read' with
     ;; point.
     (setq ido-context-switch-command #'ido-fallback-command)))
 
-;;; Debug messages
+;;; Debug mode
 
+;; This is defined at the end so it goes at the bottom of the
+;; customization group
 (define-minor-mode ido-cr+-debug-mode
   "If non-nil, ido-cr+ will print debug info.
 
@@ -234,22 +258,6 @@ Debug info is printed to the *Messages* buffer."
   :global t
   :group 'ido-cr+)
 
-;; Defined as a macro for efficiency (args are not evaluated unless
-;; debug mode is on)
-(defmacro ido-cr+--debug-message (format-string &rest args)
-  `(when ido-cr+-debug-mode
-     (message (concat "ido-completing-read+: " ,format-string) ,@args)))
-
-(defun ido-cr+--explain-fallback (arg)
-  ;; This function accepts a string, or an ido-cr+-fallback
-  ;; signal.
-  (when ido-cr+-debug-mode
-    (when (and (listp arg)
-               (eq (car arg) 'ido-cr+-fallback))
-      (setq arg (cdr arg)))
-    (ido-cr+--debug-message "Falling back to `%s' because %s."
-                                   ido-cr+-fallback-function arg)))
-
 (provide 'ido-completing-read+)
 
 ;;; ido-completing-read+.el ends here

+ 48 - 36
ido-ubiquitous.el

@@ -82,6 +82,26 @@ be updated until you restart Emacs.")
 ;; because if it isn't we need enable a workaround.
 (require 'nadvice nil 'noerror)
 
+;;; Debug messages
+
+(defvar ido-ubiquitous-debug-mode)
+
+;; Defined as a macro for efficiency (args are not evaluated unless
+;; debug mode is on)
+(defmacro ido-ubiquitous--debug-message (format-string &rest args)
+  `(when ido-ubiquitous-debug-mode
+     (message (concat "ido-ubiquitous: " ,format-string) ,@args)))
+
+(defun ido-ubiquitous--explain-fallback (arg)
+  ;; This function accepts a string, or an ido-ubiquitous-fallback
+  ;; signal.
+  (when ido-ubiquitous-debug-mode
+    (when (and (listp arg)
+               (eq (car arg) 'ido-ubiquitous-fallback))
+      (setq arg (cdr arg)))
+    (ido-ubiquitous--debug-message "Falling back to `%s' because %s."
+                                   ido-cr+-fallback-function arg)))
+
 ;;; Internal utility functions
 
 (defun ido-ubiquitous--as-string (sym-or-str)
@@ -604,14 +624,18 @@ appropriate debug messages."
   (ido-ubiquitous-set-initial-item nil))
 
 ;; Clear initial item after `self-insert-command'
-(add-hook
- 'ido-minibuffer-setup-hook
- (lambda ()
-   (add-hook
-    'post-self-insert-hook
-    (lambda () (ido-ubiquitous-set-initial-item nil))
-    nil
-    'local)))
+(defun ido-ubiquitous-post-insert-hook ()
+  (eval '(ido-ubiquitous-set-initial-item nil)))
+
+(defun ido-ubiquitous-ido-minibuffer-setup-hook ()
+  (add-hook
+   'post-self-insert-hook
+   #'ido-ubiquitous-post-insert-hook
+   nil
+   'local))
+
+(add-hook 'ido-minibuffer-setup-hook
+          #'ido-ubiquitous-ido-minibuffer-setup-hook)
 
 (defun ido-ubiquitous-should-use-old-style-default ()
   "Returns non nil if ido-ubiquitous should emulate old-style default.
@@ -621,18 +645,18 @@ done in order to decide whether to swap RET and C-j. See
 `ido-ubiquitous-default-state' for more information."
   ;; These checks outside the loop don't produce debug messages
   (and
-   (bound-and-true-p ido-cur-item)
-   ;; Only if completing a list, not a buffer or file
-   (eq ido-cur-item 'list)
-   ;; Only if this call was done through ido-ubiquitous
-   ido-ubiquitous-enable-this-call
    ;; Only if old-style default enabled
    (eq ido-ubiquitous-active-state 'enable-old)
    ;; This loop is just an implementation of `and' that reports which
    ;; arg was nil for debugging purposes.
-   (loop
+   (cl-loop
     for test in
-    '(;; Only if default is nil
+    '((bound-and-true-p ido-cur-item)
+      ;; Only if completing a list, not a buffer or file
+      (eq ido-cur-item 'list)
+      ;; Only if this call was done through ido-ubiquitous
+      ido-ubiquitous-enable-this-call
+      ;; Only if default is nil
       (null ido-default-item)
       ;; Only if input is empty
       (string= ido-text "")
@@ -665,7 +689,9 @@ advice has any effect."
           (let ((ido-ubiquitous-active-state 'enable))
             (ido-select-text))
         ad-do-it)
-    (error ad-do-it))
+    (error
+     (display-warning 'ido-ubiquitous "Advice on `ido-exit-minibuffer' failed." :warning)
+     ad-do-it))
   (ido-ubiquitous-set-initial-item nil))
 
 (defadvice ido-select-text (around old-style-default-compat activate)
@@ -682,7 +708,9 @@ advice has any effect."
           (let ((ido-ubiquitous-active-state 'enable))
             (ido-exit-minibuffer))
         ad-do-it)
-    (error ad-do-it))
+    (error
+     (display-warning 'ido-ubiquitous "Advice on `ido-select-text' failed." :warning)
+     ad-do-it))
   (ido-ubiquitous-set-initial-item nil))
 
 ;;; Overrides
@@ -887,8 +915,10 @@ This advice completely overrides the original definition."
       ;; implementation
       (error ad-do-it))))
 
-;;; Debug messages
+;;; Other
 
+;; This is defined at the end so it goes at the bottom of the
+;; customization group
 (define-minor-mode ido-ubiquitous-debug-mode
   "If non-nil, ido-ubiquitous will print debug info.
 
@@ -897,24 +927,6 @@ Debug info is printed to the *Messages* buffer."
   :global t
   :group 'ido-ubiquitous)
 
-;; Defined as a macro for efficiency (args are not evaluated unless
-;; debug mode is on)
-(defmacro ido-ubiquitous--debug-message (format-string &rest args)
-  `(when ido-ubiquitous-debug-mode
-     (message (concat "ido-ubiquitous: " ,format-string) ,@args)))
-
-(defun ido-ubiquitous--explain-fallback (arg)
-  ;; This function accepts a string, or an ido-ubiquitous-fallback
-  ;; signal.
-  (when ido-ubiquitous-debug-mode
-    (when (and (listp arg)
-               (eq (car arg) 'ido-ubiquitous-fallback))
-      (setq arg (cdr arg)))
-    (ido-ubiquitous--debug-message "Falling back to `%s' because %s."
-                                   ido-cr+-fallback-function arg)))
-
-;;; Other
-
 (defun ido-ubiquitous-initialize ()
   "Do initial setup for ido-ubiquitous.