aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGeoff Voelker1999-08-06 20:40:10 +0000
committerGeoff Voelker1999-08-06 20:40:10 +0000
commit4424b2557f0dc7dd6cf89fd73212e6063353bcd3 (patch)
tree15fd575cb2d618664145296f879b56b8a8a47846 /src
parent9b4a7047ab50bfbad27d26c048babd55fccbf0a2 (diff)
downloademacs-4424b2557f0dc7dd6cf89fd73212e6063353bcd3.tar.gz
emacs-4424b2557f0dc7dd6cf89fd73212e6063353bcd3.zip
(directory_files_internal, Fdirectory_files_and_attributes,
Ffile_attributes_lessp): New functions. (Fdirectory_files): Use directory_files_internal. (syms_of_dired): Initialize Fdirectory_files_and_attributes, Ffile_attributes_lessp.
Diffstat (limited to 'src')
-rw-r--r--src/dired.c142
1 files changed, 114 insertions, 28 deletions
diff --git a/src/dired.c b/src/dired.c
index afeb8cb2e2f..49e95a54795 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -105,20 +105,19 @@ extern Lisp_Object Vfile_name_coding_system, Vdefault_file_name_coding_system;
105Lisp_Object Vcompletion_ignored_extensions; 105Lisp_Object Vcompletion_ignored_extensions;
106Lisp_Object Qcompletion_ignore_case; 106Lisp_Object Qcompletion_ignore_case;
107Lisp_Object Qdirectory_files; 107Lisp_Object Qdirectory_files;
108Lisp_Object Qdirectory_files_and_attributes;
108Lisp_Object Qfile_name_completion; 109Lisp_Object Qfile_name_completion;
109Lisp_Object Qfile_name_all_completions; 110Lisp_Object Qfile_name_all_completions;
110Lisp_Object Qfile_attributes; 111Lisp_Object Qfile_attributes;
112Lisp_Object Qfile_attributes_lessp;
111 113
112DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 4, 0, 114/* Function shared by Fdirectory_files and Fdirectory_files_and_attributes.
113 "Return a list of names of files in DIRECTORY.\n\ 115 When ATTRS is zero, return a list of directory filenames; when
114There are three optional arguments:\n\ 116 non-zero, return a list of directory filenames and their attributes. */
115If FULL is non-nil, return absolute file names. Otherwise return names\n\ 117Lisp_Object
116 that are relative to the specified directory.\n\ 118directory_files_internal (directory, full, match, nosort, attrs)
117If MATCH is non-nil, mention only file names that match the regexp MATCH.\n\
118If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
119 NOSORT is useful if you plan to sort the result yourself.")
120 (directory, full, match, nosort)
121 Lisp_Object directory, full, match, nosort; 119 Lisp_Object directory, full, match, nosort;
120 int attrs;
122{ 121{
123 DIR *d; 122 DIR *d;
124 int dirnamelen; 123 int dirnamelen;
@@ -129,22 +128,6 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
129 int needsep = 0; 128 int needsep = 0;
130 struct gcpro gcpro1, gcpro2; 129 struct gcpro gcpro1, gcpro2;
131 130
132 /* If the file name has special constructs in it,
133 call the corresponding file handler. */
134 handler = Ffind_file_name_handler (directory, Qdirectory_files);
135 if (!NILP (handler))
136 {
137 Lisp_Object args[6];
138
139 args[0] = handler;
140 args[1] = Qdirectory_files;
141 args[2] = directory;
142 args[3] = full;
143 args[4] = match;
144 args[5] = nosort;
145 return Ffuncall (6, args);
146 }
147
148 /* Because of file name handlers, these functions might call 131 /* Because of file name handlers, these functions might call
149 Ffuncall, and cause a GC. */ 132 Ffuncall, and cause a GC. */
150 GCPRO1 (match); 133 GCPRO1 (match);
@@ -216,6 +199,9 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
216 if (NILP (match) 199 if (NILP (match)
217 || (0 <= re_search (bufp, XSTRING (name)->data, len, 0, len, 0))) 200 || (0 <= re_search (bufp, XSTRING (name)->data, len, 0, len, 0)))
218 { 201 {
202 Lisp_Object finalname;
203
204 finalname = name;
219 if (!NILP (full)) 205 if (!NILP (full))
220 { 206 {
221 int afterdirindex = dirnamelen; 207 int afterdirindex = dirnamelen;
@@ -236,9 +222,25 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
236 XSTRING (fullname)->size = nchars; 222 XSTRING (fullname)->size = nchars;
237 if (nchars == STRING_BYTES (XSTRING (fullname))) 223 if (nchars == STRING_BYTES (XSTRING (fullname)))
238 SET_STRING_BYTES (XSTRING (fullname), -1); 224 SET_STRING_BYTES (XSTRING (fullname), -1);
239 name = fullname; 225 finalname = fullname;
226 }
227
228 if (attrs)
229 {
230 /* Construct an expanded filename for the directory entry.
231 Use the decoded names for input to Ffile_attributes. */
232 Lisp_Object decoded_fullname;
233 Lisp_Object fileattrs;
234
235 decoded_fullname = Fexpand_file_name (name, directory);
236 fileattrs = Ffile_attributes (decoded_fullname);
237
238 list = Fcons (Fcons (finalname, fileattrs), list);
239 }
240 else
241 {
242 list = Fcons (finalname, list);
240 } 243 }
241 list = Fcons (name, list);
242 } 244 }
243 } 245 }
244 } 246 }
@@ -246,8 +248,77 @@ If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
246 UNGCPRO; 248 UNGCPRO;
247 if (!NILP (nosort)) 249 if (!NILP (nosort))
248 return list; 250 return list;
249 return Fsort (Fnreverse (list), Qstring_lessp); 251 if (attrs)
252 return Fsort (Fnreverse (list), Qfile_attributes_lessp);
253 else
254 return Fsort (Fnreverse (list), Qstring_lessp);
250} 255}
256
257
258DEFUN ("directory-files", Fdirectory_files, Sdirectory_files, 1, 4, 0,
259 "Return a list of names of files in DIRECTORY.\n\
260There are three optional arguments:\n\
261If FULL is non-nil, return absolute file names. Otherwise return names\n\
262 that are relative to the specified directory.\n\
263If MATCH is non-nil, mention only file names that match the regexp MATCH.\n\
264If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
265 NOSORT is useful if you plan to sort the result yourself.")
266 (directory, full, match, nosort)
267 Lisp_Object directory, full, match, nosort;
268{
269 Lisp_Object handler;
270
271 /* If the file name has special constructs in it,
272 call the corresponding file handler. */
273 handler = Ffind_file_name_handler (directory, Qdirectory_files);
274 if (!NILP (handler))
275 {
276 Lisp_Object args[6];
277
278 args[0] = handler;
279 args[1] = Qdirectory_files;
280 args[2] = directory;
281 args[3] = full;
282 args[4] = match;
283 args[5] = nosort;
284 return Ffuncall (6, args);
285 }
286
287 return directory_files_internal (directory, full, match, nosort, 0);
288}
289
290DEFUN ("directory-files-and-attributes", Fdirectory_files_and_attributes, Sdirectory_files_and_attributes, 1, 4, 0,
291 "Return a list of names of files and their attributes in DIRECTORY.\n\
292There are three optional arguments:\n\
293If FULL is non-nil, return absolute file names. Otherwise return names\n\
294 that are relative to the specified directory.\n\
295If MATCH is non-nil, mention only file names that match the regexp MATCH.\n\
296If NOSORT is non-nil, the list is not sorted--its order is unpredictable.\n\
297 NOSORT is useful if you plan to sort the result yourself.")
298 (directory, full, match, nosort)
299 Lisp_Object directory, full, match, nosort;
300{
301 Lisp_Object handler;
302
303 /* If the file name has special constructs in it,
304 call the corresponding file handler. */
305 handler = Ffind_file_name_handler (directory, Qdirectory_files_and_attributes);
306 if (!NILP (handler))
307 {
308 Lisp_Object args[6];
309
310 args[0] = handler;
311 args[1] = Qdirectory_files_and_attributes;
312 args[2] = directory;
313 args[3] = full;
314 args[4] = match;
315 args[5] = nosort;
316 return Ffuncall (6, args);
317 }
318
319 return directory_files_internal (directory, full, match, nosort, 1);
320}
321
251 322
252Lisp_Object file_name_completion (); 323Lisp_Object file_name_completion ();
253 324
@@ -754,21 +825,35 @@ If file does not exist, returns nil.")
754 values[11] = make_number (s.st_dev); 825 values[11] = make_number (s.st_dev);
755 return Flist (sizeof(values) / sizeof(values[0]), values); 826 return Flist (sizeof(values) / sizeof(values[0]), values);
756} 827}
828
829DEFUN ("file-attributes-lessp", Ffile_attributes_lessp, Sfile_attributes_lessp, 2, 2, 0,
830 "Return t if first arg file attributes list is less than second.\n\
831Comparison is in lexicographic order and case is significant.")
832 (f1, f2)
833 Lisp_Object f1, f2;
834{
835 return Fstring_lessp (Fcar (f1), Fcar (f2));
836}
757 837
758void 838void
759syms_of_dired () 839syms_of_dired ()
760{ 840{
761 Qdirectory_files = intern ("directory-files"); 841 Qdirectory_files = intern ("directory-files");
842 Qdirectory_files_and_attributes = intern ("directory-files-and-attributes");
762 Qfile_name_completion = intern ("file-name-completion"); 843 Qfile_name_completion = intern ("file-name-completion");
763 Qfile_name_all_completions = intern ("file-name-all-completions"); 844 Qfile_name_all_completions = intern ("file-name-all-completions");
764 Qfile_attributes = intern ("file-attributes"); 845 Qfile_attributes = intern ("file-attributes");
846 Qfile_attributes_lessp = intern ("file-attributes-lessp");
765 847
766 staticpro (&Qdirectory_files); 848 staticpro (&Qdirectory_files);
849 staticpro (&Qdirectory_files_and_attributes);
767 staticpro (&Qfile_name_completion); 850 staticpro (&Qfile_name_completion);
768 staticpro (&Qfile_name_all_completions); 851 staticpro (&Qfile_name_all_completions);
769 staticpro (&Qfile_attributes); 852 staticpro (&Qfile_attributes);
853 staticpro (&Qfile_attributes_lessp);
770 854
771 defsubr (&Sdirectory_files); 855 defsubr (&Sdirectory_files);
856 defsubr (&Sdirectory_files_and_attributes);
772 defsubr (&Sfile_name_completion); 857 defsubr (&Sfile_name_completion);
773#ifdef VMS 858#ifdef VMS
774 defsubr (&Sfile_name_all_versions); 859 defsubr (&Sfile_name_all_versions);
@@ -776,6 +861,7 @@ syms_of_dired ()
776#endif /* VMS */ 861#endif /* VMS */
777 defsubr (&Sfile_name_all_completions); 862 defsubr (&Sfile_name_all_completions);
778 defsubr (&Sfile_attributes); 863 defsubr (&Sfile_attributes);
864 defsubr (&Sfile_attributes_lessp);
779 865
780#ifdef VMS 866#ifdef VMS
781 Qcompletion_ignore_case = intern ("completion-ignore-case"); 867 Qcompletion_ignore_case = intern ("completion-ignore-case");