aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorEli Zaretskii2006-06-23 13:05:40 +0000
committerEli Zaretskii2006-06-23 13:05:40 +0000
commit08fd202a3d870cfbafa1dcddf189b5a0d1d63fa7 (patch)
tree669ac54edb2b8943dc3bec2c3fa043e017c8d39b /lisp
parent6453a10ed837bfbb36508dfeb18e8d8473236797 (diff)
downloademacs-08fd202a3d870cfbafa1dcddf189b5a0d1d63fa7.tar.gz
emacs-08fd202a3d870cfbafa1dcddf189b5a0d1d63fa7.zip
(PC-do-completion): Retain capitalization of user input, when possible, even
if completion-ignore-case is set.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/complete.el70
2 files changed, 55 insertions, 20 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1508381ce4c..27a6f573aaf 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12006-06-23 Michael Ernst <mernst@alum.mit.edu>
2
3 * complete.el (PC-do-completion): Retain capitalization of user
4 input, when possible, even if completion-ignore-case is set.
5
12006-06-23 Eli Zaretskii <eliz@gnu.org> 62006-06-23 Eli Zaretskii <eliz@gnu.org>
2 7
3 * generic-x.el (bat-generic-mode): Support .cmd files. 8 * generic-x.el (bat-generic-mode): Support .cmd files.
diff --git a/lisp/complete.el b/lisp/complete.el
index d0e3fbe8ddf..df1bc2bfd8b 100644
--- a/lisp/complete.el
+++ b/lisp/complete.el
@@ -196,7 +196,7 @@ as much as possible and `*' characters are treated likewise in file names.
196For example, M-x p-c-m expands to M-x partial-completion-mode since no other 196For example, M-x p-c-m expands to M-x partial-completion-mode since no other
197command begins with that sequence of characters, and 197command begins with that sequence of characters, and
198\\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no 198\\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no
199other file in that directory begin with that sequence of characters. 199other file in that directory begins with that sequence of characters.
200 200
201Unless `PC-disable-includes' is non-nil, the `<...>' sequence is interpreted 201Unless `PC-disable-includes' is non-nil, the `<...>' sequence is interpreted
202specially in \\[find-file]. For example, 202specially in \\[find-file]. For example,
@@ -358,13 +358,36 @@ See `PC-complete' for details."
358The function takes no arguments, and typically looks at the value 358The function takes no arguments, and typically looks at the value
359of `minibuffer-completion-table' and the minibuffer contents.") 359of `minibuffer-completion-table' and the minibuffer contents.")
360 360
361;; Returns the sequence of non-delimiter characters that follow regexp in string.
362(defun PC-chunk-after (string regexp)
363 (if (not (string-match regexp string))
364 (let ((message (format "String %s didn't match regexp %s" string regexp)))
365 (message message)
366 (error message)))
367 (let ((result (substring string (match-end 0))))
368 ;; result may contain multiple chunks
369 (if (string-match PC-delim-regex result)
370 (setq result (substring result 0 (match-beginning 0))))
371 result))
372
373(defun test-completion-ignore-case (str table pred)
374 "Like `test-completion', but ignores case when possible."
375 ;; Binding completion-ignore-case to nil ensures, for compatibility with
376 ;; standard completion, that the return value is exactly one of the
377 ;; possibilities. Do this binding only if pred is nil, out of paranoia;
378 ;; perhaps it is safe even if pred is non-nil.
379 (if pred
380 (test-completion str table pred)
381 (let ((completion-ignore-case nil))
382 (test-completion str table pred))))
383
361(defun PC-do-completion (&optional mode beg end) 384(defun PC-do-completion (&optional mode beg end)
362 (or beg (setq beg (minibuffer-prompt-end))) 385 (or beg (setq beg (minibuffer-prompt-end)))
363 (or end (setq end (point-max))) 386 (or end (setq end (point-max)))
364 (let* ((table minibuffer-completion-table) 387 (let* ((table minibuffer-completion-table)
365 (pred minibuffer-completion-predicate) 388 (pred minibuffer-completion-predicate)
366 (filename (funcall PC-completion-as-file-name-predicate)) 389 (filename (funcall PC-completion-as-file-name-predicate))
367 (dirname nil) 390 (dirname nil) ; non-nil only if a filename is being completed
368 (dirlength 0) 391 (dirlength 0)
369 (str (buffer-substring beg end)) 392 (str (buffer-substring beg end))
370 (incname (and filename (string-match "<\\([^\"<>]*\\)>?$" str))) 393 (incname (and filename (string-match "<\\([^\"<>]*\\)>?$" str)))
@@ -379,7 +402,7 @@ of `minibuffer-completion-table' and the minibuffer contents.")
379 402
380 ;; Check if buffer contents can already be considered complete 403 ;; Check if buffer contents can already be considered complete
381 (if (and (eq mode 'exit) 404 (if (and (eq mode 'exit)
382 (test-completion str table pred)) 405 (test-completion-ignore-case str table pred))
383 'complete 406 'complete
384 407
385 ;; Do substitutions in directory names 408 ;; Do substitutions in directory names
@@ -598,35 +621,38 @@ of `minibuffer-completion-table' and the minibuffer contents.")
598 621
599 ;; Check if next few letters are the same in all cases 622 ;; Check if next few letters are the same in all cases
600 (if (and (not (eq mode 'help)) 623 (if (and (not (eq mode 'help))
601 (setq prefix (try-completion "" (mapcar 'list poss)))) 624 (setq prefix (try-completion (PC-chunk-after basestr skip) (mapcar 'list poss))))
602 (let ((first t) i) 625 (let ((first t) i)
626 ;; Retain capitalization of user input even if
627 ;; completion-ignore-case is set.
603 (if (eq mode 'word) 628 (if (eq mode 'word)
604 (setq prefix (PC-chop-word prefix basestr))) 629 (setq prefix (PC-chop-word prefix basestr)))
605 (goto-char (+ beg (length dirname))) 630 (goto-char (+ beg (length dirname)))
606 (while (and (progn 631 (while (and (progn
607 (setq i 0) 632 (setq i 0) ; index into prefix string
608 (while (< i (length prefix)) 633 (while (< i (length prefix))
609 (if (and (< (point) end) 634 (if (and (< (point) end)
610 (eq (aref prefix i) 635 (eq (downcase (aref prefix i))
611 (following-char))) 636 (downcase (following-char))))
637 ;; same char (modulo case); no action
612 (forward-char 1) 638 (forward-char 1)
613 (if (and (< (point) end) 639 (if (and (< (point) end)
614 (or (and (looking-at " ") 640 (and (looking-at " ")
615 (memq (aref prefix i) 641 (memq (aref prefix i)
616 PC-delims-list)) 642 PC-delims-list)))
617 (eq (downcase (aref prefix i)) 643 ;; replace " " by the actual delimiter
618 (downcase
619 (following-char)))))
620 (progn 644 (progn
621 (delete-char 1) 645 (delete-char 1)
622 (setq end (1- end))) 646 (insert (substring prefix i (1+ i))))
647 ;; insert a new character
648 (progn
623 (and filename (looking-at "\\*") 649 (and filename (looking-at "\\*")
624 (progn 650 (progn
625 (delete-char 1) 651 (delete-char 1)
626 (setq end (1- end)))) 652 (setq end (1- end))))
627 (setq improved t)) 653 (setq improved t)
628 (insert (substring prefix i (1+ i))) 654 (insert (substring prefix i (1+ i)))
629 (setq end (1+ end))) 655 (setq end (1+ end)))))
630 (setq i (1+ i))) 656 (setq i (1+ i)))
631 (or pt (setq pt (point))) 657 (or pt (setq pt (point)))
632 (looking-at PC-delim-regex)) 658 (looking-at PC-delim-regex))
@@ -634,7 +660,12 @@ of `minibuffer-completion-table' and the minibuffer contents.")
634 (regexp-quote prefix) 660 (regexp-quote prefix)
635 PC-ndelims-regex) 661 PC-ndelims-regex)
636 prefix (try-completion 662 prefix (try-completion
637 "" 663 (PC-chunk-after
664 ;; not basestr, because that does
665 ;; not reflect insertions
666 (buffer-substring
667 (+ beg (length dirname)) end)
668 skip)
638 (mapcar 669 (mapcar
639 (function 670 (function
640 (lambda (x) 671 (lambda (x)
@@ -666,7 +697,7 @@ of `minibuffer-completion-table' and the minibuffer contents.")
666 697
667 ;; We changed it... enough to be complete? 698 ;; We changed it... enough to be complete?
668 (and (eq mode 'exit) 699 (and (eq mode 'exit)
669 (test-completion (field-string) table pred)) 700 (test-completion-ignore-case (field-string) table pred))
670 701
671 ;; If totally ambiguous, display a list of completions 702 ;; If totally ambiguous, display a list of completions
672 (if (or (eq completion-auto-help t) 703 (if (or (eq completion-auto-help t)
@@ -950,11 +981,10 @@ absolute rather than relative to some directory on the SEARCH-PATH."
950 (if (string-match "<\\([^\"<>]*\\)>?\\'" (ad-get-arg 0)) 981 (if (string-match "<\\([^\"<>]*\\)>?\\'" (ad-get-arg 0))
951 (let* ((string (ad-get-arg 0)) 982 (let* ((string (ad-get-arg 0))
952 (action (ad-get-arg 2)) 983 (action (ad-get-arg 2))
953 (name (match-string 1 string)) 984 (name (substring string (match-beginning 1) (match-end 1)))
954 (str2 (substring string (match-beginning 0))) 985 (str2 (substring string (match-beginning 0)))
955 (completion-table 986 (completion-table
956 (mapcar (lambda (x) 987 (mapcar (lambda (x) (format "<%s>" x))
957 (format (if (string-match "/\\'" x) "<%s" "<%s>") x))
958 (PC-include-file-all-completions 988 (PC-include-file-all-completions
959 name (PC-include-file-path))))) 989 name (PC-include-file-path)))))
960 (setq ad-return-value 990 (setq ad-return-value