diff options
| author | Chong Yidong | 2008-04-01 17:34:20 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-04-01 17:34:20 +0000 |
| commit | 4543e21391c7f4af94af84d913dcbd795f887b02 (patch) | |
| tree | 839af2214454e322c35215a22b37a896b99a23e7 | |
| parent | 96c0d8d474b63115470a0676f6c852cceef793f4 (diff) | |
| download | emacs-4543e21391c7f4af94af84d913dcbd795f887b02.tar.gz emacs-4543e21391c7f4af94af84d913dcbd795f887b02.zip | |
(find-dired-filter): Align columns by padding file sizes and link
numbers.
| -rw-r--r-- | lisp/find-dired.el | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/lisp/find-dired.el b/lisp/find-dired.el index e49e1f304be..79a6a3b18c3 100644 --- a/lisp/find-dired.el +++ b/lisp/find-dired.el | |||
| @@ -240,37 +240,50 @@ Thus ARG can also contain additional grep options." | |||
| 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 | ||