-;;;; 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.
+;;; FIND FILE AT POINT.
+
+(defvar dired-x-hands-off-my-keys t
+ "*Non-nil 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 is 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.
+
+;; Fixme: This should probably use `thing-at-point'. -- fx