Mercurial > emacs
comparison lisp/net/ange-ftp.el @ 46178:cd546ee24e14
Use add-hook and find-file-hook.
(ange-ftp-parse-netrc): Use run-hooks and find-file-hook.
(ange-ftp-ls-parser): Make it into a function.
Ignore trailing @ in symlink targets.
(ange-ftp-file-entry-p): Ignore FTP errors.
(ange-ftp-insert-directory): Use ange-ftp-expand-symlink
to correctly expand "/flint:/bla -> ./etc" to /flint:/etc.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 04 Jul 2002 20:37:14 +0000 |
parents | 5023425b4a55 |
children | af464c20ffb2 |
comparison
equal
deleted
inserted
replaced
46177:76bedba7ffd6 | 46178:cd546ee24e14 |
---|---|
1432 (set-buffer (generate-new-buffer "*ftp-.netrc*")) | 1432 (set-buffer (generate-new-buffer "*ftp-.netrc*")) |
1433 (ange-ftp-real-insert-file-contents file) | 1433 (ange-ftp-real-insert-file-contents file) |
1434 (setq buffer-file-name file) | 1434 (setq buffer-file-name file) |
1435 (setq default-directory (file-name-directory file)) | 1435 (setq default-directory (file-name-directory file)) |
1436 (normal-mode t) | 1436 (normal-mode t) |
1437 (mapcar 'funcall find-file-hooks) | 1437 (run-hooks 'find-file-hook) |
1438 (setq buffer-file-name nil) | 1438 (setq buffer-file-name nil) |
1439 (goto-char (point-min)) | 1439 (goto-char (point-min)) |
1440 (skip-chars-forward " \t\r\n") | 1440 (skip-chars-forward " \t\r\n") |
1441 (while (not (eobp)) | 1441 (while (not (eobp)) |
1442 (ange-ftp-parse-netrc-group)) | 1442 (ange-ftp-parse-netrc-group)) |
2758 | 2758 |
2759 ;; This deals with the F switch. Should also do something about | 2759 ;; This deals with the F switch. Should also do something about |
2760 ;; unquoting names obtained with the SysV b switch and the GNU Q | 2760 ;; unquoting names obtained with the SysV b switch and the GNU Q |
2761 ;; switch. See Sebastian's dired-get-filename. | 2761 ;; switch. See Sebastian's dired-get-filename. |
2762 | 2762 |
2763 (defmacro ange-ftp-ls-parser () | 2763 (defun ange-ftp-ls-parser () |
2764 ;; Note that switches is dynamically bound. | 2764 ;; Note that switches is dynamically bound. |
2765 ;; Meant to be called by ange-ftp-parse-dired-listing | 2765 ;; Meant to be called by ange-ftp-parse-dired-listing |
2766 `(let ((tbl (ange-ftp-make-hashtable)) | 2766 (let ((tbl (ange-ftp-make-hashtable)) |
2767 (used-F (and (stringp switches) | 2767 (used-F (and (stringp switches) |
2768 (string-match "F" switches))) | 2768 (string-match "F" switches))) |
2769 file-type symlink directory file) | 2769 file-type symlink directory file) |
2770 (while (setq file (ange-ftp-parse-filename)) | 2770 (while (setq file (ange-ftp-parse-filename)) |
2771 (beginning-of-line) | 2771 (beginning-of-line) |
2772 (skip-chars-forward "\t 0-9") | 2772 (skip-chars-forward "\t 0-9") |
2773 (setq file-type (following-char) | 2773 (setq file-type (following-char) |
2774 directory (eq file-type ?d)) | 2774 directory (eq file-type ?d)) |
2775 (if (eq file-type ?l) | 2775 (if (eq file-type ?l) |
2776 (if (string-match " -> " file) | 2776 (let ((end (string-match " -> " file))) |
2777 (setq symlink (substring file (match-end 0)) | 2777 (if end |
2778 file (substring file 0 (match-beginning 0))) | 2778 ;; Sometimes `ls' appends a @ at the end of the target. |
2779 ;; Shouldn't happen | 2779 (setq symlink (substring file (match-end 0) |
2780 (setq symlink "")) | 2780 (string-match "@\\'" file)) |
2781 (setq symlink nil)) | 2781 file (substring file 0 end)) |
2782 ;; Only do a costly regexp search if the F switch was used. | 2782 ;; Shouldn't happen |
2783 (if (and used-F | 2783 (setq symlink ""))) |
2784 (not (string-equal file "")) | 2784 (setq symlink nil)) |
2785 (looking-at | 2785 ;; Only do a costly regexp search if the F switch was used. |
2786 ".[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)")) | 2786 (if (and used-F |
2787 (let ((socket (eq file-type ?s)) | 2787 (not (string-equal file "")) |
2788 (executable | 2788 (looking-at |
2789 (and (not symlink) ; x bits don't mean a thing for symlinks | 2789 ".[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)")) |
2790 (string-match | 2790 (let ((socket (eq file-type ?s)) |
2791 "[xst]" | 2791 (executable |
2792 (concat (buffer-substring | 2792 (and (not symlink) ; x bits don't mean a thing for symlinks |
2793 (match-beginning 1) (match-end 1)) | 2793 (string-match |
2794 (buffer-substring | 2794 "[xst]" |
2795 (match-beginning 2) (match-end 2)) | 2795 (concat (buffer-substring |
2796 (buffer-substring | 2796 (match-beginning 1) (match-end 1)) |
2797 (match-beginning 3) (match-end 3))))))) | 2797 (buffer-substring |
2798 ;; Some ls's with the F switch mark symlinks with an @ (ULTRIX) | 2798 (match-beginning 2) (match-end 2)) |
2799 ;; and others don't. (sigh...) Beware, that some Unix's don't | 2799 (buffer-substring |
2800 ;; seem to believe in the F-switch | 2800 (match-beginning 3) (match-end 3))))))) |
2801 (if (or (and symlink (string-match "@$" file)) | 2801 ;; Some ls's with the F switch mark symlinks with an @ (ULTRIX) |
2802 (and directory (string-match "/$" file)) | 2802 ;; and others don't. (sigh...) Beware, that some Unix's don't |
2803 (and executable (string-match "*$" file)) | 2803 ;; seem to believe in the F-switch |
2804 (and socket (string-match "=$" file))) | 2804 (if (or (and symlink (string-match "@$" file)) |
2805 (setq file (substring file 0 -1))))) | 2805 (and directory (string-match "/$" file)) |
2806 (ange-ftp-put-hash-entry file (or symlink directory) tbl) | 2806 (and executable (string-match "*$" file)) |
2807 (forward-line 1)) | 2807 (and socket (string-match "=$" file))) |
2808 (setq file (substring file 0 -1))))) | |
2809 (ange-ftp-put-hash-entry file (or symlink directory) tbl) | |
2810 (forward-line 1)) | |
2808 (ange-ftp-put-hash-entry "." t tbl) | 2811 (ange-ftp-put-hash-entry "." t tbl) |
2809 (ange-ftp-put-hash-entry ".." t tbl) | 2812 (ange-ftp-put-hash-entry ".." t tbl) |
2810 tbl)) | 2813 tbl)) |
2811 | 2814 |
2812 ;;; The dl stuff for descriptive listings | 2815 ;;; The dl stuff for descriptive listings |
2981 ;; then dumb hosts will give an ftp error. Smart unix hosts | 2984 ;; then dumb hosts will give an ftp error. Smart unix hosts |
2982 ;; will simply send back the ls | 2985 ;; will simply send back the ls |
2983 ;; error message. | 2986 ;; error message. |
2984 (ange-ftp-get-hash-entry "." ent)) | 2987 (ange-ftp-get-hash-entry "." ent)) |
2985 ;; Child lookup failed, so try the parent. | 2988 ;; Child lookup failed, so try the parent. |
2986 (let ((table (ange-ftp-get-files dir))) | 2989 (let ((table (ange-ftp-get-files dir 'no-error))) |
2987 ;; If the dir doesn't exist, don't use it as a hash table. | 2990 ;; If the dir doesn't exist, don't use it as a hash table. |
2988 (and table | 2991 (and table |
2989 (ange-ftp-hash-entry-exists-p file | 2992 (ange-ftp-hash-entry-exists-p file |
2990 table))))))) | 2993 table))))))) |
2991 | 2994 |
4370 | 4373 |
4371 ;;; The above two forms are sufficient to cause this file to be loaded | 4374 ;;; The above two forms are sufficient to cause this file to be loaded |
4372 ;;; if the user ever uses a file name with a colon in it. | 4375 ;;; if the user ever uses a file name with a colon in it. |
4373 | 4376 |
4374 ;;; This sets the mode | 4377 ;;; This sets the mode |
4375 (or (memq 'ange-ftp-set-buffer-mode find-file-hooks) | 4378 (add-hook 'find-file-hook 'ange-ftp-set-buffer-mode) |
4376 (setq find-file-hooks | |
4377 (cons 'ange-ftp-set-buffer-mode find-file-hooks))) | |
4378 | 4379 |
4379 ;;; Now say where to find the handlers for particular operations. | 4380 ;;; Now say where to find the handlers for particular operations. |
4380 | 4381 |
4381 (put 'file-name-directory 'ange-ftp 'ange-ftp-file-name-directory) | 4382 (put 'file-name-directory 'ange-ftp 'ange-ftp-file-name-directory) |
4382 (put 'file-name-nondirectory 'ange-ftp 'ange-ftp-file-name-nondirectory) | 4383 (put 'file-name-nondirectory 'ange-ftp 'ange-ftp-file-name-nondirectory) |
4515 tem) | 4516 tem) |
4516 (if parsed | 4517 (if parsed |
4517 (if (and (not wildcard) | 4518 (if (and (not wildcard) |
4518 (setq tem (file-symlink-p (directory-file-name file)))) | 4519 (setq tem (file-symlink-p (directory-file-name file)))) |
4519 (ange-ftp-insert-directory | 4520 (ange-ftp-insert-directory |
4520 (ange-ftp-replace-name-component file tem) | 4521 (ange-ftp-expand-symlink |
4522 tem (file-name-directory (directory-file-name file))) | |
4521 switches wildcard full) | 4523 switches wildcard full) |
4522 (insert | 4524 (insert |
4523 (if wildcard | 4525 (if wildcard |
4524 (let ((default-directory (file-name-directory file))) | 4526 (let ((default-directory (file-name-directory file))) |
4525 (ange-ftp-ls (file-name-nondirectory file) switches nil nil t)) | 4527 (ange-ftp-ls (file-name-nondirectory file) switches nil nil t)) |