unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#13575: 24.1; dired-mark-sexp misparses directory contents
@ 2013-01-28  2:49 Sean McAfee
  2013-01-28 19:19 ` Wolfgang Jenkner
  0 siblings, 1 reply; 5+ messages in thread
From: Sean McAfee @ 2013-01-28  2:49 UTC (permalink / raw)
  To: 13575

[-- Attachment #1: Type: text/plain, Size: 5823 bytes --]

This bug report will be sent to the Bug-GNU-Emacs mailing list
and the GNU bug tracker at debbugs.gnu.org.  Please check that
the From: line contains a valid email address.  After a delay of up
to one day, you should receive an acknowledgement at that address.

Please write in English if possible, as the Emacs maintainers
usually do not have translators for other languages.

Please describe exactly what actions triggered the bug, and
the precise symptoms of the bug.  If you can, give a recipe
starting from `emacs -Q':

I recently wanted to mark all zero-size files in a dired buffer.  I
found that dired-mark-sexp seemed to be just what I needed, but when I
invoked it with the expression (= size 0), I found that it marked every
file, even those of nonzero size.

Here's a test directory I set up:

  /home/mcafee/test:
  total used in directory 28 available 102379756
  drwxrwxr-x  2 mcafee mcafee  4096 Jan 27 18:31 .
  drwxr-xr-x 44 mcafee mcafee 12288 Jan 27 18:31 ..
  -rw-rw-r--  1 mcafee mcafee     8 Jan 27 18:31 bar
  -rw-rw-r--  1 mcafee mcafee    12 Jan 27 18:31 baz
  -rw-rw-r--  1 mcafee mcafee     4 Jan 27 18:31 foo

In this directory, I ran dired-mark-sexp with the following expression,
intended to exercise all of the available symbols:

(progn (message
"name=%s;inode=%s;s=%s;mode=%s;nlink=%s;uid=%s;gid=%s;size=%s;time=%s;sym=%s"
name inodes mode nlink uid gid size time sym) nil)

Here are the messages that were produced:
name=.;inode=0;s=0;mode=drwxrwxr-x;nlink=2;uid=mcafee;gid=2;size=0;time=
mcafee  4096 Jan 27 18:31;sym=
name=..;inode=0;s=0;mode=drwxr-xr-x;nlink=44;uid=mcafee;gid=44;size=0;time=
mcafee 12288 Jan 27 18:31;sym=
name=bar;inode=0;s=0;mode=-rw-rw-r--;nlink=1;uid=mcafee;gid=1;size=0;time=
mcafee     8 Jan 27 18:31;sym=
name=baz;inode=0;s=0;mode=-rw-rw-r--;nlink=1;uid=mcafee;gid=1;size=0;time=
mcafee    12 Jan 27 18:31;sym=
name=foo;inode=0;s=0;mode=-rw-rw-r--;nlink=1;uid=mcafee;gid=1;size=0;time=
mcafee     4 Jan 27 18:31;sym=

Clearly, the "time" variable includes more of the directory listing than
it should, and "size" is incorrectly set to zero for all files, as I
originally noticed.

If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
    `bt full' and `xbacktrace'.
For information about debugging Emacs, please read the file
/usr/share/emacs/24.1/etc/DEBUG.


In GNU Emacs 24.1.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.12)
 of 2012-09-22 on batsu, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11300000
Configured using:
 `configure '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu'
 '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
 '--localstatedir=/var/lib' '--infodir=/usr/share/info'
 '--mandir=/usr/share/man' '--with-pop=yes'
 '--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.1/site-lisp:/usr/share/emacs/site-lisp'
 '--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes'
 '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars'
 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector
 --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -O2'
 'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Dired by name

Minor modes in effect:
  gnus-dired-mode: t
  recentf-mode: t
  shell-dirtrack-mode: t
  minibuffer-depth-indicate-mode: t
  ido-everywhere: t
  global-undo-tree-mode: t
  diff-auto-refine-mode: t
  desktop-save-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
y SPC = SPC . 2 5 SPC = SPC <backspace> <backspace>
* S-SPC 3 0 SPC = SPC C-u M-: ( * S-SPC 2 <backspace>
. 2 5 SPC 3 0 ) <S-return> <return> C-p C-p C-n C-n
C-p RET C-/ M-x t w i t <return> i ESC ESC ESC ESC
ESC ESC ESC ESC ESC ESC ESC ESC ESC ESC ESC ESC C-p
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p
C-p C-p C-p C-p C-a C-n C-f C-f C-f C-f <return> v
i C-v C-x k <return> C-a M-< <return> C-p <return>
C-n q C-n C-n M-x g n u s <return> <return> q M-B C-x
d ~ / C-j <S-backspace> + t e s t <return> a M-! t
p <backspace> <backspace> e c h o SPC f o o SPC > S-SPC
f o o ; SPC e h o SPC b <backspace> <backspace> <backspace>
<backspace> c h o SPC b a r SPC b a r SPC > S-SPC b
a r ; SPC e c h o SPC b a z SPC b a z SPC b a z SPC
> S-SPC b a z <return> g C-p C-n M-: C-g M-( ( p r
o g n SPC ( m e s s a g e S-SPC C-g M-( M-p M-p M-n
C-e <return> C-x b m e s s <return> M-x r e [ p r =
e <backspace> <backspace> <backspace> <backspace> <backspace>
p o r t e m <tab> <backspace> <backspace> - e m <tab>
b u <tab> <return> C-g C-x b <return> k M-( C-h C-g
C-h k C-g C-g M-( C-g C-h k M-( C-x 1 M-x M-p <return>
d i C-g C-g C-h k M-( C-g C-x 1 M-x M-p <return>

Recent messages:
name=foo;inode=0;s=0;mode=-rw-rw-r--;nlink=1;uid=mcafee;gid=1;size=0;time=
mcafee     4 Jan 27 18:31;sym=
0 '(progn (message
name=%s;inode=%s;s=%s;mode=%s;nlink=%s;uid=%s;gid=%s;size=%s;time=%s;sym=%s
name inode s mode nlink uid gid size time sym) nil) files marked.
Quit
Killed 0 lines.
Quit
Type C-x 1 to delete the help window.
Quit [2 times]

Quit [2 times]
Type C-x 1 to delete the help window, C-M-v to scroll help.
Quit

Load-path shadows:

[-- Attachment #2: Type: text/html, Size: 6883 bytes --]

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

* bug#13575: 24.1; dired-mark-sexp misparses directory contents
  2013-01-28  2:49 bug#13575: 24.1; dired-mark-sexp misparses directory contents Sean McAfee
@ 2013-01-28 19:19 ` Wolfgang Jenkner
  2013-01-29  5:35   ` Wolfgang Jenkner
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Jenkner @ 2013-01-28 19:19 UTC (permalink / raw)
  To: Sean McAfee; +Cc: 13575

On Mon, Jan 28 2013, Sean McAfee wrote:

> I recently wanted to mark all zero-size files in a dired buffer.  I
> found that dired-mark-sexp seemed to be just what I needed, but when I
> invoked it with the expression (= size 0), I found that it marked every
> file, even those of nonzero size.
>
> Here's a test directory I set up:
>
>   /home/mcafee/test:
>   total used in directory 28 available 102379756
>   drwxrwxr-x  2 mcafee mcafee  4096 Jan 27 18:31 .
>   drwxr-xr-x 44 mcafee mcafee 12288 Jan 27 18:31 ..
>   -rw-rw-r--  1 mcafee mcafee     8 Jan 27 18:31 bar
>   -rw-rw-r--  1 mcafee mcafee    12 Jan 27 18:31 baz
>   -rw-rw-r--  1 mcafee mcafee     4 Jan 27 18:31 foo
>
> In this directory, I ran dired-mark-sexp with the following expression,
> intended to exercise all of the available symbols:
>
> (progn (message
> "name=%s;inode=%s;s=%s;mode=%s;nlink=%s;uid=%s;gid=%s;size=%s;time=%s;sym=%s"
> name inodes mode nlink uid gid size time sym) nil)
-------^ inode s

I think you have to customize dired-listing-switches to something like
"-alis" so that inode number and block count are actually shown in the
buffer.

> Here are the messages that were produced:
> name=.;inode=0;s=0;mode=drwxrwxr-x;nlink=2;uid=mcafee;gid=2;size=0;time=
> mcafee  4096 Jan 27 18:31;sym=
> name=..;inode=0;s=0;mode=drwxr-xr-x;nlink=44;uid=mcafee;gid=44;size=0;time=
> mcafee 12288 Jan 27 18:31;sym=
[...]
> Clearly, the "time" variable includes more of the directory listing than
> it should, and "size" is incorrectly set to zero for all files, as I
> originally noticed.

That's a bug in dired-x (wrong use of the somewhat awkward
directory-listing-before-filename-regexp variable).  As a first attempt
to fix this I propose the following barely tested patch.

Wolfgang

diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index a2c1303..73eebd1 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -1449,8 +1449,7 @@ to mark all zero length files."
         ;; to nil or the appropriate value, so they need not be initialized.
         ;; Moves point within the current line.
         (dired-move-to-filename)
-        (let (pos
-              (mode-len 10) ; length of mode string
+        (let ((mode-len 10) ; length of mode string
               ;; like in dired.el, but with subexpressions \1=inode, \2=s:
               (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?"))
           (beginning-of-line)
@@ -1472,22 +1471,18 @@ to mark all zero length files."
           ;; Karsten Wenger <kw@cis.uni-muenchen.de> fixed uid.
           (setq uid (buffer-substring (1+ (point))
                                       (progn (forward-word 1) (point))))
-          (re-search-forward directory-listing-before-filename-regexp)
-          (goto-char (match-beginning 1))
-          (forward-char -1)
-          (setq size (string-to-number
-                      (buffer-substring (save-excursion
-                                          (backward-word 1)
-                                          (setq pos (point)))
-                                        (point))))
-          (goto-char pos)
-          (backward-word 1)
+	  (re-search-forward directory-listing-before-filename-regexp)
+	  (re-search-backward directory-listing-before-filename-regexp)
+	  (forward-word 1)
+	  (save-excursion
+	    (setq size (string-to-number
+			(buffer-substring (point) (progn (backward-word 1)
+							 (point))))
+		  gid (buffer-substring (1- (point)) (progn (backward-word 1)
+							    (point)))))
           ;; if no gid is displayed, gid will be set to uid
           ;; but user will then not reference it anyway in PREDICATE.
-          (setq gid (buffer-substring (save-excursion
-                                        (forward-word 1) (point))
-                                      (point))
-                time (buffer-substring (match-beginning 1)
+          (setq time (buffer-substring (1+ (point))
                                        (1- (dired-move-to-filename)))
                 name (buffer-substring (point)
                                        (or





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

* bug#13575: 24.1; dired-mark-sexp misparses directory contents
  2013-01-28 19:19 ` Wolfgang Jenkner
@ 2013-01-29  5:35   ` Wolfgang Jenkner
  2015-06-26 12:54     ` Wolfgang Jenkner
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Jenkner @ 2013-01-29  5:35 UTC (permalink / raw)
  To: Sean McAfee; +Cc: 13575

On Mon, Jan 28 2013, Wolfgang Jenkner wrote:

> As a first attempt
> to fix this I propose the following barely tested patch.

Or perhaps rather try the patch below, which I tested a bit with GNU and
FreeBSD ls, and also with ls-lisp.el.  It's still WIP but I hope it
works for you.

Please note that the output of "ls -lh" is parsed correctly, but the
unit suffixes are simply ignored for the time being; I'll try to fix
this, though.

Also, specifying "-s" without also passing "-i" to "ls" will do the
wrong thing: the output being ambiguous in this case, a number before
the permission string is (arbitrarily) interpreted as inode number; that
can't be fixed without actually looking at dired-listing-switches.

Wolfgang

diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index a2c1303..5a33479 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -1449,54 +1449,57 @@ to mark all zero length files."
         ;; to nil or the appropriate value, so they need not be initialized.
         ;; Moves point within the current line.
         (dired-move-to-filename)
-        (let (pos
-              (mode-len 10) ; length of mode string
-              ;; like in dired.el, but with subexpressions \1=inode, \2=s:
-              (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?"))
-          (beginning-of-line)
-          (forward-char 2)
-          (if (looking-at dired-re-inode-size)
-              (progn
-                (goto-char (match-end 0))
-                (setq inode (string-to-number
-                             (buffer-substring (match-beginning 1)
-                                               (match-end 1)))
-                      s (string-to-number
-                         (buffer-substring (match-beginning 2)
-                                           (match-end 2)))))
-            (setq inode nil
-                  s nil))
+        (let ((mode-len 10) ; length of mode string
+	      ;; like in dired.el, but with subexpressions \1=inode, \2=s:
+	      ;; GNU ls -hs suffixes the block count with a unit and
+	      ;; prints it as a float, FreeBSD does neither.
+	      (dired-re-inode-size "\\=\\s *\\([0-9]+\\s +\\)?\\(?:\\([0-9]+\\(?:\\.[0-9]*\\)?[BkKMGTPEZY]?\\)? ?\\)"))
+	  (beginning-of-line)
+	  (forward-char 2)
+	  (search-forward-regexp dired-re-inode-size nil t)
+	  ;; XXX Might be a size without unit.
+	  (setq inode (when (match-string 1)
+			(string-to-number (match-string 1))))
+	  (setq s (when (match-string 2)
+		    ;; XXX Deal with units (for the -h switch).
+		    (string-to-number (match-string 2))))
           (setq mode (buffer-substring (point) (+ mode-len (point))))
           (forward-char mode-len)
           (setq nlink (read (current-buffer)))
           ;; Karsten Wenger <kw@cis.uni-muenchen.de> fixed uid.
-          (setq uid (buffer-substring (1+ (point))
-                                      (progn (forward-word 1) (point))))
-          (re-search-forward directory-listing-before-filename-regexp)
-          (goto-char (match-beginning 1))
-          (forward-char -1)
-          (setq size (string-to-number
-                      (buffer-substring (save-excursion
-                                          (backward-word 1)
-                                          (setq pos (point)))
-                                        (point))))
-          (goto-char pos)
-          (backward-word 1)
-          ;; if no gid is displayed, gid will be set to uid
-          ;; but user will then not reference it anyway in PREDICATE.
-          (setq gid (buffer-substring (save-excursion
-                                        (forward-word 1) (point))
-                                      (point))
-                time (buffer-substring (match-beginning 1)
-                                       (1- (dired-move-to-filename)))
-                name (buffer-substring (point)
-                                       (or
-                                        (dired-move-to-end-of-filename t)
-                                        (point)))
-                sym (if (looking-at " -> ")
-                        (buffer-substring (progn (forward-char 4) (point))
-                                          (line-end-position))
-                      ""))
+	  ;; GNU ls -n right-justifies numerical UIDs and GIDs,
+	  ;; while FreeBSD left-justifies them.  Both of them
+	  ;; right-justify all other numbers.
+          (setq uid (buffer-substring (progn (forward-word 1) (point))
+                                      (progn (forward-word -1) (point))))
+	  (dired-move-to-filename)
+	  (save-excursion
+	    ;; Don't do (forward-char -1) since the regexp search will
+	    ;; then match in the preceding line.
+	    (setq time (buffer-substring (1- (point))
+					 (progn
+					   (re-search-backward directory-listing-before-filename-regexp)
+					   (forward-word 1)
+					   (1+ (point))))
+		  ;; XXX Deal with units (for the -h switch).
+		  size (string-to-number
+			(buffer-substring (point) (progn (forward-word -1)
+							 (when (= (char-before) ?.)
+							   (forward-char -1)
+							   (forward-word -1))
+							 (point))))
+		  ;; if no gid is displayed, gid will be set to uid
+		  ;; but user will then not reference it anyway in PREDICATE.
+		  gid (buffer-substring (progn (forward-word -1) (point))
+					(progn (forward-word 1) (point)))))
+	  (setq name (buffer-substring (point)
+				       (or
+					(dired-move-to-end-of-filename t)
+					(point)))
+		sym (if (looking-at " -> ")
+			(buffer-substring (progn (forward-char 4) (point))
+					  (line-end-position))
+		      ""))
           t)
         (eval predicate)))
      (format "'%s file" predicate))))





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

* bug#13575: 24.1; dired-mark-sexp misparses directory contents
  2013-01-29  5:35   ` Wolfgang Jenkner
@ 2015-06-26 12:54     ` Wolfgang Jenkner
  2015-07-06 13:08       ` Wolfgang Jenkner
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Jenkner @ 2015-06-26 12:54 UTC (permalink / raw)
  To: Sean McAfee; +Cc: 13575

Since I haven't quite been able to just totally forget about this bug,
here's an updated patch instead.

-- >8 --
Subject: [PATCH] Fix parsing glitches in dired-mark-sexp (bug#13575)

* lisp/dired-x.el (dired-x--string-to-number): New function.
(dired-mark-sexp): Use it.  Tweak dired-re-inode-size.  Fix usage
of directory-listing-before-filename-regexp.  Consider
forward-word harmful and replace it.  Add more verbiage in
comments and doc string.
---
 lisp/dired-x.el | 139 ++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 96 insertions(+), 43 deletions(-)

diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index eebfa91..93e32e0 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -1396,6 +1396,20 @@ Considers buffers closer to the car of `buffer-list' to be more recent."
 ;;     result))
 
 \f
+(defun dired-x--string-to-number (str)
+  "Like `string-to-number' but recognize trailing unit prefixes (for ls -h).
+The caller should make sure that STR is valid."
+  (let* ((val (string-to-number str))
+         (u (unless (zerop val)
+              (aref str (1- (length str))))))
+    (when (and u (> u ?9))
+      (when (= u ?k)
+        (setq u ?K))
+      (let ((units '(?B ?K ?M ?G ?T ?P ?E ?Z ?Y)))
+        (while (and units (/= (pop units) u))
+          (setq val (* 1024.0 val)))))
+    val))
+
 ;; Does anyone use this? - lrd 6/29/93.
 ;; Apparently people do use it. - lrd 12/22/97.
 
@@ -1422,7 +1436,19 @@ For example, use
 
         (equal 0 size)
 
-to mark all zero length files."
+to mark all zero length files.
+
+There's an ambiguity when a single integer not followed by a unit
+prefix precedes the file mode: It is then parsed as inode number
+and not as block size (this always works for GNU coreutils ls).
+
+Another limitation is that the uid field is needed for the
+function to work correctly.  In particular, the field is not
+present for some values of `ls-lisp-emulation'.
+
+This function operates only on the buffer content and does not
+refer at all to the underlying file system.  Contrast this with
+`find-dired', which might be preferable for the task at hand."
   ;; Using sym="" instead of nil avoids the trap of
   ;; (string-match "foo" sym) into which a user would soon fall.
   ;; Give `equal' instead of `=' in the example, as this works on
@@ -1442,23 +1468,23 @@ to mark all zero length files."
         ;; to nil or the appropriate value, so they need not be initialized.
         ;; Moves point within the current line.
         (dired-move-to-filename)
-        (let (pos
-              (mode-len 10) ; length of mode string
-              ;; like in dired.el, but with subexpressions \1=inode, \2=s:
-              (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?"))
-          (beginning-of-line)
-          (forward-char 2)
-          (if (looking-at dired-re-inode-size)
-              (progn
-                (goto-char (match-end 0))
-                (setq inode (string-to-number
-                             (buffer-substring (match-beginning 1)
-                                               (match-end 1)))
-                      s (string-to-number
-                         (buffer-substring (match-beginning 2)
-                                           (match-end 2)))))
-            (setq inode nil
-                  s nil))
+        (let ((mode-len 10) ; length of mode string
+	      ;; like in dired.el, but with subexpressions \1=inode, \2=s:
+	      ;; GNU ls -hs suffixes the block count with a unit and
+	      ;; prints it as a float, FreeBSD does neither.
+	      (dired-re-inode-size "\\=\\s *\\([0-9]+\\s +\\)?\
+\\(?:\\([0-9]+\\(?:\\.[0-9]*\\)?[BkKMGTPEZY]?\\)? ?\\)"))
+	  (beginning-of-line)
+	  (forward-char 2)
+	  (search-forward-regexp dired-re-inode-size nil t)
+          ;; XXX Might be a size not followed by a unit prefix.
+          ;; We could set s to inode if it were otherwise nil,
+          ;; with a similar reasoning as below for setting gid to uid,
+          ;; but it would be even more whimsical.
+	  (setq inode (when (match-string 1)
+			(string-to-number (match-string 1))))
+	  (setq s (when (match-string 2)
+		    (dired-x--string-to-number (match-string 2))))
           (setq mode (buffer-substring (point) (+ mode-len (point))))
           (forward-char mode-len)
           ;; Skip any extended attributes marker ("." or "+").
@@ -1466,33 +1492,60 @@ to mark all zero length files."
               (forward-char 1))
           (setq nlink (read (current-buffer)))
           ;; Karsten Wenger <kw@cis.uni-muenchen.de> fixed uid.
-          (setq uid (buffer-substring (1+ (point))
-                                      (progn (forward-word 1) (point))))
-          (re-search-forward directory-listing-before-filename-regexp)
-          (goto-char (match-beginning 1))
-          (forward-char -1)
-          (setq size (string-to-number
-                      (buffer-substring (save-excursion
-                                          (backward-word 1)
-                                          (setq pos (point)))
+          ;; Another issue is that GNU ls -n right-justifies numerical
+          ;; UIDs and GIDs, while FreeBSD left-justifies them, so
+          ;; don't rely on a specific whitespace layout.  Both of them
+          ;; right-justify all other numbers, though.
+          ;; XXX Return a number if the uid or gid seems to be
+          ;; numerical?
+          (setq uid (buffer-substring (progn
+                                        (skip-chars-forward " \t")
+                                        (point))
+                                      (progn
+                                        (skip-chars-forward "^ \t")
                                         (point))))
-          (goto-char pos)
-          (backward-word 1)
-          ;; if no gid is displayed, gid will be set to uid
-          ;; but user will then not reference it anyway in PREDICATE.
-          (setq gid (buffer-substring (save-excursion
-                                        (forward-word 1) (point))
+	  (dired-move-to-filename)
+          (save-excursion
+            (setq time
+                  ;; The regexp below tries to match from the last
+                  ;; digit of the size field through a space after the
+                  ;; date.  Also, dates may have different formats
+                  ;; depending on file age, so the date column need
+                  ;; not be aligned to the right.
+                  (buffer-substring (save-excursion
+                                      (skip-chars-backward " \t")
                                       (point))
-                time (buffer-substring (match-beginning 1)
-                                       (1- (dired-move-to-filename)))
-                name (buffer-substring (point)
-                                       (or
-                                        (dired-move-to-end-of-filename t)
-                                        (point)))
-                sym (if (looking-at-p " -> ")
-                        (buffer-substring (progn (forward-char 4) (point))
-                                          (line-end-position))
-                      ""))
+                                    (progn
+                                      (re-search-backward
+                                       directory-listing-before-filename-regexp)
+                                      (skip-chars-forward "^ \t")
+                                      (1+ (point))))
+                  size (dired-x--string-to-number
+                        ;; We know that there's some kind of number
+                        ;; before point because the regexp search
+                        ;; above succeeded.  I don't think it's worth
+                        ;; doing an extra check for leading garbage.
+                        (buffer-substring (point)
+                                          (progn
+                                            (skip-chars-backward "^ \t")
+                                            (point))))
+                  ;; If no gid is displayed, gid will be set to uid
+                  ;; but the user will then not reference it anyway in
+                  ;; PREDICATE.
+                  gid (buffer-substring (progn
+                                          (skip-chars-backward " \t")
+                                          (point))
+                                        (progn
+                                          (skip-chars-backward "^ \t")
+                                          (point)))))
+	  (setq name (buffer-substring (point)
+				       (or
+					(dired-move-to-end-of-filename t)
+					(point)))
+		sym (if (looking-at " -> ")
+			(buffer-substring (progn (forward-char 4) (point))
+					  (line-end-position))
+		      ""))
           t)
         (eval predicate
               `((inode . ,inode)
-- 
2.4.2












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

* bug#13575: 24.1; dired-mark-sexp misparses directory contents
  2015-06-26 12:54     ` Wolfgang Jenkner
@ 2015-07-06 13:08       ` Wolfgang Jenkner
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Jenkner @ 2015-07-06 13:08 UTC (permalink / raw)
  To: Sean McAfee; +Cc: 13575-done

Version: 25.1

No complaints, so pushed.

For the record, the OP's example can easily be tested like this: Yank
the directory listing into some new buffer, load dired-x and call
virtual-dired.  Then run dired-mark-sexp as described (but correct the
typo "inodes" to "inode s").  The relevant output in *Messages* is

name=.;inode=nil;s=nil;mode=drwxrwxr-x;nlink=2;uid=mcafee;gid=mcafee;size=4096;time=Jan 27 18:31;sym=
name=..;inode=nil;s=nil;mode=drwxr-xr-x;nlink=44;uid=mcafee;gid=mcafee;size=12288;time=Jan 27 18:31;sym=
name=bar;inode=nil;s=nil;mode=-rw-rw-r--;nlink=1;uid=mcafee;gid=mcafee;size=8;time=Jan 27 18:31;sym=
name=baz;inode=nil;s=nil;mode=-rw-rw-r--;nlink=1;uid=mcafee;gid=mcafee;size=12;time=Jan 27 18:31;sym=
name=foo;inode=nil;s=nil;mode=-rw-rw-r--;nlink=1;uid=mcafee;gid=mcafee;size=4;time=Jan 27 18:31;sym=





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

end of thread, other threads:[~2015-07-06 13:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-28  2:49 bug#13575: 24.1; dired-mark-sexp misparses directory contents Sean McAfee
2013-01-28 19:19 ` Wolfgang Jenkner
2013-01-29  5:35   ` Wolfgang Jenkner
2015-06-26 12:54     ` Wolfgang Jenkner
2015-07-06 13:08       ` Wolfgang Jenkner

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