aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1992-09-13 04:35:22 +0000
committerRichard M. Stallman1992-09-13 04:35:22 +0000
commitc3554e95658a0ea4b90cc4d6110664c12d463b5a (patch)
tree00cd42e03486cd8abe6e4eaf4c598e6e469fdb87
parent078a88f4d69b422af3cb8defe4d7f97590437b60 (diff)
downloademacs-c3554e95658a0ea4b90cc4d6110664c12d463b5a.tar.gz
emacs-c3554e95658a0ea4b90cc4d6110664c12d463b5a.zip
*** empty log message ***
-rw-r--r--lisp/ange-ftp.el276
-rw-r--r--lisp/dired.el52
-rw-r--r--lisp/files.el117
3 files changed, 114 insertions, 331 deletions
diff --git a/lisp/ange-ftp.el b/lisp/ange-ftp.el
index 4be219f87f1..a08f010d53f 100644
--- a/lisp/ange-ftp.el
+++ b/lisp/ange-ftp.el
@@ -3704,6 +3704,7 @@ to the directory part of the contents of the current buffer."
3704(put 'file-attributes 'ange-ftp 'ange-ftp-file-attributes) 3704(put 'file-attributes 'ange-ftp 'ange-ftp-file-attributes)
3705(put 'file-name-all-completions 'ange-ftp 'ange-ftp-file-name-all-completions) 3705(put 'file-name-all-completions 'ange-ftp 'ange-ftp-file-name-all-completions)
3706(put 'file-name-completion 'ange-ftp 'ange-ftp-file-name-completion) 3706(put 'file-name-completion 'ange-ftp 'ange-ftp-file-name-completion)
3707(put 'insert-directory 'ange-ftp 'ange-ftp-insert-directory)
3707 3708
3708;;; Define ways of getting at unmodified Emacs primitives, 3709;;; Define ways of getting at unmodified Emacs primitives,
3709;;; turning off our handler. 3710;;; turning off our handler.
@@ -3780,128 +3781,21 @@ to the directory part of the contents of the current buffer."
3780(defun ange-ftp-real-file-name-completion (&rest args) 3781(defun ange-ftp-real-file-name-completion (&rest args)
3781 (let (file-name-handler-alist) 3782 (let (file-name-handler-alist)
3782 (apply 'file-name-completion args))) 3783 (apply 'file-name-completion args)))
3783 3784(defun ange-ftp-real-insert-directory (&rest args)
3784;;; This is obsolete and won't work 3785 (let (file-name-handler-alist)
3785 3786 (apply 'insert-directory args)))
3786;; Attention!
3787;; It would be nice if ange-ftp-add-hook was generalized to
3788;; (defun ange-ftp-add-hook (hook-var hook-function &optional postpend),
3789;; where the optional postpend variable stipulates that hook-function
3790;; should be post-pended to the hook-var, rather than prepended.
3791;; Then, maybe we should overwrite dired with
3792;; (ange-ftp-add-hook 'dired-load-hook 'ange-ftp-overwrite-dired t).
3793;; This is because dired-load-hook is commonly used to add the dired extras
3794;; features (dired-x.el, dired-trns.el, dired-nstd.el, ...). Some of these
3795;; extras features overwrite functions in dired.el with fancier versions.
3796;; The "extras" overwrites would then clobber the ange-ftp overwrites.
3797;; As long as the ange-ftp overwrites are carefully written to use
3798;; ange-ftp-real-... when the directory is local, then doing the ange-ftp
3799;; overwrites after the extras overwites should be OK.
3800;; At the moment, I think that there aren't any conflicts between the extras
3801;; overwrites, and the ange-ftp overwrites. This may not last though.
3802
3803(defun ange-ftp-add-hook (hook-var hook-function)
3804 "Prepend hook-function to hook-var's value, if it is not already an element.
3805hook-var's value may be a single function or a list of functions."
3806 (if (boundp hook-var)
3807 (let ((value (symbol-value hook-var)))
3808 (if (and (listp value) (not (eq (car value) 'lambda)))
3809 (and (not (memq hook-function value))
3810 (set hook-var
3811 (if value (cons hook-function value) hook-function)))
3812 (and (not (eq hook-function value))
3813 (set hook-var
3814 (list hook-function value)))))
3815 (set hook-var hook-function)))
3816
3817;; To load ange-ftp and not dired (leaving it to autoload), define
3818;; dired-load-hook and make sure dired.el ends with:
3819;; (run-hooks 'dired-load-hook)
3820;;
3821(if (and (boundp 'dired-load-hook)
3822 (not (featurep 'dired)))
3823 (ange-ftp-add-hook 'dired-load-hook 'ange-ftp-overwrite-dired)
3824 (require 'dired)
3825 (ange-ftp-overwrite-dired))
3826
3827(defun ange-ftp-overwrite-dired ()
3828 (if (not (fboundp 'dired-ls)) ;dired should have been loaded by now
3829 (ange-ftp-overwrite-fn 'dired-readin) ; classic dired
3830 (ange-ftp-overwrite-fn 'make-directory) ; tree dired and v19 stuff
3831 (ange-ftp-overwrite-fn 'remove-directory)
3832 (ange-ftp-overwrite-fn 'diff)
3833 (ange-ftp-overwrite-fn 'dired-run-shell-command)
3834 (ange-ftp-overwrite-fn 'dired-ls)
3835 (ange-ftp-overwrite-fn 'dired-call-process)
3836 ;; Can't use (fset 'ange-ftp-dired-readin 'ange-ftp-tree-dired-readin)
3837 ;; here because it confuses ange-ftp-overwrite-fn.
3838 (fset 'ange-ftp-dired-readin (symbol-function 'ange-ftp-tree-dired-readin))
3839 (ange-ftp-overwrite-fn 'dired-readin)
3840 (ange-ftp-overwrite-fn 'dired-insert-headerline)
3841 (ange-ftp-overwrite-fn 'dired-move-to-filename)
3842 (ange-ftp-overwrite-fn 'dired-move-to-end-of-filename)
3843 (ange-ftp-overwrite-fn 'dired-get-filename)
3844 (ange-ftp-overwrite-fn 'dired-between-files)
3845 (ange-ftp-overwrite-fn 'dired-clean-directory)
3846 (ange-ftp-overwrite-fn 'dired-flag-backup-files)
3847 (ange-ftp-overwrite-fn 'dired-backup-diff)
3848 (if (fboundp 'dired-do-create-files)
3849 ;; dired 6.0 or later.
3850 (progn
3851 (ange-ftp-overwrite-fn 'dired-copy-file)
3852 (ange-ftp-overwrite-fn 'dired-create-files)
3853 (ange-ftp-overwrite-fn 'dired-do-create-files)))
3854 (if (fboundp 'dired-compress-make-compressed-filename)
3855 ;; it's V5.255 or later
3856 (ange-ftp-overwrite-fn 'dired-compress-make-compressed-filename)
3857 ;; ange-ftp-overwrite-fn confuses dired-mark-map here.
3858 (fset 'ange-ftp-real-dired-compress (symbol-function 'dired-compress))
3859 (fset 'dired-compress 'ange-ftp-dired-compress)
3860 (fset 'ange-ftp-real-dired-uncompress (symbol-function 'dired-uncompress))
3861 (fset 'dired-uncompress 'ange-ftp-dired-uncompress)))
3862
3863 (ange-ftp-overwrite-fn 'dired-find-file)
3864 (ange-ftp-overwrite-fn 'dired-revert))
3865 3787
3866;;;; ------------------------------------------------------------ 3788;;;; ------------------------------------------------------------
3867;;;; Classic Dired support. 3789;;;; Classic Dired support.
3868;;;; ------------------------------------------------------------ 3790;;;; ------------------------------------------------------------
3869 3791
3870(defvar ange-ftp-dired-host-type nil 3792(defun ange-ftp-insert-directory (file switches &optional wildcard full)
3871 "The host type associated with a dired buffer. (buffer local)")
3872(make-variable-buffer-local 'ange-ftp-dired-host-type)
3873
3874(defun ange-ftp-dired-readin (dirname buffer)
3875 "Documented as original." 3793 "Documented as original."
3876 (let ((file (ange-ftp-abbreviate-filename dirname)) 3794 (setq file (ange-ftp-abbreviate-filename file))
3877 (parsed (ange-ftp-ftp-path dirname))) 3795 (let ((parsed (ange-ftp-ftp-path file)))
3878 (save-excursion 3796 (if parsed
3879 (ange-ftp-message "Reading directory %s..." file) 3797 (insert (ange-ftp-ls dirname switches t))
3880 (set-buffer buffer) 3798 (ange-ftp-real-insert-directory file switches wildcard full))))
3881 (let ((buffer-read-only nil))
3882 (widen)
3883 (erase-buffer)
3884 (setq dirname (expand-file-name dirname))
3885 (if parsed
3886 (let ((host-type (ange-ftp-host-type (car parsed))))
3887 (setq ange-ftp-dired-host-type host-type)
3888 (insert (ange-ftp-ls dirname dired-listing-switches t)))
3889 (if (ange-ftp-real-file-directory-p dirname)
3890 (call-process "ls" nil buffer nil
3891 dired-listing-switches dirname)
3892 (let ((default-directory
3893 (ange-ftp-real-file-name-directory dirname)))
3894 (call-process
3895 shell-file-name nil buffer nil
3896 "-c" (concat
3897 "ls " dired-listing-switches " "
3898 (ange-ftp-real-file-name-nondirectory dirname))))))
3899 (goto-char (point-min))
3900 (while (not (eobp))
3901 (insert " ")
3902 (forward-line 1))
3903 (goto-char (point-min))))
3904 (ange-ftp-message "Reading directory %s...done" file)))
3905 3799
3906(defun ange-ftp-dired-revert (&optional arg noconfirm) 3800(defun ange-ftp-dired-revert (&optional arg noconfirm)
3907 "Documented as original." 3801 "Documented as original."
@@ -3909,147 +3803,21 @@ hook-var's value may be a single function or a list of functions."
3909 (ange-ftp-ftp-path (expand-file-name dired-directory))) 3803 (ange-ftp-ftp-path (expand-file-name dired-directory)))
3910 (setq ange-ftp-ls-cache-file nil)) 3804 (setq ange-ftp-ls-cache-file nil))
3911 (ange-ftp-real-dired-revert arg noconfirm)) 3805 (ange-ftp-real-dired-revert arg noconfirm))
3912
3913;;;; ------------------------------------------------------------
3914;;;; Tree Dired support (ange & Sebastian Kremer)
3915;;;; ------------------------------------------------------------
3916
3917(defvar ange-ftp-dired-re-exe-alist nil
3918 "Association list of regexps \(strings\) which match file lines of
3919 executable files.")
3920
3921(defvar ange-ftp-dired-re-dir-alist nil
3922 "Association list of regexps \(strings\) which match file lines of
3923 subdirectories.")
3924
3925(defvar ange-ftp-dired-insert-headerline-alist nil
3926 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
3927the function to be used by dired to insert the headerline of
3928the dired buffer.")
3929
3930(defvar ange-ftp-dired-move-to-filename-alist nil
3931 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
3932the function to be used by dired to move to the beginning of a
3933filename.")
3934
3935(defvar ange-ftp-dired-move-to-end-of-filename-alist nil
3936 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
3937the function to be used by dired to move to the end of a
3938filename.")
3939
3940(defvar ange-ftp-dired-get-filename-alist nil
3941 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
3942the function to be used by dired to get a filename from the
3943current line.")
3944
3945(defvar ange-ftp-dired-between-files-alist nil
3946 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
3947the function to be used by dired to determine when the point
3948is on a line between files.")
3949
3950(defvar ange-ftp-dired-ls-trim-alist nil
3951 "Association list of \( TYPE \. FUNC \) pairs, where FUNC is
3952a function which trims extraneous lines from a directory listing.")
3953
3954(defvar ange-ftp-dired-clean-directory-alist nil
3955 "Association list of \( TYPE \. FUNC \) pairs, where FUNC is
3956a function which cleans out old versions of files in the OS TYPE.")
3957
3958(defvar ange-ftp-dired-flag-backup-files-alist nil
3959 "Association list of \( TYPE \. FUNC \) pairs, where FUNC is
3960a functions which flags the backup files for deletion in the OS TYPE.")
3961
3962(defvar ange-ftp-dired-backup-diff-alist nil
3963 "Association list of \( TYPE \. FUNC \) pairs, where FUNC diffs
3964a file with its backup. The backup file is determined according to
3965the OS TYPE.")
3966
3967;; Could use dired-before-readin-hook here, instead of overloading
3968;; dired-readin. However, if people change this hook after ange-ftp
3969;; is loaded, they'll break things.
3970;; Also, why overload dired-readin rather than dired-mode?
3971;; Because I don't want to muck up virtual dired (see dired-x.el).
3972
3973(defun ange-ftp-tree-dired-readin (dirname buffer)
3974 "Documented as original."
3975 (let ((parsed (ange-ftp-ftp-path dirname)))
3976 (if parsed
3977 (save-excursion
3978 (set-buffer buffer)
3979 (setq ange-ftp-dired-host-type
3980 (ange-ftp-host-type (car parsed)))
3981 (and ange-ftp-dl-dir-regexp
3982 (eq ange-ftp-dired-host-type 'unix)
3983 (string-match ange-ftp-dl-dir-regexp dirname)
3984 (setq ange-ftp-dired-host-type 'unix:dl))
3985 (let ((eentry (assq ange-ftp-dired-host-type
3986 ange-ftp-dired-re-exe-alist))
3987 (dentry (assq ange-ftp-dired-host-type
3988 ange-ftp-dired-re-dir-alist)))
3989 (if eentry
3990 (set (make-local-variable 'dired-re-exe) (cdr eentry)))
3991 (if dentry
3992 (set (make-local-variable 'dired-re-dir) (cdr dentry)))
3993 ;; No switches are sent to dumb hosts, so don't confuse dired.
3994 ;; I hope that dired doesn't get excited if it doesn't see the l
3995 ;; switch. If it does, then maybe fake things by setting this to
3996 ;; "-Al".
3997 (if (memq ange-ftp-dired-host-type ange-ftp-dumb-host-types)
3998 (setq dired-actual-switches "-Al"))))))
3999 (ange-ftp-real-dired-readin dirname buffer))
4000
4001(defun ange-ftp-dired-insert-headerline (dir)
4002 "Documented as original."
4003 (funcall (or (and ange-ftp-dired-host-type
4004 (cdr (assq ange-ftp-dired-host-type
4005 ange-ftp-dired-insert-headerline-alist)))
4006 'ange-ftp-real-dired-insert-headerline)
4007 dir))
4008
4009(defun ange-ftp-dired-move-to-filename (&optional raise-error eol)
4010 "Documented as original."
4011 (funcall (or (and ange-ftp-dired-host-type
4012 (cdr (assq ange-ftp-dired-host-type
4013 ange-ftp-dired-move-to-filename-alist)))
4014 'ange-ftp-real-dired-move-to-filename)
4015 raise-error eol))
4016 3806
4017(defun ange-ftp-dired-move-to-end-of-filename (&optional no-error) 3807(defvar ange-ftp-sans-version-alist nil
4018 "Documented as original." 3808 "Alist of mapping host type into function to remove file version numbers.")
4019 (funcall (or (and ange-ftp-dired-host-type
4020 (cdr (assq ange-ftp-dired-host-type
4021 ange-ftp-dired-move-to-end-of-filename-alist)))
4022 'ange-ftp-real-dired-move-to-end-of-filename)
4023 no-error))
4024 3809
4025(defun ange-ftp-dired-get-filename (&optional localp no-error-if-not-filep) 3810(defun ange-ftp-file-name-sans-versions (file keep-backup-version)
4026 "Documented as original." 3811 "Documented as original."
4027 (funcall (or (and ange-ftp-dired-host-type 3812 (setq file (ange-ftp-abbreviate-filename file))
4028 (cdr (assq ange-ftp-dired-host-type 3813 (let ((parsed (ange-ftp-ftp-path file))
4029 ange-ftp-dired-get-filename-alist))) 3814 host-type func)
4030 'ange-ftp-real-dired-get-filename) 3815 (if parsed
4031 localp no-error-if-not-filep)) 3816 (setq host-type (ange-ftp-host-type (car parsed))
4032 3817 func (cdr (assq ange-ftp-dired-host-type
4033(defun ange-ftp-dired-between-files () 3818 ange-ftp-sans-version-alist))))
4034 "Documented as original." 3819 (if func (funcall func file keep-backup-version)
4035 (funcall (or (and ange-ftp-dired-host-type 3820 (ange-ftp-real-file-name-sans-versions file keep-backup-version))))
4036 (cdr (assq ange-ftp-dired-host-type
4037 ange-ftp-dired-between-files-alist)))
4038 'ange-ftp-real-dired-between-files)))
4039
4040(defvar ange-ftp-bob-version-alist nil
4041 "Association list of pairs \( TYPE \. FUNC \), where FUNC is
4042a function to be used to bob the version number off of a filename
4043in OS TYPE.")
4044
4045(defun ange-ftp-dired-find-file ()
4046 "Documented as original."
4047 (interactive)
4048 (find-file (funcall (or (and ange-ftp-dired-host-type
4049 (cdr (assq ange-ftp-dired-host-type
4050 ange-ftp-bob-version-alist)))
4051 'identity)
4052 (dired-get-filename))))
4053 3821
4054;; Need the following functions for making filenames of compressed 3822;; Need the following functions for making filenames of compressed
4055;; files, because some OS's (unlike UNIX) do not allow a filename to 3823;; files, because some OS's (unlike UNIX) do not allow a filename to
diff --git a/lisp/dired.el b/lisp/dired.el
index 99ae4681075..d4788e7cac6 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -50,13 +50,9 @@ may contain even `F', `b', `i' and `s'.")
50 "Name of chown command (usully `chown' or `/etc/chown').") 50 "Name of chown command (usully `chown' or `/etc/chown').")
51 51
52;;;###autoload 52;;;###autoload
53(defvar dired-ls-program "ls"
54 "Absolute or relative name of the `ls' program used by dired.")
55
56;;;###autoload
57(defvar dired-ls-F-marks-symlinks nil 53(defvar dired-ls-F-marks-symlinks nil
58 "*Informs dired about how `ls -lF' marks symbolic links. 54 "*Informs dired about how `ls -lF' marks symbolic links.
59Set this to t if `dired-ls-program' with `-lF' marks the symbolic link 55Set this to t if `insert-directory-program' with `-lF' marks the symbolic link
60itself with a trailing @ (usually the case under Ultrix). 56itself with a trailing @ (usually the case under Ultrix).
61 57
62Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to 58Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to
@@ -307,39 +303,6 @@ Optional second argument ARG forces to use other files. If ARG is an
307 303
308;; Function dired-ls is redefinable for VMS, ange-ftp, Prospero or 304;; Function dired-ls is redefinable for VMS, ange-ftp, Prospero or
309;; other special applications. 305;; other special applications.
310
311;; dired-ls
312;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
313;; FULL-DIRECTORY-P is nil.
314;; The single line of output must display FILE's name as it was
315;; given, namely, an absolute path name.
316;; - must insert exactly one line for each file if WILDCARD or
317;; FULL-DIRECTORY-P is t, plus one optional "total" line
318;; before the file lines, plus optional text after the file lines.
319;; Lines are delimited by "\n", so filenames containing "\n" are not
320;; allowed.
321;; File lines should display the basename, not a path name.
322;; - must drag point after inserted text
323;; - must be consistent with
324;; - functions dired-move-to-filename, (these two define what a file line is)
325;; dired-move-to-end-of-filename,
326;; dired-between-files, (shortcut for (not (dired-move-to-filename)))
327;; dired-insert-headerline
328;; dired-after-subdir-garbage (defines what a "total" line is)
329;; - variables dired-subdir-regexp
330(defun dired-ls (file switches &optional wildcard full-directory-p)
331; "Insert `ls' output of FILE, formatted according to SWITCHES.
332;Optional third arg WILDCARD means treat FILE as shell wildcard.
333;Optional fourth arg FULL-DIRECTORY-P means file is a directory and
334;switches do not contain `d', so that a full listing is expected.
335;
336;Uses dired-ls-program (and shell-file-name if WILDCARD) to do the work."
337 (if wildcard
338 (let ((default-directory (file-name-directory file)))
339 (call-process shell-file-name nil t nil
340 "-c" (concat dired-ls-program " -d " switches " "
341 (file-name-nondirectory file))))
342 (call-process dired-ls-program nil t nil switches file)))
343 306
344;; The dired command 307;; The dired command
345 308
@@ -496,12 +459,12 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
496(defun dired-readin-insert (dirname) 459(defun dired-readin-insert (dirname)
497 ;; Just insert listing for DIRNAME, assuming a clean buffer. 460 ;; Just insert listing for DIRNAME, assuming a clean buffer.
498 (if (equal default-directory dirname);; i.e., (file-directory-p dirname) 461 (if (equal default-directory dirname);; i.e., (file-directory-p dirname)
499 (dired-ls dirname dired-actual-switches nil t) 462 (insert-directory dirname dired-actual-switches nil t)
500 (if (not (file-readable-p 463 (if (not (file-readable-p
501 (directory-file-name (file-name-directory dirname)))) 464 (directory-file-name (file-name-directory dirname))))
502 (error "Directory %s inaccessible or nonexistent" dirname) 465 (error "Directory %s inaccessible or nonexistent" dirname)
503 ;; else assume it contains wildcards: 466 ;; else assume it contains wildcards:
504 (dired-ls dirname dired-actual-switches t) 467 (insert-directory dirname dired-actual-switches t)
505 (save-excursion;; insert wildcard instead of total line: 468 (save-excursion;; insert wildcard instead of total line:
506 (goto-char (point-min)) 469 (goto-char (point-min))
507 (insert "wildcard " (file-name-nondirectory dirname) "\n"))))) 470 (insert "wildcard " (file-name-nondirectory dirname) "\n")))))
@@ -881,7 +844,7 @@ Creates a buffer if necessary."
881(defun dired-find-file () 844(defun dired-find-file ()
882 "In dired, visit the file or directory named on this line." 845 "In dired, visit the file or directory named on this line."
883 (interactive) 846 (interactive)
884 (find-file (dired-get-filename))) 847 (find-file (file-name-sans-versions (dired-get-filename) t)))
885 848
886(defun dired-view-file () 849(defun dired-view-file ()
887 "In dired, examine a file in view mode, returning to dired when done. 850 "In dired, examine a file in view mode, returning to dired when done.
@@ -891,17 +854,18 @@ otherwise, display it in another buffer."
891 (if (file-directory-p (dired-get-filename)) 854 (if (file-directory-p (dired-get-filename))
892 (or (and dired-subdir-alist (dired-goto-subdir (dired-get-filename))) 855 (or (and dired-subdir-alist (dired-goto-subdir (dired-get-filename)))
893 (dired (dired-get-filename))) 856 (dired (dired-get-filename)))
894 (view-file (dired-get-filename)))) 857 (view-file (file-name-sans-versions (dired-get-filename) t))))
895 858
896(defun dired-find-file-other-window () 859(defun dired-find-file-other-window ()
897 "In dired, visit this file or directory in another window." 860 "In dired, visit this file or directory in another window."
898 (interactive) 861 (interactive)
899 (find-file-other-window (dired-get-filename))) 862 (find-file-other-window (file-name-sans-versions (dired-get-filename) t)))
900 863
901(defun dired-display-file () 864(defun dired-display-file ()
902 "In dired, display this file or directory in another window." 865 "In dired, display this file or directory in another window."
903 (interactive) 866 (interactive)
904 (display-buffer (find-file-noselect (dired-get-filename)))) 867 (let ((file (file-name-sans-versions (dired-get-filename) t)))
868 (display-buffer (find-file-noselect file))))
905 869
906;;; Functions for extracting and manipulating file names in dired buffers. 870;;; Functions for extracting and manipulating file names in dired buffers.
907 871
diff --git a/lisp/files.el b/lisp/files.el
index 07c2d2c301e..bd7cf7d8864 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -824,25 +824,38 @@ the modes of the new file to agree with the old modes."
824 setmodes) 824 setmodes)
825 (file-error nil))))) 825 (file-error nil)))))
826 826
827(defun file-name-sans-versions (name) 827(defun file-name-sans-versions (name &optional keep-backup-version)
828 "Return FILENAME sans backup versions or strings. 828 "Return FILENAME sans backup versions or strings.
829This is a separate procedure so your site-init or startup file can 829This is a separate procedure so your site-init or startup file can
830redefine it." 830redefine it.
831 (substring name 0 831If the optional argument KEEP-BACKUP-VERSION is non-nil,
832 (if (eq system-type 'vax-vms) 832we do not remove backup version numbers, only true file version numbers."
833 ;; VMS version number is (a) semicolon, optional 833 (let (handler (handlers file-name-handler-alist))
834 ;; sign, zero or more digits or (b) period, option 834 (while (and (consp handlers) (null handler))
835 ;; sign, zero or more digits, provided this is the 835 (if (and (consp (car handlers))
836 ;; second period encountered outside of the 836 (stringp (car (car handlers)))
837 ;; device/directory part of the file name. 837 (string-match (car (car handlers)) name))
838 (or (string-match ";[---+]?[0-9]*\\'" name) 838 (setq handler (cdr (car handlers))))
839 (if (string-match "\\.[^]>:]*\\(\\.[---+]?[0-9]*\\)\\'" 839 (setq handlers (cdr handlers)))
840 name) 840 (if handler
841 (match-beginning 1)) 841 (funcall handler 'file-name-sans-versions name keep-backup-version)
842 (length name)) 842 (substring name 0
843 (or (string-match "\\.~[0-9]+~\\'" name) 843 (if (eq system-type 'vax-vms)
844 (string-match "~\\'" name) 844 ;; VMS version number is (a) semicolon, optional
845 (length name))))) 845 ;; sign, zero or more digits or (b) period, option
846 ;; sign, zero or more digits, provided this is the
847 ;; second period encountered outside of the
848 ;; device/directory part of the file name.
849 (or (string-match ";[---+]?[0-9]*\\'" name)
850 (if (string-match "\\.[^]>:]*\\(\\.[---+]?[0-9]*\\)\\'"
851 name)
852 (match-beginning 1))
853 (length name))
854 (if keep-backup-version
855 (length name)
856 (or (string-match "\\.~[0-9]+~\\'" name)
857 (string-match "~\\'" name)
858 (length name))))))))
846 859
847(defun make-backup-file-name (file) 860(defun make-backup-file-name (file)
848 "Create the non-numeric backup file name for FILE. 861 "Create the non-numeric backup file name for FILE.
@@ -1380,23 +1393,61 @@ and `list-directory-verbose-switches'."
1380 (princ "Directory ") 1393 (princ "Directory ")
1381 (princ dirname) 1394 (princ dirname)
1382 (terpri) 1395 (terpri)
1396 (save-excursion
1397 (set-buffer "*Directory*")
1398 (let ((wildcard (not (file-directory-p dirname))))
1399 (insert-directory dirname switches wildcard (not wildcard)))))))
1400
1401(defvar insert-directory-program "ls"
1402 "Absolute or relative name of the `ls' program used by `insert-directory'.")
1403
1404;; insert-directory
1405;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
1406;; FULL-DIRECTORY-P is nil.
1407;; The single line of output must display FILE's name as it was
1408;; given, namely, an absolute path name.
1409;; - must insert exactly one line for each file if WILDCARD or
1410;; FULL-DIRECTORY-P is t, plus one optional "total" line
1411;; before the file lines, plus optional text after the file lines.
1412;; Lines are delimited by "\n", so filenames containing "\n" are not
1413;; allowed.
1414;; File lines should display the basename.
1415;; - must be consistent with
1416;; - functions dired-move-to-filename, (these two define what a file line is)
1417;; dired-move-to-end-of-filename,
1418;; dired-between-files, (shortcut for (not (dired-move-to-filename)))
1419;; dired-insert-headerline
1420;; dired-after-subdir-garbage (defines what a "total" line is)
1421;; - variable dired-subdir-regexp
1422(defun insert-directory (file switches &optional wildcard full-directory-p)
1423 "Insert directory listing for of FILE, formatted according to SWITCHES.
1424Leaves point after the inserted text.
1425Optional third arg WILDCARD means treat FILE as shell wildcard.
1426Optional fourth arg FULL-DIRECTORY-P means file is a directory and
1427switches do not contain `d', so that a full listing is expected.
1428
1429This works by running a directory listing program
1430whose name is in the variable `ls-program'.
1431If WILDCARD, it also runs the shell specified by `shell-file-name'."
1432 (let (handler (handlers file-name-handler-alist))
1433 (while (and (consp handlers) (null handler))
1434 (if (and (consp (car handlers))
1435 (stringp (car (car handlers)))
1436 (string-match (car (car handlers)) file))
1437 (setq handler (cdr (car handlers))))
1438 (setq handlers (cdr handlers)))
1439 (if handler
1440 (funcall handler 'insert-directory file switches
1441 wildcard full-directory-p)
1383 (if (eq system-type 'vax-vms) 1442 (if (eq system-type 'vax-vms)
1384 (vms-read-directory dirname switches standard-output) 1443 (vms-read-directory file switches (current-buffer))
1385 (if (file-directory-p dirname) 1444 (if wildcard
1386 (save-excursion 1445 (let ((default-directory (file-name-directory file)))
1387 (set-buffer "*Directory*") 1446 (call-process shell-file-name nil t nil
1388 (call-process "ls" nil standard-output nil switches 1447 "-c" (concat insert-directory-program
1389 (setq default-directory 1448 " -d " switches " "
1390 (file-name-as-directory dirname)))) 1449 (file-name-nondirectory file))))
1391 (let ((default-directory (file-name-directory dirname))) 1450 (call-process insert-directory-program nil t nil switches file))))))
1392 (if (file-exists-p default-directory)
1393 (call-process shell-file-name nil standard-output nil
1394 "-c" (concat "exec ls "
1395 switches " "
1396 (file-name-nondirectory dirname)))
1397 (princ "No such directory: ")
1398 (princ dirname)
1399 (terpri))))))))
1400 1451
1401(defun save-buffers-kill-emacs (&optional arg) 1452(defun save-buffers-kill-emacs (&optional arg)
1402 "Offer to save each buffer, then kill this Emacs process. 1453 "Offer to save each buffer, then kill this Emacs process.