diff options
| author | Richard M. Stallman | 1998-02-14 08:41:32 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-02-14 08:41:32 +0000 |
| commit | 62f555a5af8a020b6a86f57fa440050fa429cf22 (patch) | |
| tree | c80ed564728ad8a4b8e19d9973d36b20aa9ba544 /src | |
| parent | 9ce37c9d19e468a97c1e0c0e3dcf39b017ecf21f (diff) | |
| download | emacs-62f555a5af8a020b6a86f57fa440050fa429cf22.tar.gz emacs-62f555a5af8a020b6a86f57fa440050fa429cf22.zip | |
(Fread_file_name): Alter the history
to contain just the actual file name, and not any
other preinserted text that is not really used.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 99 |
1 files changed, 34 insertions, 65 deletions
diff --git a/src/fileio.c b/src/fileio.c index 6993003a8f1..168858d9090 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -5029,6 +5029,8 @@ DIR defaults to current buffer's directory default.") | |||
| 5029 | Lisp_Object val, insdef, insdef1, tem; | 5029 | Lisp_Object val, insdef, insdef1, tem; |
| 5030 | struct gcpro gcpro1, gcpro2; | 5030 | struct gcpro gcpro1, gcpro2; |
| 5031 | register char *homedir; | 5031 | register char *homedir; |
| 5032 | int replace_in_history = 0; | ||
| 5033 | int add_to_history = 0; | ||
| 5032 | int count; | 5034 | int count; |
| 5033 | 5035 | ||
| 5034 | if (NILP (dir)) | 5036 | if (NILP (dir)) |
| @@ -5090,13 +5092,25 @@ DIR defaults to current buffer's directory default.") | |||
| 5090 | val = Fcompleting_read (prompt, intern ("read-file-name-internal"), | 5092 | val = Fcompleting_read (prompt, intern ("read-file-name-internal"), |
| 5091 | dir, mustmatch, insdef1, | 5093 | dir, mustmatch, insdef1, |
| 5092 | Qfile_name_history, default_filename, Qnil); | 5094 | Qfile_name_history, default_filename, Qnil); |
| 5093 | /* If Fcompleting_read returned the default string itself | 5095 | |
| 5096 | tem = Fsymbol_value (Qfile_name_history); | ||
| 5097 | if (CONSP (tem) && EQ (XCONS (tem)->car, val)) | ||
| 5098 | replace_in_history = 1; | ||
| 5099 | |||
| 5100 | /* If Fcompleting_read returned the inserted default string itself | ||
| 5094 | (rather than a new string with the same contents), | 5101 | (rather than a new string with the same contents), |
| 5095 | it has to mean that the user typed RET with the minibuffer empty. | 5102 | it has to mean that the user typed RET with the minibuffer empty. |
| 5096 | In that case, we really want to return "" | 5103 | In that case, we really want to return "" |
| 5097 | so that commands such as set-visited-file-name can distinguish. */ | 5104 | so that commands such as set-visited-file-name can distinguish. */ |
| 5098 | if (EQ (val, default_filename)) | 5105 | if (EQ (val, default_filename)) |
| 5099 | val = build_string (""); | 5106 | { |
| 5107 | /* In this case, Fcompleting_read has not added an element | ||
| 5108 | to the history. Maybe we should. */ | ||
| 5109 | if (! replace_in_history) | ||
| 5110 | add_to_history = 1; | ||
| 5111 | |||
| 5112 | val = build_string (""); | ||
| 5113 | } | ||
| 5100 | 5114 | ||
| 5101 | #ifdef VMS | 5115 | #ifdef VMS |
| 5102 | unbind_to (count, Qnil); | 5116 | unbind_to (count, Qnil); |
| @@ -5105,80 +5119,35 @@ DIR defaults to current buffer's directory default.") | |||
| 5105 | UNGCPRO; | 5119 | UNGCPRO; |
| 5106 | if (NILP (val)) | 5120 | if (NILP (val)) |
| 5107 | error ("No file name specified"); | 5121 | error ("No file name specified"); |
| 5122 | |||
| 5108 | tem = Fstring_equal (val, insdef); | 5123 | tem = Fstring_equal (val, insdef); |
| 5124 | |||
| 5109 | if (!NILP (tem) && !NILP (default_filename)) | 5125 | if (!NILP (tem) && !NILP (default_filename)) |
| 5110 | return default_filename; | 5126 | val = default_filename; |
| 5111 | if (XSTRING (val)->size == 0 && NILP (insdef)) | 5127 | else if (XSTRING (val)->size == 0 && NILP (insdef)) |
| 5112 | { | 5128 | { |
| 5113 | if (!NILP (default_filename)) | 5129 | if (!NILP (default_filename)) |
| 5114 | return default_filename; | 5130 | val = default_filename; |
| 5115 | else | 5131 | else |
| 5116 | error ("No default file name"); | 5132 | error ("No default file name"); |
| 5117 | } | 5133 | } |
| 5118 | return Fsubstitute_in_file_name (val); | 5134 | val = Fsubstitute_in_file_name (val); |
| 5119 | } | ||
| 5120 | |||
| 5121 | #if 0 /* Old version */ | ||
| 5122 | DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 5, 0, | ||
| 5123 | /* Don't confuse make-docfile by having two doc strings for this function. | ||
| 5124 | make-docfile does not pay attention to #if, for good reason! */ | ||
| 5125 | 0) | ||
| 5126 | (prompt, dir, defalt, mustmatch, initial) | ||
| 5127 | Lisp_Object prompt, dir, defalt, mustmatch, initial; | ||
| 5128 | { | ||
| 5129 | Lisp_Object val, insdef, tem; | ||
| 5130 | struct gcpro gcpro1, gcpro2; | ||
| 5131 | register char *homedir; | ||
| 5132 | int count; | ||
| 5133 | |||
| 5134 | if (NILP (dir)) | ||
| 5135 | dir = current_buffer->directory; | ||
| 5136 | if (NILP (defalt)) | ||
| 5137 | defalt = current_buffer->filename; | ||
| 5138 | 5135 | ||
| 5139 | /* If dir starts with user's homedir, change that to ~. */ | 5136 | if (replace_in_history) |
| 5140 | homedir = (char *) egetenv ("HOME"); | 5137 | /* Replace what Fcompleting_read added to the history |
| 5141 | if (homedir != 0 | 5138 | with what we will actually return. */ |
| 5142 | && STRINGP (dir) | 5139 | XCONS (Fsymbol_value (Qfile_name_history))->car = val; |
| 5143 | && !strncmp (homedir, XSTRING (dir)->data, strlen (homedir)) | 5140 | else if (add_to_history) |
| 5144 | && XSTRING (dir)->data[strlen (homedir)] == '/') | ||
| 5145 | { | 5141 | { |
| 5146 | dir = make_string (XSTRING (dir)->data + strlen (homedir) - 1, | 5142 | /* Add the value to the history--but not if it matches |
| 5147 | XSTRING (dir)->size - strlen (homedir) + 1); | 5143 | the last value already there. */ |
| 5148 | XSTRING (dir)->data[0] = '~'; | 5144 | tem = Fsymbol_value (Qfile_name_history); |
| 5145 | if (! CONSP (tem) || NILP (Fequal (XCONS (tem)->car, val))) | ||
| 5146 | Fset (Qfile_name_history, | ||
| 5147 | Fcons (val, tem)); | ||
| 5149 | } | 5148 | } |
| 5150 | 5149 | return val; | |
| 5151 | if (!NILP (initial)) | ||
| 5152 | insdef = initial; | ||
| 5153 | else if (insert_default_directory) | ||
| 5154 | insdef = dir; | ||
| 5155 | else | ||
| 5156 | insdef = build_string (""); | ||
| 5157 | |||
| 5158 | #ifdef VMS | ||
| 5159 | count = specpdl_ptr - specpdl; | ||
| 5160 | specbind (intern ("completion-ignore-case"), Qt); | ||
| 5161 | #endif | ||
| 5162 | |||
| 5163 | GCPRO2 (insdef, defalt); | ||
| 5164 | val = Fcompleting_read (prompt, intern ("read-file-name-internal"), | ||
| 5165 | dir, mustmatch, | ||
| 5166 | insert_default_directory ? insdef : Qnil, | ||
| 5167 | Qfile_name_history, Qnil, Qnil); | ||
| 5168 | |||
| 5169 | #ifdef VMS | ||
| 5170 | unbind_to (count, Qnil); | ||
| 5171 | #endif | ||
| 5172 | |||
| 5173 | UNGCPRO; | ||
| 5174 | if (NILP (val)) | ||
| 5175 | error ("No file name specified"); | ||
| 5176 | tem = Fstring_equal (val, insdef); | ||
| 5177 | if (!NILP (tem) && !NILP (defalt)) | ||
| 5178 | return defalt; | ||
| 5179 | return Fsubstitute_in_file_name (val); | ||
| 5180 | } | 5150 | } |
| 5181 | #endif /* Old version */ | ||
| 5182 | 5151 | ||
| 5183 | syms_of_fileio () | 5152 | syms_of_fileio () |
| 5184 | { | 5153 | { |