Mercurial > hg > xemacs-beta
comparison lisp/minibuf.el @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 501cfd01ee6d |
children | 95016f13131a |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
1 ;;; minibuf.el --- Minibuffer functions for XEmacs | 1 ;;; minibuf.el --- Minibuffer functions for XEmacs |
2 | 2 |
3 ;; Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995 Tinker Systems. | 4 ;; Copyright (C) 1995 Tinker Systems |
5 ;; Copyright (C) 1995, 1996, 2000 Ben Wing. | 5 ;; Copyright (C) 1995, 1996 Ben Wing |
6 | 6 |
7 ;; Author: Richard Mlynarik | 7 ;; Author: Richard Mlynarik |
8 ;; Created: 2-Oct-92 | 8 ;; Created: 2-Oct-92 |
9 ;; Maintainer: XEmacs Development Team | 9 ;; Maintainer: XEmacs Development Team |
10 ;; Keywords: internal, dumped | 10 ;; Keywords: internal, dumped |
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 (defcustom minibuffer-confirm-incomplete nil | 80 (defvar 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) | |
86 | 84 |
87 (defcustom completion-auto-help t | 85 (defcustom completion-auto-help t |
88 "*Non-nil means automatically provide help for invalid completion input." | 86 "*Non-nil means automatically provide help for invalid completion input." |
89 :type 'boolean | 87 :type 'boolean |
90 :group 'minibuffer) | 88 :group 'minibuffer) |
109 ;; Moved to C. The minibuffer prompt must be setup before this is run | 107 ;; Moved to C. The minibuffer prompt must be setup before this is run |
110 ;; and that can only be done from the C side. | 108 ;; and that can only be done from the C side. |
111 ;(defvar minibuffer-setup-hook nil | 109 ;(defvar minibuffer-setup-hook nil |
112 ; "Normal hook run just after entry to minibuffer.") | 110 ; "Normal hook run just after entry to minibuffer.") |
113 | 111 |
114 ;; see comment at list-mode-hook. | |
115 (put 'minibuffer-setup-hook 'permanent-local t) | |
116 | |
117 (defvar minibuffer-exit-hook nil | 112 (defvar minibuffer-exit-hook nil |
118 "Normal hook run just after exit from minibuffer.") | 113 "Normal hook run just after exit from minibuffer.") |
119 (put 'minibuffer-exit-hook 'permanent-local t) | |
120 | 114 |
121 (defvar minibuffer-help-form nil | 115 (defvar minibuffer-help-form nil |
122 "Value that `help-form' takes on inside the minibuffer.") | 116 "Value that `help-form' takes on inside the minibuffer.") |
123 | 117 |
124 (defvar minibuffer-default nil | 118 (defvar minibuffer-default nil |
348 | 342 |
349 (defun read-from-minibuffer (prompt &optional initial-contents | 343 (defun read-from-minibuffer (prompt &optional initial-contents |
350 keymap | 344 keymap |
351 readp | 345 readp |
352 history | 346 history |
353 abbrev-table | 347 abbrev-table) |
354 default) | |
355 "Read a string from the minibuffer, prompting with string PROMPT. | 348 "Read a string from the minibuffer, prompting with string PROMPT. |
356 If optional second arg INITIAL-CONTENTS is non-nil, it is a string | 349 If optional second arg INITIAL-CONTENTS is non-nil, it is a string |
357 to be inserted into the minibuffer before reading input. | 350 to be inserted into the minibuffer before reading input. |
358 If INITIAL-CONTENTS is (STRING . POSITION), the initial input | 351 If INITIAL-CONTENTS is (STRING . POSITION), the initial input |
359 is STRING, but point is placed POSITION characters into the string. | 352 is STRING, but point is placed POSITION characters into the string. |
371 which INITIAL-CONTENTS corresponds to). | 364 which INITIAL-CONTENTS corresponds to). |
372 If HISTORY is `t', no history will be recorded. | 365 If HISTORY is `t', no history will be recorded. |
373 Positions are counted starting from 1 at the beginning of the list. | 366 Positions are counted starting from 1 at the beginning of the list. |
374 Sixth arg ABBREV-TABLE, if non-nil, becomes the value of `local-abbrev-table' | 367 Sixth arg ABBREV-TABLE, if non-nil, becomes the value of `local-abbrev-table' |
375 in the minibuffer. | 368 in the minibuffer. |
376 Seventh arg DEFAULT, if non-nil, will be returned when user enters | |
377 an empty string. | |
378 | 369 |
379 See also the variable completion-highlight-first-word-only for control over | 370 See also the variable completion-highlight-first-word-only for control over |
380 completion display." | 371 completion display." |
381 (if (and (not enable-recursive-minibuffers) | 372 (if (and (not enable-recursive-minibuffers) |
382 (> (minibuffer-depth) 0) | 373 (> (minibuffer-depth) 0) |
419 (oconfig (current-window-configuration)) | 410 (oconfig (current-window-configuration)) |
420 ;; dynamic scope sucks sucks sucks sucks sucks sucks. | 411 ;; dynamic scope sucks sucks sucks sucks sucks sucks. |
421 ;; `M-x doctor' makes history a local variable, and thus | 412 ;; `M-x doctor' makes history a local variable, and thus |
422 ;; our binding above is buffer-local and doesn't apply | 413 ;; our binding above is buffer-local and doesn't apply |
423 ;; once we switch buffers!!!! We demand better scope! | 414 ;; once we switch buffers!!!! We demand better scope! |
424 (_history_ history) | 415 (_history_ history)) |
425 (minibuffer-default default)) | |
426 (unwind-protect | 416 (unwind-protect |
427 (progn | 417 (progn |
428 (set-buffer (reset-buffer buffer)) | 418 (set-buffer (reset-buffer buffer)) |
429 (setq default-directory dir) | 419 (setq default-directory dir) |
430 (make-local-variable 'print-escape-newlines) | 420 (make-local-variable 'print-escape-newlines) |
498 (signal 'quit '()) | 488 (signal 'quit '()) |
499 ;; return value | 489 ;; return value |
500 (let* ((val (progn (set-buffer buffer) | 490 (let* ((val (progn (set-buffer buffer) |
501 (if minibuffer-exit-hook | 491 (if minibuffer-exit-hook |
502 (run-hooks 'minibuffer-exit-hook)) | 492 (run-hooks 'minibuffer-exit-hook)) |
503 (if (and (eq (char-after (point-min)) nil) | 493 (buffer-string))) |
504 default) | 494 (histval val) |
505 default | |
506 (buffer-string)))) | |
507 (histval (if (and default (string= val "")) | |
508 default | |
509 val)) | |
510 (err nil)) | 495 (err nil)) |
511 (if readp | 496 (if readp |
512 (condition-case e | 497 (condition-case e |
513 (let ((v (read-from-string val))) | 498 (let ((v (read-from-string val))) |
514 (if (< (cdr v) (length val)) | 499 (if (< (cdr v) (length val)) |
610 | 595 |
611 ;;;; Guts of minibuffer completion | 596 ;;;; Guts of minibuffer completion |
612 | 597 |
613 | 598 |
614 ;; Used by minibuffer-do-completion | 599 ;; Used by minibuffer-do-completion |
615 (defvar last-exact-completion nil) | 600 (defvar last-exact-completion) |
616 | 601 |
617 (defun temp-minibuffer-message (m) | 602 (defun temp-minibuffer-message (m) |
618 (let ((savemax (point-max))) | 603 (let ((savemax (point-max))) |
619 (save-excursion | 604 (save-excursion |
620 (goto-char (point-max)) | 605 (goto-char (point-max)) |
761 | 746 |
762 ;;;; completing-read | 747 ;;;; completing-read |
763 | 748 |
764 (defun completing-read (prompt table | 749 (defun completing-read (prompt table |
765 &optional predicate require-match | 750 &optional predicate require-match |
766 initial-contents history default) | 751 initial-contents history) |
767 "Read a string in the minibuffer, with completion. | 752 "Read a string in the minibuffer, with completion. |
768 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-CONTENTS, HISTORY. | 753 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-CONTENTS, HISTORY. |
769 PROMPT is a string to prompt with; normally it ends in a colon and a space. | 754 PROMPT is a string to prompt with; normally it ends in a colon and a space. |
770 TABLE is an alist whose elements' cars are strings, or an obarray. | 755 TABLE is an alist whose elements' cars are strings, or an obarray. |
771 PREDICATE limits completion to a subset of TABLE. | 756 PREDICATE limits completion to a subset of TABLE. |
783 In that case, HISTVAR is the history list variable to use, | 768 In that case, HISTVAR is the history list variable to use, |
784 and HISTPOS is the initial position (the position in the list | 769 and HISTPOS is the initial position (the position in the list |
785 which INITIAL-CONTENTS corresponds to). | 770 which INITIAL-CONTENTS corresponds to). |
786 If HISTORY is `t', no history will be recorded. | 771 If HISTORY is `t', no history will be recorded. |
787 Positions are counted starting from 1 at the beginning of the list. | 772 Positions are counted starting from 1 at the beginning of the list. |
788 DEFAULT, if non-nil, is the default value. | |
789 Completion ignores case if the ambient value of | 773 Completion ignores case if the ambient value of |
790 `completion-ignore-case' is non-nil." | 774 `completion-ignore-case' is non-nil." |
791 (let ((minibuffer-completion-table table) | 775 (let ((minibuffer-completion-table table) |
792 (minibuffer-completion-predicate predicate) | 776 (minibuffer-completion-predicate predicate) |
793 (minibuffer-completion-confirm (if (eq require-match 't) nil t)) | 777 (minibuffer-completion-confirm (if (eq require-match 't) nil t)) |
794 (last-exact-completion nil) | 778 (last-exact-completion nil)) |
795 ret) | 779 (read-from-minibuffer prompt |
796 (setq ret (read-from-minibuffer prompt | 780 initial-contents |
797 initial-contents | 781 (if (not require-match) |
798 (if (not require-match) | 782 minibuffer-local-completion-map |
799 minibuffer-local-completion-map | 783 minibuffer-local-must-match-map) |
800 minibuffer-local-must-match-map) | 784 nil |
801 nil | 785 history))) |
802 history | |
803 nil | |
804 default)) | |
805 (if (and (string= ret "") | |
806 default) | |
807 default | |
808 ret))) | |
809 | 786 |
810 | 787 |
811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
812 ;;;; Minibuffer completion commands ;;;; | 789 ;;;; Minibuffer completion commands ;;;; |
813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1252 \(Previous history elements refer to earlier actions.) | 1229 \(Previous history elements refer to earlier actions.) |
1253 With prefix argument N, search for Nth previous match. | 1230 With prefix argument N, search for Nth previous match. |
1254 If N is negative, find the next or Nth next match." | 1231 If N is negative, find the next or Nth next match." |
1255 (interactive | 1232 (interactive |
1256 (let ((enable-recursive-minibuffers t) | 1233 (let ((enable-recursive-minibuffers t) |
1257 (minibuffer-history-sexp-flag nil) | 1234 (minibuffer-history-sexp-flag nil)) |
1258 (minibuffer-max-depth (and minibuffer-max-depth | |
1259 (1+ minibuffer-max-depth)))) | |
1260 (if (eq 't (symbol-value minibuffer-history-variable)) | 1235 (if (eq 't (symbol-value minibuffer-history-variable)) |
1261 (error "History is not being recorded in this context")) | 1236 (error "History is not being recorded in this context")) |
1262 (list (read-from-minibuffer "Previous element matching (regexp): " | 1237 (list (read-from-minibuffer "Previous element matching (regexp): " |
1263 (car minibuffer-history-search-history) | 1238 (car minibuffer-history-search-history) |
1264 minibuffer-local-map | 1239 minibuffer-local-map |
1302 \(The next history element refers to a more recent action.) | 1277 \(The next history element refers to a more recent action.) |
1303 With prefix argument N, search for Nth next match. | 1278 With prefix argument N, search for Nth next match. |
1304 If N is negative, find the previous or Nth previous match." | 1279 If N is negative, find the previous or Nth previous match." |
1305 (interactive | 1280 (interactive |
1306 (let ((enable-recursive-minibuffers t) | 1281 (let ((enable-recursive-minibuffers t) |
1307 (minibuffer-history-sexp-flag nil) | 1282 (minibuffer-history-sexp-flag nil)) |
1308 (minibuffer-max-depth (and minibuffer-max-depth | |
1309 (1+ minibuffer-max-depth)))) | |
1310 (if (eq t (symbol-value minibuffer-history-variable)) | 1283 (if (eq t (symbol-value minibuffer-history-variable)) |
1311 (error "History is not being recorded in this context")) | 1284 (error "History is not being recorded in this context")) |
1312 (list (read-from-minibuffer "Next element matching (regexp): " | 1285 (list (read-from-minibuffer "Next element matching (regexp): " |
1313 (car minibuffer-history-search-history) | 1286 (car minibuffer-history-search-history) |
1314 minibuffer-local-map | 1287 minibuffer-local-map |
1328 (setq current-minibuffer-contents (buffer-string) | 1301 (setq current-minibuffer-contents (buffer-string) |
1329 current-minibuffer-point (point))) | 1302 current-minibuffer-point (point))) |
1330 (let ((narg (- minibuffer-history-position n)) | 1303 (let ((narg (- minibuffer-history-position n)) |
1331 (minimum (if minibuffer-default -1 0))) | 1304 (minimum (if minibuffer-default -1 0))) |
1332 (cond ((< narg minimum) | 1305 (cond ((< narg minimum) |
1333 (error (if minibuffer-default | 1306 (error "No following item in %s" minibuffer-history-variable)) |
1334 "No following item in %s" | |
1335 "No following item in %s; no default available") | |
1336 minibuffer-history-variable)) | |
1337 ((> narg (length (symbol-value minibuffer-history-variable))) | 1307 ((> narg (length (symbol-value minibuffer-history-variable))) |
1338 (error "No preceding item in %s" minibuffer-history-variable))) | 1308 (error "No preceding item in %s" minibuffer-history-variable))) |
1339 (erase-buffer) | 1309 (erase-buffer) |
1340 (setq minibuffer-history-position narg) | 1310 (setq minibuffer-history-position narg) |
1341 (if (eq narg initial-minibuffer-history-position) | 1311 (if (eq narg initial-minibuffer-history-position) |
1382 | 1352 |
1383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1384 ;;;; reading various things from a minibuffer ;;;; | 1354 ;;;; reading various things from a minibuffer ;;;; |
1385 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1386 | 1356 |
1387 (defun read-expression (prompt &optional initial-contents history default-value) | 1357 (defun read-expression (prompt &optional initial-contents history) |
1388 "Return a Lisp object read using the minibuffer, prompting with PROMPT. | 1358 "Return a Lisp object read using the minibuffer. |
1389 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert | 1359 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS |
1390 in the minibuffer before reading. | 1360 is a string to insert in the minibuffer before reading. |
1391 Third arg HISTORY, if non-nil, specifies a history list. | 1361 Third arg HISTORY, if non-nil, specifies a history list." |
1392 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used | |
1393 for history command, and as the value to return if the user enters the | |
1394 empty string." | |
1395 (let ((minibuffer-history-sexp-flag t) | 1362 (let ((minibuffer-history-sexp-flag t) |
1396 ;; Semi-kludge to get around M-x C-x o M-ESC trying to do completion. | 1363 ;; Semi-kludge to get around M-x C-x o M-ESC trying to do completion. |
1397 (minibuffer-completion-table nil)) | 1364 (minibuffer-completion-table nil)) |
1398 (read-from-minibuffer prompt | 1365 (read-from-minibuffer prompt |
1399 initial-contents | 1366 initial-contents |
1400 read-expression-map | 1367 read-expression-map |
1401 t | 1368 t |
1402 (or history 'read-expression-history) | 1369 (or history 'read-expression-history) |
1403 lisp-mode-abbrev-table | 1370 lisp-mode-abbrev-table))) |
1404 default-value))) | 1371 |
1405 | 1372 (defun read-string (prompt &optional initial-contents history) |
1406 (defun read-string (prompt &optional initial-contents history default-value) | |
1407 "Return a string from the minibuffer, prompting with string PROMPT. | 1373 "Return a string from the minibuffer, prompting with string PROMPT. |
1408 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert | 1374 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert |
1409 in the minibuffer before reading. | 1375 in the minibuffer before reading. |
1410 Third arg HISTORY, if non-nil, specifies a history list. | 1376 Third arg HISTORY, if non-nil, specifies a history list." |
1411 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used | |
1412 for history command, and as the value to return if the user enters the | |
1413 empty string." | |
1414 (let ((minibuffer-completion-table nil)) | 1377 (let ((minibuffer-completion-table nil)) |
1415 (read-from-minibuffer prompt | 1378 (read-from-minibuffer prompt |
1416 initial-contents | 1379 initial-contents |
1417 minibuffer-local-map | 1380 minibuffer-local-map |
1418 nil history nil default-value))) | 1381 nil history))) |
1419 | 1382 |
1420 (defun eval-minibuffer (prompt &optional initial-contents history default-value) | 1383 (defun eval-minibuffer (prompt &optional initial-contents history) |
1421 "Return value of Lisp expression read using the minibuffer. | 1384 "Return value of Lisp expression read using the minibuffer. |
1422 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS | 1385 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS |
1423 is a string to insert in the minibuffer before reading. | 1386 is a string to insert in the minibuffer before reading. |
1424 Third arg HISTORY, if non-nil, specifies a history list. | 1387 Third arg HISTORY, if non-nil, specifies a history list." |
1425 Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used | 1388 (eval (read-expression prompt initial-contents history))) |
1426 for history command, and as the value to return if the user enters the | |
1427 empty string." | |
1428 (eval (read-expression prompt initial-contents history default-value))) | |
1429 | 1389 |
1430 ;; The name `command-history' is already taken | 1390 ;; The name `command-history' is already taken |
1431 (defvar read-command-history '()) | 1391 (defvar read-command-history '()) |
1432 | 1392 |
1433 (defun read-command (prompt &optional default-value) | 1393 (defun read-command (prompt) |
1434 "Read the name of a command and return as a symbol. | 1394 "Read the name of a command and return as a symbol. |
1435 Prompts with PROMPT. By default, return DEFAULT-VALUE." | 1395 Prompts with PROMPT." |
1436 (intern (completing-read prompt obarray 'commandp t nil | 1396 (intern (completing-read prompt obarray 'commandp t nil |
1437 ;; 'command-history is not right here: that's a | 1397 ;; 'command-history is not right here: that's a |
1438 ;; list of evalable forms, not a history list. | 1398 ;; list of evalable forms, not a history list. |
1439 'read-command-history | 1399 'read-command-history |
1440 default-value))) | 1400 ))) |
1441 | 1401 |
1442 (defun read-function (prompt &optional default-value) | 1402 (defun read-function (prompt) |
1443 "Read the name of a function and return as a symbol. | 1403 "Read the name of a function and return as a symbol. |
1444 Prompts with PROMPT. By default, return DEFAULT-VALUE." | 1404 Prompts with PROMPT." |
1445 (intern (completing-read prompt obarray 'fboundp t nil | 1405 (intern (completing-read prompt obarray 'fboundp t nil |
1446 'function-history default-value))) | 1406 'function-history))) |
1447 | 1407 |
1448 (defun read-variable (prompt &optional default-value) | 1408 (defun read-variable (prompt) |
1449 "Read the name of a user variable and return it as a symbol. | 1409 "Read the name of a user variable and return it as a symbol. |
1450 Prompts with PROMPT. By default, return DEFAULT-VALUE. | 1410 Prompts with PROMPT. |
1451 A user variable is one whose documentation starts with a `*' character." | 1411 A user variable is one whose documentation starts with a `*' character." |
1452 (intern (completing-read prompt obarray 'user-variable-p t nil | 1412 (intern (completing-read prompt obarray 'user-variable-p t nil |
1453 'variable-history | 1413 'variable-history))) |
1454 (if (symbolp default-value) | |
1455 (symbol-name default-value) | |
1456 default-value)))) | |
1457 | 1414 |
1458 (defun read-buffer (prompt &optional default require-match) | 1415 (defun read-buffer (prompt &optional default require-match) |
1459 "Read the name of a buffer and return as a string. | 1416 "Read the name of a buffer and return as a string. |
1460 Prompts with PROMPT. Optional second arg DEFAULT is value to return if user | 1417 Prompts with PROMPT. Optional second arg DEFAULT is value to return if user |
1461 enters an empty line. If optional third arg REQUIRE-MATCH is non-nil, | 1418 enters an empty line. If optional third arg REQUIRE-MATCH is non-nil, |
1469 (alist (mapcar #'(lambda (b) (cons (buffer-name b) b)) | 1426 (alist (mapcar #'(lambda (b) (cons (buffer-name b) b)) |
1470 (buffer-list))) | 1427 (buffer-list))) |
1471 result) | 1428 result) |
1472 (while (progn | 1429 (while (progn |
1473 (setq result (completing-read prompt alist nil require-match | 1430 (setq result (completing-read prompt alist nil require-match |
1474 nil 'buffer-history | 1431 nil 'buffer-history)) |
1475 (if (bufferp default) | |
1476 (buffer-name default) | |
1477 default))) | |
1478 (cond ((not (equal result "")) | 1432 (cond ((not (equal result "")) |
1479 nil) | 1433 nil) |
1480 ((not require-match) | 1434 ((not require-match) |
1481 (setq result default) | 1435 (setq result default) |
1482 nil) | 1436 nil) |
1489 nil)))) | 1443 nil)))) |
1490 (if (bufferp result) | 1444 (if (bufferp result) |
1491 (buffer-name result) | 1445 (buffer-name result) |
1492 result))) | 1446 result))) |
1493 | 1447 |
1494 (defun read-number (prompt &optional integers-only default-value) | 1448 (defun read-number (prompt &optional integers-only) |
1495 "Read a number from the minibuffer, prompting with PROMPT. | 1449 "Read a number from the minibuffer." |
1496 If optional second argument INTEGERS-ONLY is non-nil, accept | |
1497 only integer input. | |
1498 If DEFAULT-VALUE is non-nil, return that if user enters an empty | |
1499 line." | |
1500 (let ((pred (if integers-only 'integerp 'numberp)) | 1450 (let ((pred (if integers-only 'integerp 'numberp)) |
1501 num) | 1451 num) |
1502 (while (not (funcall pred num)) | 1452 (while (not (funcall pred num)) |
1503 (setq num (condition-case () | 1453 (setq num (condition-case () |
1504 (let ((minibuffer-completion-table nil)) | 1454 (let ((minibuffer-completion-table nil)) |
1505 (read-from-minibuffer | 1455 (read-from-minibuffer |
1506 prompt (if num (prin1-to-string num)) nil t | 1456 prompt (if num (prin1-to-string num)) nil t |
1507 nil nil default-value)) | 1457 t)) ;no history |
1508 (input-error nil) | 1458 (input-error nil) |
1509 (invalid-read-syntax nil) | 1459 (invalid-read-syntax nil) |
1510 (end-of-file nil))) | 1460 (end-of-file nil))) |
1511 (or (funcall pred num) (beep))) | 1461 (or (funcall pred num) (beep))) |
1512 num)) | 1462 num)) |
1513 | 1463 |
1514 (defun read-shell-command (prompt &optional initial-input history default-value) | 1464 (defun read-shell-command (prompt &optional initial-input history) |
1515 "Just like read-string, but uses read-shell-command-map: | 1465 "Just like read-string, but uses read-shell-command-map: |
1516 \\{read-shell-command-map}" | 1466 \\{read-shell-command-map}" |
1517 (let ((minibuffer-completion-table nil)) | 1467 (let ((minibuffer-completion-table nil)) |
1518 (read-from-minibuffer prompt initial-input read-shell-command-map | 1468 (read-from-minibuffer prompt initial-input read-shell-command-map |
1519 nil (or history 'shell-command-history) | 1469 nil (or history 'shell-command-history)))) |
1520 nil default-value))) | |
1521 | 1470 |
1522 | 1471 |
1523 ;;; This read-file-name stuff probably belongs in files.el | 1472 ;;; This read-file-name stuff probably belongs in files.el |
1524 | 1473 |
1525 ;; Quote "$" as "$$" to get it past substitute-in-file-name | 1474 ;; Quote "$" as "$$" to get it past substitute-in-file-name |
1541 (setq o (1+ o) n (1+ n)) | 1490 (setq o (1+ o) n (1+ n)) |
1542 (if (eq ch ?$) | 1491 (if (eq ch ?$) |
1543 ;; already aset by make-string initial-value | 1492 ;; already aset by make-string initial-value |
1544 (setq n (1+ n)))) | 1493 (setq n (1+ n)))) |
1545 new))) | 1494 new))) |
1546 | |
1547 | |
1548 ;; Wrapper for `directory-files' for use in generating completion lists. | |
1549 ;; Generates output in the same format as `file-name-all-completions'. | |
1550 ;; | |
1551 ;; The EFS replacement for `directory-files' doesn't support the FILES-ONLY | |
1552 ;; option, so it has to be faked. The listing cache will hopefully | |
1553 ;; improve the performance of this operation. | |
1554 (defun minibuf-directory-files (dir &optional match-regexp files-only) | |
1555 (let ((want-file (or (eq files-only nil) (eq files-only t))) | |
1556 (want-dirs (or (eq files-only nil) (not (eq files-only t))))) | |
1557 (delete nil | |
1558 (mapcar (function (lambda (f) | |
1559 (if (file-directory-p (expand-file-name f dir)) | |
1560 (and want-dirs (file-name-as-directory f)) | |
1561 (and want-file f)))) | |
1562 (delete "." (directory-files dir nil match-regexp)))))) | |
1563 | |
1564 | 1495 |
1565 (defun read-file-name-2 (history prompt dir default | 1496 (defun read-file-name-2 (history prompt dir default |
1566 must-match initial-contents | 1497 must-match initial-contents |
1567 completer) | 1498 completer) |
1568 (if (not dir) | 1499 (if (not dir) |
1598 insert | 1529 insert |
1599 (if (not must-match) | 1530 (if (not must-match) |
1600 read-file-name-map | 1531 read-file-name-map |
1601 read-file-name-must-match-map) | 1532 read-file-name-must-match-map) |
1602 nil | 1533 nil |
1603 history | 1534 history)) |
1604 nil | 1535 )) |
1605 default)))) | |
1606 ;;; ;; Kludge! Put "/foo/bar" on history rather than "/default//foo/bar" | 1536 ;;; ;; Kludge! Put "/foo/bar" on history rather than "/default//foo/bar" |
1607 ;;; (let ((hist (cond ((not history) 'minibuffer-history) | 1537 ;;; (let ((hist (cond ((not history) 'minibuffer-history) |
1608 ;;; ((consp history) (car history)) | 1538 ;;; ((consp history) (car history)) |
1609 ;;; (t history)))) | 1539 ;;; (t history)))) |
1610 ;;; (if (and val | 1540 ;;; (if (and val |
1648 (insert-string (file-name-as-directory | 1578 (insert-string (file-name-as-directory |
1649 (abbreviate-file-name full t)) minibuf) | 1579 (abbreviate-file-name full t)) minibuf) |
1650 (reset-buffer completion-buf) | 1580 (reset-buffer completion-buf) |
1651 (let ((standard-output completion-buf)) | 1581 (let ((standard-output completion-buf)) |
1652 (display-completion-list | 1582 (display-completion-list |
1653 (minibuf-directory-files full nil (if dir-p 'directory)) | 1583 (delete "." (directory-files full nil nil nil (if dir-p 'directory))) |
1654 :user-data dir-p | 1584 :user-data dir-p |
1655 :reference-buffer minibuf | 1585 :reference-buffer minibuf |
1656 :activate-callback 'read-file-name-activate-callback) | 1586 :activate-callback 'read-file-name-activate-callback) |
1657 (goto-char (point-min) completion-buf))))) | 1587 (goto-char (point-min) completion-buf))))) |
1658 | 1588 |
1661 completer) | 1591 completer) |
1662 (if (should-use-dialog-box-p) | 1592 (if (should-use-dialog-box-p) |
1663 ;; this calls read-file-name-2 | 1593 ;; this calls read-file-name-2 |
1664 (mouse-read-file-name-1 history prompt dir default must-match | 1594 (mouse-read-file-name-1 history prompt dir default must-match |
1665 initial-contents completer) | 1595 initial-contents completer) |
1666 (add-one-shot-hook | 1596 (let ((rfhookfun |
1667 'minibuffer-setup-hook | 1597 (lambda () |
1668 (lambda () | 1598 ;; #### SCREAM! Create a `file-system-ignore-case' |
1669 ;; #### SCREAM! Create a `file-system-ignore-case' | 1599 ;; function, so this kind of stuff is generalized! |
1670 ;; function, so this kind of stuff is generalized! | 1600 (and (eq system-type 'windows-nt) |
1671 (and (eq system-type 'windows-nt) | 1601 (set (make-local-variable 'completion-ignore-case) t)) |
1672 (set (make-local-variable 'completion-ignore-case) t)) | 1602 (set |
1673 (set | 1603 (make-local-variable |
1674 (make-local-variable | 1604 'completion-display-completion-list-function) |
1675 'completion-display-completion-list-function) | 1605 #'(lambda (completions) |
1676 #'(lambda (completions) | 1606 (display-completion-list |
1677 (display-completion-list | 1607 completions |
1678 completions | 1608 :user-data (not (eq completer 'read-file-name-internal)) |
1679 :user-data (not (eq completer 'read-file-name-internal)) | 1609 :activate-callback |
1680 :activate-callback | 1610 'read-file-name-activate-callback))) |
1681 'read-file-name-activate-callback))))) | 1611 ;; kludge! |
1682 (read-file-name-2 history prompt dir default must-match | 1612 (remove-hook 'minibuffer-setup-hook rfhookfun) |
1683 initial-contents completer))) | 1613 ))) |
1614 (unwind-protect | |
1615 (progn | |
1616 (add-hook 'minibuffer-setup-hook rfhookfun) | |
1617 (read-file-name-2 history prompt dir default must-match | |
1618 initial-contents completer)) | |
1619 (remove-hook 'minibuffer-setup-hook rfhookfun))))) | |
1684 | 1620 |
1685 (defun read-file-name (prompt | 1621 (defun read-file-name (prompt |
1686 &optional dir default must-match initial-contents | 1622 &optional dir default must-match initial-contents |
1687 history) | 1623 history) |
1688 "Read file name, prompting with PROMPT and completing in directory DIR. | 1624 "Read file name, prompting with PROMPT and completing in directory DIR. |
1689 This will prompt with a dialog box if appropriate, according to | 1625 This will prompt with a dialog box if appropriate, according to |
1690 `should-use-dialog-box-p'. | 1626 `should-use-dialog-box-p'. |
1691 Value is not expanded---you must call `expand-file-name' yourself. | 1627 Value is not expanded---you must call `expand-file-name' yourself. |
1692 Value is subject to interpretation by `substitute-in-file-name' however. | 1628 Value is subject to interpreted by substitute-in-file-name however. |
1693 Default name to DEFAULT if user enters a null string. | 1629 Default name to DEFAULT if user enters a null string. |
1694 (If DEFAULT is omitted, the visited file name is used, | 1630 (If DEFAULT is omitted, the visited file name is used, |
1695 except that if INITIAL-CONTENTS is specified, that combined with DIR is | 1631 except that if INITIAL-CONTENTS is specified, that combined with DIR is |
1696 used.) | 1632 used.) |
1697 Fourth arg MUST-MATCH non-nil means require existing file's name. | 1633 Fourth arg MUST-MATCH non-nil means require existing file's name. |
1698 Non-nil and non-t means also require confirmation after completion. | 1634 Non-nil and non-t means also require confirmation after completion. |
1699 Fifth arg INITIAL-CONTENTS specifies text to start with. If this is not | 1635 Fifth arg INITIAL-CONTENTS specifies text to start with. |
1700 specified, and `insert-default-directory' is non-nil, DIR or the current | |
1701 directory will be used. | |
1702 Sixth arg HISTORY specifies the history list to use. Default is | 1636 Sixth arg HISTORY specifies the history list to use. Default is |
1703 `file-name-history'. | 1637 `file-name-history'. |
1704 DIR defaults to current buffer's directory default." | 1638 DIR defaults to current buffer's directory default." |
1705 (read-file-name-1 | 1639 (read-file-name-1 |
1706 (or history 'file-name-history) | 1640 (or history 'file-name-history) |
1707 prompt dir (or default | 1641 prompt dir (or default |
1708 (and initial-contents | 1642 (if initial-contents (expand-file-name initial-contents dir) |
1709 (abbreviate-file-name (expand-file-name | 1643 buffer-file-name)) |
1710 initial-contents dir) t)) | |
1711 (and buffer-file-truename | |
1712 (abbreviate-file-name buffer-file-name t))) | |
1713 must-match initial-contents | 1644 must-match initial-contents |
1714 ;; A separate function (not an anonymous lambda-expression) | 1645 ;; A separate function (not an anonymous lambda-expression) |
1715 ;; and passed as a symbol because of disgusting kludges in various | 1646 ;; and passed as a symbol because of disgusting kludges in various |
1716 ;; places which do stuff like (let ((filename-kludge-p (eq minibuffer-completion-table 'read-file-name-internal))) ...) | 1647 ;; places which do stuff like (let ((filename-kludge-p (eq minibuffer-completion-table 'read-file-name-internal))) ...) |
1717 'read-file-name-internal)) | 1648 'read-file-name-internal)) |
1841 nil | 1772 nil |
1842 (file-exists-p sstring))))) | 1773 (file-exists-p sstring))))) |
1843 ((eq action 't) | 1774 ((eq action 't) |
1844 ;; all completions | 1775 ;; all completions |
1845 (mapcar #'un-substitute-in-file-name | 1776 (mapcar #'un-substitute-in-file-name |
1846 (if (string= name "") | 1777 (file-name-all-completions name dir))) |
1847 (delete "./" (file-name-all-completions "" dir)) | |
1848 (file-name-all-completions name dir)))) | |
1849 (t;; nil | 1778 (t;; nil |
1850 ;; complete | 1779 ;; complete |
1851 (let* ((d (or dir default-directory)) | 1780 (let* ((d (or dir default-directory)) |
1852 (val (file-name-completion name d))) | 1781 (val (file-name-completion name d))) |
1853 (if (and (eq val 't) | 1782 (if (and (eq val 't) |
1872 (read-file-name-internal-1 | 1801 (read-file-name-internal-1 |
1873 string dir action | 1802 string dir action |
1874 #'(lambda (action orig string specdir dir name) | 1803 #'(lambda (action orig string specdir dir name) |
1875 (let* ((dirs #'(lambda (fn) | 1804 (let* ((dirs #'(lambda (fn) |
1876 (let ((l (if (equal name "") | 1805 (let ((l (if (equal name "") |
1877 (minibuf-directory-files | 1806 (directory-files |
1878 dir | 1807 dir |
1808 nil | |
1879 "" | 1809 "" |
1810 nil | |
1880 'directories) | 1811 'directories) |
1881 (minibuf-directory-files | 1812 (directory-files |
1882 dir | 1813 dir |
1814 nil | |
1883 (concat "\\`" (regexp-quote name)) | 1815 (concat "\\`" (regexp-quote name)) |
1816 nil | |
1884 'directories)))) | 1817 'directories)))) |
1885 (mapcar fn | 1818 (mapcar fn |
1886 ;; Wretched unix | 1819 ;; Wretched unix |
1887 (delete "." l)))))) | 1820 (delete "." l)))))) |
1888 (cond ((eq action 'lambda) | 1821 (cond ((eq action 'lambda) |
1940 (error file)) | 1873 (error file)) |
1941 "" nil)))) | 1874 "" nil)))) |
1942 result) | 1875 result) |
1943 (t file)))) | 1876 (t file)))) |
1944 | 1877 |
1945 (defun mouse-rfn-setup-vars (prompt) | |
1946 ;; a specifier would be nice. | |
1947 (set (make-local-variable 'frame-title-format) | |
1948 (capitalize-string-as-title | |
1949 ;; Delete ": " off the end. There must be an easier way! | |
1950 (let ((end-pos (length prompt))) | |
1951 (if (and (> end-pos 0) (eq (aref prompt (1- end-pos)) ? )) | |
1952 (setq end-pos (1- end-pos))) | |
1953 (if (and (> end-pos 0) (eq (aref prompt (1- end-pos)) ?:)) | |
1954 (setq end-pos (1- end-pos))) | |
1955 (substring prompt 0 end-pos)))) | |
1956 ;; ensure that killing the frame works right, | |
1957 ;; instead of leaving us in the minibuffer. | |
1958 (add-local-hook 'delete-frame-hook | |
1959 #'(lambda (frame) | |
1960 (abort-recursive-edit)))) | |
1961 | |
1962 (defun mouse-file-display-completion-list (window dir minibuf user-data) | 1878 (defun mouse-file-display-completion-list (window dir minibuf user-data) |
1963 (let ((standard-output (window-buffer window))) | 1879 (let ((standard-output (window-buffer window))) |
1964 (condition-case nil | 1880 (condition-case nil |
1965 (display-completion-list | 1881 (display-completion-list |
1966 (minibuf-directory-files dir nil t) | 1882 (directory-files dir nil nil nil t) |
1967 :window-width (window-width window) | 1883 :window-width (* 2 (window-width window)) |
1968 :window-height (window-text-area-height window) | |
1969 :completion-string "" | |
1970 :activate-callback | 1884 :activate-callback |
1971 'mouse-read-file-name-activate-callback | 1885 'mouse-read-file-name-activate-callback |
1972 :user-data user-data | 1886 :user-data user-data |
1973 :reference-buffer minibuf | 1887 :reference-buffer minibuf |
1974 :help-string "") | 1888 :help-string "") |
1975 (t nil)) | 1889 (t nil)))) |
1976 )) | |
1977 | 1890 |
1978 (defun mouse-directory-display-completion-list (window dir minibuf user-data) | 1891 (defun mouse-directory-display-completion-list (window dir minibuf user-data) |
1979 (let ((standard-output (window-buffer window))) | 1892 (let ((standard-output (window-buffer window))) |
1980 (condition-case nil | 1893 (condition-case nil |
1981 (display-completion-list | 1894 (display-completion-list |
1982 (minibuf-directory-files dir nil 1) | 1895 (delete "." (directory-files dir nil nil nil 1)) |
1983 :window-width (window-width window) | 1896 :window-width (window-width window) |
1984 :window-height (window-text-area-height window) | |
1985 :completion-string "" | |
1986 :activate-callback | 1897 :activate-callback |
1987 'mouse-read-file-name-activate-callback | 1898 'mouse-read-file-name-activate-callback |
1988 :user-data user-data | 1899 :user-data user-data |
1989 :reference-buffer minibuf | 1900 :reference-buffer minibuf |
1990 :help-string "") | 1901 :help-string "") |
1991 (t nil)) | 1902 (t nil)))) |
1992 )) | |
1993 | 1903 |
1994 (defun mouse-read-file-name-activate-callback (event extent user-data) | 1904 (defun mouse-read-file-name-activate-callback (event extent user-data) |
1995 (let* ((file (extent-string extent)) | 1905 (let* ((file (extent-string extent)) |
1996 (minibuf (symbol-value-in-buffer 'completion-reference-buffer | 1906 (minibuf (symbol-value-in-buffer 'completion-reference-buffer |
1997 (extent-object extent))) | 1907 (extent-object extent))) |
1998 (ministring (buffer-substring nil nil minibuf)) | 1908 (in-dir (buffer-substring nil nil minibuf)) |
1999 (in-dir (file-name-directory ministring)) | |
2000 (full (expand-file-name file in-dir)) | 1909 (full (expand-file-name file in-dir)) |
2001 (filebuf (nth 0 user-data)) | 1910 (filebuf (nth 0 user-data)) |
2002 (dirbuf (nth 1 user-data)) | 1911 (dirbuff (nth 1 user-data)) |
2003 (filewin (nth 2 user-data)) | 1912 (filewin (nth 2 user-data)) |
2004 (dirwin (nth 3 user-data))) | 1913 (dirwin (nth 3 user-data))) |
2005 (if (file-regular-p full) | 1914 (if (file-regular-p full) |
2006 (default-choose-completion event extent minibuf) | 1915 (default-choose-completion event extent minibuf) |
2007 (erase-buffer minibuf) | 1916 (erase-buffer minibuf) |
2008 (insert-string (file-name-as-directory | 1917 (insert-string (file-name-as-directory |
2009 (abbreviate-file-name full t)) minibuf) | 1918 (abbreviate-file-name full t)) minibuf) |
2010 (reset-buffer filebuf) | 1919 (reset-buffer filebuf) |
2011 (if (not dirbuf) | 1920 (if (not dirbuff) |
2012 (mouse-directory-display-completion-list filewin full minibuf | 1921 (mouse-directory-display-completion-list filewin full minibuf |
2013 user-data) | 1922 user-data) |
2014 (mouse-file-display-completion-list filewin full minibuf user-data) | 1923 (mouse-file-display-completion-list filewin full minibuf user-data) |
2015 (reset-buffer dirbuf) | 1924 (reset-buffer dirbuff) |
2016 (mouse-directory-display-completion-list dirwin full minibuf | 1925 (mouse-directory-display-completion-list dirwin full minibuf |
2017 user-data))))) | 1926 user-data))))) |
2018 | 1927 |
2019 ;; our cheesy but god-awful time consuming file dialog box implementation. | 1928 ;; this is rather cheesified but gets the job done. |
2020 ;; this will be replaced with use of the native file dialog box (when | |
2021 ;; available). | |
2022 (defun mouse-read-file-name-1 (history prompt dir default | 1929 (defun mouse-read-file-name-1 (history prompt dir default |
2023 must-match initial-contents | 1930 must-match initial-contents |
2024 completer) | 1931 completer) |
2025 ;; file-p is t if we're reading files, nil if directories. | |
2026 (let* ((file-p (eq 'read-file-name-internal completer)) | 1932 (let* ((file-p (eq 'read-file-name-internal completer)) |
2027 (filebuf (get-buffer-create "*Completions*")) | 1933 (filebuf (get-buffer-create "*Completions*")) |
2028 (dirbuf (and file-p (generate-new-buffer " *mouse-read-file*"))) | 1934 (dirbuff (and file-p (generate-new-buffer " *mouse-read-file*"))) |
2029 (butbuf (generate-new-buffer " *mouse-read-file*")) | 1935 (butbuff (generate-new-buffer " *mouse-read-file*")) |
2030 (frame (make-dialog-frame)) | 1936 (frame (make-dialog-frame)) |
2031 filewin dirwin | 1937 filewin dirwin |
2032 user-data) | 1938 user-data) |
2033 (unwind-protect | 1939 (unwind-protect |
2034 (progn | 1940 (progn |
2035 (reset-buffer filebuf) | 1941 (reset-buffer filebuf) |
2036 | 1942 (select-frame frame) |
2037 ;; set up the frame. | |
2038 (focus-frame frame) | |
2039 (let ((window-min-height 1)) | 1943 (let ((window-min-height 1)) |
2040 ;; #### should be 2 not 3, but that causes | 1944 ;; #### should be 2 not 3, but that causes |
2041 ;; "window too small to split" errors for some | 1945 ;; "window too small to split" errors for some |
2042 ;; people (but not for me ...) There's a more | 1946 ;; people (but not for me ...) There's a more |
2043 ;; fundamental bug somewhere. | 1947 ;; fundamental bug somewhere. |
2046 (progn | 1950 (progn |
2047 (split-window-horizontally 16) | 1951 (split-window-horizontally 16) |
2048 (setq filewin (frame-rightmost-window frame) | 1952 (setq filewin (frame-rightmost-window frame) |
2049 dirwin (frame-leftmost-window frame)) | 1953 dirwin (frame-leftmost-window frame)) |
2050 (set-window-buffer filewin filebuf) | 1954 (set-window-buffer filewin filebuf) |
2051 (set-window-buffer dirwin dirbuf)) | 1955 (set-window-buffer dirwin dirbuff)) |
2052 (setq filewin (frame-highest-window frame)) | 1956 (setq filewin (frame-highest-window frame)) |
2053 (set-window-buffer filewin filebuf)) | 1957 (set-window-buffer filewin filebuf)) |
2054 (setq user-data (list filebuf dirbuf filewin dirwin)) | 1958 (setq user-data (list filebuf dirbuff filewin dirwin)) |
2055 (set-window-buffer (frame-lowest-window frame) butbuf) | 1959 (set-window-buffer (frame-lowest-window frame) butbuff) |
2056 | 1960 (set-buffer butbuff) |
2057 ;; set up completion buffers. | |
2058 (let ((rfcshookfun | |
2059 ;; kludge! | |
2060 ;; #### I really need to flesh out the object | |
2061 ;; hierarchy better to avoid these kludges. | |
2062 ;; (?? I wrote this comment above some time ago, | |
2063 ;; and I don't understand what I'm referring to | |
2064 ;; any more. --ben | |
2065 (lambda () | |
2066 (mouse-rfn-setup-vars prompt) | |
2067 (when (featurep 'scrollbar) | |
2068 (set-specifier scrollbar-width 0 (current-buffer))) | |
2069 (setq truncate-lines t)))) | |
2070 | |
2071 (set-buffer filebuf) | |
2072 (add-local-hook 'completion-setup-hook rfcshookfun) | |
2073 (when file-p | |
2074 (set-buffer dirbuf) | |
2075 (add-local-hook 'completion-setup-hook rfcshookfun))) | |
2076 | |
2077 ;; set up minibuffer. | |
2078 (add-one-shot-hook | |
2079 'minibuffer-setup-hook | |
2080 (lambda () | |
2081 (if (not file-p) | |
2082 (mouse-directory-display-completion-list | |
2083 filewin dir (current-buffer) user-data) | |
2084 (mouse-file-display-completion-list | |
2085 filewin dir (current-buffer) user-data) | |
2086 (mouse-directory-display-completion-list | |
2087 dirwin dir (current-buffer) user-data)) | |
2088 (set | |
2089 (make-local-variable | |
2090 'completion-display-completion-list-function) | |
2091 (lambda (completions) | |
2092 (display-completion-list | |
2093 completions | |
2094 :help-string "" | |
2095 :window-width (window-width filewin) | |
2096 :window-height (window-text-area-height filewin) | |
2097 :completion-string "" | |
2098 :activate-callback | |
2099 'mouse-read-file-name-activate-callback | |
2100 :user-data user-data))) | |
2101 (mouse-rfn-setup-vars prompt) | |
2102 (save-selected-window | |
2103 ;; kludge to ensure the frame title is correct. | |
2104 ;; the minibuffer leaves the frame title the way | |
2105 ;; it was before (i.e. of the selected window before | |
2106 ;; the dialog box was opened), so to get it correct | |
2107 ;; we have to be tricky. | |
2108 (select-window filewin) | |
2109 (redisplay-frame nil t) | |
2110 ;; #### another kludge. sometimes the focus ends up | |
2111 ;; back in the main window, not the dialog box. it | |
2112 ;; occurs randomly and it's not possible to reliably | |
2113 ;; reproduce. We try to fix it by draining non-user | |
2114 ;; events and then setting the focus back on the frame. | |
2115 (sit-for 0 t) | |
2116 (focus-frame frame)))) | |
2117 | |
2118 ;; set up button buffer. | |
2119 (set-buffer butbuf) | |
2120 (mouse-rfn-setup-vars prompt) | |
2121 (when dir | 1961 (when dir |
2122 (setq default-directory dir)) | 1962 (setq default-directory dir)) |
2123 (when (featurep 'scrollbar) | 1963 (when (featurep 'scrollbar) |
2124 (set-specifier scrollbar-width 0 butbuf)) | 1964 (set-specifier scrollbar-width 0 butbuff)) |
2125 (insert " ") | 1965 (insert " ") |
2126 (insert-gui-button (make-gui-button "OK" | 1966 (insert-gui-button (make-gui-button "OK" |
2127 (lambda (foo) | 1967 (lambda (foo) |
2128 (exit-minibuffer)))) | 1968 (exit-minibuffer)))) |
2129 (insert " ") | 1969 (insert " ") |
2130 (insert-gui-button (make-gui-button "Cancel" | 1970 (insert-gui-button (make-gui-button "Cancel" |
2131 (lambda (foo) | 1971 (lambda (foo) |
2132 (abort-recursive-edit)))) | 1972 (abort-recursive-edit)))) |
2133 | 1973 (let ((rfhookfun |
2134 ;; now start reading filename. | 1974 (lambda () |
2135 (read-file-name-2 history prompt dir default | 1975 (if (not file-p) |
2136 must-match initial-contents | 1976 (mouse-directory-display-completion-list |
2137 completer)) | 1977 filewin dir (current-buffer) user-data) |
2138 | 1978 (mouse-file-display-completion-list filewin dir |
2139 ;; always clean up. | 1979 (current-buffer) |
2140 ;; get rid of our hook that calls abort-recursive-edit -- not a good | 1980 user-data) |
2141 ;; idea here. | 1981 (mouse-directory-display-completion-list dirwin dir |
2142 (kill-local-variable 'delete-frame-hook) | 1982 (current-buffer) |
1983 user-data)) | |
1984 (set | |
1985 (make-local-variable | |
1986 'completion-display-completion-list-function) | |
1987 #'(lambda (completions) | |
1988 (display-completion-list | |
1989 completions | |
1990 :help-string "" | |
1991 :activate-callback | |
1992 'mouse-read-file-name-activate-callback | |
1993 :user-data user-data))) | |
1994 ;; kludge! | |
1995 (remove-hook 'minibuffer-setup-hook rfhookfun) | |
1996 )) | |
1997 (rfcshookfun | |
1998 ;; kludge! | |
1999 ;; #### I really need to flesh out the object | |
2000 ;; hierarchy better to avoid these kludges. | |
2001 (lambda () | |
2002 (save-excursion | |
2003 (set-buffer standard-output) | |
2004 (setq truncate-lines t))))) | |
2005 (unwind-protect | |
2006 (progn | |
2007 (add-hook 'minibuffer-setup-hook rfhookfun) | |
2008 (add-hook 'completion-setup-hook rfcshookfun) | |
2009 (read-file-name-2 history prompt dir default | |
2010 must-match initial-contents | |
2011 completer)) | |
2012 (remove-hook 'minibuffer-setup-hook rfhookfun) | |
2013 (remove-hook 'completion-setup-hook rfcshookfun)))) | |
2143 (delete-frame frame) | 2014 (delete-frame frame) |
2144 (kill-buffer filebuf) | 2015 (kill-buffer filebuf) |
2145 (kill-buffer butbuf) | 2016 (kill-buffer butbuff) |
2146 (and dirbuf (kill-buffer dirbuf))))) | 2017 (and dirbuff (kill-buffer dirbuff))))) |
2147 | 2018 |
2148 (defun read-face (prompt &optional must-match) | 2019 (defun read-face (prompt &optional must-match) |
2149 "Read the name of a face from the minibuffer and return it as a symbol." | 2020 "Read the name of a face from the minibuffer and return it as a symbol." |
2150 (intern (completing-read prompt obarray 'find-face must-match))) | 2021 (intern (completing-read prompt obarray 'find-face must-match))) |
2151 | 2022 |
2234 ;; only include these if the mule feature is present. Strangely, | 2105 ;; only include these if the mule feature is present. Strangely, |
2235 ;; read-coding-system doesn't. | 2106 ;; read-coding-system doesn't. |
2236 | 2107 |
2237 ;;(if (featurep 'mule) | 2108 ;;(if (featurep 'mule) |
2238 | 2109 |
2239 (defun read-coding-system (prompt &optional default-coding-system) | 2110 (defun read-coding-system (prompt) |
2240 "Read a coding-system (or nil) from the minibuffer. | 2111 "Read a coding-system (or nil) from the minibuffer. |
2241 Prompting with string PROMPT. | 2112 Prompting with string PROMPT." |
2242 If the user enters null input, return second argument DEFAULT-CODING-SYSTEM. | 2113 (intern (completing-read prompt obarray 'find-coding-system t))) |
2243 DEFAULT-CODING-SYSTEM can be a string, symbol, or coding-system object." | |
2244 (intern (completing-read prompt obarray 'find-coding-system t nil nil | |
2245 (cond ((symbolp default-coding-system) | |
2246 (symbol-name default-coding-system)) | |
2247 ((coding-system-p default-coding-system) | |
2248 (symbol-name (coding-system-name default-coding-system))) | |
2249 (t | |
2250 default-coding-system))))) | |
2251 | 2114 |
2252 (defun read-non-nil-coding-system (prompt) | 2115 (defun read-non-nil-coding-system (prompt) |
2253 "Read a non-nil coding-system from the minibuffer. | 2116 "Read a non-nil coding-system from the minibuffer. |
2254 Prompt with string PROMPT." | 2117 Prompt with string PROMPT." |
2255 (let ((retval (intern ""))) | 2118 (let ((retval (intern ""))) |