emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dired-do-toggle


From: Stefan Monnier
Subject: Re: dired-do-toggle
Date: 04 Nov 2001 17:41:47 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1.50

>>>>> "Eli" == Eli Zaretskii <address@hidden> writes:
> Emacs 20 supported quite a few non-English formats; Emacs 21.1
> supports even more.  Some of these formats are specifically targeted
> to Japanese environments.  So it should work, at least in principle.
> However, it's possible that we need to add yet another regexp in
> dired-move-to-filename-regexp ;-)

How about something like the patch below ?
It's not a real solution, but at least with it, most things still
work even when the Emacs gets confused by a strange `ls' date format.


        Stefan


@@ -1409,7 +1413,7 @@
 
 ;;; Functions for extracting and manipulating file names in dired buffers.
 
-(defun dired-get-filename (&optional localp no-error-if-not-filep)
+(defun dired-get-filename (&optional localp no-error-if-not-filep bof)
   "In dired, return name of file mentioned on this line.
 Value returned normally includes the directory name.
 Optional arg LOCALP with value `no-dir' means don't include directory
@@ -1417,10 +1421,13 @@
   it occurs in the buffer, and a value of t means construct name relative to
   `default-directory', which still may contain slashes if in a subdirectory.
 Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on
-  this line, otherwise an error occurs."
+  this line, otherwise an error occurs.
+BOF if non-nil is the position of the beginning of the file name that
+  should be used."
   (let (case-fold-search file p1 p2 already-absolute)
     (save-excursion
-      (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
+      (if (setq p1 (if bof (goto-char bof)
+                    (dired-move-to-filename (not no-error-if-not-filep))))
          (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
     ;; nil if no file on this line, but no-error-if-not-filep is t:
     (if (setq file (and p1 p2 (buffer-substring p1 p2)))
@@ -1433,7 +1440,7 @@
          (setq file
                (read
                 (concat "\""
-                        ;; some ls -b don't escape quotes, argh!
+                        ;; Some ls -b don't escape quotes, argh!
                         ;; This is not needed for GNU ls, though.
                         (or (dired-string-replace-match
                              "\\([^\\]\\|\\`\\)\"" file "\\1\\\\\"" nil t)
@@ -1556,12 +1563,31 @@
 ;; Returns position (point) or nil if no filename on this line."
 (defun dired-move-to-filename (&optional raise-error eol)
   ;; This is the UNIX version.
-  (or eol (setq eol (progn (end-of-line) (point))))
-  (beginning-of-line)
-  (if (re-search-forward dired-move-to-filename-regexp eol t)
-      (goto-char (match-end 0))
-    (if raise-error
-       (error "No file on this line"))))
+  (or eol (setq eol (line-end-position)))
+  (forward-line 0)
+  (or
+   (when (re-search-forward dired-move-to-filename-regexp eol t)
+     (goto-char (match-end 0)))
+   (when (re-search-forward dired-permission-flags-regexp eol t)
+     ;; Ha!  There *is* a file.  Our regexp-from-hell just failed to find it.
+     (message "Unrecognized line!  Check `dired-move-to-filename-regexp'.")
+     (let ((beg (point)))
+       (goto-char eol)
+       (when (eq (char-after (match-beginning 1)) ?l)
+        ;; Skip the link's content if any.
+        (re-search-backward " -> " beg t))
+       ;; Check all possible file names until you find one that exists.
+       (let ((pos nil))
+        (while (and (not pos) (re-search-backward " " beg t))
+          (save-excursion
+            (goto-char (match-end 0))
+            (let ((file (dired-get-filename t 'no-error (point))))
+              ;; It might be a symlink pointing nowhere.
+              (when (and file (or (file-exists-p file) (file-symlink-p file)))
+                (setq pos (point))))))
+        (when pos (goto-char pos)))))
+   (when raise-error
+     (error "No file on this line"))))
 
 (defun dired-move-to-end-of-filename (&optional no-error)
   ;; Assumes point is at beginning of filename,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]