comparison lisp/minibuf.el @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 84b14dcb0985
children abe6d1db359e
comparison
equal deleted inserted replaced
439:357dd071b03c 440:8de8e3f6228a
1324 (setq current-minibuffer-contents (buffer-string) 1324 (setq current-minibuffer-contents (buffer-string)
1325 current-minibuffer-point (point))) 1325 current-minibuffer-point (point)))
1326 (let ((narg (- minibuffer-history-position n)) 1326 (let ((narg (- minibuffer-history-position n))
1327 (minimum (if minibuffer-default -1 0))) 1327 (minimum (if minibuffer-default -1 0)))
1328 (cond ((< narg minimum) 1328 (cond ((< narg minimum)
1329 (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))
1330 ((> narg (length (symbol-value minibuffer-history-variable))) 1333 ((> narg (length (symbol-value minibuffer-history-variable)))
1331 (error "No preceding item in %s" minibuffer-history-variable))) 1334 (error "No preceding item in %s" minibuffer-history-variable)))
1332 (erase-buffer) 1335 (erase-buffer)
1333 (setq minibuffer-history-position narg) 1336 (setq minibuffer-history-position narg)
1334 (if (eq narg initial-minibuffer-history-position) 1337 (if (eq narg initial-minibuffer-history-position)
1375 1378
1376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1377 ;;;; reading various things from a minibuffer ;;;; 1380 ;;;; reading various things from a minibuffer ;;;;
1378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1379 1382
1380 (defun read-expression (prompt &optional initial-contents history) 1383 (defun read-expression (prompt &optional initial-contents history default-value)
1381 "Return a Lisp object read using the minibuffer. 1384 "Return a Lisp object read using the minibuffer, prompting with PROMPT.
1382 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
1383 is a string to insert in the minibuffer before reading. 1386 in the minibuffer before reading.
1384 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."
1385 (let ((minibuffer-history-sexp-flag t) 1391 (let ((minibuffer-history-sexp-flag t)
1386 ;; 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.
1387 (minibuffer-completion-table nil)) 1393 (minibuffer-completion-table nil))
1388 (read-from-minibuffer prompt 1394 (read-from-minibuffer prompt
1389 initial-contents 1395 initial-contents
1390 read-expression-map 1396 read-expression-map
1391 t 1397 t
1392 (or history 'read-expression-history) 1398 (or history 'read-expression-history)
1393 lisp-mode-abbrev-table))) 1399 lisp-mode-abbrev-table
1394 1400 default-value)))
1395 (defun read-string (prompt &optional initial-contents history) 1401
1402 (defun read-string (prompt &optional initial-contents history default-value)
1396 "Return a string from the minibuffer, prompting with string PROMPT. 1403 "Return a string from the minibuffer, prompting with string PROMPT.
1397 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
1398 in the minibuffer before reading. 1405 in the minibuffer before reading.
1399 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."
1400 (let ((minibuffer-completion-table nil)) 1410 (let ((minibuffer-completion-table nil))
1401 (read-from-minibuffer prompt 1411 (read-from-minibuffer prompt
1402 initial-contents 1412 initial-contents
1403 minibuffer-local-map 1413 minibuffer-local-map
1404 nil history))) 1414 nil history nil default-value)))
1405 1415
1406 (defun eval-minibuffer (prompt &optional initial-contents history) 1416 (defun eval-minibuffer (prompt &optional initial-contents history default-value)
1407 "Return value of Lisp expression read using the minibuffer. 1417 "Return value of Lisp expression read using the minibuffer.
1408 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS 1418 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
1409 is a string to insert in the minibuffer before reading. 1419 is a string to insert in the minibuffer before reading.
1410 Third arg HISTORY, if non-nil, specifies a history list." 1420 Third arg HISTORY, if non-nil, specifies a history list.
1411 (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)))
1412 1425
1413 ;; The name `command-history' is already taken 1426 ;; The name `command-history' is already taken
1414 (defvar read-command-history '()) 1427 (defvar read-command-history '())
1415 1428
1416 (defun read-command (prompt) 1429 (defun read-command (prompt &optional default-value)
1417 "Read the name of a command and return as a symbol. 1430 "Read the name of a command and return as a symbol.
1418 Prompts with PROMPT." 1431 Prompts with PROMPT. By default, return DEFAULT-VALUE."
1419 (intern (completing-read prompt obarray 'commandp t nil 1432 (intern (completing-read prompt obarray 'commandp t nil
1420 ;; 'command-history is not right here: that's a 1433 ;; 'command-history is not right here: that's a
1421 ;; list of evalable forms, not a history list. 1434 ;; list of evalable forms, not a history list.
1422 'read-command-history 1435 'read-command-history
1423 ))) 1436 default-value)))
1424 1437
1425 (defun read-function (prompt) 1438 (defun read-function (prompt &optional default-value)
1426 "Read the name of a function and return as a symbol. 1439 "Read the name of a function and return as a symbol.
1427 Prompts with PROMPT." 1440 Prompts with PROMPT. By default, return DEFAULT-VALUE."
1428 (intern (completing-read prompt obarray 'fboundp t nil 1441 (intern (completing-read prompt obarray 'fboundp t nil
1429 'function-history))) 1442 'function-history default-value)))
1430 1443
1431 (defun read-variable (prompt) 1444 (defun read-variable (prompt &optional default-value)
1432 "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.
1433 Prompts with PROMPT. 1446 Prompts with PROMPT. By default, return DEFAULT-VALUE.
1434 A user variable is one whose documentation starts with a `*' character." 1447 A user variable is one whose documentation starts with a `*' character."
1435 (intern (completing-read prompt obarray 'user-variable-p t nil 1448 (intern (completing-read prompt obarray 'user-variable-p t nil
1436 'variable-history))) 1449 'variable-history default-value)))
1437 1450
1438 (defun read-buffer (prompt &optional default require-match) 1451 (defun read-buffer (prompt &optional default require-match)
1439 "Read the name of a buffer and return as a string. 1452 "Read the name of a buffer and return as a string.
1440 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
1441 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,
1469 nil)))) 1482 nil))))
1470 (if (bufferp result) 1483 (if (bufferp result)
1471 (buffer-name result) 1484 (buffer-name result)
1472 result))) 1485 result)))
1473 1486
1474 (defun read-number (prompt &optional integers-only) 1487 (defun read-number (prompt &optional integers-only default-value)
1475 "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."
1476 (let ((pred (if integers-only 'integerp 'numberp)) 1493 (let ((pred (if integers-only 'integerp 'numberp))
1477 num) 1494 num)
1478 (while (not (funcall pred num)) 1495 (while (not (funcall pred num))
1479 (setq num (condition-case () 1496 (setq num (condition-case ()
1480 (let ((minibuffer-completion-table nil)) 1497 (let ((minibuffer-completion-table nil))
1481 (read-from-minibuffer 1498 (read-from-minibuffer
1482 prompt (if num (prin1-to-string num)) nil t 1499 prompt (if num (prin1-to-string num)) nil t
1483 t)) ;no history 1500 nil nil default-value))
1484 (input-error nil) 1501 (input-error nil)
1485 (invalid-read-syntax nil) 1502 (invalid-read-syntax nil)
1486 (end-of-file nil))) 1503 (end-of-file nil)))
1487 (or (funcall pred num) (beep))) 1504 (or (funcall pred num) (beep)))
1488 num)) 1505 num))
1489 1506
1490 (defun read-shell-command (prompt &optional initial-input history) 1507 (defun read-shell-command (prompt &optional initial-input history default-value)
1491 "Just like read-string, but uses read-shell-command-map: 1508 "Just like read-string, but uses read-shell-command-map:
1492 \\{read-shell-command-map}" 1509 \\{read-shell-command-map}"
1493 (let ((minibuffer-completion-table nil)) 1510 (let ((minibuffer-completion-table nil))
1494 (read-from-minibuffer prompt initial-input read-shell-command-map 1511 (read-from-minibuffer prompt initial-input read-shell-command-map
1495 nil (or history 'shell-command-history)))) 1512 nil (or history 'shell-command-history)
1513 nil default-value)))
1496 1514
1497 1515
1498 ;;; This read-file-name stuff probably belongs in files.el 1516 ;;; This read-file-name stuff probably belongs in files.el
1499 1517
1500 ;; Quote "$" as "$$" to get it past substitute-in-file-name 1518 ;; Quote "$" as "$$" to get it past substitute-in-file-name
1657 (If DEFAULT is omitted, the visited file name is used, 1675 (If DEFAULT is omitted, the visited file name is used,
1658 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
1659 used.) 1677 used.)
1660 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.
1661 Non-nil and non-t means also require confirmation after completion. 1679 Non-nil and non-t means also require confirmation after completion.
1662 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.
1663 Sixth arg HISTORY specifies the history list to use. Default is 1683 Sixth arg HISTORY specifies the history list to use. Default is
1664 `file-name-history'. 1684 `file-name-history'.
1665 DIR defaults to current buffer's directory default." 1685 DIR defaults to current buffer's directory default."
1666 (read-file-name-1 1686 (read-file-name-1
1667 (or history 'file-name-history) 1687 (or history 'file-name-history)
1668 prompt dir (or default 1688 prompt dir (or default
1669 (if initial-contents (expand-file-name initial-contents dir) 1689 (and initial-contents
1670 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)))
1671 must-match initial-contents 1694 must-match initial-contents
1672 ;; A separate function (not an anonymous lambda-expression) 1695 ;; A separate function (not an anonymous lambda-expression)
1673 ;; and passed as a symbol because of disgusting kludges in various 1696 ;; and passed as a symbol because of disgusting kludges in various
1674 ;; 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))) ...)
1675 'read-file-name-internal)) 1698 'read-file-name-internal))