comparison lisp/dired-x.el @ 8078:1dd92ac02141

(dired-x-hands-off-my-keys): New user-defined variable. (dired-x-bind-find-file): Use it. (dired-x-find-file): New function to substitute find-file. (dired-x-find-file-other-window): New function to substitute find-file-other-window.
author Richard M. Stallman <rms@gnu.org>
date Tue, 28 Jun 1994 18:41:05 +0000
parents d3e50535e6da
children fad4e60c964d
comparison
equal deleted inserted replaced
8077:edcb7fcf3f28 8078:1dd92ac02141
1 ;;; dired-x.el --- Sebastian Kremer's Extra DIRED hacked up for GNU Emacs19 1 ;;; dired-x.el --- Sebastian Kremer's Extra DIRED hacked up for GNU Emacs19
2 2
3 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de> 3 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
4 ;; Lawrence R. Dodd <dodd@roebling.poly.edu> 4 ;; Lawrence R. Dodd <dodd@roebling.poly.edu>
5 ;; Maintainer: Lawrence R. Dodd <dodd@roebling.poly.edu> 5 ;; Maintainer: Lawrence R. Dodd <dodd@roebling.poly.edu>
6 ;; Version: 2.31 6 ;; Version: 2.37
7 ;; Date: 1994/06/09 21:31:53 7 ;; Date: 1994/06/28 15:53:34
8 ;; Keywords: dired extensions 8 ;; Keywords: dired extensions
9 9
10 ;; Copyright (C) 1993, 1994 Free Software Foundation 10 ;; Copyright (C) 1993, 1994 Free Software Foundation
11 11
12 ;; This file is part of GNU Emacs. 12 ;; This file is part of GNU Emacs.
29 29
30 ;;; This is Sebastian Kremer's excellent dired-x.el (Dired Extra), version 30 ;;; This is Sebastian Kremer's excellent dired-x.el (Dired Extra), version
31 ;;; 1.191, hacked up for GNU Emacs 19. Redundant or conflicting material 31 ;;; 1.191, hacked up for GNU Emacs 19. Redundant or conflicting material
32 ;;; has been removed or renamed in order to work properly with dired of 32 ;;; has been removed or renamed in order to work properly with dired of
33 ;;; GNU Emacs 19. All suggestions or comments are most welcomed. 33 ;;; GNU Emacs 19. All suggestions or comments are most welcomed.
34
34 ;;; 35 ;;;
35 ;;; *Please* see the info pages. 36 ;;; Please, PLEASE, *PLEASE* see the info pages.
36 37 ;;;
38
37 ;;; BUGS: Type M-x dired-x-submit-report and a report will be generated. 39 ;;; BUGS: Type M-x dired-x-submit-report and a report will be generated.
38 40
39 ;;; INSTALLATION: In your ~/.emacs, 41 ;;; INSTALLATION: In your ~/.emacs,
40 ;;; 42 ;;;
41 ;;; (add-hook 'dired-load-hook 43 ;;; (add-hook 'dired-load-hook
47 ;;; ))) 49 ;;; )))
48 ;;; 50 ;;;
49 ;;; At load time dired-x.el will install itself, redefine some functions, and 51 ;;; At load time dired-x.el will install itself, redefine some functions, and
50 ;;; bind some dired keys. *Please* see the info pages for more details. 52 ;;; bind some dired keys. *Please* see the info pages for more details.
51 53
54 ;;; CAUTION: If you are using a version of GNU Emacs earlier than 19.20 than
55 ;;; you may have to edit dired.el. The copy of dired.el in GNU Emacs versions
56 ;;; earlier than 19.20 incorrectly had the call to run-hooks *before* the call
57 ;;; to provide. In such a case, it is possible that byte-compiling and/or
58 ;;; loading dired can cause an infinite loop. To prevent this, make sure the
59 ;;; line of code
60 ;;;
61 ;;; (run-hooks 'dired-load-hook)
62 ;;;
63 ;;; is the *last* executable line in the file dired.el. That is, make sure it
64 ;;; comes *after* the line
65 ;;;
66 ;;; (provide 'dired)
67 ;;;
68 ;;; *Please* see the info pages for more details.
69
52 ;;; User defined variables: 70 ;;; User defined variables:
53 ;;; 71 ;;;
54 ;;; dired-bind-vm 72 ;;; dired-bind-vm
55 ;;; dired-vm-read-only-folders 73 ;;; dired-vm-read-only-folders
56 ;;; dired-bind-jump 74 ;;; dired-bind-jump
57 ;;; dired-bind-info 75 ;;; dired-bind-info
58 ;;; dired-bind-man 76 ;;; dired-bind-man
77 ;;; dired-x-hands-off-my-keys
59 ;;; dired-find-subdir 78 ;;; dired-find-subdir
60 ;;; dired-enable-local-variables 79 ;;; dired-enable-local-variables
61 ;;; dired-local-variables-file 80 ;;; dired-local-variables-file
62 ;;; dired-guess-shell-gnutar 81 ;;; dired-guess-shell-gnutar
63 ;;; dired-guess-shell-gzip-quiet 82 ;;; dired-guess-shell-gzip-quiet
1486 (eval predicate))) 1505 (eval predicate)))
1487 (format "'%s file" predicate)))) 1506 (format "'%s file" predicate))))
1488 1507
1489 1508
1490 ;;;; FIND FILE AT POINT. 1509 ;;;; FIND FILE AT POINT.
1491 (defun dired-find-this-file (&optional other-window) 1510
1492 "Edit filename or directory at point. 1511 (defvar dired-x-hands-off-my-keys t
1493 Switch to a buffer visiting filename, creating one if none already exists. 1512 "*t means don't bind `dired-x-find-file' over `find-file' on keyboard.
1494 With non-nil prefix argument OTHER-WINDOW do so in the other window. 1513 Similarly for `dired-x-find-file-other-window' over `find-file-other-window'.
1495 1514 If you change this variable after dired-x.el is loaded then do
1496 Useful for editing the file mentioned in the buffer you are viewing, or to 1515 \\[dired-x-bind-find-file].")
1497 test if that file exists. Use minibuffer after snatching the filename." 1516
1498 1517 ;;; Bind `dired-x-find-file{-other-window}' over wherever
1499 (interactive "P") 1518 ;;; `find-file{-other-window}' is bound?
1500 (let* ((guess (dired-filename-at-point)) 1519 (defun dired-x-bind-find-file ()
1501 (file (read-file-name "Find file: " guess guess nil nil))) 1520 "Bind `dired-x-find-file' in place of `find-file' \(or reverse\).
1502 (if other-window 1521 Similarly for `dired-x-find-file-other-window' and `find-file-other-window'.
1503 (find-file-other-window (expand-file-name file)) 1522 Binding direction based on `dired-x-hands-off-my-keys'.
1504 (find-file (expand-file-name file))))) 1523 This function part of `after-init-hook'."
1505 1524 (interactive)
1506 (fset 'find-this-file 'dired-find-this-file) 1525 (if (interactive-p)
1507 1526 (setq dired-x-hands-off-my-keys
1508 ;;; Internal function. 1527 (not (y-or-n-p "Bind dired-x-find-file over find-file? "))))
1528 (cond ((not dired-x-hands-off-my-keys)
1529 (substitute-key-definition 'find-file
1530 'dired-x-find-file
1531 (current-global-map))
1532 (substitute-key-definition 'find-file-other-window
1533 'dired-x-find-file-other-window
1534 (current-global-map)))
1535 (t
1536 (substitute-key-definition 'dired-x-find-file
1537 'find-file
1538 (current-global-map))
1539 (substitute-key-definition 'dired-x-find-file-other-window
1540 'find-file-other-window
1541 (current-global-map))))
1542 ;; Clear mini-buffer.
1543 (message nil))
1544
1545 ;;; Now call it so binding is correct and put on `after-init-hook' in case
1546 ;;; user changes binding.
1547 (dired-x-bind-find-file)
1548 (add-hook 'after-init-hook 'dired-x-bind-find-file)
1549
1550 (defun dired-x-find-file (filename)
1551 "Edit file FILENAME.
1552 May create a new window, or reuse an existing one.
1553 See the function `display-buffer'.
1554
1555 Identical to `find-file' except when called interactively, with a prefix arg
1556 \(e.g., \\[universal-argument]\), in which case it guesses filename near
1557 point. Useful for editing file mentioned in buffer you are viewing, or to
1558 test if that file exists. Use minibuffer after snatching filename."
1559 (interactive (list (read-filename-at-point "Find file: ")))
1560 (find-file (expand-file-name filename)))
1561
1562 (defun dired-x-find-file-other-window (filename)
1563 "Edit file FILENAME, in another window.
1564 May create a new window, or reuse an existing one.
1565 See the function `display-buffer'.
1566
1567 Identical to `find-file-other-window' except when called interactively, with a
1568 prefix arg \(e.g., \\[universal-argument]\), in which case it guesses filename
1569 near point. Useful for editing file mentioned in buffer you are viewing, or
1570 to test if that file exists. Use minibuffer after snatching filename."
1571 (interactive (list (read-filename-at-point "Find file: ")))
1572 (find-file-other-window (expand-file-name filename)))
1573
1574 ;;; Internal functions.
1509 (defun dired-filename-at-point () 1575 (defun dired-filename-at-point ()
1510 1576
1511 ;; Get the filename closest to point, but do not change position. Has a 1577 ;; Get the filename closest to point, but do not change position. Has a
1512 ;; preference for looking backward when not directly on a symbol. Not 1578 ;; preference for looking backward when not directly on a symbol. Not
1513 ;; perfect - point must be in middle of or end of filename. 1579 ;; perfect - point must be in middle of or end of filename.
1538 (error "No file found around point!")) 1604 (error "No file found around point!"))
1539 1605
1540 ;; Return string. 1606 ;; Return string.
1541 (expand-file-name (buffer-substring start (point)))))) 1607 (expand-file-name (buffer-substring start (point))))))
1542 1608
1609 (defun read-filename-at-point (prompt)
1610 ;;; Returns filename prompting with PROMPT with completion. If
1611 ;;; `current-prefix-arg' is non-nil, uses name at point as guess.
1612 (if current-prefix-arg
1613 (let ((guess (dired-filename-at-point)))
1614 (read-file-name prompt
1615 (file-name-directory guess)
1616 guess
1617 nil (file-name-nondirectory guess)))
1618 (read-file-name prompt default-directory)))
1619
1543 1620
1544 ;;;; BUG REPORTS 1621 ;;;; BUG REPORTS
1545 1622
1546 ;;; This section is provided for reports. It uses Barry A. Warsaw's 1623 ;;; This section is provided for reports. It uses Barry A. Warsaw's
1547 ;;; reporter.el which is bundled with GNU Emacs v19. 1624 ;;; reporter.el which is bundled with GNU Emacs v19.
1548 1625
1549 (defconst dired-x-version "2.31" 1626 (defconst dired-x-version "2.37"
1550 "Revision number of dired-x.el -- dired extra for GNU Emacs v19. 1627 "Revision number of dired-x.el -- dired extra for GNU Emacs v19.
1551 Type \\[dired-x-submit-report] to send a bug report. Available via anonymous 1628 Type \\[dired-x-submit-report] to send a bug report. Available via anonymous
1552 ftp in 1629 ftp in
1553 1630
1554 /roebling.poly.edu:/pub/packages/dired-x.tar.gz") 1631 /roebling.poly.edu:/pub/packages/dired-x.tar.gz")