dynwind fixes
[bpt/emacs.git] / lisp / dired-x.el
index 2a9bc16..25c6f8b 100644 (file)
@@ -1,7 +1,6 @@
-;;; dired-x.el --- extra Dired functionality
+;;; dired-x.el --- extra Dired functionality  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1993-1994, 1997, 2001-2013 Free Software Foundation,
-;; Inc.
+;; Copyright (C) 1993-1994, 1997, 2001-2014 Free Software Foundation, Inc.
 
 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
 ;;     Lawrence R. Dodd <dodd@roebling.poly.edu>
@@ -241,7 +240,7 @@ to nil: a pipe using `zcat' or `gunzip -c' will be used."
 
 ;;; KEY BINDINGS.
 
-(define-key dired-mode-map "\M-o" 'dired-omit-mode)
+(define-key dired-mode-map "\C-x\M-o" 'dired-omit-mode)
 (define-key dired-mode-map "*O" 'dired-mark-omitted)
 (define-key dired-mode-map "\M-(" 'dired-mark-sexp)
 (define-key dired-mode-map "*(" 'dired-mark-sexp)
@@ -331,9 +330,9 @@ See also the functions:
 ;; Mark files with some extension.
 (defun dired-mark-extension (extension &optional marker-char)
   "Mark all files with a certain EXTENSION for use in later commands.
-A `.' is *not* automatically prepended to the string entered."
-  ;; EXTENSION may also be a list of extensions instead of a single one.
-  ;; Optional MARKER-CHAR is marker to use.
+A `.' is *not* automatically prepended to the string entered.
+EXTENSION may also be a list of extensions instead of a single one.
+Optional MARKER-CHAR is marker to use."
   (interactive "sMarking extension: \nP")
   (or (listp extension)
       (setq extension (list extension)))
@@ -556,17 +555,18 @@ interactively, prompt for REGEXP.
 With prefix argument, unflag all those files.
 Optional fourth argument LOCALP is as in `dired-get-filename'."
   (interactive
-   (list (dired-read-regexp
-         "Mark unmarked files matching regexp (default all): ")
+   (list (read-regexp
+         "Mark unmarked files matching regexp (default all): "
+          nil 'dired-regexp-history)
         nil current-prefix-arg nil))
   (let ((dired-marker-char (if unflag-p ?\s dired-marker-char)))
     (dired-mark-if
      (and
       ;; not already marked
-      (looking-at " ")
+      (looking-at-p " ")
       ;; uninteresting
       (let ((fn (dired-get-filename localp t)))
-        (and fn (string-match regexp fn))))
+        (and fn (string-match-p regexp fn))))
      msg)))
 
 \f
@@ -610,7 +610,7 @@ you can relist single subdirs using \\[dired-do-redisplay]."
   (interactive
    (list (read-string "Virtual Dired directory: " (dired-virtual-guess-dir))))
   (goto-char (point-min))
-  (or (looking-at "  ")
+  (or (looking-at-p "  ")
       ;; if not already indented, do it now:
       (indent-region (point-min) (point-max) 2))
   (or dirname (setq dirname default-directory))
@@ -627,7 +627,7 @@ you can relist single subdirs using \\[dired-do-redisplay]."
   ;; If raw ls listing (not a saved old dired buffer), give it a
   ;; decent subdir headerline:
   (goto-char (point-min))
-  (or (looking-at dired-subdir-regexp)
+  (or (looking-at-p dired-subdir-regexp)
       (insert "  "
              (directory-file-name (file-name-directory default-directory))
              ":\n"))
@@ -1047,7 +1047,8 @@ Each element of this list looks like
     (REGEXP COMMAND...)
 
 where each COMMAND can either be a string or a Lisp expression that evaluates
-to a string.  If several COMMANDs are given, the first one will be the default
+to a string.  This expression can access the file name as the variable `file'.
+If several COMMANDs are given, the first one will be the default
 and the rest will be added temporarily to the history and can be retrieved
 with \\[previous-history-element] (M-p) .
 
@@ -1089,13 +1090,13 @@ See `dired-guess-shell-alist-user'."
       (setq elt (car alist)
             regexp (car elt)
             alist (cdr alist))
-      (if (string-match regexp file)
+      (if (string-match-p regexp file)
           (setq cmds (cdr elt)
                 alist nil)))
 
     ;; If more than one file, see if all of FILES match regular expression.
     (while (and flist
-                (string-match regexp (car flist)))
+                (string-match-p regexp (car flist)))
       (setq flist (cdr flist)))
 
     ;; If flist is still non-nil, then do not guess since this means that not
@@ -1105,8 +1106,8 @@ See `dired-guess-shell-alist-user'."
     ;; Return commands or nil if flist is still non-nil.
     ;; Evaluate the commands in order that any logical testing will be done.
     (if (cdr cmds)
-       (delete-dups (mapcar #'eval cmds))
-      (eval (car cmds)))))             ; single command
+       (delete-dups (mapcar (lambda (cmd) (eval cmd `((file . ,file)))) cmds))
+      (eval (car cmds) `((file . ,file))))))           ; single command
 
 (defun dired-guess-shell-command (prompt files)
   "Ask user with PROMPT for a shell command, guessing a default from FILES."
@@ -1185,7 +1186,7 @@ results in
           (setq count (1+ count)
                 start (1+ start)))
         ;; ... and prepend a "../" for each slash found:
-        (dotimes (_n count)
+        (dotimes (_ count)
           (setq name1 (concat "../" name1)))))
     (make-symbolic-link
      (directory-file-name name1)        ; must not link to foo/
@@ -1397,22 +1398,6 @@ Considers buffers closer to the car of `buffer-list' to be more recent."
 ;; Does anyone use this? - lrd 6/29/93.
 ;; Apparently people do use it. - lrd 12/22/97.
 
-(with-no-warnings
-  ;; Warnings are suppressed to avoid "global/dynamic var `X' lacks a prefix".
-  ;; This is unbearably ugly, but not more than having global variables
-  ;; named size, time, name or s, however practical it can be while writing
-  ;; `dired-mark-sexp' predicates.
-  (defvar inode)
-  (defvar s)
-  (defvar mode)
-  (defvar nlink)
-  (defvar uid)
-  (defvar gid)
-  (defvar size)
-  (defvar time)
-  (defvar name)
-  (defvar sym))
-
 (defun dired-mark-sexp (predicate &optional unflag-p)
   "Mark files for which PREDICATE returns non-nil.
 With a prefix arg, unmark or unflag those files instead.
@@ -1475,6 +1460,9 @@ to mark all zero length files."
                   s nil))
           (setq mode (buffer-substring (point) (+ mode-len (point))))
           (forward-char mode-len)
+          ;; Skip any extended attributes marker ("." or "+").
+          (or (looking-at " ")
+              (forward-char 1))
           (setq nlink (read (current-buffer)))
           ;; Karsten Wenger <kw@cis.uni-muenchen.de> fixed uid.
           (setq uid (buffer-substring (1+ (point))
@@ -1500,12 +1488,22 @@ to mark all zero length files."
                                        (or
                                         (dired-move-to-end-of-filename t)
                                         (point)))
-                sym (if (looking-at " -> ")
+                sym (if (looking-at-p " -> ")
                         (buffer-substring (progn (forward-char 4) (point))
                                           (line-end-position))
                       ""))
           t)
-        (eval predicate)))
+        (eval predicate
+              `((inode . ,inode)
+                (s . ,s)
+                (mode . ,mode)
+                (nlink . ,nlink)
+                (uid . ,uid)
+                (gid . ,gid)
+                (size . ,size)
+                (time . ,time)
+                (name . ,name)
+                (sym . ,sym)))))
      (format "'%s file" predicate))))
 
 \f
@@ -1564,12 +1562,12 @@ Point should be in or after a filename."
   (save-excursion
     ;; First see if just past a filename.
     (or (eobp)                             ; why?
-        (when (looking-at "[] \t\n[{}()]") ; whitespace or some parens
+        (when (looking-at-p "[] \t\n[{}()]") ; whitespace or some parens
           (skip-chars-backward " \n\t\r({[]})")
           (or (bobp) (backward-char 1))))
     (let ((filename-chars "-.[:alnum:]_/:$+@")
           start prefix)
-      (if (looking-at (format "[%s]" filename-chars))
+      (if (looking-at-p (format "[%s]" filename-chars))
           (progn
             (skip-chars-backward filename-chars)
             (setq start (point)
@@ -1577,11 +1575,11 @@ Point should be in or after a filename."
                   ;; This is something to do with ange-ftp filenames.
                   ;; It convert foo@bar to /foo@bar.
                   ;; But when does the former occur in dired buffers?
-                 (and (string-match
+                 (and (string-match-p
                        "^\\w+@"
                        (buffer-substring start (line-end-position)))
                       "/"))
-            (if (string-match "[/~]" (char-to-string (preceding-char)))
+            (if (string-match-p "[/~]" (char-to-string (preceding-char)))
                 (setq start (1- start)))
             (skip-chars-forward filename-chars))
         (error "No file found around point!"))