comparison lisp/minibuf.el @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
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 Ben Wing 5 ;; Copyright (C) 1995, 1996, 2000 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
50 :type 'boolean 50 :type 'boolean
51 :group 'minibuffer) 51 :group 'minibuffer)
52 52
53 (defcustom minibuffer-history-uniquify t 53 (defcustom minibuffer-history-uniquify t
54 "*Non-nil means when adding an item to a minibuffer history, remove 54 "*Non-nil means when adding an item to a minibuffer history, remove
55 previous occurances of the same item from the history list first, 55 previous occurrences of the same item from the history list first,
56 rather than just consing the new element onto the front of the list." 56 rather than just consing the new element onto the front of the list."
57 :type 'boolean 57 :type 'boolean
58 :group 'minibuffer) 58 :group 'minibuffer)
59 59
60 (defvar minibuffer-completion-table nil 60 (defvar minibuffer-completion-table nil
109 ;; Moved to C. The minibuffer prompt must be setup before this is run 109 ;; Moved to C. The minibuffer prompt must be setup before this is run
110 ;; and that can only be done from the C side. 110 ;; and that can only be done from the C side.
111 ;(defvar minibuffer-setup-hook nil 111 ;(defvar minibuffer-setup-hook nil
112 ; "Normal hook run just after entry to minibuffer.") 112 ; "Normal hook run just after entry to minibuffer.")
113 113
114 ;; see comment at list-mode-hook.
115 (put 'minibuffer-setup-hook 'permanent-local t)
116
114 (defvar minibuffer-exit-hook nil 117 (defvar minibuffer-exit-hook nil
115 "Normal hook run just after exit from minibuffer.") 118 "Normal hook run just after exit from minibuffer.")
119 (put 'minibuffer-exit-hook 'permanent-local t)
116 120
117 (defvar minibuffer-help-form nil 121 (defvar minibuffer-help-form nil
118 "Value that `help-form' takes on inside the minibuffer.") 122 "Value that `help-form' takes on inside the minibuffer.")
119 123
120 (defvar minibuffer-default nil 124 (defvar minibuffer-default nil
606 610
607 ;;;; Guts of minibuffer completion 611 ;;;; Guts of minibuffer completion
608 612
609 613
610 ;; Used by minibuffer-do-completion 614 ;; Used by minibuffer-do-completion
611 (defvar last-exact-completion) 615 (defvar last-exact-completion nil)
612 616
613 (defun temp-minibuffer-message (m) 617 (defun temp-minibuffer-message (m)
614 (let ((savemax (point-max))) 618 (let ((savemax (point-max)))
615 (save-excursion 619 (save-excursion
616 (goto-char (point-max)) 620 (goto-char (point-max))
1323 initial-minibuffer-history-position) 1327 initial-minibuffer-history-position)
1324 (setq current-minibuffer-contents (buffer-string) 1328 (setq current-minibuffer-contents (buffer-string)
1325 current-minibuffer-point (point))) 1329 current-minibuffer-point (point)))
1326 (let ((narg (- minibuffer-history-position n)) 1330 (let ((narg (- minibuffer-history-position n))
1327 (minimum (if minibuffer-default -1 0))) 1331 (minimum (if minibuffer-default -1 0)))
1332 ;; a weird special case here; when in repeat-complex-command, we're
1333 ;; trying to edit the top command, and minibuffer-history-position
1334 ;; points to 1, the next-to-top command. in this case, the top
1335 ;; command in the history is suppressed in favor of the one being
1336 ;; edited, and there is no more command below it, except maybe the
1337 ;; default.
1338 (if (and (zerop narg) (eq minibuffer-history-position
1339 initial-minibuffer-history-position))
1340 (setq minimum (1+ minimum)))
1328 (cond ((< narg minimum) 1341 (cond ((< narg minimum)
1329 (error (if minibuffer-default 1342 (error (if minibuffer-default
1330 "No following item in %s" 1343 "No following item in %s"
1331 "No following item in %s; no default available") 1344 "No following item in %s; no default available")
1332 minibuffer-history-variable)) 1345 minibuffer-history-variable))
1336 (setq minibuffer-history-position narg) 1349 (setq minibuffer-history-position narg)
1337 (if (eq narg initial-minibuffer-history-position) 1350 (if (eq narg initial-minibuffer-history-position)
1338 (progn 1351 (progn
1339 (insert current-minibuffer-contents) 1352 (insert current-minibuffer-contents)
1340 (goto-char current-minibuffer-point)) 1353 (goto-char current-minibuffer-point))
1341 (let ((elt (if (>= narg 0) 1354 (let ((elt (if (> narg 0)
1342 (nth (1- minibuffer-history-position) 1355 (nth (1- minibuffer-history-position)
1343 (symbol-value minibuffer-history-variable)) 1356 (symbol-value minibuffer-history-variable))
1344 minibuffer-default))) 1357 minibuffer-default)))
1345 (insert 1358 (insert
1346 (if (not (stringp elt)) 1359 (if (not (stringp elt))
1444 (defun read-variable (prompt &optional default-value) 1457 (defun read-variable (prompt &optional default-value)
1445 "Read the name of a user variable and return it as a symbol. 1458 "Read the name of a user variable and return it as a symbol.
1446 Prompts with PROMPT. By default, return DEFAULT-VALUE. 1459 Prompts with PROMPT. By default, return DEFAULT-VALUE.
1447 A user variable is one whose documentation starts with a `*' character." 1460 A user variable is one whose documentation starts with a `*' character."
1448 (intern (completing-read prompt obarray 'user-variable-p t nil 1461 (intern (completing-read prompt obarray 'user-variable-p t nil
1449 'variable-history default-value))) 1462 'variable-history
1463 (if (symbolp default-value)
1464 (symbol-name default-value)
1465 default-value))))
1450 1466
1451 (defun read-buffer (prompt &optional default require-match) 1467 (defun read-buffer (prompt &optional default require-match)
1452 "Read the name of a buffer and return as a string. 1468 "Read the name of a buffer and return as a string.
1453 Prompts with PROMPT. Optional second arg DEFAULT is value to return if user 1469 Prompts with PROMPT. Optional second arg DEFAULT is value to return if user
1454 enters an empty line. If optional third arg REQUIRE-MATCH is non-nil, 1470 enters an empty line. If optional third arg REQUIRE-MATCH is non-nil,
1534 (setq o (1+ o) n (1+ n)) 1550 (setq o (1+ o) n (1+ n))
1535 (if (eq ch ?$) 1551 (if (eq ch ?$)
1536 ;; already aset by make-string initial-value 1552 ;; already aset by make-string initial-value
1537 (setq n (1+ n)))) 1553 (setq n (1+ n))))
1538 new))) 1554 new)))
1555
1556
1557 ;; Wrapper for `directory-files' for use in generating completion lists.
1558 ;; Generates output in the same format as `file-name-all-completions'.
1559 ;;
1560 ;; The EFS replacement for `directory-files' doesn't support the FILES-ONLY
1561 ;; option, so it has to be faked. The listing cache will hopefully
1562 ;; improve the performance of this operation.
1563 (defun minibuf-directory-files (dir &optional match-regexp files-only)
1564 (let ((want-file (or (eq files-only nil) (eq files-only t)))
1565 (want-dirs (or (eq files-only nil) (not (eq files-only t)))))
1566 (delete nil
1567 (mapcar (function (lambda (f)
1568 (if (file-directory-p (expand-file-name f dir))
1569 (and want-dirs (file-name-as-directory f))
1570 (and want-file f))))
1571 (delete "." (directory-files dir nil match-regexp))))))
1572
1539 1573
1540 (defun read-file-name-2 (history prompt dir default 1574 (defun read-file-name-2 (history prompt dir default
1541 must-match initial-contents 1575 must-match initial-contents
1542 completer) 1576 completer)
1543 (if (not dir) 1577 (if (not dir)
1623 (insert-string (file-name-as-directory 1657 (insert-string (file-name-as-directory
1624 (abbreviate-file-name full t)) minibuf) 1658 (abbreviate-file-name full t)) minibuf)
1625 (reset-buffer completion-buf) 1659 (reset-buffer completion-buf)
1626 (let ((standard-output completion-buf)) 1660 (let ((standard-output completion-buf))
1627 (display-completion-list 1661 (display-completion-list
1628 (delete "." (directory-files full nil nil nil (if dir-p 'directory))) 1662 (minibuf-directory-files full nil (if dir-p 'directory))
1629 :user-data dir-p 1663 :user-data dir-p
1630 :reference-buffer minibuf 1664 :reference-buffer minibuf
1631 :activate-callback 'read-file-name-activate-callback) 1665 :activate-callback 'read-file-name-activate-callback)
1632 (goto-char (point-min) completion-buf))))) 1666 (goto-char (point-min) completion-buf)))))
1633 1667
1634 (defun read-file-name-1 (history prompt dir default 1668 (defun read-file-name-1 (history prompt dir default
1635 must-match initial-contents 1669 must-match initial-contents
1636 completer) 1670 completer)
1637 (if (should-use-dialog-box-p) 1671 (if (should-use-dialog-box-p)
1638 ;; this calls read-file-name-2 1672 (condition-case nil
1639 (mouse-read-file-name-1 history prompt dir default must-match 1673 (let ((file
1640 initial-contents completer) 1674 (apply #'make-dialog-box
1641 (let ((rfhookfun 1675 'file `(:title ,(capitalize-string-as-title
1642 (lambda () 1676 ;; Kludge: Delete ": " off the end.
1643 ;; #### SCREAM! Create a `file-system-ignore-case' 1677 (replace-in-string prompt ": $" ""))
1644 ;; function, so this kind of stuff is generalized! 1678 ,@(and dir (list :initial-directory
1645 (and (eq system-type 'windows-nt) 1679 dir))
1646 (set (make-local-variable 'completion-ignore-case) t)) 1680 :file-must-exist ,must-match
1647 (set 1681 ,@(and initial-contents
1648 (make-local-variable 1682 (list :initial-filename
1649 'completion-display-completion-list-function) 1683 initial-contents))))))
1650 #'(lambda (completions) 1684 ;; hack -- until we implement reading a directory properly,
1651 (display-completion-list 1685 ;; allow a file as indicating the directory it's in
1652 completions 1686 (if (and (eq completer 'read-directory-name-internal)
1653 :user-data (not (eq completer 'read-file-name-internal)) 1687 (not (file-directory-p file)))
1654 :activate-callback 1688 (file-name-directory file)
1655 'read-file-name-activate-callback))) 1689 file))
1656 ;; kludge! 1690 (unimplemented
1657 (remove-hook 'minibuffer-setup-hook rfhookfun) 1691 ;; this calls read-file-name-2
1658 ))) 1692 (mouse-read-file-name-1 history prompt dir default must-match
1659 (unwind-protect 1693 initial-contents completer)
1660 (progn 1694 ))
1661 (add-hook 'minibuffer-setup-hook rfhookfun) 1695 (add-one-shot-hook
1662 (read-file-name-2 history prompt dir default must-match 1696 'minibuffer-setup-hook
1663 initial-contents completer)) 1697 (lambda ()
1664 (remove-hook 'minibuffer-setup-hook rfhookfun))))) 1698 ;; #### SCREAM! Create a `file-system-ignore-case'
1699 ;; function, so this kind of stuff is generalized!
1700 (and (eq system-type 'windows-nt)
1701 (set (make-local-variable 'completion-ignore-case) t))
1702 (set
1703 (make-local-variable
1704 'completion-display-completion-list-function)
1705 #'(lambda (completions)
1706 (display-completion-list
1707 completions
1708 :user-data (not (eq completer 'read-file-name-internal))
1709 :activate-callback
1710 'read-file-name-activate-callback)))))
1711 (read-file-name-2 history prompt dir default must-match
1712 initial-contents completer)))
1665 1713
1666 (defun read-file-name (prompt 1714 (defun read-file-name (prompt
1667 &optional dir default must-match initial-contents 1715 &optional dir default must-match initial-contents
1668 history) 1716 history)
1669 "Read file name, prompting with PROMPT and completing in directory DIR. 1717 "Read file name, prompting with PROMPT and completing in directory DIR.
1822 nil 1870 nil
1823 (file-exists-p sstring))))) 1871 (file-exists-p sstring)))))
1824 ((eq action 't) 1872 ((eq action 't)
1825 ;; all completions 1873 ;; all completions
1826 (mapcar #'un-substitute-in-file-name 1874 (mapcar #'un-substitute-in-file-name
1827 (file-name-all-completions name dir))) 1875 (if (string= name "")
1876 (delete "./" (file-name-all-completions "" dir))
1877 (file-name-all-completions name dir))))
1828 (t;; nil 1878 (t;; nil
1829 ;; complete 1879 ;; complete
1830 (let* ((d (or dir default-directory)) 1880 (let* ((d (or dir default-directory))
1831 (val (file-name-completion name d))) 1881 (val (file-name-completion name d)))
1832 (if (and (eq val 't) 1882 (if (and (eq val 't)
1851 (read-file-name-internal-1 1901 (read-file-name-internal-1
1852 string dir action 1902 string dir action
1853 #'(lambda (action orig string specdir dir name) 1903 #'(lambda (action orig string specdir dir name)
1854 (let* ((dirs #'(lambda (fn) 1904 (let* ((dirs #'(lambda (fn)
1855 (let ((l (if (equal name "") 1905 (let ((l (if (equal name "")
1856 (directory-files 1906 (minibuf-directory-files
1857 dir 1907 dir
1858 nil
1859 "" 1908 ""
1860 nil
1861 'directories) 1909 'directories)
1862 (directory-files 1910 (minibuf-directory-files
1863 dir 1911 dir
1864 nil
1865 (concat "\\`" (regexp-quote name)) 1912 (concat "\\`" (regexp-quote name))
1866 nil
1867 'directories)))) 1913 'directories))))
1868 (mapcar fn 1914 (mapcar fn
1869 ;; Wretched unix 1915 ;; Wretched unix
1870 (delete "." l)))))) 1916 (delete "." l))))))
1871 (cond ((eq action 'lambda) 1917 (cond ((eq action 'lambda)
1923 (error file)) 1969 (error file))
1924 "" nil)))) 1970 "" nil))))
1925 result) 1971 result)
1926 (t file)))) 1972 (t file))))
1927 1973
1974 (defun mouse-rfn-setup-vars (prompt)
1975 ;; a specifier would be nice.
1976 (set (make-local-variable 'frame-title-format)
1977 (capitalize-string-as-title
1978 ;; Kludge: Delete ": " off the end.
1979 (replace-in-string prompt ": $" "")))
1980 ;; ensure that killing the frame works right,
1981 ;; instead of leaving us in the minibuffer.
1982 (add-local-hook 'delete-frame-hook
1983 #'(lambda (frame)
1984 (abort-recursive-edit))))
1985
1928 (defun mouse-file-display-completion-list (window dir minibuf user-data) 1986 (defun mouse-file-display-completion-list (window dir minibuf user-data)
1929 (let ((standard-output (window-buffer window))) 1987 (let ((standard-output (window-buffer window)))
1930 (condition-case nil 1988 (condition-case nil
1931 (display-completion-list 1989 (display-completion-list
1932 (directory-files dir nil nil nil t) 1990 (minibuf-directory-files dir nil t)
1933 :window-width (* 2 (window-width window)) 1991 :window-width (window-width window)
1992 :window-height (window-text-area-height window)
1993 :completion-string ""
1934 :activate-callback 1994 :activate-callback
1935 'mouse-read-file-name-activate-callback 1995 'mouse-read-file-name-activate-callback
1936 :user-data user-data 1996 :user-data user-data
1937 :reference-buffer minibuf 1997 :reference-buffer minibuf
1938 :help-string "") 1998 :help-string "")
1939 (t nil)))) 1999 (t nil))
2000 ))
1940 2001
1941 (defun mouse-directory-display-completion-list (window dir minibuf user-data) 2002 (defun mouse-directory-display-completion-list (window dir minibuf user-data)
1942 (let ((standard-output (window-buffer window))) 2003 (let ((standard-output (window-buffer window)))
1943 (condition-case nil 2004 (condition-case nil
1944 (display-completion-list 2005 (display-completion-list
1945 (delete "." (directory-files dir nil nil nil 1)) 2006 (minibuf-directory-files dir nil 1)
1946 :window-width (window-width window) 2007 :window-width (window-width window)
2008 :window-height (window-text-area-height window)
2009 :completion-string ""
1947 :activate-callback 2010 :activate-callback
1948 'mouse-read-file-name-activate-callback 2011 'mouse-read-file-name-activate-callback
1949 :user-data user-data 2012 :user-data user-data
1950 :reference-buffer minibuf 2013 :reference-buffer minibuf
1951 :help-string "") 2014 :help-string "")
1952 (t nil)))) 2015 (t nil))
2016 ))
1953 2017
1954 (defun mouse-read-file-name-activate-callback (event extent user-data) 2018 (defun mouse-read-file-name-activate-callback (event extent user-data)
1955 (let* ((file (extent-string extent)) 2019 (let* ((file (extent-string extent))
1956 (minibuf (symbol-value-in-buffer 'completion-reference-buffer 2020 (minibuf (symbol-value-in-buffer 'completion-reference-buffer
1957 (extent-object extent))) 2021 (extent-object extent)))
1958 (in-dir (buffer-substring nil nil minibuf)) 2022 (ministring (buffer-substring nil nil minibuf))
2023 (in-dir (file-name-directory ministring))
1959 (full (expand-file-name file in-dir)) 2024 (full (expand-file-name file in-dir))
1960 (filebuf (nth 0 user-data)) 2025 (filebuf (nth 0 user-data))
1961 (dirbuff (nth 1 user-data)) 2026 (dirbuf (nth 1 user-data))
1962 (filewin (nth 2 user-data)) 2027 (filewin (nth 2 user-data))
1963 (dirwin (nth 3 user-data))) 2028 (dirwin (nth 3 user-data)))
1964 (if (file-regular-p full) 2029 (if (file-regular-p full)
1965 (default-choose-completion event extent minibuf) 2030 (default-choose-completion event extent minibuf)
1966 (erase-buffer minibuf) 2031 (erase-buffer minibuf)
1967 (insert-string (file-name-as-directory 2032 (insert-string (file-name-as-directory
1968 (abbreviate-file-name full t)) minibuf) 2033 (abbreviate-file-name full t)) minibuf)
1969 (reset-buffer filebuf) 2034 (reset-buffer filebuf)
1970 (if (not dirbuff) 2035 (if (not dirbuf)
1971 (mouse-directory-display-completion-list filewin full minibuf 2036 (mouse-directory-display-completion-list filewin full minibuf
1972 user-data) 2037 user-data)
1973 (mouse-file-display-completion-list filewin full minibuf user-data) 2038 (mouse-file-display-completion-list filewin full minibuf user-data)
1974 (reset-buffer dirbuff) 2039 (reset-buffer dirbuf)
1975 (mouse-directory-display-completion-list dirwin full minibuf 2040 (mouse-directory-display-completion-list dirwin full minibuf
1976 user-data))))) 2041 user-data)))))
1977 2042
1978 ;; this is rather cheesified but gets the job done. 2043 ;; our cheesy but god-awful time consuming file dialog box implementation.
2044 ;; this will be replaced with use of the native file dialog box (when
2045 ;; available).
1979 (defun mouse-read-file-name-1 (history prompt dir default 2046 (defun mouse-read-file-name-1 (history prompt dir default
1980 must-match initial-contents 2047 must-match initial-contents
1981 completer) 2048 completer)
2049 ;; file-p is t if we're reading files, nil if directories.
1982 (let* ((file-p (eq 'read-file-name-internal completer)) 2050 (let* ((file-p (eq 'read-file-name-internal completer))
1983 (filebuf (get-buffer-create "*Completions*")) 2051 (filebuf (get-buffer-create "*Completions*"))
1984 (dirbuff (and file-p (generate-new-buffer " *mouse-read-file*"))) 2052 (dirbuf (and file-p (generate-new-buffer " *mouse-read-file*")))
1985 (butbuff (generate-new-buffer " *mouse-read-file*")) 2053 (butbuf (generate-new-buffer " *mouse-read-file*"))
1986 (frame (make-dialog-frame)) 2054 (frame (make-dialog-frame))
1987 filewin dirwin 2055 filewin dirwin
1988 user-data) 2056 user-data)
1989 (unwind-protect 2057 (unwind-protect
1990 (progn 2058 (progn
1991 (reset-buffer filebuf) 2059 (reset-buffer filebuf)
1992 (select-frame frame) 2060
2061 ;; set up the frame.
2062 (focus-frame frame)
1993 (let ((window-min-height 1)) 2063 (let ((window-min-height 1))
1994 ;; #### should be 2 not 3, but that causes 2064 ;; #### should be 2 not 3, but that causes
1995 ;; "window too small to split" errors for some 2065 ;; "window too small to split" errors for some
1996 ;; people (but not for me ...) There's a more 2066 ;; people (but not for me ...) There's a more
1997 ;; fundamental bug somewhere. 2067 ;; fundamental bug somewhere.
2000 (progn 2070 (progn
2001 (split-window-horizontally 16) 2071 (split-window-horizontally 16)
2002 (setq filewin (frame-rightmost-window frame) 2072 (setq filewin (frame-rightmost-window frame)
2003 dirwin (frame-leftmost-window frame)) 2073 dirwin (frame-leftmost-window frame))
2004 (set-window-buffer filewin filebuf) 2074 (set-window-buffer filewin filebuf)
2005 (set-window-buffer dirwin dirbuff)) 2075 (set-window-buffer dirwin dirbuf))
2006 (setq filewin (frame-highest-window frame)) 2076 (setq filewin (frame-highest-window frame))
2007 (set-window-buffer filewin filebuf)) 2077 (set-window-buffer filewin filebuf))
2008 (setq user-data (list filebuf dirbuff filewin dirwin)) 2078 (setq user-data (list filebuf dirbuf filewin dirwin))
2009 (set-window-buffer (frame-lowest-window frame) butbuff) 2079 (set-window-buffer (frame-lowest-window frame) butbuf)
2010 (set-buffer butbuff) 2080
2081 ;; set up completion buffers.
2082 (let ((rfcshookfun
2083 ;; kludge!
2084 ;; #### I really need to flesh out the object
2085 ;; hierarchy better to avoid these kludges.
2086 ;; (?? I wrote this comment above some time ago,
2087 ;; and I don't understand what I'm referring to
2088 ;; any more. --ben
2089 (lambda ()
2090 (mouse-rfn-setup-vars prompt)
2091 (when (featurep 'scrollbar)
2092 (set-specifier scrollbar-width 0 (current-buffer)))
2093 (setq truncate-lines t))))
2094
2095 (set-buffer filebuf)
2096 (add-local-hook 'completion-setup-hook rfcshookfun)
2097 (when file-p
2098 (set-buffer dirbuf)
2099 (add-local-hook 'completion-setup-hook rfcshookfun)))
2100
2101 ;; set up minibuffer.
2102 (add-one-shot-hook
2103 'minibuffer-setup-hook
2104 (lambda ()
2105 (if (not file-p)
2106 (mouse-directory-display-completion-list
2107 filewin dir (current-buffer) user-data)
2108 (mouse-file-display-completion-list
2109 filewin dir (current-buffer) user-data)
2110 (mouse-directory-display-completion-list
2111 dirwin dir (current-buffer) user-data))
2112 (set
2113 (make-local-variable
2114 'completion-display-completion-list-function)
2115 (lambda (completions)
2116 (display-completion-list
2117 completions
2118 :help-string ""
2119 :window-width (window-width filewin)
2120 :window-height (window-text-area-height filewin)
2121 :completion-string ""
2122 :activate-callback
2123 'mouse-read-file-name-activate-callback
2124 :user-data user-data)))
2125 (mouse-rfn-setup-vars prompt)
2126 (save-selected-window
2127 ;; kludge to ensure the frame title is correct.
2128 ;; the minibuffer leaves the frame title the way
2129 ;; it was before (i.e. of the selected window before
2130 ;; the dialog box was opened), so to get it correct
2131 ;; we have to be tricky.
2132 (select-window filewin)
2133 (redisplay-frame nil t)
2134 ;; #### another kludge. sometimes the focus ends up
2135 ;; back in the main window, not the dialog box. it
2136 ;; occurs randomly and it's not possible to reliably
2137 ;; reproduce. We try to fix it by draining non-user
2138 ;; events and then setting the focus back on the frame.
2139 (sit-for 0 t)
2140 (focus-frame frame))))
2141
2142 ;; set up button buffer.
2143 (set-buffer butbuf)
2144 (mouse-rfn-setup-vars prompt)
2011 (when dir 2145 (when dir
2012 (setq default-directory dir)) 2146 (setq default-directory dir))
2013 (when (featurep 'scrollbar) 2147 (when (featurep 'scrollbar)
2014 (set-specifier scrollbar-width 0 butbuff)) 2148 (set-specifier scrollbar-width 0 butbuf))
2015 (insert " ") 2149 (insert " ")
2016 (insert-gui-button (make-gui-button "OK" 2150 (insert-gui-button (make-gui-button "OK"
2017 (lambda (foo) 2151 (lambda (foo)
2018 (exit-minibuffer)))) 2152 (exit-minibuffer))))
2019 (insert " ") 2153 (insert " ")
2020 (insert-gui-button (make-gui-button "Cancel" 2154 (insert-gui-button (make-gui-button "Cancel"
2021 (lambda (foo) 2155 (lambda (foo)
2022 (abort-recursive-edit)))) 2156 (abort-recursive-edit))))
2023 (let ((rfhookfun 2157
2024 (lambda () 2158 ;; now start reading filename.
2025 (if (not file-p) 2159 (read-file-name-2 history prompt dir default
2026 (mouse-directory-display-completion-list 2160 must-match initial-contents
2027 filewin dir (current-buffer) user-data) 2161 completer))
2028 (mouse-file-display-completion-list filewin dir 2162
2029 (current-buffer) 2163 ;; always clean up.
2030 user-data) 2164 ;; get rid of our hook that calls abort-recursive-edit -- not a good
2031 (mouse-directory-display-completion-list dirwin dir 2165 ;; idea here.
2032 (current-buffer) 2166 (kill-local-variable 'delete-frame-hook)
2033 user-data))
2034 (set
2035 (make-local-variable
2036 'completion-display-completion-list-function)
2037 #'(lambda (completions)
2038 (display-completion-list
2039 completions
2040 :help-string ""
2041 :activate-callback
2042 'mouse-read-file-name-activate-callback
2043 :user-data user-data)))
2044 ;; kludge!
2045 (remove-hook 'minibuffer-setup-hook rfhookfun)
2046 ))
2047 (rfcshookfun
2048 ;; kludge!
2049 ;; #### I really need to flesh out the object
2050 ;; hierarchy better to avoid these kludges.
2051 (lambda ()
2052 (save-excursion
2053 (set-buffer standard-output)
2054 (setq truncate-lines t)))))
2055 (unwind-protect
2056 (progn
2057 (add-hook 'minibuffer-setup-hook rfhookfun)
2058 (add-hook 'completion-setup-hook rfcshookfun)
2059 (read-file-name-2 history prompt dir default
2060 must-match initial-contents
2061 completer))
2062 (remove-hook 'minibuffer-setup-hook rfhookfun)
2063 (remove-hook 'completion-setup-hook rfcshookfun))))
2064 (delete-frame frame) 2167 (delete-frame frame)
2065 (kill-buffer filebuf) 2168 (kill-buffer filebuf)
2066 (kill-buffer butbuff) 2169 (kill-buffer butbuf)
2067 (and dirbuff (kill-buffer dirbuff))))) 2170 (and dirbuf (kill-buffer dirbuf)))))
2068 2171
2069 (defun read-face (prompt &optional must-match) 2172 (defun read-face (prompt &optional must-match)
2070 "Read the name of a face from the minibuffer and return it as a symbol." 2173 "Read the name of a face from the minibuffer and return it as a symbol."
2071 (intern (completing-read prompt obarray 'find-face must-match))) 2174 (intern (completing-read prompt obarray 'find-face must-match)))
2072 2175