unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#14791: 24.3.50; [PATCH] find-dired doesn't work correctly
@ 2013-07-04 17:12 Shigeru Fukaya
  2016-02-24  4:48 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Shigeru Fukaya @ 2013-07-04 17:12 UTC (permalink / raw)
  To: 14791


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))))





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#14791: 24.3.50; [PATCH] find-dired doesn't work correctly
  2013-07-04 17:12 bug#14791: 24.3.50; [PATCH] find-dired doesn't work correctly Shigeru Fukaya
@ 2016-02-24  4:48 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-24  4:48 UTC (permalink / raw)
  To: Shigeru Fukaya; +Cc: 14791

Shigeru Fukaya <shigeru.fukaya@gmail.com> writes:

> 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.

It seems to work for me in Emacs 25 on Ubuntu, which surely uses GNU
find and ls.  Are you still seeing this problem?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-24  4:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-04 17:12 bug#14791: 24.3.50; [PATCH] find-dired doesn't work correctly Shigeru Fukaya
2016-02-24  4:48 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).