diff options
| author | Chong Yidong | 2012-03-10 13:20:58 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-03-10 13:20:58 +0800 |
| commit | 82dcf4e4d8d761c26ef0a54e90e0e4a02fa4c430 (patch) | |
| tree | c410e2e33af9be126a4ce584c0e4327fc07c68db | |
| parent | 8ae818e48e84af00998ebab2ad4f9a0e3834c0f0 (diff) | |
| download | emacs-82dcf4e4d8d761c26ef0a54e90e0e4a02fa4c430.tar.gz emacs-82dcf4e4d8d761c26ef0a54e90e0e4a02fa4c430.zip | |
* dired.el (dired-goto-file): Recognize absolute file name listings.
(dired-goto-file-1): New helper function.
(dired-toggle-read-only): Inhibit warnings.
Fixes: debbugs:7126
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/dired.el | 110 |
2 files changed, 64 insertions, 53 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0684afde475..44190993887 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2012-03-10 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * dired.el (dired-goto-file): Recognize absolute file name | ||
| 4 | listings (Bug#7126). | ||
| 5 | (dired-goto-file-1): New helper function. | ||
| 6 | (dired-toggle-read-only): Inhibit warnings. | ||
| 7 | |||
| 1 | 2012-03-09 Michael Albinus <michael.albinus@gmx.de> | 8 | 2012-03-09 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 9 | ||
| 3 | * net/dbus.el: (dbus-property-handler): Return empty array if | 10 | * net/dbus.el: (dbus-property-handler): Return empty array if |
diff --git a/lisp/dired.el b/lisp/dired.el index 57bf3c88322..d26e7004cc3 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -1964,7 +1964,8 @@ Otherwise, for buffers inheriting from dired-mode, call `toggle-read-only'." | |||
| 1964 | (interactive) | 1964 | (interactive) |
| 1965 | (if (eq major-mode 'dired-mode) | 1965 | (if (eq major-mode 'dired-mode) |
| 1966 | (wdired-change-to-wdired-mode) | 1966 | (wdired-change-to-wdired-mode) |
| 1967 | (toggle-read-only))) | 1967 | (with-no-warnings |
| 1968 | (toggle-read-only)))) | ||
| 1968 | 1969 | ||
| 1969 | (defun dired-next-line (arg) | 1970 | (defun dired-next-line (arg) |
| 1970 | "Move down lines then position at filename. | 1971 | "Move down lines then position at filename. |
| @@ -2622,58 +2623,61 @@ instead of `dired-actual-switches'." | |||
| 2622 | (read-file-name "Goto file: " | 2623 | (read-file-name "Goto file: " |
| 2623 | (dired-current-directory)))) | 2624 | (dired-current-directory)))) |
| 2624 | (push-mark))) | 2625 | (push-mark))) |
| 2625 | (setq file (directory-file-name file)) ; does no harm if no directory | 2626 | (unless (file-name-absolute-p file) |
| 2626 | (let (found case-fold-search dir) | 2627 | (error "File name `%s' is not absolute" file)) |
| 2627 | (setq dir (or (file-name-directory file) | 2628 | (setq file (directory-file-name file)) ; does no harm if not a directory |
| 2628 | (error "File name `%s' is not absolute" file))) | 2629 | (let* ((case-fold-search nil) |
| 2629 | (save-excursion | 2630 | (dir (file-name-directory file)) |
| 2630 | ;; The hair here is to get the result of dired-goto-subdir | 2631 | (found (or |
| 2631 | ;; without really calling it if we don't have any subdirs. | 2632 | ;; First, look for a listing under the absolute name. |
| 2632 | (if (if (string= dir (expand-file-name default-directory)) | 2633 | (save-excursion |
| 2633 | (goto-char (point-min)) | 2634 | (goto-char (point-min)) |
| 2634 | (and (cdr dired-subdir-alist) | 2635 | (dired-goto-file-1 file file (point-max))) |
| 2635 | (dired-goto-subdir dir))) | 2636 | ;; Otherwise, look for it as a relative name. The |
| 2636 | (let ((base (file-name-nondirectory file)) | 2637 | ;; hair is to get the result of `dired-goto-subdir' |
| 2637 | search-string | 2638 | ;; without calling it if we don't have any subdirs. |
| 2638 | (boundary (dired-subdir-max))) | 2639 | (save-excursion |
| 2639 | (setq search-string | 2640 | (when (if (string= dir (expand-file-name default-directory)) |
| 2640 | (replace-regexp-in-string "\^m" "\\^m" base nil t)) | 2641 | (goto-char (point-min)) |
| 2641 | (setq search-string | 2642 | (and (cdr dired-subdir-alist) |
| 2642 | (replace-regexp-in-string "\\\\" "\\\\" search-string nil t)) | 2643 | (dired-goto-subdir dir))) |
| 2643 | (and (dired-switches-escape-p dired-actual-switches) | 2644 | (dired-goto-file-1 (file-name-nondirectory file) |
| 2644 | (string-match "[ \t\n]" search-string) | 2645 | file |
| 2645 | ;; FIXME to fix this for all possible file names | 2646 | (dired-subdir-max))))))) |
| 2646 | ;; (embedded control characters etc), we need to | 2647 | ;; Return buffer position, if found. |
| 2647 | ;; escape everything that `ls -b' does. | 2648 | (if found |
| 2648 | (setq search-string | 2649 | (goto-char found)))) |
| 2649 | (replace-regexp-in-string " " "\\ " | 2650 | |
| 2650 | search-string nil t) | 2651 | (defun dired-goto-file-1 (file full-name limit) |
| 2651 | search-string | 2652 | "Advance to the Dired listing labeled by FILE; return its position. |
| 2652 | (replace-regexp-in-string "\t" "\\t" | 2653 | Return nil if the listing is not found. If FILE contains |
| 2653 | search-string nil t) | 2654 | characters that would not appear in a Dired buffer, search using |
| 2654 | search-string | 2655 | the quoted forms of those characters. |
| 2655 | (replace-regexp-in-string "\n" "\\n" | 2656 | |
| 2656 | search-string nil t))) | 2657 | FULL-NAME specifies the actual file name the listing must have, |
| 2657 | (while (and (not found) | 2658 | as returned by `dired-get-filename'. LIMIT is the search limit." |
| 2658 | ;; filenames are preceded by SPC, this makes | 2659 | (let (str) |
| 2659 | ;; the search faster (e.g. for the filename "-"!). | 2660 | (setq str (replace-regexp-in-string "\^m" "\\^m" file nil t)) |
| 2660 | (search-forward (concat " " search-string) | 2661 | (setq str (replace-regexp-in-string "\\\\" "\\\\" str nil t)) |
| 2661 | boundary 'move)) | 2662 | (and (dired-switches-escape-p dired-actual-switches) |
| 2662 | ;; Match could have BASE just as initial substring or | 2663 | (string-match "[ \t\n]" str) |
| 2663 | ;; or in permission bits or date or | 2664 | ;; FIXME: to fix this for embedded control characters etc, we |
| 2664 | ;; not be a proper filename at all: | 2665 | ;; should escape everything that `ls -b' does. |
| 2665 | (if (equal base (dired-get-filename 'no-dir t)) | 2666 | (setq str (replace-regexp-in-string " " "\\ " str nil t) |
| 2666 | ;; Must move to filename since an (actually | 2667 | str (replace-regexp-in-string "\t" "\\t" str nil t) |
| 2667 | ;; correct) match could have been elsewhere on the | 2668 | str (replace-regexp-in-string "\n" "\\n" str nil t))) |
| 2668 | ;; ;; line (e.g. "-" would match somewhere in the | 2669 | (let ((found nil) |
| 2669 | ;; permission bits). | 2670 | ;; filenames are preceded by SPC, this makes the search faster |
| 2670 | (setq found (dired-move-to-filename)) | 2671 | ;; (e.g. for the filename "-"). |
| 2671 | ;; If this isn't the right line, move forward to avoid | 2672 | (search-string (concat " " str))) |
| 2672 | ;; trying this line again. | 2673 | (while (and (not found) |
| 2673 | (forward-line 1)))))) | 2674 | (search-forward search-string limit 'move)) |
| 2674 | (and found | 2675 | ;; Check that we are in the right place. Match could have |
| 2675 | ;; return value of point (i.e., FOUND): | 2676 | ;; BASE just as initial substring or in permission bits etc. |
| 2676 | (goto-char found)))) | 2677 | (if (equal full-name (dired-get-filename nil t)) |
| 2678 | (setq found (dired-move-to-filename)) | ||
| 2679 | (forward-line 1))) | ||
| 2680 | found))) | ||
| 2677 | 2681 | ||
| 2678 | (defvar dired-find-subdir) | 2682 | (defvar dired-find-subdir) |
| 2679 | 2683 | ||