diff options
| author | Richard M. Stallman | 1994-06-28 18:41:05 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-06-28 18:41:05 +0000 |
| commit | ccb1d39acef811b9d392a4b1c0f577a81ce32b76 (patch) | |
| tree | e714b58900de5c71de6f39357148097d46320580 | |
| parent | be4d8b37c8f38063e80aa9f3f7427af60e69c6cb (diff) | |
| download | emacs-ccb1d39acef811b9d392a4b1c0f577a81ce32b76.tar.gz emacs-ccb1d39acef811b9d392a4b1c0f577a81ce32b76.zip | |
(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.
| -rw-r--r-- | lisp/dired-x.el | 121 |
1 files changed, 99 insertions, 22 deletions
diff --git a/lisp/dired-x.el b/lisp/dired-x.el index d800bbb9aa8..f2da28e92f6 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el | |||
| @@ -3,8 +3,8 @@ | |||
| 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 |
| @@ -31,9 +31,11 @@ | |||
| 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 | ;;; | ||
| 35 | ;;; *Please* see the info pages. | ||
| 36 | 34 | ||
| 35 | ;;; | ||
| 36 | ;;; Please, PLEASE, *PLEASE* see the info pages. | ||
| 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, |
| @@ -49,6 +51,22 @@ | |||
| 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 |
| @@ -56,6 +74,7 @@ | |||
| 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 |
| @@ -1488,24 +1507,71 @@ to mark all zero length files." | |||
| 1488 | 1507 | ||
| 1489 | 1508 | ||
| 1490 | ;;;; FIND FILE AT POINT. | 1509 | ;;;; FIND FILE AT POINT. |
| 1491 | (defun dired-find-this-file (&optional other-window) | ||
| 1492 | "Edit filename or directory at point. | ||
| 1493 | Switch to a buffer visiting filename, creating one if none already exists. | ||
| 1494 | With non-nil prefix argument OTHER-WINDOW do so in the other window. | ||
| 1495 | 1510 | ||
| 1496 | Useful for editing the file mentioned in the buffer you are viewing, or to | 1511 | (defvar dired-x-hands-off-my-keys t |
| 1497 | test if that file exists. Use minibuffer after snatching the filename." | 1512 | "*t means don't bind `dired-x-find-file' over `find-file' on keyboard. |
| 1498 | 1513 | Similarly for `dired-x-find-file-other-window' over `find-file-other-window'. | |
| 1499 | (interactive "P") | 1514 | If you change this variable after dired-x.el is loaded then do |
| 1500 | (let* ((guess (dired-filename-at-point)) | 1515 | \\[dired-x-bind-find-file].") |
| 1501 | (file (read-file-name "Find file: " guess guess nil nil))) | 1516 | |
| 1502 | (if other-window | 1517 | ;;; Bind `dired-x-find-file{-other-window}' over wherever |
| 1503 | (find-file-other-window (expand-file-name file)) | 1518 | ;;; `find-file{-other-window}' is bound? |
| 1504 | (find-file (expand-file-name file))))) | 1519 | (defun dired-x-bind-find-file () |
| 1505 | 1520 | "Bind `dired-x-find-file' in place of `find-file' \(or reverse\). | |
| 1506 | (fset 'find-this-file 'dired-find-this-file) | 1521 | Similarly for `dired-x-find-file-other-window' and `find-file-other-window'. |
| 1507 | 1522 | Binding direction based on `dired-x-hands-off-my-keys'. | |
| 1508 | ;;; Internal function. | 1523 | This function part of `after-init-hook'." |
| 1524 | (interactive) | ||
| 1525 | (if (interactive-p) | ||
| 1526 | (setq dired-x-hands-off-my-keys | ||
| 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 |
| @@ -1540,13 +1606,24 @@ test if that file exists. Use minibuffer after snatching the filename." | |||
| 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 |