aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2008-04-23 18:19:57 +0000
committerStefan Monnier2008-04-23 18:19:57 +0000
commitdbd50d4b777798eedb485df334b0876fa4ce7354 (patch)
tree1e562ce28202b8345edcae1bf95779c67ddf6c06 /lisp
parent1160644b5d47328fa6ef725a580682daa13cff5a (diff)
downloademacs-dbd50d4b777798eedb485df334b0876fa4ce7354.tar.gz
emacs-dbd50d4b777798eedb485df334b0876fa4ce7354.zip
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
(read-file-name-completion-ignore-case, insert-default-directory): New vars, moved from fileio.c. (read-file-name): New fun, moved from fileio.c. * lisp/cus-start.el: Remove insert-default-directory and read-file-name-completion-ignore-case. * src/fileio.c (Vread_file_name_function, Vread_file_name_predicate) (read_file_name_completion_ignore_case, insert_default_directory) (Qdefault_directory): Move to minibuffer.el. (Fread_file_name): Call the new `read-file-name' instead.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/cus-start.el3
-rw-r--r--lisp/minibuffer.el145
3 files changed, 152 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2d491b3bc64..a50ef0cf512 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,12 @@
12008-04-23 Stefan Monnier <monnier@iro.umontreal.ca> 12008-04-23 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * minibuffer.el (read-file-name-function, read-file-name-predicate)
4 (read-file-name-completion-ignore-case, insert-default-directory):
5 New vars, moved from fileio.c.
6 (read-file-name): New fun, moved from fileio.c.
7 * cus-start.el: Remove insert-default-directory and
8 read-file-name-completion-ignore-case.
9
3 * Makefile.in (emacs-deps): Leave it empty. 10 * Makefile.in (emacs-deps): Leave it empty.
4 11
52008-04-23 Magnus Henoch <mange@freemail.hu> 122008-04-23 Magnus Henoch <mange@freemail.hu>
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 2227735582e..af343610f3b 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -164,9 +164,6 @@ Leaving \"Default\" unchecked is equivalent with specifying a default of
164 :value (nil) 164 :value (nil)
165 (symbol :format "%v")) 165 (symbol :format "%v"))
166 (const :tag "always" t))) 166 (const :tag "always" t)))
167 ;; fileio.c
168 (insert-default-directory minibuffer boolean)
169 (read-file-name-completion-ignore-case minibuffer boolean "22.1")
170 ;; fns.c 167 ;; fns.c
171 (use-dialog-box menu boolean "21.1") 168 (use-dialog-box menu boolean "21.1")
172 (use-file-dialog menu boolean "22.1") 169 (use-file-dialog menu boolean "22.1")
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index c06010f1550..3651aa439bd 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -764,6 +764,151 @@ during running `completion-setup-hook'."
764 'completion--file-name-table) 764 'completion--file-name-table)
765 "Internal subroutine for `read-file-name'. Do not call this.") 765 "Internal subroutine for `read-file-name'. Do not call this.")
766 766
767(defvar read-file-name-function nil
768 "If this is non-nil, `read-file-name' does its work by calling this function.")
769
770(defvar read-file-name-predicate nil
771 "Current predicate used by `read-file-name-internal'.")
772
773(defcustom read-file-name-completion-ignore-case
774 (if (memq system-type '(ms-dos windows-nt darwin macos vax-vms axp-vms))
775 t nil)
776 "Non-nil means when reading a file name completion ignores case."
777 :group 'minibuffer
778 :type 'boolean
779 :version "22.1")
780
781(defcustom insert-default-directory t
782 "Non-nil means when reading a filename start with default dir in minibuffer.
783
784When the initial minibuffer contents show a name of a file or a directory,
785typing RETURN without editing the initial contents is equivalent to typing
786the default file name.
787
788If this variable is non-nil, the minibuffer contents are always
789initially non-empty, and typing RETURN without editing will fetch the
790default name, if one is provided. Note however that this default name
791is not necessarily the same as initial contents inserted in the minibuffer,
792if the initial contents is just the default directory.
793
794If this variable is nil, the minibuffer often starts out empty. In
795that case you may have to explicitly fetch the next history element to
796request the default name; typing RETURN without editing will leave
797the minibuffer empty.
798
799For some commands, exiting with an empty minibuffer has a special meaning,
800such as making the current buffer visit no file in the case of
801`set-visited-file-name'."
802 :group 'minibuffer
803 :type 'boolean)
804
805(defun read-file-name (prompt &optional dir default-filename mustmatch initial predicate)
806 "Read file name, prompting with PROMPT and completing in directory DIR.
807Value is not expanded---you must call `expand-file-name' yourself.
808Default name to DEFAULT-FILENAME if user exits the minibuffer with
809the same non-empty string that was inserted by this function.
810 (If DEFAULT-FILENAME is omitted, the visited file name is used,
811 except that if INITIAL is specified, that combined with DIR is used.)
812If the user exits with an empty minibuffer, this function returns
813an empty string. (This can only happen if the user erased the
814pre-inserted contents or if `insert-default-directory' is nil.)
815Fourth arg MUSTMATCH non-nil means require existing file's name.
816 Non-nil and non-t means also require confirmation after completion.
817Fifth arg INITIAL specifies text to start with.
818If optional sixth arg PREDICATE is non-nil, possible completions and
819the resulting file name must satisfy (funcall PREDICATE NAME).
820DIR should be an absolute directory name. It defaults to the value of
821`default-directory'.
822
823If this command was invoked with the mouse, use a file dialog box if
824`use-dialog-box' is non-nil, and the window system or X toolkit in use
825provides a file dialog box.
826
827See also `read-file-name-completion-ignore-case'
828and `read-file-name-function'."
829 (unless dir (setq dir default-directory))
830 (unless (file-name-absolute-p dir) (setq dir (expand-file-name dir)))
831 (unless default-filename
832 (setq default-filename (if initial (expand-file-name initial dir)
833 buffer-file-name)))
834 ;; If dir starts with user's homedir, change that to ~.
835 (setq dir (abbreviate-file-name dir))
836 ;; Likewise for default-filename.
837 (setq default-filename (abbreviate-file-name default-filename))
838 (let ((insdef (cond
839 ((and insert-default-directory (stringp dir))
840 (if initial
841 (cons (minibuffer--double-dollars (concat dir initial))
842 (length (minibuffer--double-dollars dir)))
843 (minibuffer--double-dollars dir)))
844 (initial (cons (minibuffer--double-dollars initial) 0)))))
845
846 (if read-file-name-function
847 (funcall read-file-name-function
848 prompt dir default-filename mustmatch initial predicate)
849 (let ((default-directory (file-name-as-directory (expand-file-name dir)))
850 (completion-ignore-case read-file-name-completion-ignore-case)
851 (minibuffer-completing-file-name t)
852 (read-file-name-predicate (or predicate 'file-exists-p))
853 (add-to-history nil))
854
855 (let* ((val
856 (if (not (next-read-file-uses-dialog-p))
857 (completing-read prompt 'read-file-name-internal
858 nil mustmatch insdef 'file-name-history
859 default-filename)
860 ;; If DIR contains a file name, split it.
861 (let ((file (file-name-nondirectory dir)))
862 (when (and default-filename (not (zerop (length file))))
863 (setq default-filename file)
864 (setq dir (file-name-directory dir)))
865 (if default-filename
866 (setq default-filename
867 (expand-file-name default-filename dir)))
868 (setq add-to-history t)
869 (x-file-dialog prompt dir default-filename mustmatch
870 (eq predicate 'file-directory-p)))))
871
872 (replace-in-history (eq (car-safe file-name-history) val)))
873 ;; If completing-read returned the inserted default string itself
874 ;; (rather than a new string with the same contents),
875 ;; it has to mean that the user typed RET with the minibuffer empty.
876 ;; In that case, we really want to return ""
877 ;; so that commands such as set-visited-file-name can distinguish.
878 (when (eq val default-filename)
879 ;; In this case, completing-read has not added an element
880 ;; to the history. Maybe we should.
881 (if (not replace-in-history)
882 (setq add-to-history t))
883 (setq val ""))
884 (unless val (error "No file name specified"))
885
886 (if (and default-filename
887 (string-equal val (if (consp insdef) (car insdef) insdef)))
888 (setq val default-filename))
889 (setq val (substitute-in-file-name val))
890
891 (if replace-in-history
892 ;; Replace what Fcompleting_read added to the history
893 ;; with what we will actually return.
894 (let ((val1 (minibuffer--double-dollars val)))
895 (if history-delete-duplicates
896 (setcdr file-name-history
897 (delete val1 (cdr file-name-history))))
898 (setcar file-name-history val1))
899 (if add-to-history
900 ;; Add the value to the history--but not if it matches
901 ;; the last value already there.
902 (let ((val1 (minibuffer--double-dollars val)))
903 (unless (and (consp file-name-history)
904 (equal (car file-name-history) val1))
905 (setq file-name-history
906 (cons val1
907 (if history-delete-duplicates
908 (delete val1 file-name-history)
909 file-name-history)))))))
910 val)))))
911
767(defun internal-complete-buffer-except (&optional buffer) 912(defun internal-complete-buffer-except (&optional buffer)
768 "Perform completion on all buffers excluding BUFFER. 913 "Perform completion on all buffers excluding BUFFER.
769Like `internal-complete-buffer', but removes BUFFER from the completion list." 914Like `internal-complete-buffer', but removes BUFFER from the completion list."