Merged from miles@gnu.org--gnu-2005 (patch 142-148, 615-628)
[bpt/emacs.git] / lisp / files.el
index 0065e45..80f849e 100644 (file)
@@ -861,6 +861,43 @@ it means chase no more than that many links and then stop."
        (setq count (1+ count))))
     newname))
 
+(defun make-temp-file (prefix &optional dir-flag suffix)
+  "Create a temporary file.
+The returned file name (created by appending some random characters at the end
+of PREFIX, and expanding against `temporary-file-directory' if necessary),
+is guaranteed to point to a newly created empty file.
+You can then use `write-region' to write new data into the file.
+
+If DIR-FLAG is non-nil, create a new empty directory instead of a file.
+
+If SUFFIX is non-nil, add that at the end of the file name."
+  (let ((umask (default-file-modes))
+       file)
+    (unwind-protect
+       (progn
+         ;; Create temp files with strict access rights.  It's easy to
+         ;; loosen them later, whereas it's impossible to close the
+         ;; time-window of loose permissions otherwise.
+         (set-default-file-modes ?\700)
+         (while (condition-case ()
+                    (progn
+                      (setq file
+                            (make-temp-name
+                             (expand-file-name prefix temporary-file-directory)))
+                      (if suffix
+                          (setq file (concat file suffix)))
+                      (if dir-flag
+                          (make-directory file)
+                        (write-region "" nil file nil 'silent nil 'excl))
+                      nil)
+                  (file-already-exists t))
+           ;; the file was somehow created by someone else between
+           ;; `make-temp-name' and `write-region', let's try again.
+           nil)
+         file)
+      ;; Reset the umask.
+      (set-default-file-modes umask))))
+
 (defun recode-file-name (file coding new-coding &optional ok-if-already-exists)
   "Change the encoding of FILE's name from CODING to NEW-CODING.
 The value is a new name of FILE.
@@ -4438,6 +4475,57 @@ program specified by `directory-free-space-program' if that is non-nil."
                  (forward-word -1)
                  (buffer-substring (point) end)))))))))
 
+;; The following expression replaces `dired-move-to-filename-regexp'.
+(defvar directory-listing-before-filename-regexp
+  (let* ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
+        (l-or-quote "\\([A-Za-z']\\|[^\0-\177]\\)")
+        ;; In some locales, month abbreviations are as short as 2 letters,
+        ;; and they can be followed by ".".
+        ;; In Breton, a month name  can include a quote character.
+        (month (concat l-or-quote l-or-quote "+\\.?"))
+        (s " ")
+        (yyyy "[0-9][0-9][0-9][0-9]")
+        (dd "[ 0-3][0-9]")
+        (HH:MM "[ 0-2][0-9][:.][0-5][0-9]")
+        (seconds "[0-6][0-9]\\([.,][0-9]+\\)?")
+        (zone "[-+][0-2][0-9][0-5][0-9]")
+        (iso-mm-dd "[01][0-9]-[0-3][0-9]")
+        (iso-time (concat HH:MM "\\(:" seconds "\\( ?" zone "\\)?\\)?"))
+        (iso (concat "\\(\\(" yyyy "-\\)?" iso-mm-dd "[ T]" iso-time
+                     "\\|" yyyy "-" iso-mm-dd "\\)"))
+        (western (concat "\\(" month s "+" dd "\\|" dd "\\.?" s month "\\)"
+                         s "+"
+                         "\\(" HH:MM "\\|" yyyy "\\)"))
+        (western-comma (concat month s "+" dd "," s "+" yyyy))
+        ;; Japanese MS-Windows ls-lisp has one-digit months, and
+        ;; omits the Kanji characters after month and day-of-month.
+        ;; On Mac OS X 10.3, the date format in East Asian locales is
+        ;; day-of-month digits followed by month digits.
+        (mm "[ 0-1]?[0-9]")
+        (east-asian
+         (concat "\\(" mm l "?" s dd l "?" s "+"
+                 "\\|" dd s mm s "+" "\\)"
+                 "\\(" HH:MM "\\|" yyyy l "?" "\\)")))
+        ;; The "[0-9]" below requires the previous column to end in a digit.
+        ;; This avoids recognizing `1 may 1997' as a date in the line:
+        ;; -r--r--r--   1 may      1997        1168 Oct 19 16:49 README
+
+        ;; The "[BkKMGTPEZY]?" below supports "ls -alh" output.
+        ;; The ".*" below finds the last match if there are multiple matches.
+        ;; This avoids recognizing `jservice  10  1024' as a date in the line:
+        ;; drwxr-xr-x  3 jservice  10  1024 Jul  2  1997 esg-host
+
+         ;; vc dired listings provide the state or blanks between file
+         ;; permissions and date.  The state is always surrounded by
+         ;; parantheses:
+         ;; -rw-r--r-- (modified) 2005-10-22 21:25 files.el
+         ;; This is not supported yet.
+    (concat ".*[0-9][BkKMGTPEZY]?" s
+           "\\(" western "\\|" western-comma "\\|" east-asian "\\|" iso "\\)"
+           s "+"))
+  "Regular expression to match up to the file name in a directory listing.
+The default value is designed to recognize dates and times
+regardless of the language.")
 
 (defvar insert-directory-ls-version 'unknown)