From: Shigeru Fukaya <shigeru.fukaya@gmail.com>
To: 14791@debbugs.gnu.org
Subject: bug#14791: 24.3.50; [PATCH] find-dired doesn't work correctly
Date: Fri, 05 Jul 2013 02:12:56 +0900 [thread overview]
Message-ID: <CCCE78D9BA32D5shigeru.fukaya@gmail.com> (raw)
find-dired doesn't work well, at least for GNU find and ls output.
It is `find-dired-filter' doesn't format the process output correctly.
Its hard-coded regexp never match `find DIR -ls' output.
The function also fails right-adjusting filesize columns of `ls -ld'
output.
The following sample is a changed code that handles GNU find and ls
output.
Regards,
Shigeru
;;; find-dired.el
(defun find-dired-filter (proc string)
;; Filter for \\[find-dired] processes.
(let ((buf (process-buffer proc))
(inhibit-read-only t))
(if (buffer-name buf)
(with-current-buffer buf
(save-excursion
(save-restriction
(widen)
(let ((beg (point-max))
(l-opt (and (consp find-ls-option)
(string-match "l" (cdr find-ls-option))))
ls-regexp
ls-replace)
(when l-opt
(if (equal "-ls" (car find-ls-option))
(setq ls-regexp (concat
;; 1 - inode,allocSize to remove
"^ +\\([0-9]+ +[0-9]+ +\\)"
;; modes
"[^ \t\r\n]+"
;; 3 - # of links
"\\( +\\([0-9]+\\) +\\)"
;; 5 - uid,gid
"\\(\\([^ \t\r\n]+ +[^ \t\r\n]+\\)"
;; 6 - filesize
" +\\([0-9.]+[^ ]?\\)\\)")
ls-replace
#'(lambda ()
(replace-match "" nil t nil 1)
(replace-match (format " %3s "
(match-string 3))
nil t nil 2)
;; Try justification of uid,gid and filesize
(let ((len (+ (- (match-end 5)
(match-beginning 5))
(- (match-end 6)
(match-beginning 6)))))
(replace-match (concat
(match-string 5)
(make-string
(max (- 30 len) 1) ?\s)
(match-string 6))
nil t nil 4))))
(setq ls-regexp
;; modes, 2 - # of links
"^ +[^ \t\r\n]+\\( +\\([0-9]+\\) +\\)"
ls-replace
#'(lambda ()
(replace-match (format " %3s " (match-string 2))
nil t nil 1)))))
(goto-char beg)
(insert string)
(goto-char beg)
(while (re-search-forward "^." nil t)
(backward-char)
(insert " "))
;; Convert ` ./FILE' to ` FILE'
;; This would lose if the current chunk of output
;; starts or ends within the ` ./', so back up a bit:
(goto-char (- beg 3)) ; no error if < 0
(while (search-forward " ./" nil t)
(delete-char -2))
;; Pad the number of links and file size. This is a
;; quick and dirty way of getting the columns to line up
;; most of the time, but it's not foolproof.
(when l-opt
(goto-char beg)
(goto-char (line-beginning-position))
(while (re-search-forward ls-regexp nil t)
(funcall ls-replace)))
;; Find all the complete lines in the unprocessed
;; output and process it to add text properties.
(goto-char (point-max))
(if (search-backward "\n" (process-mark proc) t)
(progn
(dired-insert-set-properties (process-mark proc)
(1+ (point)))
(move-marker (process-mark proc) (1+ (point)))))))))
;; The buffer has been killed.
(delete-process proc))))
next reply other threads:[~2013-07-04 17:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-04 17:12 Shigeru Fukaya [this message]
2016-02-24 4:48 ` bug#14791: 24.3.50; [PATCH] find-dired doesn't work correctly Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CCCE78D9BA32D5shigeru.fukaya@gmail.com \
--to=shigeru.fukaya@gmail.com \
--cc=14791@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.