diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/src/fileio.c b/src/fileio.c index 55d09def69a..dbc5c7d9a54 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -199,6 +199,12 @@ Lisp_Object Vwrite_region_annotations_so_far; | |||
| 199 | /* File name in which we write a list of all our auto save files. */ | 199 | /* File name in which we write a list of all our auto save files. */ |
| 200 | Lisp_Object Vauto_save_list_file_name; | 200 | Lisp_Object Vauto_save_list_file_name; |
| 201 | 201 | ||
| 202 | /* Function to call to read a file name. */ | ||
| 203 | Lisp_Object Vread_file_name_function; | ||
| 204 | |||
| 205 | /* Current predicate used by read_file_name_internal. */ | ||
| 206 | Lisp_Object Vread_file_name_predicate; | ||
| 207 | |||
| 202 | /* Nonzero means, when reading a filename in the minibuffer, | 208 | /* Nonzero means, when reading a filename in the minibuffer, |
| 203 | start out by inserting the default directory into the minibuffer. */ | 209 | start out by inserting the default directory into the minibuffer. */ |
| 204 | int insert_default_directory; | 210 | int insert_default_directory; |
| @@ -5826,6 +5832,13 @@ double_dollars (val) | |||
| 5826 | return val; | 5832 | return val; |
| 5827 | } | 5833 | } |
| 5828 | 5834 | ||
| 5835 | static Lisp_Object | ||
| 5836 | read_file_name_cleanup (arg) | ||
| 5837 | Lisp_Object arg; | ||
| 5838 | { | ||
| 5839 | current_buffer->directory = arg; | ||
| 5840 | } | ||
| 5841 | |||
| 5829 | DEFUN ("read-file-name-internal", Fread_file_name_internal, Sread_file_name_internal, | 5842 | DEFUN ("read-file-name-internal", Fread_file_name_internal, Sread_file_name_internal, |
| 5830 | 3, 3, 0, | 5843 | 3, 3, 0, |
| 5831 | doc: /* Internal subroutine for read-file-name. Do not call this. */) | 5844 | doc: /* Internal subroutine for read-file-name. Do not call this. */) |
| @@ -5890,7 +5903,26 @@ DEFUN ("read-file-name-internal", Fread_file_name_internal, Sread_file_name_inte | |||
| 5890 | UNGCPRO; | 5903 | UNGCPRO; |
| 5891 | 5904 | ||
| 5892 | if (EQ (action, Qt)) | 5905 | if (EQ (action, Qt)) |
| 5893 | return Ffile_name_all_completions (name, realdir); | 5906 | { |
| 5907 | Lisp_Object all = Ffile_name_all_completions (name, realdir); | ||
| 5908 | Lisp_Object comp; | ||
| 5909 | int count; | ||
| 5910 | |||
| 5911 | if (NILP (Vread_file_name_predicate) | ||
| 5912 | || EQ (Vread_file_name_predicate, Qfile_exists_p)) | ||
| 5913 | return all; | ||
| 5914 | GCPRO3 (all, comp, specdir); | ||
| 5915 | count = specpdl_ptr - specpdl; | ||
| 5916 | record_unwind_protect (read_file_name_cleanup, current_buffer->directory); | ||
| 5917 | current_buffer->directory = realdir; | ||
| 5918 | for (comp = Qnil; CONSP (all); all = XCDR (all)) | ||
| 5919 | if (!NILP (call1 (Vread_file_name_predicate, XCAR (all)))) | ||
| 5920 | comp = Fcons (XCAR (all), comp); | ||
| 5921 | unbind_to (count, Qnil); | ||
| 5922 | UNGCPRO; | ||
| 5923 | return Fnreverse (comp); | ||
| 5924 | } | ||
| 5925 | |||
| 5894 | /* Only other case actually used is ACTION = lambda */ | 5926 | /* Only other case actually used is ACTION = lambda */ |
| 5895 | #ifdef VMS | 5927 | #ifdef VMS |
| 5896 | /* Supposedly this helps commands such as `cd' that read directory names, | 5928 | /* Supposedly this helps commands such as `cd' that read directory names, |
| @@ -5898,10 +5930,12 @@ DEFUN ("read-file-name-internal", Fread_file_name_internal, Sread_file_name_inte | |||
| 5898 | if (XSTRING (name)->size == 0) | 5930 | if (XSTRING (name)->size == 0) |
| 5899 | return Qt; | 5931 | return Qt; |
| 5900 | #endif /* VMS */ | 5932 | #endif /* VMS */ |
| 5933 | if (!NILP (Vread_file_name_predicate)) | ||
| 5934 | return call1 (Vread_file_name_predicate, string); | ||
| 5901 | return Ffile_exists_p (string); | 5935 | return Ffile_exists_p (string); |
| 5902 | } | 5936 | } |
| 5903 | 5937 | ||
| 5904 | DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 5, 0, | 5938 | DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 6, 0, |
| 5905 | doc: /* Read file name, prompting with PROMPT and completing in directory DIR. | 5939 | doc: /* Read file name, prompting with PROMPT and completing in directory DIR. |
| 5906 | Value is not expanded---you must call `expand-file-name' yourself. | 5940 | Value is not expanded---you must call `expand-file-name' yourself. |
| 5907 | Default name to DEFAULT-FILENAME if user enters a null string. | 5941 | Default name to DEFAULT-FILENAME if user enters a null string. |
| @@ -5910,13 +5944,15 @@ Default name to DEFAULT-FILENAME if user enters a null string. | |||
| 5910 | Fourth arg MUSTMATCH non-nil means require existing file's name. | 5944 | Fourth arg MUSTMATCH non-nil means require existing file's name. |
| 5911 | Non-nil and non-t means also require confirmation after completion. | 5945 | Non-nil and non-t means also require confirmation after completion. |
| 5912 | Fifth arg INITIAL specifies text to start with. | 5946 | Fifth arg INITIAL specifies text to start with. |
| 5947 | If optional sixth arg PREDICATE is non-nil, possible completions and the | ||
| 5948 | resulting file name must satisfy (funcall PREDICATE NAME). | ||
| 5913 | DIR defaults to current buffer's directory default. | 5949 | DIR defaults to current buffer's directory default. |
| 5914 | 5950 | ||
| 5915 | If this command was invoked with the mouse, use a file dialog box if | 5951 | If this command was invoked with the mouse, use a file dialog box if |
| 5916 | `use-dialog-box' is non-nil, and the window system or X toolkit in use | 5952 | `use-dialog-box' is non-nil, and the window system or X toolkit in use |
| 5917 | provides a file dialog box. */) | 5953 | provides a file dialog box. */) |
| 5918 | (prompt, dir, default_filename, mustmatch, initial) | 5954 | (prompt, dir, default_filename, mustmatch, initial, predicate) |
| 5919 | Lisp_Object prompt, dir, default_filename, mustmatch, initial; | 5955 | Lisp_Object prompt, dir, default_filename, mustmatch, initial, predicate; |
| 5920 | { | 5956 | { |
| 5921 | Lisp_Object val, insdef, tem; | 5957 | Lisp_Object val, insdef, tem; |
| 5922 | struct gcpro gcpro1, gcpro2; | 5958 | struct gcpro gcpro1, gcpro2; |
| @@ -5993,12 +6029,29 @@ provides a file dialog box. */) | |||
| 5993 | else | 6029 | else |
| 5994 | insdef = Qnil; | 6030 | insdef = Qnil; |
| 5995 | 6031 | ||
| 6032 | if (!NILP (Vread_file_name_function)) | ||
| 6033 | { | ||
| 6034 | Lisp_Object args[7]; | ||
| 6035 | |||
| 6036 | GCPRO2 (insdef, default_filename); | ||
| 6037 | args[0] = Vread_file_name_function; | ||
| 6038 | args[1] = prompt; | ||
| 6039 | args[2] = dir; | ||
| 6040 | args[3] = default_filename; | ||
| 6041 | args[4] = mustmatch; | ||
| 6042 | args[5] = initial; | ||
| 6043 | args[6] = predicate; | ||
| 6044 | RETURN_UNGCPRO (Ffuncall (7, args)); | ||
| 6045 | } | ||
| 6046 | |||
| 5996 | count = specpdl_ptr - specpdl; | 6047 | count = specpdl_ptr - specpdl; |
| 5997 | #ifdef VMS | 6048 | #ifdef VMS |
| 5998 | specbind (intern ("completion-ignore-case"), Qt); | 6049 | specbind (intern ("completion-ignore-case"), Qt); |
| 5999 | #endif | 6050 | #endif |
| 6000 | 6051 | ||
| 6001 | specbind (intern ("minibuffer-completing-file-name"), Qt); | 6052 | specbind (intern ("minibuffer-completing-file-name"), Qt); |
| 6053 | specbind (intern ("read-file-name-predicate"), | ||
| 6054 | (NILP (predicate) ? Qfile_exists_p : predicate)); | ||
| 6002 | 6055 | ||
| 6003 | GCPRO2 (insdef, default_filename); | 6056 | GCPRO2 (insdef, default_filename); |
| 6004 | 6057 | ||
| @@ -6223,6 +6276,14 @@ same format as a regular save would use. */); | |||
| 6223 | Fput (Qfile_date_error, Qerror_message, | 6276 | Fput (Qfile_date_error, Qerror_message, |
| 6224 | build_string ("Cannot set file date")); | 6277 | build_string ("Cannot set file date")); |
| 6225 | 6278 | ||
| 6279 | DEFVAR_LISP ("read-file-name-function", &Vread_file_name_function, | ||
| 6280 | doc: /* If this is non-nil, `read-file-name' does its work by calling this function. */); | ||
| 6281 | Vread_file_name_function = Qnil; | ||
| 6282 | |||
| 6283 | DEFVAR_LISP ("read-file-name-predicate", &Vread_file_name_predicate, | ||
| 6284 | doc: /* Current predicate used by `read-file-name-internal'. */); | ||
| 6285 | Vread_file_name_predicate = Qnil; | ||
| 6286 | |||
| 6226 | DEFVAR_BOOL ("insert-default-directory", &insert_default_directory, | 6287 | DEFVAR_BOOL ("insert-default-directory", &insert_default_directory, |
| 6227 | doc: /* *Non-nil means when reading a filename start with default dir in minibuffer. */); | 6288 | doc: /* *Non-nil means when reading a filename start with default dir in minibuffer. */); |
| 6228 | insert_default_directory = 1; | 6289 | insert_default_directory = 1; |