]> code.delx.au - gnu-emacs/blobdiff - lisp/dired-x.el
(calendar-astro-from-absolute): Autoload it.
[gnu-emacs] / lisp / dired-x.el
index 4beefd1033618d34244d3f4cc8736a2a47c2463a..c8300886cdc9fbe40314fff34162a5ffb7da9d8e 100644 (file)
@@ -3,8 +3,8 @@
 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
 ;;     Lawrence R. Dodd <dodd@roebling.poly.edu>
 ;; Maintainer: Lawrence R. Dodd <dodd@roebling.poly.edu>
-;; Version: 2.27
-;; Date: 1994/04/05 12:45:30
+;; Version: 2.37+
+;; Date: 1994/08/18 19:27:42
 ;; Keywords: dired extensions
 
 ;; Copyright (C) 1993, 1994 Free Software Foundation
 ;;; 1.191, hacked up for GNU Emacs 19.  Redundant or conflicting material
 ;;; has been removed or renamed in order to work properly with dired of
 ;;; GNU Emacs 19.  All suggestions or comments are most welcomed.
-;;;  
-;;; *Please* see the info pages.
 
+;;;  
+;;; Please, PLEASE, *PLEASE* see the info pages.
+;;; 
 ;;; BUGS: Type M-x dired-x-submit-report and a report will be generated.
 
 ;;; INSTALLATION: In your ~/.emacs,
 ;;; (add-hook 'dired-load-hook
 ;;;           (function (lambda ()
 ;;;                       (load "dired-x")
-;;;                       ;; Set variables here.  For example:
+;;;                       ;; Set global variables here.  For example:
 ;;;                       ;; (setq dired-guess-shell-gnutar "gtar")
+;;;                       )))
+;;; (add-hook 'dired-mode-hook
+;;;           (function (lambda ()
+;;;                       ;; Set buffer-local variables here.  For example:
 ;;;                       ;; (setq dired-omit-files-p t)
 ;;;                       )))
 ;;;
 ;;; At load time dired-x.el will install itself, redefine some functions, and
 ;;; bind some dired keys.  *Please* see the info pages for more details.
 
+;;; CAUTION: If you are using a version of GNU Emacs earlier than 19.20 than
+;;; you may have to edit dired.el.  The copy of dired.el in GNU Emacs versions
+;;; earlier than 19.20 incorrectly had the call to run-hooks *before* the call
+;;; to provide.  In such a case, it is possible that byte-compiling and/or
+;;; loading dired can cause an infinite loop.  To prevent this, make sure the
+;;; line of code
+;;;  
+;;;         (run-hooks 'dired-load-hook) 
+;;;  
+;;; is the *last* executable line in the file dired.el.  That is, make sure it
+;;; comes *after* the line
+;;;  
+;;;         (provide 'dired) 
+;;; 
+;;; *Please* see the info pages for more details. 
+
 ;;; User defined variables:
 ;;;
 ;;;      dired-bind-vm
@@ -56,6 +78,7 @@
 ;;;      dired-bind-jump
 ;;;      dired-bind-info
 ;;;      dired-bind-man
+;;;      dired-x-hands-off-my-keys 
 ;;;      dired-find-subdir
 ;;;      dired-enable-local-variables
 ;;;      dired-local-variables-file
 ;;;   dired-clean-up-after-deletion    ../lisp/dired.el
 ;;;   dired-find-buffer-nocreate       ../lisp/dired.el
 ;;;   dired-initial-position           ../lisp/dired.el
-;;;   dired-up-directory               ../lisp/dired.el
 ;;;
 ;;;   dired-add-entry                  ../lisp/dired-aux.el
 ;;;   dired-read-shell-command         ../lisp/dired-aux.el
 ;;; here in case the user has autoloaded dired-x via the dired-jump key binding
 ;;; (instead of autoloading to dired as is suggested in the info-pages).
 
-;;; WARNING: The copy of dired.el in GNU Emacs versions earlier than 19.20 had
-;;; the `provide' *after* the `run-hooks'.  In such a case, loading dired below
-;;; will cause an infinite loop.  To prevent this we test the value of the GNU
-;;; Emacs major version number before requiring dired.
-
-(if (string< "19.19"
-             ;; Compare with major version number (i.e., 19.22 not 19.22.11).
-             (substring emacs-version 0
-                        (and (string-match "^[0-9]*\\.[0-9]*" emacs-version)
-                             (match-end 0))))
-    (require 'dired))
+(require 'dired)
 
 ;;; We will redefine some functions and also need some macros so we need to
-;;; load dired stuff of GNU Emacs.  Since dired-aux.el (at least up to GNU
-;;; Emacs 19.22) does not `provide' itself, we do it here.  This avoids the
-;;; possibility recursive loading because of the nasty `eval-when-compile' that
-;;; is in dired-aux.el.
+;;; load dired stuff of GNU Emacs.
 
-(and (not (featurep 'dired-aux))
-     (load "dired-aux" nil t)
-     (not (featurep 'dired-aux))
-     (provide 'dired-aux))
+(require 'dired-aux)
 
 ;;;; User-defined variables.
 
@@ -152,15 +158,19 @@ Read-only folders only work in VM 5, not in VM 4.")
 Use \\[dired-omit-toggle] to toggle its value.
 Uninteresting files are those whose filenames match regexp `dired-omit-files',
 plus those ending with extensions in `dired-omit-extensions'.")
+(make-variable-buffer-local 'dired-omit-files-p)
 
-(defvar dired-omit-files "^#\\|\\.$"
-  "*Filenames matching this regexp will not be displayed (buffer-local).
-This only has effect when `dired-omit-files-p' is t.
-See also `dired-omit-extensions'.")
+(defvar dired-omit-files "^#\\|^\\.$\\|^\\.\\.$"
+  "*Filenames matching this regexp will not be displayed.
+This only has effect when `dired-omit-files-p' is t.  See interactive function
+`dired-omit-toggle' \(\\[dired-omit-toggle]\) and variable
+`dired-omit-extensions'.  The default is to omit  `.', `..', and auto-save
+files.")
 
 (defvar dired-find-subdir nil           ; t is pretty near to DWIM...
-  "*If non-nil, Dired does not make a new buffer for a directory if it
-can be found (perhaps as subdir) in some existing Dired buffer.
+  "*If non-nil, Dired always finds a directory in a buffer of its own.
+If nil, Dired finds the directory as a subdirectory in some other buffer
+if it is present as one.
 
 If there are several Dired buffers for a directory, the most recently
 used is chosen.
@@ -296,7 +306,7 @@ See also functions
                                 (file-name-nondirectory fn)))
                (save-excursion ; you never know where kill-buffer leaves you
                  (kill-buffer buf))))
-        (let ((buf-list (dired-buffers-for-dir fn))
+        (let ((buf-list (dired-buffers-for-dir (expand-file-name fn)))
               (buf nil))
           (and buf-list
                (y-or-n-p (format "Kill dired buffer%s of %s, too? "
@@ -387,6 +397,7 @@ See variables `dired-texinfo-unclean-extensions',
 \f
 ;;;; JUMP.
 
+;;;###autoload
 (defun dired-jump (&optional other-window)
   "Jump to dired buffer corresponding to current buffer.
 If in a file, dired the current directory and move to file's line.
@@ -423,28 +434,6 @@ buffer and try again."
   "Like \\[dired-jump] (dired-jump) but in other window."
   (interactive)
   (dired-jump t))
-
-;;; REDEFINE.
-;;; This replaces the version in dired.el
-;;; It simply adds the OTHER-WINDOW option to the one in dired.el.
-(defun dired-up-directory (&optional other-window)
-  "Run dired on parent directory of current directory.
-Find the parent directory either in this buffer or another buffer.
-Finds in current window or in other window with optional OTHER-WINDOW.
-Creates a buffer if necessary."
-  (interactive "P")
-  (let* ((dir (dired-current-directory))
-         (up (file-name-directory (directory-file-name dir))))
-    (or (dired-goto-file (directory-file-name dir))
-        ;; Only try dired-goto-subdir if buffer has more than one dir.
-        (and (cdr dired-subdir-alist)
-             (dired-goto-subdir up))
-        (progn
-          (if other-window
-              (dired-other-window up)
-            (dired up))
-          (dired-goto-file dir)))))
-
 \f
 ;;;; TOGGLE.
 ;;; Toggle marked files with unmarked files.
@@ -521,13 +510,12 @@ whole pathname.")
 Should never be used as marker by the user or other packages.")
 
 (defun dired-omit-startup ()
-  (make-local-variable 'dired-omit-files-p)
   (or (assq 'dired-omit-files-p minor-mode-alist)
       (setq minor-mode-alist
             (append '((dired-omit-files-p " Omit")) minor-mode-alist))))
 
 (defun dired-omit-toggle (&optional flag)
-  "Toggle between displaying and omitting files matching `dired-omit-files'.
+  "Toggle omitting files matching `dired-omit-files' and `dired-omit-extensions'.
 With an arg, and if omitting was off, don't toggle and just mark the
   files but don't actually omit them.
 With an arg, and if omitting was on, turn it off but don't refresh the buffer."
@@ -549,10 +537,13 @@ With an arg, and if omitting was on, turn it off but don't refresh the buffer."
           dired-latex-unclean-extensions
           dired-bibtex-unclean-extensions
           dired-texinfo-unclean-extensions)
-  "If non-nil, a list of extensions (strings) to omit from Dired
-listings.  Defaults to the elements of
-`completion-ignored-extensions', `dired-latex-unclean-extensions',
-`dired-bibtex-unclean-extensions' and `dired-texinfo-unclean-extensions'.")
+  "If non-nil, a list of extensions \(strings\) to omit from Dired listings.  
+Defaults to elements of `completion-ignored-extensions',
+`dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions', and
+`dired-texinfo-unclean-extensions'.  
+
+See interactive function `dired-omit-toggle' \(\\[dired-omit-toggle]\) and
+variables `dired-omit-files-p' and `dired-omit-files'.")
 
 (defun dired-omit-expunge (&optional regexp)
   "Erases all unmarked files matching REGEXP.
@@ -566,6 +557,7 @@ This functions works by temporarily binding `dired-marker-char' to
   (interactive "sOmit files (regexp): ")
   (if dired-omit-files-p
       (let ((omit-re (or regexp (dired-omit-regexp)))
+            (old-modified-p (buffer-modified-p))
             count)
         (or (string= omit-re "")
             (let ((dired-marker-char dired-omit-marker-char))
@@ -573,9 +565,14 @@ This functions works by temporarily binding `dired-marker-char' to
               (if (dired-mark-unmarked-files omit-re nil nil dired-omit-localp)
                   (progn
                     (setq count (dired-do-kill-lines nil "Omitted %d line%s."))
-                    ;; Force an update of modeline.
-                    (set-buffer-modified-p (buffer-modified-p)))
+                    (force-mode-line-update))
                 (message "(Nothing to omit)"))))
+        ;; Try to preserve modified state of buffer.  So `%*' doesn't appear
+        ;; in mode-line of omitted buffers.
+        (set-buffer-modified-p (and old-modified-p 
+                                    (save-excursion
+                                      (goto-char (point-min))
+                                      (re-search-forward dired-re-mark nil t))))
         count)))
 
 (defun dired-omit-regexp ()
@@ -761,7 +758,7 @@ to put saved dired buffers automatically into virtual dired mode.
 
 Also useful for `auto-mode-alist' (which see) like this:
 
-  \(setq auto-mode-alist (cons '(\"[^/]\\.dired$\" . dired-virtual-mode)
+  \(setq auto-mode-alist (cons '(\"[^/]\\.dired\\'\" . dired-virtual-mode)
                               auto-mode-alist)\)"
   (interactive)
   (dired-virtual (dired-virtual-guess-dir)))
@@ -889,7 +886,7 @@ dired."
 ;;;   that matches the first file in the file list.
 ;;;
 ;;; * If the REGEXP matches all the entries of the file list then evaluate
-;;;   COMMAND, which is either a string or an elisp expression returning a
+;;;   COMMAND, which is either a string or a Lisp expression returning a
 ;;;   string.  COMMAND may be a list of commands.
 ;;;
 ;;; * Return this command to `dired-guess-shell-command' which prompts user
@@ -1287,52 +1284,12 @@ To display just marked files, type \\[delete-other-windows] first."
 
 (defun dired-man ()
   "Run man on this file.  Display old buffer if buffer name matches filename.
-Results displayed based on value of `Man-notify'.  See that variable."
+Uses ../lisp/man.el of \\[manual-entry] fame."
   (interactive)
-  (let* ((file (dired-get-filename))
-         (string (format "*man %s*" (file-name-nondirectory file)))
-         (Man-buffer (get-buffer string))
-         (msg "Expanding manual page...cleaning...done"))
-
-    ;; If Man-buffer already exists and has not been modified, display it.
-    ;; Otherwise, create a fresh one.
-    (if (and Man-buffer
-             (save-excursion
-               (set-buffer Man-buffer)
-               (not (buffer-modified-p))
-               buffer-read-only))
-
-        (setq msg "Displaying pre-existing manual page.")
-
-      ;; Create Man-buffer.
-      (save-excursion
-
-        ;; Prepare buffer.
-        (setq Man-buffer (get-buffer-create string))
-        (set-buffer Man-buffer)
-        (setq buffer-read-only nil)
-        (erase-buffer)
-
-        ;; Expand and clean man page.
-        (message "Expanding manual page...")
-        (call-process shell-file-name nil t nil "-c"
-                      (concat " nroff -man -h " file))
-        (message "Expanding manual page...cleaning...")
-        (call-process-region (point-min) (point-max)
-                             shell-file-name t t nil "-c" " col -b")
-        (goto-char (point-min))
-
-        ;; Reset buffer.
-        (setq buffer-read-only t)
-        (buffer-disable-undo (current-buffer))
-        (set-buffer-modified-p nil)))
-
-    ;; Display results.  Use display function of ../lisp/man.el whose behavior
-    ;; is determined by user-defined variable Man-notify.
-    (require 'man)
-    (Man-notify-when-ready Man-buffer)
-    ;; Overrides any message issued by above function.
-    (message msg)))
+  (require 'man)
+  (let ((file (dired-get-filename))
+        (manual-program "nroff -man -h"))
+    (Man-getpage-in-background file)))
 
 ;;; Run Info on files.
 
@@ -1385,19 +1342,22 @@ See also variable `dired-vm-read-only-folders'."
 
 ;;; REDEFINE.
 ;;; Redefines dired.el's version of `dired-find-buffer-nocreate'
-(defun dired-find-buffer-nocreate (dirname)
-  (if dired-find-subdir
+(defun dired-find-buffer-nocreate (dirname &optional mode)
+  (if (and dired-find-subdir
+          ;; don't try to find a wildcard as a subdirectory
+          (string-equal dirname (file-name-directory dirname)))
       (let* ((cur-buf (current-buffer))
-             (buffers (nreverse (dired-buffers-for-dir dirname)))
-             (cur-buf-matches (and (memq cur-buf buffers)
-                                   ;; wildcards must match, too:
-                                   (equal dired-directory dirname))))
-        ;; We don't want to switch to the same buffer---
-        (setq buffers (delq cur-buf buffers));;need setq with delq
-        (or (car (sort buffers (function dired-buffer-more-recently-used-p)))
-            ;; ---unless it's the only possibility:
-            (and cur-buf-matches cur-buf)))
-    (dired-old-find-buffer-nocreate dirname)))
+            (buffers (nreverse
+                      (dired-buffers-for-dir (expand-file-name dirname))))
+            (cur-buf-matches (and (memq cur-buf buffers)
+                                  ;; wildcards must match, too:
+                                  (equal dired-directory dirname))))
+       ;; We don't want to switch to the same buffer---
+       (setq buffers (delq cur-buf buffers));;need setq with delq
+       (or (car (sort buffers (function dired-buffer-more-recently-used-p)))
+           ;; ---unless it's the only possibility:
+           (and cur-buf-matches cur-buf)))
+    (dired-old-find-buffer-nocreate dirname mode)))
 
 ;; This should be a builtin
 (defun dired-buffer-more-recently-used-p (buffer1 buffer2)
@@ -1538,24 +1498,71 @@ to mark all zero length files."
 
 \f
 ;;;; FIND FILE AT POINT.
-(defun dired-find-this-file (&optional other-window)
-  "Edit filename or directory at point.
-Switch to a buffer visiting filename, creating one if none already exists.
-With non-nil prefix argument OTHER-WINDOW do so in the other window.
-
-Useful for editing the file mentioned in the buffer you are viewing, or to
-test if that file exists.  Use minibuffer after snatching the filename."
 
-  (interactive "P")
-  (let* ((guess (dired-filename-at-point))
-         (file (read-file-name "Find file: " guess guess nil nil)))
-    (if other-window
-        (find-file-other-window (expand-file-name file))
-      (find-file (expand-file-name file)))))
-
-(fset 'find-this-file 'dired-find-this-file)
-
-;;; Internal function.
+(defvar dired-x-hands-off-my-keys t
+  "*t means don't bind `dired-x-find-file' over `find-file' on keyboard.
+Similarly for `dired-x-find-file-other-window' over `find-file-other-window'.
+If you change this variable after dired-x.el is loaded then do
+\\[dired-x-bind-find-file].")
+
+;;; Bind `dired-x-find-file{-other-window}' over wherever
+;;; `find-file{-other-window}' is bound?
+(defun dired-x-bind-find-file ()
+  "Bind `dired-x-find-file' in place of `find-file' \(or reverse\).
+Similarly for `dired-x-find-file-other-window' and `find-file-other-window'.
+Binding direction based on `dired-x-hands-off-my-keys'.
+This function part of `after-init-hook'."
+  (interactive)
+  (if (interactive-p)
+      (setq dired-x-hands-off-my-keys
+            (not (y-or-n-p "Bind dired-x-find-file over find-file? "))))
+  (cond ((not dired-x-hands-off-my-keys)
+         (substitute-key-definition 'find-file
+                                    'dired-x-find-file
+                                    (current-global-map))
+         (substitute-key-definition 'find-file-other-window
+                                    'dired-x-find-file-other-window
+                                    (current-global-map)))
+        (t
+         (substitute-key-definition 'dired-x-find-file
+                                    'find-file
+                                    (current-global-map))
+         (substitute-key-definition 'dired-x-find-file-other-window
+                                    'find-file-other-window
+                                    (current-global-map))))
+  ;; Clear mini-buffer.
+  (message nil))
+
+;;; Now call it so binding is correct and put on `after-init-hook' in case
+;;; user changes binding.
+(dired-x-bind-find-file)
+(add-hook 'after-init-hook 'dired-x-bind-find-file)
+
+(defun dired-x-find-file (filename)
+  "Edit file FILENAME.
+May create a new window, or reuse an existing one.
+See the function `display-buffer'.
+
+Identical to `find-file' except when called interactively, with a prefix arg
+\(e.g., \\[universal-argument]\), in which case it guesses filename near
+point.  Useful for editing file mentioned in buffer you are viewing, or to
+test if that file exists.  Use minibuffer after snatching filename."
+  (interactive (list (read-filename-at-point "Find file: ")))
+  (find-file (expand-file-name filename)))
+
+(defun dired-x-find-file-other-window (filename)
+  "Edit file FILENAME, in another window.
+May create a new window, or reuse an existing one.
+See the function `display-buffer'.
+
+Identical to `find-file-other-window' except when called interactively, with a
+prefix arg \(e.g., \\[universal-argument]\), in which case it guesses filename
+near point.  Useful for editing file mentioned in buffer you are viewing, or
+to test if that file exists.  Use minibuffer after snatching filename."
+  (interactive (list (read-filename-at-point "Find file: ")))
+  (find-file-other-window (expand-file-name filename)))
+
+;;; Internal functions.
 (defun dired-filename-at-point ()
 
   ;; Get the filename closest to point, but do not change position.  Has a
@@ -1590,13 +1597,24 @@ test if that file exists.  Use minibuffer after snatching the filename."
       ;; Return string.
       (expand-file-name (buffer-substring start (point))))))
 
+(defun read-filename-at-point (prompt)
+  ;;; Returns filename prompting with PROMPT with completion.  If
+  ;;; `current-prefix-arg' is non-nil, uses name at point as guess.
+  (if current-prefix-arg
+      (let ((guess (dired-filename-at-point)))
+        (read-file-name prompt
+                        (file-name-directory guess)
+                        guess
+                        nil (file-name-nondirectory guess)))
+    (read-file-name prompt default-directory)))
+
 \f
 ;;;; BUG REPORTS
 
 ;;; This section is provided for reports.  It uses Barry A. Warsaw's
 ;;; reporter.el which is bundled with GNU Emacs v19.
 
-(defconst dired-x-version "2.27"
+(defconst dired-x-version "2.37"
   "Revision number of dired-x.el -- dired extra for GNU Emacs v19.
 Type \\[dired-x-submit-report] to send a bug report.  Available via anonymous
 ftp in