Show
Ignore:
Timestamp:
07/01/06 08:27:06 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/complete.el

    r4091 r4098  
    197197command begins with that sequence of characters, and 
    198198\\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no 
    199 other file in that directory begin with that sequence of characters. 
     199other file in that directory begins with that sequence of characters. 
    200200 
    201201Unless `PC-disable-includes' is non-nil, the `<...>' sequence is interpreted 
     
    235235   (if partial-completion-mode 'add-hook 'remove-hook) 
    236236   'choose-completion-string-functions 
    237    (lambda (&rest x) (goto-char (point-max)) nil)) 
     237   (lambda (choice buffer mini-p base-size) 
     238     (if mini-p (goto-char (point-max))) 
     239     nil)) 
    238240  ;; Build the env-completion and mapping table. 
    239241  (when (and partial-completion-mode (null PC-env-vars-alist)) 
     
    359361of `minibuffer-completion-table' and the minibuffer contents.") 
    360362 
     363;; Returns the sequence of non-delimiter characters that follow regexp in string. 
     364(defun PC-chunk-after (string regexp) 
     365  (if (not (string-match regexp string)) 
     366      (let ((message (format "String %s didn't match regexp %s" string regexp))) 
     367        (message message) 
     368        (error message))) 
     369  (let ((result (substring string (match-end 0)))) 
     370    ;; result may contain multiple chunks 
     371    (if (string-match PC-delim-regex result) 
     372        (setq result (substring result 0 (match-beginning 0)))) 
     373    result)) 
     374 
     375(defun test-completion-ignore-case (str table pred) 
     376  "Like `test-completion', but ignores case when possible." 
     377  ;; Binding completion-ignore-case to nil ensures, for compatibility with 
     378  ;; standard completion, that the return value is exactly one of the 
     379  ;; possibilities.  Do this binding only if pred is nil, out of paranoia; 
     380  ;; perhaps it is safe even if pred is non-nil. 
     381  (if pred 
     382      (test-completion str table pred) 
     383    (let ((completion-ignore-case nil)) 
     384      (test-completion str table pred)))) 
     385 
    361386(defun PC-do-completion (&optional mode beg end) 
    362387  (or beg (setq beg (minibuffer-prompt-end))) 
     
    365390         (pred minibuffer-completion-predicate) 
    366391         (filename (funcall PC-completion-as-file-name-predicate)) 
    367          (dirname nil) 
     392         (dirname nil)         ; non-nil only if a filename is being completed 
    368393         (dirlength 0) 
    369394         (str (buffer-substring beg end)) 
     
    380405    ;; Check if buffer contents can already be considered complete 
    381406    (if (and (eq mode 'exit) 
    382              (test-completion str table pred)) 
     407             (test-completion-ignore-case str table pred)) 
    383408        'complete 
    384409 
     
    599624            ;; Check if next few letters are the same in all cases 
    600625            (if (and (not (eq mode 'help)) 
    601                      (setq prefix (try-completion "" (mapcar 'list poss)))) 
     626                     (setq prefix (try-completion (PC-chunk-after basestr skip) (mapcar 'list poss)))) 
    602627                (let ((first t) i) 
     628                  ;; Retain capitalization of user input even if 
     629                  ;; completion-ignore-case is set. 
    603630                  (if (eq mode 'word) 
    604631                      (setq prefix (PC-chop-word prefix basestr))) 
    605632                  (goto-char (+ beg (length dirname))) 
    606633                  (while (and (progn 
    607                                 (setq i 0) 
     634                                (setq i 0) ; index into prefix string 
    608635                                (while (< i (length prefix)) 
    609636                                  (if (and (< (point) end) 
    610                                            (eq (aref prefix i) 
    611                                                (following-char))) 
     637                                           (eq (downcase (aref prefix i)) 
     638                                               (downcase (following-char)))) 
     639                                      ;; same char (modulo case); no action 
    612640                                      (forward-char 1) 
    613641                                    (if (and (< (point) end) 
    614                                              (or (and (looking-at " ") 
     642                                             (and (looking-at " ") 
    615643                                                      (memq (aref prefix i) 
    616                                                             PC-delims-list)) 
    617                                                  (eq (downcase (aref prefix i)) 
    618                                                      (downcase 
    619                                                       (following-char))))) 
     644                                                        PC-delims-list))) 
     645                                        ;; replace " " by the actual delimiter 
    620646                                        (progn 
    621647                                          (delete-char 1) 
    622                                           (setq end (1- end))) 
     648                                          (insert (substring prefix i (1+ i)))) 
     649                                      ;; insert a new character 
     650                                      (progn 
    623651                                      (and filename (looking-at "\\*") 
    624652                                           (progn 
    625653                                             (delete-char 1) 
    626654                                             (setq end (1- end)))) 
    627                                       (setq improved t)
     655                                       (setq improved t
    628656                                    (insert (substring prefix i (1+ i))) 
    629                                     (setq end (1+ end))) 
     657                                       (setq end (1+ end))))) 
    630658                                  (setq i (1+ i))) 
    631659                                (or pt (setq pt (point))) 
     
    635663                                                 PC-ndelims-regex) 
    636664                                    prefix (try-completion 
    637                                             "" 
     665                                            (PC-chunk-after 
     666                                             ;; not basestr, because that does 
     667                                             ;; not reflect insertions 
     668                                             (buffer-substring 
     669                                              (+ beg (length dirname)) end) 
     670                                             skip) 
    638671                                            (mapcar 
    639672                                             (function 
     
    667700                  ;; We changed it... enough to be complete? 
    668701                  (and (eq mode 'exit) 
    669                        (test-completion (field-string) table pred)) 
     702                       (test-completion-ignore-case (field-string) table pred)) 
    670703 
    671704                ;; If totally ambiguous, display a list of completions 
     
    951984      (let* ((string (ad-get-arg 0)) 
    952985             (action (ad-get-arg 2)) 
    953              (name (match-string 1 string)) 
     986             (name (substring string (match-beginning 1) (match-end 1))) 
    954987             (str2 (substring string (match-beginning 0))) 
    955988             (completion-table 
    956               (mapcar (lambda (x) 
    957                         (format (if (string-match "/\\'" x) "<%s" "<%s>") x)) 
     989              (mapcar (lambda (x) (format "<%s>" x)) 
    958990                      (PC-include-file-all-completions 
    959991                       name (PC-include-file-path)))))