Changeset 4098 for trunk/lisp/complete.el
- Timestamp:
- 07/01/06 08:27:06 (2 years ago)
- Files:
-
- trunk/lisp/complete.el (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lisp/complete.el
r4091 r4098 197 197 command begins with that sequence of characters, and 198 198 \\[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.199 other file in that directory begins with that sequence of characters. 200 200 201 201 Unless `PC-disable-includes' is non-nil, the `<...>' sequence is interpreted … … 235 235 (if partial-completion-mode 'add-hook 'remove-hook) 236 236 '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)) 238 240 ;; Build the env-completion and mapping table. 239 241 (when (and partial-completion-mode (null PC-env-vars-alist)) … … 359 361 of `minibuffer-completion-table' and the minibuffer contents.") 360 362 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 361 386 (defun PC-do-completion (&optional mode beg end) 362 387 (or beg (setq beg (minibuffer-prompt-end))) … … 365 390 (pred minibuffer-completion-predicate) 366 391 (filename (funcall PC-completion-as-file-name-predicate)) 367 (dirname nil) 392 (dirname nil) ; non-nil only if a filename is being completed 368 393 (dirlength 0) 369 394 (str (buffer-substring beg end)) … … 380 405 ;; Check if buffer contents can already be considered complete 381 406 (if (and (eq mode 'exit) 382 (test-completion str table pred))407 (test-completion-ignore-case str table pred)) 383 408 'complete 384 409 … … 599 624 ;; Check if next few letters are the same in all cases 600 625 (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)))) 602 627 (let ((first t) i) 628 ;; Retain capitalization of user input even if 629 ;; completion-ignore-case is set. 603 630 (if (eq mode 'word) 604 631 (setq prefix (PC-chop-word prefix basestr))) 605 632 (goto-char (+ beg (length dirname))) 606 633 (while (and (progn 607 (setq i 0) 634 (setq i 0) ; index into prefix string 608 635 (while (< i (length prefix)) 609 636 (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 612 640 (forward-char 1) 613 641 (if (and (< (point) end) 614 ( or (and (looking-at " ")642 (and (looking-at " ") 615 643 (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 620 646 (progn 621 647 (delete-char 1) 622 (setq end (1- end))) 648 (insert (substring prefix i (1+ i)))) 649 ;; insert a new character 650 (progn 623 651 (and filename (looking-at "\\*") 624 652 (progn 625 653 (delete-char 1) 626 654 (setq end (1- end)))) 627 (setq improved t))655 (setq improved t) 628 656 (insert (substring prefix i (1+ i))) 629 (setq end (1+ end)))657 (setq end (1+ end))))) 630 658 (setq i (1+ i))) 631 659 (or pt (setq pt (point))) … … 635 663 PC-ndelims-regex) 636 664 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) 638 671 (mapcar 639 672 (function … … 667 700 ;; We changed it... enough to be complete? 668 701 (and (eq mode 'exit) 669 (test-completion (field-string) table pred))702 (test-completion-ignore-case (field-string) table pred)) 670 703 671 704 ;; If totally ambiguous, display a list of completions … … 951 984 (let* ((string (ad-get-arg 0)) 952 985 (action (ad-get-arg 2)) 953 (name ( match-string 1 string))986 (name (substring string (match-beginning 1) (match-end 1))) 954 987 (str2 (substring string (match-beginning 0))) 955 988 (completion-table 956 (mapcar (lambda (x) 957 (format (if (string-match "/\\'" x) "<%s" "<%s>") x)) 989 (mapcar (lambda (x) (format "<%s>" x)) 958 990 (PC-include-file-all-completions 959 991 name (PC-include-file-path)))))
