Mercurial > hg > xemacs-beta
comparison lisp/files.el @ 1606:5d5a604cb3ed
[xemacs-hg @ 2003-08-06 09:11:39 by michaels]
2003-08-03 Mike Sperber <mike@xemacs.org>
* files.el (insert-directory): Massage somewhat to be slightly
closer to FSF version. Support "--dired" as argument for GNU ls,
and, if given, create extents with 'dired-file-name property set
to t, similar to what the FSF version does.
author | michaels |
---|---|
date | Wed, 06 Aug 2003 09:11:40 +0000 |
parents | 01c57eb70ae9 |
children | eeb607577f17 |
comparison
equal
deleted
inserted
replaced
1605:244f35b6ec2d | 1606:5d5a604cb3ed |
---|---|
4070 ;; dired-move-to-end-of-filename, | 4070 ;; dired-move-to-end-of-filename, |
4071 ;; dired-between-files, (shortcut for (not (dired-move-to-filename))) | 4071 ;; dired-between-files, (shortcut for (not (dired-move-to-filename))) |
4072 ;; dired-insert-headerline | 4072 ;; dired-insert-headerline |
4073 ;; dired-after-subdir-garbage (defines what a "total" line is) | 4073 ;; dired-after-subdir-garbage (defines what a "total" line is) |
4074 ;; - variable dired-subdir-regexp | 4074 ;; - variable dired-subdir-regexp |
4075 ;; - may be passed "--dired" as argument in SWITCHES. | |
4076 ;; Filename handlers might have to remove this switch if their | |
4077 ;; "ls" command does not support it. | |
4075 | 4078 |
4076 ;; END SYNC WITH FSF 21.2. | 4079 ;; END SYNC WITH FSF 21.2. |
4077 | 4080 |
4078 (defun insert-directory (file switches &optional wildcard full-directory-p) | 4081 (defun insert-directory (file switches &optional wildcard full-directory-p) |
4079 "Insert directory listing for FILE, formatted according to SWITCHES. | 4082 "Insert directory listing for FILE, formatted according to SWITCHES. |
4087 whose name is in the variable `insert-directory-program'. | 4090 whose name is in the variable `insert-directory-program'. |
4088 If WILDCARD, it also runs the shell specified by `shell-file-name'." | 4091 If WILDCARD, it also runs the shell specified by `shell-file-name'." |
4089 ;; We need the directory in order to find the right handler. | 4092 ;; We need the directory in order to find the right handler. |
4090 (let ((handler (find-file-name-handler (expand-file-name file) | 4093 (let ((handler (find-file-name-handler (expand-file-name file) |
4091 'insert-directory))) | 4094 'insert-directory))) |
4092 (if handler | 4095 (cond |
4093 (funcall handler 'insert-directory file switches | 4096 (handler |
4094 wildcard full-directory-p) | 4097 (funcall handler 'insert-directory file switches |
4095 (cond | 4098 wildcard full-directory-p)) |
4096 ;; [mswindows-insert-directory should be called | 4099 ;; [mswindows-insert-directory should be called |
4097 ;; nt-insert-directory - kkm]. not true any more according to | 4100 ;; nt-insert-directory - kkm]. not true any more according to |
4098 ;; my new naming scheme. --ben | 4101 ;; my new naming scheme. --ben |
4099 ((and (fboundp 'mswindows-insert-directory) | 4102 ((and (fboundp 'mswindows-insert-directory) |
4100 (eq system-type 'windows-nt)) | 4103 (eq system-type 'windows-nt)) |
4101 (declare-fboundp (mswindows-insert-directory | 4104 (declare-fboundp (mswindows-insert-directory |
4102 file switches wildcard full-directory-p))) | 4105 file switches wildcard full-directory-p))) |
4103 (t | 4106 (t |
4104 (if wildcard | 4107 (let* ((beg (point)) |
4105 ;; Run ls in the directory of the file pattern we asked for. | 4108 (result |
4106 (let ((default-directory | 4109 (if wildcard |
4107 (if (file-name-absolute-p file) | 4110 ;; Run ls in the directory of the file pattern we asked for. |
4108 (file-name-directory file) | 4111 (let ((default-directory |
4109 (file-name-directory (expand-file-name file)))) | 4112 (if (file-name-absolute-p file) |
4110 (pattern (file-name-nondirectory file)) | 4113 (file-name-directory file) |
4111 (start 0)) | 4114 (file-name-directory (expand-file-name file)))) |
4112 ;; Quote some characters that have special meanings in shells; | 4115 (pattern (file-name-nondirectory file)) |
4113 ;; but don't quote the wildcards--we want them to be special. | 4116 (start 0)) |
4114 ;; We also currently don't quote the quoting characters | 4117 ;; Quote some characters that have special meanings in shells; |
4115 ;; in case people want to use them explicitly to quote | 4118 ;; but don't quote the wildcards--we want them to be special. |
4116 ;; wildcard characters. | 4119 ;; We also currently don't quote the quoting characters |
4117 ;;#### Unix-specific | 4120 ;; in case people want to use them explicitly to quote |
4118 (while (string-match "[ \t\n;<>&|()#$]" pattern start) | 4121 ;; wildcard characters. |
4119 (setq pattern | 4122 ;;#### Unix-specific |
4120 (concat (substring pattern 0 (match-beginning 0)) | 4123 (while (string-match "[ \t\n;<>&|()#$]" pattern start) |
4121 "\\" | 4124 (setq pattern |
4122 (substring pattern (match-beginning 0))) | 4125 (concat (substring pattern 0 (match-beginning 0)) |
4123 start (1+ (match-end 0)))) | 4126 "\\" |
4124 (call-process shell-file-name nil t nil | 4127 (substring pattern (match-beginning 0))) |
4125 "-c" (concat "\\" ;; Disregard shell aliases! | 4128 start (1+ (match-end 0)))) |
4126 insert-directory-program | 4129 (call-process shell-file-name nil t nil |
4127 " -d " | 4130 "-c" (concat "\\" ;; Disregard shell aliases! |
4128 (if (stringp switches) | 4131 insert-directory-program |
4129 switches | 4132 " -d " |
4130 (mapconcat 'identity switches " ")) | 4133 (if (stringp switches) |
4131 " " | 4134 switches |
4132 pattern))) | 4135 (mapconcat 'identity switches " ")) |
4133 ;; SunOS 4.1.3, SVr4 and others need the "." to list the | 4136 " " |
4134 ;; directory if FILE is a symbolic link. | 4137 pattern))) |
4135 (apply 'call-process | 4138 ;; SunOS 4.1.3, SVr4 and others need the "." to list the |
4136 insert-directory-program nil t nil | 4139 ;; directory if FILE is a symbolic link. |
4137 (let (list) | 4140 (apply 'call-process |
4138 (if (listp switches) | 4141 insert-directory-program nil t nil |
4139 (setq list switches) | 4142 (let (list) |
4140 (if (not (equal switches "")) | 4143 (if (listp switches) |
4141 (progn | 4144 (setq list switches) |
4142 ;; Split the switches at any spaces | 4145 (if (not (equal switches "")) |
4143 ;; so we can pass separate options as separate args. | 4146 (let ((switches switches)) |
4144 (while (string-match " " switches) | 4147 ;; Split the switches at any spaces |
4145 (setq list (cons (substring switches 0 (match-beginning 0)) | 4148 ;; so we can pass separate options as separate args. |
4146 list) | 4149 (while (string-match " " switches) |
4147 switches (substring switches (match-end 0)))) | 4150 (setq list (cons (substring switches 0 (match-beginning 0)) |
4148 (setq list (cons switches list))))) | 4151 list) |
4149 (append list | 4152 switches (substring switches (match-end 0)))) |
4150 (list | 4153 (setq list (cons switches list))))) |
4151 (if full-directory-p | 4154 (append list |
4152 (concat (file-name-as-directory file) | 4155 (list |
4153 ;;#### Unix-specific | 4156 (if full-directory-p |
4154 ".") | 4157 (concat (file-name-as-directory file) |
4155 file))))))))))) | 4158 ;;#### Unix-specific |
4159 ".") | |
4160 file)))))))) | |
4161 ;; If `insert-directory-program' failed, signal an error. | |
4162 (if (/= result 0) | |
4163 ;; On non-Posix systems, we cannot open a directory, so | |
4164 ;; don't even try, because that will always result in | |
4165 ;; the ubiquitous "Access denied". Instead, show the | |
4166 ;; command line so the user can try to guess what went wrong. | |
4167 (error "Listing directory failed.")) | |
4168 | |
4169 (when (or (and (listp switches) | |
4170 (member "--dired" switches)) | |
4171 (string-match "--dired\\>" switches)) | |
4172 (forward-line -2) | |
4173 (when (looking-at "//SUBDIRED//") | |
4174 (delete-region (point) (progn (forward-line 1) (point))) | |
4175 (forward-line -1)) | |
4176 (let ((end (line-end-position))) | |
4177 (forward-word 1) | |
4178 (forward-char 3) | |
4179 (while (< (point) end) | |
4180 (let ((start (+ beg (read (current-buffer)))) | |
4181 (end (+ beg (read (current-buffer))))) | |
4182 (if (= (char-after end) ?\n) | |
4183 (let ((filename-extent (make-extent start end))) | |
4184 (set-extent-property filename-extent 'dired-file-name t) | |
4185 (set-extent-property filename-extent 'start-open t) | |
4186 (set-extent-property filename-extent 'end-open t)) | |
4187 ;; It seems that we can't trust ls's output as to | |
4188 ;; byte positions of filenames. | |
4189 (map-extents | |
4190 #'(lambda (extent maparg) | |
4191 (delete-extent extent) | |
4192 nil) | |
4193 nil beg (point) nil nil 'dired-file-name) | |
4194 (end-of-line)))) | |
4195 (goto-char end) | |
4196 (beginning-of-line) | |
4197 (delete-region (point) (progn (forward-line 2) (point)))))))))) | |
4156 | 4198 |
4157 ;; BEGIN SYNC WITH FSF 21.2. | 4199 ;; BEGIN SYNC WITH FSF 21.2. |
4158 | 4200 |
4159 (defun insert-directory-safely (file switches | 4201 (defun insert-directory-safely (file switches |
4160 &optional wildcard full-directory-p) | 4202 &optional wildcard full-directory-p) |