emacs-devel
[Top][All Lists]
Advanced

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

Re: For after-the-release: enhanced partial completion


From: Sean O'Rourke
Subject: Re: For after-the-release: enhanced partial completion
Date: Mon, 04 Jun 2007 15:20:29 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (darwin)

Here's a diff with "-w", which better shows the intent.

/s
Index: complete.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/complete.el,v
retrieving revision 1.72
diff -p -u -w -r1.72 complete.el
--- complete.el 14 Apr 2007 20:23:31 -0000      1.72
+++ complete.el 4 Jun 2007 22:12:42 -0000
@@ -454,6 +454,7 @@ GOTO-END is non-nil, however, it instead
         env-on
         regex
         p offset
+         abbreviated
         (poss nil)
         helpposs
         (case-fold-search completion-ignore-case))
@@ -590,17 +591,23 @@ GOTO-END is non-nil, however, it instead
                  pred nil))
 
       ;; Find an initial list of possible completions
-      (if (not (setq p (string-match (concat PC-delim-regex
+        (unless (setq p (string-match (concat PC-delim-regex
                                             (if filename "\\|\\*" ""))
                                     str
-                                    (+ (length dirname) offset))))
+                                      (+ (length dirname) offset)))
 
          ;; Minibuffer contains no hyphens -- simple case!
-         (setq poss (all-completions (if env-on
-                                         basestr str)
+          (setq poss (all-completions (if env-on basestr str)
                                      table
                                      pred))
-
+          (unless (or filename poss)
+            ;; Try completion as an abbreviation, e.g. "mvb" -> "m-v-b"
+            ;; -> "multiple-value-bind"
+            (setq regex (concat "\\`" (mapconcat #'list str "[^-]*-"))
+                  origstr str
+                  p 1
+                  abbreviated t)))
+        (when p
        ;; Use all-completions to do an initial cull.  This is a big win,
        ;; since all-completions is written in C!
        (let ((compl (all-completions (if env-on
@@ -609,12 +616,17 @@ GOTO-END is non-nil, however, it instead
                                       table
                                       pred)))
          (setq p compl)
+            (when (and compl abbreviated)
+              (setq basestr (mapconcat 'list str "-"))
+              (delete-region beg end)
+              (setq end (+ beg (length basestr)))
+              (insert basestr)))
          (while p
            (and (string-match regex (car p))
                 (progn
                   (set-text-properties 0 (length (car p)) '() (car p))
                   (setq poss (cons (car p) poss))))
-           (setq p (cdr p)))))
+            (setq p (cdr p))))
 
       ;; If table had duplicates, they can be here.
       (delete-dups poss)
@@ -648,6 +660,7 @@ GOTO-END is non-nil, however, it instead
              (and p (setq poss p))))
 
       ;; Now we have a list of possible completions
+
       (cond
 
        ;; No valid completions found
@@ -657,6 +670,9 @@ GOTO-END is non-nil, however, it instead
            (let ((PC-word-failed-flag t))
              (delete-backward-char 1)
              (PC-do-completion 'word))
+               (when abbreviated
+                 (delete-region beg end)
+                 (insert origstr))
          (beep)
          (PC-temp-minibuffer-message (if ambig
                                          " [Ambiguous dir name]"
@@ -857,13 +873,11 @@ only symbols with function definitions a
 Otherwise, all symbols with function definitions, values
 or properties are considered."
   (interactive)
-  (let* ((end (point))
-         ;; To complete the word under point, rather than just the portion
-         ;; before point, use this:
-;;;           (save-excursion
-;;;             (with-syntax-table lisp-mode-syntax-table
-;;;               (forward-sexp 1)
-;;;               (point))))
+  (let* ((end
+          (save-excursion
+            (with-syntax-table lisp-mode-syntax-table
+              (forward-sexp 1)
+              (point))))
         (beg (save-excursion
                 (with-syntax-table lisp-mode-syntax-table
                   (backward-sexp 1)

reply via email to

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