comparison lisp/minibuf.el @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents aabb7f5b1c81
children 2f8bb876ab1d
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
75 "Within call to `completing-read', this holds the PREDICATE argument.") 75 "Within call to `completing-read', this holds the PREDICATE argument.")
76 76
77 (defvar minibuffer-completion-confirm nil 77 (defvar minibuffer-completion-confirm nil
78 "Non-nil => demand confirmation of completion before exiting minibuffer.") 78 "Non-nil => demand confirmation of completion before exiting minibuffer.")
79 79
80 (defvar minibuffer-confirm-incomplete nil 80 (defcustom minibuffer-confirm-incomplete nil
81 "If true, then in contexts where completing-read allows answers which 81 "If true, then in contexts where completing-read allows answers which
82 are not valid completions, an extra RET must be typed to confirm the 82 are not valid completions, an extra RET must be typed to confirm the
83 response. This is helpful for catching typos, etc.") 83 response. This is helpful for catching typos, etc."
84 :type 'boolean
85 :group 'minibuffer)
84 86
85 (defcustom completion-auto-help t 87 (defcustom completion-auto-help t
86 "*Non-nil means automatically provide help for invalid completion input." 88 "*Non-nil means automatically provide help for invalid completion input."
87 :type 'boolean 89 :type 'boolean
88 :group 'minibuffer) 90 :group 'minibuffer)
342 344
343 (defun read-from-minibuffer (prompt &optional initial-contents 345 (defun read-from-minibuffer (prompt &optional initial-contents
344 keymap 346 keymap
345 readp 347 readp
346 history 348 history
347 abbrev-table) 349 abbrev-table
350 default)
348 "Read a string from the minibuffer, prompting with string PROMPT. 351 "Read a string from the minibuffer, prompting with string PROMPT.
349 If optional second arg INITIAL-CONTENTS is non-nil, it is a string 352 If optional second arg INITIAL-CONTENTS is non-nil, it is a string
350 to be inserted into the minibuffer before reading input. 353 to be inserted into the minibuffer before reading input.
351 If INITIAL-CONTENTS is (STRING . POSITION), the initial input 354 If INITIAL-CONTENTS is (STRING . POSITION), the initial input
352 is STRING, but point is placed POSITION characters into the string. 355 is STRING, but point is placed POSITION characters into the string.
364 which INITIAL-CONTENTS corresponds to). 367 which INITIAL-CONTENTS corresponds to).
365 If HISTORY is `t', no history will be recorded. 368 If HISTORY is `t', no history will be recorded.
366 Positions are counted starting from 1 at the beginning of the list. 369 Positions are counted starting from 1 at the beginning of the list.
367 Sixth arg ABBREV-TABLE, if non-nil, becomes the value of `local-abbrev-table' 370 Sixth arg ABBREV-TABLE, if non-nil, becomes the value of `local-abbrev-table'
368 in the minibuffer. 371 in the minibuffer.
372 Seventh arg DEFAULT, if non-nil, will be returned when user enters
373 an empty string.
369 374
370 See also the variable completion-highlight-first-word-only for control over 375 See also the variable completion-highlight-first-word-only for control over
371 completion display." 376 completion display."
372 (if (and (not enable-recursive-minibuffers) 377 (if (and (not enable-recursive-minibuffers)
373 (> (minibuffer-depth) 0) 378 (> (minibuffer-depth) 0)
410 (oconfig (current-window-configuration)) 415 (oconfig (current-window-configuration))
411 ;; dynamic scope sucks sucks sucks sucks sucks sucks. 416 ;; dynamic scope sucks sucks sucks sucks sucks sucks.
412 ;; `M-x doctor' makes history a local variable, and thus 417 ;; `M-x doctor' makes history a local variable, and thus
413 ;; our binding above is buffer-local and doesn't apply 418 ;; our binding above is buffer-local and doesn't apply
414 ;; once we switch buffers!!!! We demand better scope! 419 ;; once we switch buffers!!!! We demand better scope!
415 (_history_ history)) 420 (_history_ history)
421 (minibuffer-default default))
416 (unwind-protect 422 (unwind-protect
417 (progn 423 (progn
418 (set-buffer (reset-buffer buffer)) 424 (set-buffer (reset-buffer buffer))
419 (setq default-directory dir) 425 (setq default-directory dir)
420 (make-local-variable 'print-escape-newlines) 426 (make-local-variable 'print-escape-newlines)
488 (signal 'quit '()) 494 (signal 'quit '())
489 ;; return value 495 ;; return value
490 (let* ((val (progn (set-buffer buffer) 496 (let* ((val (progn (set-buffer buffer)
491 (if minibuffer-exit-hook 497 (if minibuffer-exit-hook
492 (run-hooks 'minibuffer-exit-hook)) 498 (run-hooks 'minibuffer-exit-hook))
493 (buffer-string))) 499 (if (and (eq (char-after (point-min)) nil)
494 (histval val) 500 default)
501 default
502 (buffer-string))))
503 (histval (if (and default (string= val ""))
504 default
505 val))
495 (err nil)) 506 (err nil))
496 (if readp 507 (if readp
497 (condition-case e 508 (condition-case e
498 (let ((v (read-from-string val))) 509 (let ((v (read-from-string val)))
499 (if (< (cdr v) (length val)) 510 (if (< (cdr v) (length val))
746 757
747 ;;;; completing-read 758 ;;;; completing-read
748 759
749 (defun completing-read (prompt table 760 (defun completing-read (prompt table
750 &optional predicate require-match 761 &optional predicate require-match
751 initial-contents history) 762 initial-contents history default)
752 "Read a string in the minibuffer, with completion. 763 "Read a string in the minibuffer, with completion.
753 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-CONTENTS, HISTORY. 764 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-CONTENTS, HISTORY.
754 PROMPT is a string to prompt with; normally it ends in a colon and a space. 765 PROMPT is a string to prompt with; normally it ends in a colon and a space.
755 TABLE is an alist whose elements' cars are strings, or an obarray. 766 TABLE is an alist whose elements' cars are strings, or an obarray.
756 PREDICATE limits completion to a subset of TABLE. 767 PREDICATE limits completion to a subset of TABLE.
768 In that case, HISTVAR is the history list variable to use, 779 In that case, HISTVAR is the history list variable to use,
769 and HISTPOS is the initial position (the position in the list 780 and HISTPOS is the initial position (the position in the list
770 which INITIAL-CONTENTS corresponds to). 781 which INITIAL-CONTENTS corresponds to).
771 If HISTORY is `t', no history will be recorded. 782 If HISTORY is `t', no history will be recorded.
772 Positions are counted starting from 1 at the beginning of the list. 783 Positions are counted starting from 1 at the beginning of the list.
784 DEFAULT, if non-nil, is the default value.
773 Completion ignores case if the ambient value of 785 Completion ignores case if the ambient value of
774 `completion-ignore-case' is non-nil." 786 `completion-ignore-case' is non-nil."
775 (let ((minibuffer-completion-table table) 787 (let ((minibuffer-completion-table table)
776 (minibuffer-completion-predicate predicate) 788 (minibuffer-completion-predicate predicate)
777 (minibuffer-completion-confirm (if (eq require-match 't) nil t)) 789 (minibuffer-completion-confirm (if (eq require-match 't) nil t))
778 (last-exact-completion nil)) 790 (last-exact-completion nil)
779 (read-from-minibuffer prompt 791 ret)
780 initial-contents 792 (setq ret (read-from-minibuffer prompt
781 (if (not require-match) 793 initial-contents
782 minibuffer-local-completion-map 794 (if (not require-match)
783 minibuffer-local-must-match-map) 795 minibuffer-local-completion-map
784 nil 796 minibuffer-local-must-match-map)
785 history))) 797 nil
798 history
799 nil
800 default))
801 (if (and (string= ret "")
802 default)
803 default
804 ret)))
786 805
787 806
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 807 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
789 ;;;; Minibuffer completion commands ;;;; 808 ;;;; Minibuffer completion commands ;;;;
790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 809 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1229 \(Previous history elements refer to earlier actions.) 1248 \(Previous history elements refer to earlier actions.)
1230 With prefix argument N, search for Nth previous match. 1249 With prefix argument N, search for Nth previous match.
1231 If N is negative, find the next or Nth next match." 1250 If N is negative, find the next or Nth next match."
1232 (interactive 1251 (interactive
1233 (let ((enable-recursive-minibuffers t) 1252 (let ((enable-recursive-minibuffers t)
1234 (minibuffer-history-sexp-flag nil)) 1253 (minibuffer-history-sexp-flag nil)
1254 (minibuffer-max-depth (and minibuffer-max-depth
1255 (1+ minibuffer-max-depth))))
1235 (if (eq 't (symbol-value minibuffer-history-variable)) 1256 (if (eq 't (symbol-value minibuffer-history-variable))
1236 (error "History is not being recorded in this context")) 1257 (error "History is not being recorded in this context"))
1237 (list (read-from-minibuffer "Previous element matching (regexp): " 1258 (list (read-from-minibuffer "Previous element matching (regexp): "
1238 (car minibuffer-history-search-history) 1259 (car minibuffer-history-search-history)
1239 minibuffer-local-map 1260 minibuffer-local-map
1277 \(The next history element refers to a more recent action.) 1298 \(The next history element refers to a more recent action.)
1278 With prefix argument N, search for Nth next match. 1299 With prefix argument N, search for Nth next match.
1279 If N is negative, find the previous or Nth previous match." 1300 If N is negative, find the previous or Nth previous match."
1280 (interactive 1301 (interactive
1281 (let ((enable-recursive-minibuffers t) 1302 (let ((enable-recursive-minibuffers t)
1282 (minibuffer-history-sexp-flag nil)) 1303 (minibuffer-history-sexp-flag nil)
1304 (minibuffer-max-depth (and minibuffer-max-depth
1305 (1+ minibuffer-max-depth))))
1283 (if (eq t (symbol-value minibuffer-history-variable)) 1306 (if (eq t (symbol-value minibuffer-history-variable))
1284 (error "History is not being recorded in this context")) 1307 (error "History is not being recorded in this context"))
1285 (list (read-from-minibuffer "Next element matching (regexp): " 1308 (list (read-from-minibuffer "Next element matching (regexp): "
1286 (car minibuffer-history-search-history) 1309 (car minibuffer-history-search-history)
1287 minibuffer-local-map 1310 minibuffer-local-map
1301 (setq current-minibuffer-contents (buffer-string) 1324 (setq current-minibuffer-contents (buffer-string)
1302 current-minibuffer-point (point))) 1325 current-minibuffer-point (point)))
1303 (let ((narg (- minibuffer-history-position n)) 1326 (let ((narg (- minibuffer-history-position n))
1304 (minimum (if minibuffer-default -1 0))) 1327 (minimum (if minibuffer-default -1 0)))
1305 (cond ((< narg minimum) 1328 (cond ((< narg minimum)
1306 (error "No following item in %s" minibuffer-history-variable)) 1329 (error (if minibuffer-default
1330 "No following item in %s"
1331 "No following item in %s; no default available")
1332 minibuffer-history-variable))
1307 ((> narg (length (symbol-value minibuffer-history-variable))) 1333 ((> narg (length (symbol-value minibuffer-history-variable)))
1308 (error "No preceding item in %s" minibuffer-history-variable))) 1334 (error "No preceding item in %s" minibuffer-history-variable)))
1309 (erase-buffer) 1335 (erase-buffer)
1310 (setq minibuffer-history-position narg) 1336 (setq minibuffer-history-position narg)
1311 (if (eq narg initial-minibuffer-history-position) 1337 (if (eq narg initial-minibuffer-history-position)
1352 1378
1353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1354 ;;;; reading various things from a minibuffer ;;;; 1380 ;;;; reading various things from a minibuffer ;;;;
1355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1356 1382
1357 (defun read-expression (prompt &optional initial-contents history) 1383 (defun read-expression (prompt &optional initial-contents history default-value)
1358 "Return a Lisp object read using the minibuffer. 1384 "Return a Lisp object read using the minibuffer, prompting with PROMPT.
1359 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS 1385 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert
1360 is a string to insert in the minibuffer before reading. 1386 in the minibuffer before reading.
1361 Third arg HISTORY, if non-nil, specifies a history list." 1387 Third arg HISTORY, if non-nil, specifies a history list.
1388 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used
1389 for history command, and as the value to return if the user enters the
1390 empty string."
1362 (let ((minibuffer-history-sexp-flag t) 1391 (let ((minibuffer-history-sexp-flag t)
1363 ;; Semi-kludge to get around M-x C-x o M-ESC trying to do completion. 1392 ;; Semi-kludge to get around M-x C-x o M-ESC trying to do completion.
1364 (minibuffer-completion-table nil)) 1393 (minibuffer-completion-table nil))
1365 (read-from-minibuffer prompt 1394 (read-from-minibuffer prompt
1366 initial-contents 1395 initial-contents
1367 read-expression-map 1396 read-expression-map
1368 t 1397 t
1369 (or history 'read-expression-history) 1398 (or history 'read-expression-history)
1370 lisp-mode-abbrev-table))) 1399 lisp-mode-abbrev-table
1371 1400 default-value)))
1372 (defun read-string (prompt &optional initial-contents history) 1401
1402 (defun read-string (prompt &optional initial-contents history default-value)
1373 "Return a string from the minibuffer, prompting with string PROMPT. 1403 "Return a string from the minibuffer, prompting with string PROMPT.
1374 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert 1404 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert
1375 in the minibuffer before reading. 1405 in the minibuffer before reading.
1376 Third arg HISTORY, if non-nil, specifies a history list." 1406 Third arg HISTORY, if non-nil, specifies a history list.
1407 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used
1408 for history command, and as the value to return if the user enters the
1409 empty string."
1377 (let ((minibuffer-completion-table nil)) 1410 (let ((minibuffer-completion-table nil))
1378 (read-from-minibuffer prompt 1411 (read-from-minibuffer prompt
1379 initial-contents 1412 initial-contents
1380 minibuffer-local-map 1413 minibuffer-local-map
1381 nil history))) 1414 nil history nil default-value)))
1382 1415
1383 (defun eval-minibuffer (prompt &optional initial-contents history) 1416 (defun eval-minibuffer (prompt &optional initial-contents history default-value)
1384 "Return value of Lisp expression read using the minibuffer. 1417 "Return value of Lisp expression read using the minibuffer.
1385 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS 1418 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
1386 is a string to insert in the minibuffer before reading. 1419 is a string to insert in the minibuffer before reading.
1387 Third arg HISTORY, if non-nil, specifies a history list." 1420 Third arg HISTORY, if non-nil, specifies a history list.
1388 (eval (read-expression prompt initial-contents history))) 1421 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used
1422 for history command, and as the value to return if the user enters the
1423 empty string."
1424 (eval (read-expression prompt initial-contents history default-value)))
1389 1425
1390 ;; The name `command-history' is already taken 1426 ;; The name `command-history' is already taken
1391 (defvar read-command-history '()) 1427 (defvar read-command-history '())
1392 1428
1393 (defun read-command (prompt) 1429 (defun read-command (prompt &optional default-value)
1394 "Read the name of a command and return as a symbol. 1430 "Read the name of a command and return as a symbol.
1395 Prompts with PROMPT." 1431 Prompts with PROMPT. By default, return DEFAULT-VALUE."
1396 (intern (completing-read prompt obarray 'commandp t nil 1432 (intern (completing-read prompt obarray 'commandp t nil
1397 ;; 'command-history is not right here: that's a 1433 ;; 'command-history is not right here: that's a
1398 ;; list of evalable forms, not a history list. 1434 ;; list of evalable forms, not a history list.
1399 'read-command-history 1435 'read-command-history
1400 ))) 1436 default-value)))
1401 1437
1402 (defun read-function (prompt) 1438 (defun read-function (prompt &optional default-value)
1403 "Read the name of a function and return as a symbol. 1439 "Read the name of a function and return as a symbol.
1404 Prompts with PROMPT." 1440 Prompts with PROMPT. By default, return DEFAULT-VALUE."
1405 (intern (completing-read prompt obarray 'fboundp t nil 1441 (intern (completing-read prompt obarray 'fboundp t nil
1406 'function-history))) 1442 'function-history default-value)))
1407 1443
1408 (defun read-variable (prompt) 1444 (defun read-variable (prompt &optional default-value)
1409 "Read the name of a user variable and return it as a symbol. 1445 "Read the name of a user variable and return it as a symbol.
1410 Prompts with PROMPT. 1446 Prompts with PROMPT. By default, return DEFAULT-VALUE.
1411 A user variable is one whose documentation starts with a `*' character." 1447 A user variable is one whose documentation starts with a `*' character."
1412 (intern (completing-read prompt obarray 'user-variable-p t nil 1448 (intern (completing-read prompt obarray 'user-variable-p t nil
1413 'variable-history))) 1449 'variable-history default-value)))
1414 1450
1415 (defun read-buffer (prompt &optional default require-match) 1451 (defun read-buffer (prompt &optional default require-match)
1416 "Read the name of a buffer and return as a string. 1452 "Read the name of a buffer and return as a string.
1417 Prompts with PROMPT. Optional second arg DEFAULT is value to return if user 1453 Prompts with PROMPT. Optional second arg DEFAULT is value to return if user
1418 enters an empty line. If optional third arg REQUIRE-MATCH is non-nil, 1454 enters an empty line. If optional third arg REQUIRE-MATCH is non-nil,
1426 (alist (mapcar #'(lambda (b) (cons (buffer-name b) b)) 1462 (alist (mapcar #'(lambda (b) (cons (buffer-name b) b))
1427 (buffer-list))) 1463 (buffer-list)))
1428 result) 1464 result)
1429 (while (progn 1465 (while (progn
1430 (setq result (completing-read prompt alist nil require-match 1466 (setq result (completing-read prompt alist nil require-match
1431 nil 'buffer-history)) 1467 nil 'buffer-history
1468 (if (bufferp default)
1469 (buffer-name default)
1470 default)))
1432 (cond ((not (equal result "")) 1471 (cond ((not (equal result ""))
1433 nil) 1472 nil)
1434 ((not require-match) 1473 ((not require-match)
1435 (setq result default) 1474 (setq result default)
1436 nil) 1475 nil)
1443 nil)))) 1482 nil))))
1444 (if (bufferp result) 1483 (if (bufferp result)
1445 (buffer-name result) 1484 (buffer-name result)
1446 result))) 1485 result)))
1447 1486
1448 (defun read-number (prompt &optional integers-only) 1487 (defun read-number (prompt &optional integers-only default-value)
1449 "Read a number from the minibuffer." 1488 "Read a number from the minibuffer, prompting with PROMPT.
1489 If optional second argument INTEGERS-ONLY is non-nil, accept
1490 only integer input.
1491 If DEFAULT-VALUE is non-nil, return that if user enters an empty
1492 line."
1450 (let ((pred (if integers-only 'integerp 'numberp)) 1493 (let ((pred (if integers-only 'integerp 'numberp))
1451 num) 1494 num)
1452 (while (not (funcall pred num)) 1495 (while (not (funcall pred num))
1453 (setq num (condition-case () 1496 (setq num (condition-case ()
1454 (let ((minibuffer-completion-table nil)) 1497 (let ((minibuffer-completion-table nil))
1455 (read-from-minibuffer 1498 (read-from-minibuffer
1456 prompt (if num (prin1-to-string num)) nil t 1499 prompt (if num (prin1-to-string num)) nil t
1457 t)) ;no history 1500 nil nil default-value))
1458 (input-error nil) 1501 (input-error nil)
1459 (invalid-read-syntax nil) 1502 (invalid-read-syntax nil)
1460 (end-of-file nil))) 1503 (end-of-file nil)))
1461 (or (funcall pred num) (beep))) 1504 (or (funcall pred num) (beep)))
1462 num)) 1505 num))
1463 1506
1464 (defun read-shell-command (prompt &optional initial-input history) 1507 (defun read-shell-command (prompt &optional initial-input history default-value)
1465 "Just like read-string, but uses read-shell-command-map: 1508 "Just like read-string, but uses read-shell-command-map:
1466 \\{read-shell-command-map}" 1509 \\{read-shell-command-map}"
1467 (let ((minibuffer-completion-table nil)) 1510 (let ((minibuffer-completion-table nil))
1468 (read-from-minibuffer prompt initial-input read-shell-command-map 1511 (read-from-minibuffer prompt initial-input read-shell-command-map
1469 nil (or history 'shell-command-history)))) 1512 nil (or history 'shell-command-history)
1513 nil default-value)))
1470 1514
1471 1515
1472 ;;; This read-file-name stuff probably belongs in files.el 1516 ;;; This read-file-name stuff probably belongs in files.el
1473 1517
1474 ;; Quote "$" as "$$" to get it past substitute-in-file-name 1518 ;; Quote "$" as "$$" to get it past substitute-in-file-name
1529 insert 1573 insert
1530 (if (not must-match) 1574 (if (not must-match)
1531 read-file-name-map 1575 read-file-name-map
1532 read-file-name-must-match-map) 1576 read-file-name-must-match-map)
1533 nil 1577 nil
1534 history)) 1578 history
1535 )) 1579 nil
1580 default))))
1536 ;;; ;; Kludge! Put "/foo/bar" on history rather than "/default//foo/bar" 1581 ;;; ;; Kludge! Put "/foo/bar" on history rather than "/default//foo/bar"
1537 ;;; (let ((hist (cond ((not history) 'minibuffer-history) 1582 ;;; (let ((hist (cond ((not history) 'minibuffer-history)
1538 ;;; ((consp history) (car history)) 1583 ;;; ((consp history) (car history))
1539 ;;; (t history)))) 1584 ;;; (t history))))
1540 ;;; (if (and val 1585 ;;; (if (and val
1623 history) 1668 history)
1624 "Read file name, prompting with PROMPT and completing in directory DIR. 1669 "Read file name, prompting with PROMPT and completing in directory DIR.
1625 This will prompt with a dialog box if appropriate, according to 1670 This will prompt with a dialog box if appropriate, according to
1626 `should-use-dialog-box-p'. 1671 `should-use-dialog-box-p'.
1627 Value is not expanded---you must call `expand-file-name' yourself. 1672 Value is not expanded---you must call `expand-file-name' yourself.
1628 Value is subject to interpreted by substitute-in-file-name however. 1673 Value is subject to interpretation by `substitute-in-file-name' however.
1629 Default name to DEFAULT if user enters a null string. 1674 Default name to DEFAULT if user enters a null string.
1630 (If DEFAULT is omitted, the visited file name is used, 1675 (If DEFAULT is omitted, the visited file name is used,
1631 except that if INITIAL-CONTENTS is specified, that combined with DIR is 1676 except that if INITIAL-CONTENTS is specified, that combined with DIR is
1632 used.) 1677 used.)
1633 Fourth arg MUST-MATCH non-nil means require existing file's name. 1678 Fourth arg MUST-MATCH non-nil means require existing file's name.
1634 Non-nil and non-t means also require confirmation after completion. 1679 Non-nil and non-t means also require confirmation after completion.
1635 Fifth arg INITIAL-CONTENTS specifies text to start with. 1680 Fifth arg INITIAL-CONTENTS specifies text to start with. If this is not
1681 specified, and `insert-default-directory' is non-nil, DIR or the current
1682 directory will be used.
1636 Sixth arg HISTORY specifies the history list to use. Default is 1683 Sixth arg HISTORY specifies the history list to use. Default is
1637 `file-name-history'. 1684 `file-name-history'.
1638 DIR defaults to current buffer's directory default." 1685 DIR defaults to current buffer's directory default."
1639 (read-file-name-1 1686 (read-file-name-1
1640 (or history 'file-name-history) 1687 (or history 'file-name-history)
1641 prompt dir (or default 1688 prompt dir (or default
1642 (if initial-contents (expand-file-name initial-contents dir) 1689 (and initial-contents
1643 buffer-file-name)) 1690 (abbreviate-file-name (expand-file-name
1691 initial-contents dir) t))
1692 (and buffer-file-truename
1693 (abbreviate-file-name buffer-file-name t)))
1644 must-match initial-contents 1694 must-match initial-contents
1645 ;; A separate function (not an anonymous lambda-expression) 1695 ;; A separate function (not an anonymous lambda-expression)
1646 ;; and passed as a symbol because of disgusting kludges in various 1696 ;; and passed as a symbol because of disgusting kludges in various
1647 ;; places which do stuff like (let ((filename-kludge-p (eq minibuffer-completion-table 'read-file-name-internal))) ...) 1697 ;; places which do stuff like (let ((filename-kludge-p (eq minibuffer-completion-table 'read-file-name-internal))) ...)
1648 'read-file-name-internal)) 1698 'read-file-name-internal))
2105 ;; only include these if the mule feature is present. Strangely, 2155 ;; only include these if the mule feature is present. Strangely,
2106 ;; read-coding-system doesn't. 2156 ;; read-coding-system doesn't.
2107 2157
2108 ;;(if (featurep 'mule) 2158 ;;(if (featurep 'mule)
2109 2159
2110 (defun read-coding-system (prompt) 2160 (defun read-coding-system (prompt &optional default-coding-system)
2111 "Read a coding-system (or nil) from the minibuffer. 2161 "Read a coding-system (or nil) from the minibuffer.
2112 Prompting with string PROMPT." 2162 Prompting with string PROMPT.
2113 (intern (completing-read prompt obarray 'find-coding-system t))) 2163 If the user enters null input, return second argument DEFAULT-CODING-SYSTEM.
2164 DEFAULT-CODING-SYSTEM can be a string, symbol, or coding-system object."
2165 (intern (completing-read prompt obarray 'find-coding-system t nil nil
2166 (cond ((symbolp default-coding-system)
2167 (symbol-name default-coding-system))
2168 ((coding-system-p default-coding-system)
2169 (symbol-name (coding-system-name default-coding-system)))
2170 (t
2171 default-coding-system)))))
2114 2172
2115 (defun read-non-nil-coding-system (prompt) 2173 (defun read-non-nil-coding-system (prompt)
2116 "Read a non-nil coding-system from the minibuffer. 2174 "Read a non-nil coding-system from the minibuffer.
2117 Prompt with string PROMPT." 2175 Prompt with string PROMPT."
2118 (let ((retval (intern ""))) 2176 (let ((retval (intern "")))