Mercurial > emacs
comparison lisp/find-dired.el @ 93521:7587f0dc0aa9
(find-dired-filter): Align columns by padding file sizes and link
numbers.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Tue, 01 Apr 2008 17:34:20 +0000 |
parents | 73661ddc7ac7 |
children | 1e3a407766b9 |
comparison
equal
deleted
inserted
replaced
93520:8a4678b62c46 | 93521:7587f0dc0aa9 |
---|---|
238 | 238 |
239 (defun find-dired-filter (proc string) | 239 (defun find-dired-filter (proc string) |
240 ;; Filter for \\[find-dired] processes. | 240 ;; Filter for \\[find-dired] processes. |
241 (let ((buf (process-buffer proc)) | 241 (let ((buf (process-buffer proc)) |
242 (inhibit-read-only t)) | 242 (inhibit-read-only t)) |
243 (if (buffer-name buf) ; not killed? | 243 (if (buffer-name buf) |
244 (save-excursion | 244 (with-current-buffer buf |
245 (set-buffer buf) | |
246 (save-restriction | 245 (save-restriction |
247 (widen) | 246 (widen) |
248 (save-excursion | 247 (let ((buffer-read-only nil) |
249 (let ((buffer-read-only nil) | 248 (beg (point-max)) |
250 (end (point-max))) | 249 (l-opt (and (consp find-ls-option) |
251 (goto-char end) | 250 (string-match "l" (cdr find-ls-option)))) |
252 (insert string) | 251 (ls-regexp (concat "^ +[^ \t\r\n]+\\( +[^ \t\r\n]+\\) +" |
253 (goto-char end) | 252 "[^ \t\r\n]+ +[^ \t\r\n]+\\( +[0-9]+\\)"))) |
254 (or (looking-at "^") | 253 (goto-char beg) |
255 (forward-line 1)) | 254 (insert string) |
256 (while (looking-at "^") | 255 (goto-char beg) |
257 (insert " ") | 256 (or (looking-at "^") |
258 (forward-line 1)) | 257 (forward-line 1)) |
259 ;; Convert ` ./FILE' to ` FILE' | 258 (while (looking-at "^") |
260 ;; This would lose if the current chunk of output | 259 (insert " ") |
261 ;; starts or ends within the ` ./', so back up a bit: | 260 (forward-line 1)) |
262 (goto-char (- end 3)) ; no error if < 0 | 261 ;; Convert ` ./FILE' to ` FILE' |
263 (while (search-forward " ./" nil t) | 262 ;; This would lose if the current chunk of output |
264 (delete-region (point) (- (point) 2))) | 263 ;; starts or ends within the ` ./', so back up a bit: |
265 ;; Find all the complete lines in the unprocessed | 264 (goto-char (- beg 3)) ; no error if < 0 |
266 ;; output and process it to add text properties. | 265 (while (search-forward " ./" nil t) |
267 (goto-char (point-max)) | 266 (delete-region (point) (- (point) 2))) |
268 (if (search-backward "\n" (process-mark proc) t) | 267 ;; Pad the number of links and file size. This is a |
269 (progn | 268 ;; quick and dirty way of getting the columns to line up |
270 (dired-insert-set-properties (process-mark proc) | 269 ;; most of the time, but it's not foolproof. |
271 (1+ (point))) | 270 (when l-opt |
272 (move-marker (process-mark proc) (1+ (point))))) | 271 (goto-char beg) |
273 )))) | 272 (goto-char (line-beginning-position)) |
273 (while (re-search-forward ls-regexp nil t) | |
274 (replace-match (format "%4s" (match-string 1)) | |
275 nil nil nil 1) | |
276 (replace-match (format "%9s" (match-string 2)) | |
277 nil nil nil 2) | |
278 (forward-line 1))) | |
279 ;; Find all the complete lines in the unprocessed | |
280 ;; output and process it to add text properties. | |
281 (goto-char (point-max)) | |
282 (if (search-backward "\n" (process-mark proc) t) | |
283 (progn | |
284 (dired-insert-set-properties (process-mark proc) | |
285 (1+ (point))) | |
286 (move-marker (process-mark proc) (1+ (point)))))))) | |
274 ;; The buffer has been killed. | 287 ;; The buffer has been killed. |
275 (delete-process proc)))) | 288 (delete-process proc)))) |
276 | 289 |
277 (defun find-dired-sentinel (proc state) | 290 (defun find-dired-sentinel (proc state) |
278 ;; Sentinel for \\[find-dired] processes. | 291 ;; Sentinel for \\[find-dired] processes. |