X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Fminibuf.el;h=af83e9cce927819434fd5dd81469a7eb5e47ddae;hb=56faa9ebec98788eedc7fb482a3301efef26a807;hp=1217fe600a142d23b7ca542f0c1e6ad3a63c0dab;hpb=72a705551741d6f85a40eea486c222bac482d8dc;p=chise%2Fxemacs-chise.git- diff --git a/lisp/minibuf.el b/lisp/minibuf.el index 1217fe6..af83e9c 100644 --- a/lisp/minibuf.el +++ b/lisp/minibuf.el @@ -41,7 +41,7 @@ ;;; Code: (defgroup minibuffer nil - "Controling the behaviour of the minibuffer." + "Controling the behavior of the minibuffer." :group 'environment) @@ -67,7 +67,7 @@ The value may alternatively be a function, which is given three arguments: CODE, which says what kind of things to do. CODE can be nil, t or `lambda'. nil means to return the best completion of STRING, nil if there is none, - or t if it is was already a unique completion. + or t if it is already a unique completion. t means to return a list of all possible completions of STRING. `lambda' means to return t if STRING is a valid completion as it stands.") @@ -77,10 +77,12 @@ t means to return a list of all possible completions of STRING. (defvar minibuffer-completion-confirm nil "Non-nil => demand confirmation of completion before exiting minibuffer.") -(defvar minibuffer-confirm-incomplete nil +(defcustom minibuffer-confirm-incomplete nil "If true, then in contexts where completing-read allows answers which are not valid completions, an extra RET must be typed to confirm the -response. This is helpful for catching typos, etc.") +response. This is helpful for catching typos, etc." + :type 'boolean + :group 'minibuffer) (defcustom completion-auto-help t "*Non-nil means automatically provide help for invalid completion input." @@ -344,13 +346,14 @@ minibuffer history if its length is less than that value." keymap readp history - abbrev-table) + abbrev-table + default) "Read a string from the minibuffer, prompting with string PROMPT. If optional second arg INITIAL-CONTENTS is non-nil, it is a string to be inserted into the minibuffer before reading input. If INITIAL-CONTENTS is (STRING . POSITION), the initial input is STRING, but point is placed POSITION characters into the string. -Third arg KEYMAP is a keymap to use whilst reading; +Third arg KEYMAP is a keymap to use while reading; if omitted or nil, the default is `minibuffer-local-map'. If fourth arg READ is non-nil, then interpret the result as a lisp object and return that object: @@ -366,6 +369,8 @@ Fifth arg HISTORY, if non-nil, specifies a history list Positions are counted starting from 1 at the beginning of the list. Sixth arg ABBREV-TABLE, if non-nil, becomes the value of `local-abbrev-table' in the minibuffer. +Seventh arg DEFAULT, if non-nil, will be returned when user enters + an empty string. See also the variable completion-highlight-first-word-only for control over completion display." @@ -412,7 +417,8 @@ See also the variable completion-highlight-first-word-only for control over ;; `M-x doctor' makes history a local variable, and thus ;; our binding above is buffer-local and doesn't apply ;; once we switch buffers!!!! We demand better scope! - (_history_ history)) + (_history_ history) + (minibuffer-default default)) (unwind-protect (progn (set-buffer (reset-buffer buffer)) @@ -490,8 +496,13 @@ See also the variable completion-highlight-first-word-only for control over (let* ((val (progn (set-buffer buffer) (if minibuffer-exit-hook (run-hooks 'minibuffer-exit-hook)) - (buffer-string))) - (histval val) + (if (and (eq (char-after (point-min)) nil) + default) + default + (buffer-string)))) + (histval (if (and default (string= val "")) + default + val)) (err nil)) (if readp (condition-case e @@ -748,7 +759,7 @@ See also the variable completion-highlight-first-word-only for control over (defun completing-read (prompt table &optional predicate require-match - initial-contents history) + initial-contents history default) "Read a string in the minibuffer, with completion. Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-CONTENTS, HISTORY. PROMPT is a string to prompt with; normally it ends in a colon and a space. @@ -770,19 +781,27 @@ HISTORY, if non-nil, specifies a history list which INITIAL-CONTENTS corresponds to). If HISTORY is `t', no history will be recorded. Positions are counted starting from 1 at the beginning of the list. +DEFAULT, if non-nil, is the default value. Completion ignores case if the ambient value of `completion-ignore-case' is non-nil." (let ((minibuffer-completion-table table) (minibuffer-completion-predicate predicate) (minibuffer-completion-confirm (if (eq require-match 't) nil t)) - (last-exact-completion nil)) - (read-from-minibuffer prompt - initial-contents - (if (not require-match) - minibuffer-local-completion-map - minibuffer-local-must-match-map) - nil - history))) + (last-exact-completion nil) + ret) + (setq ret (read-from-minibuffer prompt + initial-contents + (if (not require-match) + minibuffer-local-completion-map + minibuffer-local-must-match-map) + nil + history + nil + default)) + (if (and (string= ret "") + default) + default + ret))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1231,7 +1250,9 @@ With prefix argument N, search for Nth previous match. If N is negative, find the next or Nth next match." (interactive (let ((enable-recursive-minibuffers t) - (minibuffer-history-sexp-flag nil)) + (minibuffer-history-sexp-flag nil) + (minibuffer-max-depth (and minibuffer-max-depth + (1+ minibuffer-max-depth)))) (if (eq 't (symbol-value minibuffer-history-variable)) (error "History is not being recorded in this context")) (list (read-from-minibuffer "Previous element matching (regexp): " @@ -1279,7 +1300,9 @@ With prefix argument N, search for Nth next match. If N is negative, find the previous or Nth previous match." (interactive (let ((enable-recursive-minibuffers t) - (minibuffer-history-sexp-flag nil)) + (minibuffer-history-sexp-flag nil) + (minibuffer-max-depth (and minibuffer-max-depth + (1+ minibuffer-max-depth)))) (if (eq t (symbol-value minibuffer-history-variable)) (error "History is not being recorded in this context")) (list (read-from-minibuffer "Next element matching (regexp): " @@ -1428,7 +1451,10 @@ only existing buffer names are allowed." result) (while (progn (setq result (completing-read prompt alist nil require-match - nil 'buffer-history)) + nil 'buffer-history + (if (bufferp default) + (buffer-name default) + default))) (cond ((not (equal result "")) nil) ((not require-match) @@ -1477,24 +1503,21 @@ only existing buffer names are allowed." (olen (length string)) new n o ch) - (cond ((eq system-type 'vax-vms) - string) - ((not (string-match regexp string)) - string) - (t - (setq n 1) - (while (string-match regexp string (match-end 0)) - (setq n (1+ n))) - (setq new (make-string (+ olen n) ?$)) - (setq n 0 o 0) - (while (< o olen) - (setq ch (aref string o)) - (aset new n ch) - (setq o (1+ o) n (1+ n)) - (if (eq ch ?$) - ;; already aset by make-string initial-value - (setq n (1+ n)))) - new)))) + (if (not (string-match regexp string)) + string + (setq n 1) + (while (string-match regexp string (match-end 0)) + (setq n (1+ n))) + (setq new (make-string (+ olen n) ?$)) + (setq n 0 o 0) + (while (< o olen) + (setq ch (aref string o)) + (aset new n ch) + (setq o (1+ o) n (1+ n)) + (if (eq ch ?$) + ;; already aset by make-string initial-value + (setq n (1+ n)))) + new))) (defun read-file-name-2 (history prompt dir default must-match initial-contents @@ -1511,8 +1534,7 @@ only existing buffer names are allowed." (length dir))) (t (un-substitute-in-file-name dir)))) - (val (let ((completion-ignore-case (or completion-ignore-case - (eq system-type 'vax-vms)))) + (val ;; Hateful, broken, case-sensitive un*x ;;; (completing-read prompt ;;; completer @@ -1520,23 +1542,24 @@ only existing buffer names are allowed." ;;; must-match ;;; insert ;;; history) - ;; #### - this is essentially the guts of completing read. - ;; There should be an elegant way to pass a pair of keymaps to - ;; completing read, but this will do for now. All sins are - ;; relative. --Stig - (let ((minibuffer-completion-table completer) - (minibuffer-completion-predicate dir) - (minibuffer-completion-confirm (if (eq must-match 't) - nil t)) - (last-exact-completion nil)) - (read-from-minibuffer prompt - insert - (if (not must-match) - read-file-name-map - read-file-name-must-match-map) - nil - history))) - )) + ;; #### - this is essentially the guts of completing read. + ;; There should be an elegant way to pass a pair of keymaps to + ;; completing read, but this will do for now. All sins are + ;; relative. --Stig + (let ((minibuffer-completion-table completer) + (minibuffer-completion-predicate dir) + (minibuffer-completion-confirm (if (eq must-match 't) + nil t)) + (last-exact-completion nil)) + (read-from-minibuffer prompt + insert + (if (not must-match) + read-file-name-map + read-file-name-must-match-map) + nil + history + nil + default)))) ;;; ;; Kludge! Put "/foo/bar" on history rather than "/default//foo/bar" ;;; (let ((hist (cond ((not history) 'minibuffer-history) ;;; ((consp history) (car history)) @@ -1629,7 +1652,7 @@ only existing buffer names are allowed." This will prompt with a dialog box if appropriate, according to `should-use-dialog-box-p'. Value is not expanded---you must call `expand-file-name' yourself. -Value is subject to interpreted by substitute-in-file-name however. +Value is subject to interpretation by `substitute-in-file-name' however. Default name to DEFAULT if user enters a null string. (If DEFAULT is omitted, the visited file name is used, except that if INITIAL-CONTENTS is specified, that combined with DIR is @@ -1728,7 +1751,7 @@ DIR defaults to current buffer's directory default." (alist #'(lambda () (mapcar #'(lambda (x) (cons (substring x 0 (string-match "=" x)) - 'nil)) + nil)) process-environment)))) (cond ((eq action 'lambda) @@ -1743,7 +1766,7 @@ DIR defaults to current buffer's directory default." (concat "$" p) (concat head "$" p))) (all-completions env (funcall alist)))) - (t ;; 'nil + (t ;; nil ;; complete (let* ((e (funcall alist)) (val (try-completion env e))) @@ -1779,7 +1802,7 @@ DIR defaults to current buffer's directory default." ;; all completions (mapcar #'un-substitute-in-file-name (file-name-all-completions name dir))) - (t;; 'nil + (t;; nil ;; complete (let* ((d (or dir default-directory)) (val (file-name-completion name d))) @@ -1820,11 +1843,8 @@ DIR defaults to current buffer's directory default." nil 'directories)))) (mapcar fn - (cond ((eq system-type 'vax-vms) - l) - (t - ;; Wretched unix - (delete "." l)))))))) + ;; Wretched unix + (delete "." l)))))) (cond ((eq action 'lambda) ;; complete? (if (not orig) @@ -2114,10 +2134,18 @@ On mswindows devices, this uses `mswindows-color-list'." ;;(if (featurep 'mule) -(defun read-coding-system (prompt) +(defun read-coding-system (prompt &optional default-coding-system) "Read a coding-system (or nil) from the minibuffer. -Prompting with string PROMPT." - (intern (completing-read prompt obarray 'find-coding-system t))) +Prompting with string PROMPT. +If the user enters null input, return second argument DEFAULT-CODING-SYSTEM. +DEFAULT-CODING-SYSTEM can be a string, symbol, or coding-system object." + (intern (completing-read prompt obarray 'find-coding-system t nil nil + (cond ((symbolp default-coding-system) + (symbol-name default-coding-system)) + ((coding-system-p default-coding-system) + (symbol-name (coding-system-name default-coding-system))) + (t + default-coding-system))))) (defun read-non-nil-coding-system (prompt) "Read a non-nil coding-system from the minibuffer.