annotate lisp/efs/emacs-19.el @ 24:4103f0995bd7 r19-15b95

Import from CVS: tag r19-15b95
author cvs
date Mon, 13 Aug 2007 08:51:03 +0200
parents 8fc7fe29b841
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;;;; Emacs 19 compatibility functions for use in Emacs 18.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;;; Based on: $Id: emacs-19.el,v 1.1 1997/02/11 05:05:14 steve Exp $
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4 ;;;; Rewritten by sandy@ibm550.sissa.it after gnu emacs 19 was
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;;;; released to make it closer to V19.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6 ;;;; Last modified: Sun Jun 12 00:06:06 1994 by sandy on ibm550
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;;; This program is free software; you can redistribute it and/or modify
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;;; it under the terms of the GNU General Public License as published by
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;;; the Free Software Foundation; either version 1, or (at your option)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;;; any later version.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 ;;; This program is distributed in the hope that it will be useful,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;;; GNU General Public License for more details.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 ;;; A copy of the GNU General Public License can be obtained from this
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 ;;; 02139, USA.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 ;; These functions are used in dired.el, but are also of general
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 ;; interest, so you may want to add this to your .emacs:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 ;; (autoload 'make-directory "emacs-19" "Make a directory." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27 ;; (autoload 'delete-directory "emacs-19" "Remove a directory." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 ;; (autoload 'member "emacs-19" "Like memq, but uses `equal' instead of `eq'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 ;; (autoload 'compiled-function-p "emacs-19" "Emacs 18 doesn't have these.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31 (provide 'emacs-19)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 ;;; Variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 (defvar insert-directory-program "ls"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 "Absolute or relative name of the `ls' program used by `insert-directory'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 (defvar bv-length) ; make the byte compiler a happy camper
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 (defconst directory-abbrev-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 "*Alist of abbreviations for file directories.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 A list of elements of the form (FROM . TO), each meaning to replace
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 FROM with TO when it appears in a directory name. This replacement is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 done when setting up the default directory of a newly visited file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 *Every* FROM string should start with `^'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 Use this feature when you have directories which you normally refer to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 via absolute symbolic links. Make TO the name of the link, and FROM
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 the name it is linked to.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 (defconst automount-dir-prefix "^/tmp_mnt/"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 "Regexp to match the automounter prefix in a directory name.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 (defvar abbreviated-home-dir nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 "The the user's homedir abbreviated according to `directory-abbrev-list'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 ;;; Autoloads
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 (autoload 'diff "diff" "Diff two files." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (autoload 'diff-backup "diff" "Diff a file with its most recent backup.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 ;;; Functions which are subroutines in Emacs 19.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 ;; Provide a non-working version of find-file-name-handler.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 ;; If you want it to work, require 'fn-handler.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (or (fboundp 'find-file-name-handler) (fset 'find-file-name-handler 'ignore))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (or (boundp 'file-name-handler-alist) (defvar file-name-handler-alist nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 ;; The name of buffer-flush-undo has changed in V19.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 (fset 'buffer-disable-undo 'buffer-flush-undo)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 (defun current-time ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 "Returns the number of seconds since midnight.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 A poor man's version of the the function `current-time' in emacs 19."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 (let ((string (current-time-string)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (+ (* 3600 (string-to-int (substring string 11 13)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 (* 60 (string-to-int (substring string 14 16)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (string-to-int (substring string 17 19)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 ;; call-process below may lose if filename starts with a `-', but I
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 ;; fear not all mkdir or rmdir implementations understand `--'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (defun delete-directory (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 "Delete a directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 This is a subr in Emacs 19."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 (list (read-file-name "Delete directory: " nil nil 'confirm)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (setq fn (expand-file-name fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 (if (file-directory-p fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (call-process "rmdir" nil nil nil fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 (error "Not a directory: %s" fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (if (file-exists-p fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 (error "Could not remove directory %s" fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (defun make-directory (dir &optional parents)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 "Create the directory DIR and any nonexistent parent dirs."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 (interactive "FMake directory: \nP")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 (if (not parents)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 (make-directory-internal dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 (let ((dir (directory-file-name (expand-file-name dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 create-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107 (while (not (file-exists-p dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 (setq create-list (cons dir create-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 dir (directory-file-name (file-name-directory dir))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 (while create-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 (make-directory-internal (car create-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (setq create-list (cdr create-list))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 (defun make-directory-internal (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 ;; This is a subroutine in emacs 19.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (let* ((fn (expand-file-name fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 (handler (find-file-name-handler fn 'make-directory-internal)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 (funcall handler 'make-directory-internal fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 (setq fn (directory-file-name fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 (if (file-exists-p fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 (error "Cannot make directory %s: file already exists" fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 (call-process "mkdir" nil nil nil fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 (or (file-directory-p fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (error "Could not make directory %s" fn)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 (defun kill-new (string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 "Save STRING as if killed in a buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 (setq kill-ring (cons string kill-ring))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 (if (> (length kill-ring) kill-ring-max)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 (setq kill-ring-yank-pointer kill-ring))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 (defun insert-directory (file switches &optional wildcard full-directory-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 "Insert directory listing for FILE, formatted according to SWITCHES.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 Leaves point after the inserted text.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 SWITCHES may be a string of options, or a list of strings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 Optional third arg WILDCARD means treat FILE as shell wildcard.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 switches do not contain `d', so that a full listing is expected.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 This works by running a directory listing program
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 whose name is in the variable `insert-directory-program'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 If WILDCARD, it also runs the shell specified by `shell-file-name'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 ;; We need the directory in order to find the right handler.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 (let ((handler (find-file-name-handler (expand-file-name file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 'insert-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 (funcall handler 'insert-directory file switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 wildcard full-directory-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (if (eq system-type 'vax-vms)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 (vms-read-directory file switches (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 (if wildcard
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 ;; Run ls in the directory of the file pattern we asked for.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 (let ((default-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 (if (file-name-absolute-p file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 (file-name-directory file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 (file-name-directory (expand-file-name file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 (pattern (file-name-nondirectory file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160 (beg 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
161 ;; Quote some characters that have special meanings in shells;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 ;; but don't quote the wildcards--we want them to be special.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 ;; We also currently don't quote the quoting characters
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164 ;; in case people want to use them explicitly to quote
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 ;; wildcard characters.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
166 (while (string-match "[ \t\n;<>&|()#$]" pattern beg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
167 (setq pattern
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
168 (concat (substring pattern 0 (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
169 "\\"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170 (substring pattern (match-beginning 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171 beg (1+ (match-end 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172 (call-process shell-file-name nil t nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173 "-c" (concat insert-directory-program
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174 " -d "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175 (if (stringp switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
176 switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
177 (mapconcat 'identity switches " "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
178 " "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
179 pattern)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
180 ;; SunOS 4.1.3, SVr4 and others need the "." to list the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
181 ;; directory if FILE is a symbolic link.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
182 (apply 'call-process
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
183 insert-directory-program nil t nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
184 (let (list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
185 (if (listp switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
186 (setq list switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
187 (if (not (equal switches ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
188 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
189 ;; Split the switches at any spaces
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
190 ;; so we can pass separate options as separate args.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
191 (while (string-match " " switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
192 (setq list (cons (substring switches 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
193 (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
194 list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
195 switches (substring switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
196 (match-end 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
197 (setq list (cons switches list)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
198 (append list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
199 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
200 (if full-directory-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
201 (concat (file-name-as-directory file) ".")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
202 file))))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
203
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
204 (defun file-local-copy (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
205 "Copy the file FILE into a temporary file on this machine.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
206 Returns the name of the local copy, or nil, if FILE is directly
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
207 accessible."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
208 (let* ((file (expand-file-name file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
209 (handler (find-file-name-handler file 'file-local-copy)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
210 ;; Does nothing, if no handler.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
211 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
212 (funcall handler 'file-local-copy file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
213
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
214 (defun file-truename (filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
215 "Return the truename of FILENAME, which should be absolute.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
216 The truename of a file name is found by chasing symbolic links
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
217 both at the level of the file and at the level of the directories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
218 containing it, until no links are left at any level."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
219 (if (or (string= filename "~")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
220 (and (string= (substring filename 0 1) "~")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
221 (string-match "~[^/]*" filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
222 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
223 (setq filename (expand-file-name filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
224 (if (string= filename "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
225 (setq filename "/"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
226 (let ((handler (find-file-name-handler filename 'file-truename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
227 ;; For file name that has a special handler, call handler.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
228 ;; This is so that ange-ftp can save time by doing a no-op.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
229 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
230 (funcall handler 'file-truename filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
231 (let ((dir (file-name-directory filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
232 target dirfile file-name-handler-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
233 ;; Get the truename of the directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
234 (setq dirfile (directory-file-name dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
235 ;; If these are equal, we have the (or a) root directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
236 (or (string= dir dirfile)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
237 (setq dir (file-name-as-directory (file-truename dirfile))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
238 (if (equal ".." (file-name-nondirectory filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
239 (directory-file-name (file-name-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
240 (directory-file-name dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
241 (if (equal "." (file-name-nondirectory filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
242 (directory-file-name dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
243 ;; Put it back on the file name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
244 (setq filename (concat dir (file-name-nondirectory filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
245 ;; Is the file name the name of a link?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
246 (setq target (file-symlink-p filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
247 (if target
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
248 ;; Yes => chase that link, then start all over
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
249 ;; since the link may point to a directory name that uses links.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
250 ;; We can't safely use expand-file-name here
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
251 ;; since target might look like foo/../bar where foo
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
252 ;; is itself a link. Instead, we handle . and .. above.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
253 (if (file-name-absolute-p target)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
254 (file-truename target)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
255 (file-truename (concat dir target)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
256 ;; No, we are done!
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
257 filename)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
258
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
259 (defun generate-new-buffer-name (name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
260 "Return a string which is the name of no existing buffer based on
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
261 NAME. If there is no live buffer named NAME, return NAME. Otherwise,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
262 modify name by appending `<NUMBER>', incrementing NUMBER until an
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
263 unused name is found. Return that name."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
264 (if (get-buffer name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
265 (let ((num 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
266 attempt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
267 (while (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
268 (setq attempt (concat name "<" (int-to-string num) ">"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
269 (get-buffer attempt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
270 (setq num (1+ num)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
271 attempt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
272 name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
273
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
274 (defun abbreviate-file-name (filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
275 "Return a version of FILENAME shortened using `directory-abbrev-alist'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
276 This also substitutes \"~\" for the user's home directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
277 Type \\[describe-variable] directory-abbrev-alist RET for more information."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
278 ;; Get rid of the prefixes added by the automounter.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
279 (if (and (string-match automount-dir-prefix filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
280 (file-exists-p (file-name-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
281 (substring filename (1- (match-end 0))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
282 (setq filename (substring filename (1- (match-end 0)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
283 (let ((tail directory-abbrev-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
284 ;; If any elt of directory-abbrev-alist matches this name,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
285 ;; abbreviate accordingly.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
286 (while tail
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
287 (if (string-match (car (car tail)) filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
288 (setq filename
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
289 (concat (cdr (car tail)) (substring filename (match-end 0)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
290 (setq tail (cdr tail)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
291 ;; Compute and save the abbreviated homedir name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
292 ;; We defer computing this until the first time it's needed, to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
293 ;; give time for directory-abbrev-alist to be set properly.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
294 (or abbreviated-home-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
295 (setq abbreviated-home-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
296 (let ((abbreviated-home-dir "$foo"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
297 (concat "^" (abbreviate-file-name (expand-file-name "~"))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
298 ;; If FILENAME starts with the abbreviated homedir,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
299 ;; make it start with `~' instead.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
300 (if (string-match abbreviated-home-dir filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
301 (setq filename
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
302 (concat "~"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
303 ;; If abbreviated-home-dir ends with a slash,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
304 ;; don't remove the corresponding slash from
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
305 ;; filename. On MS-DOS and OS/2, you can have
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
306 ;; home directories like "g:/", in which it is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
307 ;; important not to remove the slash. And what
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
308 ;; about poor root on Unix systems?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
309 (if (eq ?/ (aref abbreviated-home-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
310 (1- (length abbreviated-home-dir))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
311 "/"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
312 "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
313 (substring filename (match-end 0)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
314 filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
315
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
316 (defun file-newest-backup (filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
317 "Return most recent backup file for FILENAME or nil if no backups exist."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
318 (let* ((filename (expand-file-name filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
319 (file (file-name-nondirectory filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
320 (dir (file-name-directory filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
321 (comp (file-name-all-completions file dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
322 newest)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
323 (while comp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
324 (setq file (concat dir (car comp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
325 comp (cdr comp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
326 (if (and (backup-file-name-p file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
327 (or (null newest) (file-newer-than-file-p file newest)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
328 (setq newest file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
329 newest))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
330
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
331 ;; This is used in various files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
332 ;; The usage of bv-length is not very clean,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
333 ;; but I can't see a good alternative,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
334 ;; so as of now I am leaving it alone.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
335 (defun backup-extract-version (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
336 "Given the name of a numeric backup file, return the backup number.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
337 Uses the free variable `bv-length', whose value should be
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
338 the index in the name where the version number begins."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
339 (if (and (string-match "[0-9]+~$" fn bv-length)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
340 (= (match-beginning 0) bv-length))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
341 (string-to-int (substring fn bv-length -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
342 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
343
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
344 ;; The standard V18 version of this function doesn't support
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
345 ;; the arg KEEP-BACKUP-VERSION
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
346 (defun file-name-sans-versions (name &optional keep-backup-version)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
347 "Return FILENAME sans backup versions or strings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
348 This is a separate procedure so your site-init or startup file can
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
349 redefine it.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
350 If the optional argument KEEP-BACKUP-VERSION is non-nil,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
351 we do not remove backup version numbers, only true file version numbers."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
352 (let ((handler (find-file-name-handler name 'file-name-sans-versions)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
353 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
354 (funcall handler 'file-name-sans-versions name keep-backup-version)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
355 (substring name 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
356 (if (eq system-type 'vax-vms)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
357 ;; VMS version number is (a) semicolon, optional
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
358 ;; sign, zero or more digits or (b) period, option
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
359 ;; sign, zero or more digits, provided this is the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
360 ;; second period encountered outside of the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
361 ;; device/directory part of the file name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
362 (or (string-match ";[-+]?[0-9]*\\'" name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
363 (if (string-match "\\.[^]>:]*\\(\\.[-+]?[0-9]*\\)\\'"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
364 name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
365 (match-beginning 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
366 (length name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
367 (if keep-backup-version
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
368 (length name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
369 (or (string-match "\\.~[0-9]+~\\'" name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
370 (string-match "~\\'" name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
371 (length name))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
372
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
373 (defun member (x y)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
374 "Like memq, but uses `equal' for comparison.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
375 This is a subr in Emacs 19."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
376 (while (and y (not (equal x (car y))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
377 (setq y (cdr y)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
378 y)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
379
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
380 (defun compiled-function-p (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
381 "Emacs 18 doesn't have these."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
382 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
383
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
384 ;; punt -- this will at least allow handlers to work for this.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
385 (defun set-visited-file-modtime (&optional time)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
386 (error "set-visited-file-modtime not defined in emacs 18."))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
387
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
388 (defun add-hook (hook function &optional append)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
389 "Add to the value of HOOK the function FUNCTION.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
390 FUNCTION is not added if already present.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
391 FUNCTION is added (if necessary) at the beginning of the hook list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
392 unless the optional argument APPEND is non-nil, in which case
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
393 FUNCTION is added at the end.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
394
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
395 HOOK should be a symbol, and FUNCTION may be any valid function. If
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
396 HOOK is void, it is first set to nil. If HOOK's value is a single
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
397 function, it is changed to a list of functions."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
398 (or (boundp hook) (set hook nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
399 ;; If the hook value is a single function, turn it into a list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
400 (let ((old (symbol-value hook)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
401 (if (or (not (listp old)) (eq (car old) 'lambda))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
402 (set hook (list old))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
403 (or (if (consp function)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
404 ;; Clever way to tell whether a given lambda-expression
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
405 ;; is equal to anything in the hook.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
406 (let ((tail (assoc (cdr function) (symbol-value hook))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
407 (equal function tail))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
408 (memq function (symbol-value hook)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
409 (set hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
410 (if append
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
411 (nconc (symbol-value hook) (list function))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
412 (cons function (symbol-value hook))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
413
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
414 ;;; after-save.el (Now part of files.el in Gnu Emacs V19)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
415
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
416 ;;; Copyright (C) 1990 Roland McGrath
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
417 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
418
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
419 (or (fboundp 'real-save-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
420 (fset 'real-save-buffer (symbol-function 'save-buffer)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
421
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
422 (defvar after-save-hook nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
423 "A function or list of functions to be run after saving the current buffer.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
424
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
425 (defun save-buffer (&optional args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
426 "Save the current buffer, and then run `after-save-buffer-hook'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
427 The hooks are only run if the buffer was actually written.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
428 For more documentation, do \\[describe-function] real-save-buffer RET."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
429 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
430 (let ((modp (buffer-modified-p)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
431 (real-save-buffer args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
432 (if modp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
433 (run-hooks 'after-save-hook))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
434
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
435 ;;; end of after-save
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
436
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
437 ;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
438 ;;;; Correcting for V18 bugs, and hacking around stupidities.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
439 ;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
440
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
441 ;; The 18.57 version has a bug that causes C-x C-v RET (which usually
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
442 ;; re-visits the current buffer) to fail on dired buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
443 ;; Only the last statement was changed to avoid killing the current
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
444 ;; buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
445 (defun find-alternate-file (filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
446 "Find file FILENAME, select its buffer, kill previous buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
447 If the current buffer now contains an empty file that you just visited
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
448 \(presumably by mistake), use this command to visit the file you really want."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
449 (interactive "FFind alternate file: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
450 (and (buffer-modified-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
451 (not buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
452 (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
453 (buffer-name))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
454 (error "Aborted"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
455 (let ((obuf (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
456 (ofile buffer-file-name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
457 (oname (buffer-name)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
458 (rename-buffer " **lose**")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
459 (setq buffer-file-name nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
460 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
461 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
462 (unlock-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
463 (find-file filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
464 (cond ((eq obuf (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
465 (setq buffer-file-name ofile)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
466 (lock-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
467 (rename-buffer oname))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
468 (or (eq (current-buffer) obuf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
469 (kill-buffer obuf))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
470
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
471 ;; At least in Emacs 18.55 this defvar has been forgotten to be copied
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
472 ;; from lpr.el into loaddefs.el
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
473
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
474 (defvar lpr-command (if (eq system-type 'usg-unix-v)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
475 "lp" "lpr")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
476 "Shell command for printing a file")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
477
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
478
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
479 ;; buffer-disable-undo used to be called buffer-flush-undo in Emacs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
480 ;; 18.55:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
481 (or (fboundp 'buffer-disable-undo)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
482 (fset 'buffer-disable-undo 'buffer-flush-undo))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
483
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
484 ;;; end of emacs-19.el