98
|
1 ;; -*-Emacs-Lisp-*-
|
|
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3 ;;
|
|
4 ;; File: default-dir.el
|
|
5 ;; RCS:
|
114
|
6 ;; Version: $Revision: 1.4 $
|
98
|
7 ;; Description: Defines the function default-directory, for fancy handling
|
|
8 ;; of the initial contents in the minibuffer when reading
|
|
9 ;; file names.
|
|
10 ;; Authors: Sebastian Kremer <sk@thp.uni-koeln.de>
|
|
11 ;; Sandy Rutherford <sandy@ibm550.sissa.it>
|
|
12 ;; Created: Sun Jul 18 11:38:06 1993 by sandy on ibm550
|
|
13 ;;
|
|
14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
15
|
|
16 ;; This program is free software; you can redistribute it and/or modify
|
|
17 ;; it under the terms of the GNU General Public License as published by
|
|
18 ;; the Free Software Foundation; either version 1, or (at your option)
|
|
19 ;; any later version.
|
|
20
|
|
21 ;; This program is distributed in the hope that it will be useful,
|
|
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
24 ;; GNU General Public License for more details.
|
|
25
|
|
26 ;; You should have received a copy of the GNU General Public License
|
|
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
28 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
29
|
|
30 (provide 'default-dir)
|
|
31 (require 'efs-ovwrt)
|
|
32
|
|
33 (defconst default-dir-emacs-variant
|
|
34 (cond ((string-match "XEmacs" emacs-version) 'xemacs)
|
|
35 ((>= (string-to-int (substring emacs-version 0 2)) 19) 'fsf-19)
|
|
36 (t 'fsf-18)))
|
|
37
|
|
38 ;;;###autoload
|
|
39 (defvar default-directory-function nil
|
|
40 "A function to call to compute the default-directory for the current buffer.
|
|
41 If this is nil, the function default-directory will return the value of the
|
|
42 variable default-directory.
|
|
43 Buffer local.")
|
|
44 (make-variable-buffer-local 'default-directory-function)
|
|
45
|
|
46 ;; As a bonus we give shell-command history if possible.
|
|
47 (defvar shell-command-history nil
|
|
48 "History list of previous shell commands.")
|
|
49
|
|
50 (defun default-directory ()
|
|
51 " Returns the default-directory for the current buffer.
|
|
52 Will use the variable default-directory-function if it non-nil."
|
|
53 (if default-directory-function
|
|
54 (funcall default-directory-function)
|
|
55 (if (eq default-dir-emacs-variant 'xemacs)
|
|
56 (abbreviate-file-name default-directory t)
|
|
57 (abbreviate-file-name default-directory))))
|
|
58
|
|
59 ;;; Overloads
|
|
60
|
114
|
61 (cond
|
|
62 ((or (featurep 'mule)
|
|
63 (boundp 'MULE))
|
98
|
64
|
114
|
65 (defun default-dir-find-file (file &optional coding-system)
|
|
66 "Documented as original"
|
|
67 (interactive
|
|
68 (list
|
|
69 (expand-file-name
|
|
70 (read-file-name "Find file: " (default-directory)))
|
|
71 (and current-prefix-arg
|
|
72 (read-coding-system "Coding-system: "))))
|
|
73 (default-dir-real-find-file file coding-system))
|
|
74
|
|
75 (defun default-dir-find-file-other-window (file &optional coding-system)
|
|
76 "Documented as original"
|
|
77 (interactive
|
|
78 (list
|
|
79 (expand-file-name
|
|
80 (read-file-name "Find file in other window: " (default-directory)))
|
|
81 (and current-prefix-arg
|
|
82 (read-coding-system "Coding-system: "))))
|
|
83 (default-dir-real-find-file-other-window file coding-system))
|
98
|
84
|
114
|
85 (defun default-dir-find-file-read-only (file &optional coding-system)
|
|
86 "Documented as original"
|
|
87 (interactive
|
|
88 (list
|
|
89 (expand-file-name
|
|
90 (read-file-name "Find file read-only: " (default-directory) nil t))
|
|
91 (and current-prefix-arg
|
|
92 (read-coding-system "Coding-system: "))))
|
|
93 (default-dir-real-find-file-read-only file coding-system))
|
98
|
94
|
114
|
95 (if (fboundp 'find-file-read-only-other-window)
|
|
96 (progn
|
|
97 (defun default-dir-find-file-read-only-other-window
|
|
98 (file &optional coding-system)
|
|
99 "Documented as original"
|
|
100 (interactive
|
|
101 (list
|
|
102 (expand-file-name
|
|
103 (read-file-name
|
|
104 "Find file read-only in other window: "
|
|
105 (default-directory) nil t))
|
|
106 (and current-prefix-arg
|
|
107 (read-coding-system "Coding-system: "))))
|
|
108 (default-dir-real-find-file-read-only-other-window file
|
|
109 coding-system))))
|
|
110
|
|
111 (if (fboundp 'find-file-other-frame)
|
|
112 (progn
|
|
113 (defun default-dir-find-file-other-frame
|
|
114 (file &optional coding-system)
|
|
115 "Documented as original"
|
|
116 (interactive
|
|
117 (list
|
|
118 (expand-file-name
|
|
119 (read-file-name "Find file in other frame: "
|
|
120 (default-directory)))
|
|
121 (and current-prefix-arg
|
|
122 (read-coding-system "Coding-system: "))))
|
|
123 (default-dir-real-find-file-other-frame file
|
|
124 coding-system))))
|
98
|
125
|
114
|
126 (if (fboundp 'find-file-read-only-other-frame)
|
|
127 (progn
|
|
128 (defun default-dir-find-file-read-only-other-frame
|
|
129 (file &optional coding-system)
|
|
130 "Documented as original"
|
|
131 (interactive
|
|
132 (list
|
|
133 (expand-file-name
|
|
134 (read-file-name "Find file read-only in other frame: "
|
|
135 (default-directory) nil t))
|
|
136 (and current-prefix-arg
|
|
137 (read-coding-system "Coding-system: "))))
|
|
138 (default-dir-real-find-file-read-only-other-frame file
|
|
139 coding-system)))))
|
|
140
|
|
141 (default-dir-find-file-takes-coding-system
|
|
142 ;; This lossage is due to the fact that XEmacs 20.x without mule
|
|
143 ;; still accepts an optional argument for find-file related
|
|
144 ;; functions. Things like advice.el insist on passing nil for
|
|
145 ;; optional arguments, and the interaction screws things up.
|
|
146 ;; Therefore these functions accept an optional dummy coding-system
|
|
147 ;; argument.
|
|
148
|
|
149 (defun default-dir-find-file (file &optional coding-system)
|
|
150 "Documented as original"
|
|
151 (interactive
|
|
152 (list
|
|
153 (expand-file-name
|
|
154 (read-file-name "Find file: " (default-directory)))))
|
|
155 (default-dir-real-find-file file coding-system))
|
|
156
|
|
157 (defun default-dir-find-file-other-window (file &optional coding-system)
|
|
158 "Documented as original"
|
|
159 (interactive
|
|
160 (list
|
|
161 (expand-file-name
|
|
162 (read-file-name "Find file in other window: " (default-directory)))))
|
|
163 (default-dir-real-find-file-other-window file coding-system))
|
98
|
164
|
114
|
165 (defun default-dir-find-file-read-only (file &optional coding-system)
|
|
166 "Documented as original"
|
|
167 (interactive
|
|
168 (list
|
|
169 (expand-file-name
|
|
170 (read-file-name "Find file read-only: " (default-directory) nil t))))
|
|
171 (default-dir-real-find-file-read-only file coding-system))
|
98
|
172
|
114
|
173 (if (fboundp 'find-file-read-only-other-window)
|
|
174 (progn
|
|
175 (defun default-dir-find-file-read-only-other-window
|
|
176 (file &optional coding-system)
|
|
177 "Documented as original"
|
|
178 (interactive
|
|
179 (list
|
|
180 (expand-file-name
|
|
181 (read-file-name
|
|
182 "Find file read-only in other window: "
|
|
183 (default-directory) nil t))))
|
|
184 (default-dir-real-find-file-read-only-other-window file))))
|
98
|
185
|
114
|
186 (if (fboundp 'find-file-other-frame)
|
|
187 (progn
|
|
188 (defun default-dir-find-file-other-frame
|
|
189 (file &optional coding-system)
|
|
190 "Documented as original"
|
|
191 (interactive
|
|
192 (list
|
|
193 (expand-file-name
|
|
194 (read-file-name "Find file in other frame: "
|
|
195 (default-directory)))))
|
|
196 (default-dir-real-find-file-other-frame file))))
|
|
197
|
|
198 (if (fboundp 'find-file-read-only-other-frame)
|
|
199 (progn
|
|
200 (defun default-dir-find-file-read-only-other-frame
|
|
201 (file &optional coding-system)
|
|
202 "Documented as original"
|
|
203 (interactive
|
|
204 (list
|
|
205 (expand-file-name
|
|
206 (read-file-name "Find file read-only in other frame: "
|
|
207 (default-directory) nil t))))
|
|
208 (default-dir-real-find-file-read-only-other-frame file)))))
|
|
209
|
|
210 (t
|
98
|
211 (defun default-dir-find-file (file)
|
|
212 "Documented as original"
|
|
213 (interactive
|
|
214 (list
|
|
215 (expand-file-name
|
|
216 (read-file-name "Find file: " (default-directory)))))
|
|
217 (default-dir-real-find-file file))
|
|
218
|
|
219 (defun default-dir-find-file-other-window (file)
|
|
220 "Documented as original"
|
|
221 (interactive
|
|
222 (list
|
|
223 (expand-file-name
|
|
224 (read-file-name "Find file in other window: " (default-directory)))))
|
|
225 (default-dir-real-find-file-other-window file))
|
|
226
|
|
227 (defun default-dir-find-file-read-only (file)
|
|
228 "Documented as original"
|
|
229 (interactive
|
|
230 (list
|
|
231 (expand-file-name
|
|
232 (read-file-name "Find file read-only: " (default-directory) nil t))))
|
|
233 (default-dir-real-find-file-read-only file))
|
|
234
|
|
235 (if (fboundp 'find-file-read-only-other-window)
|
|
236 (progn
|
|
237 (defun default-dir-find-file-read-only-other-window (file)
|
|
238 "Documented as original"
|
|
239 (interactive
|
|
240 (list
|
|
241 (expand-file-name
|
|
242 (read-file-name
|
|
243 "Find file read-only in other window: "
|
|
244 (default-directory) nil t))))
|
|
245 (default-dir-real-find-file-read-only-other-window file))))
|
|
246
|
|
247 (if (fboundp 'find-file-other-frame)
|
|
248 (progn
|
|
249 (defun default-dir-find-file-other-frame (file)
|
|
250 "Documented as original"
|
|
251 (interactive
|
|
252 (list
|
|
253 (expand-file-name
|
|
254 (read-file-name "Find file in other frame: "
|
|
255 (default-directory)))))
|
|
256 (default-dir-real-find-file-other-frame file))))
|
|
257
|
|
258 (if (fboundp 'find-file-read-only-other-frame)
|
|
259 (progn
|
|
260 (defun default-dir-find-file-read-only-other-frame (file)
|
|
261 "Documented as original"
|
|
262 (interactive
|
|
263 (list
|
|
264 (expand-file-name
|
|
265 (read-file-name "Find file read-only in other frame: "
|
|
266 (default-directory) nil t))))
|
114
|
267 (default-dir-real-find-file-read-only-other-frame file))))))
|
|
268
|
|
269
|
98
|
270
|
|
271 (efs-overwrite-fn "default-dir" 'find-file 'default-dir-find-file)
|
|
272 (efs-overwrite-fn "default-dir" 'find-file-other-window
|
|
273 'default-dir-find-file-other-window)
|
|
274 (if (fboundp 'find-file-other-frame)
|
|
275 (efs-overwrite-fn "default-dir" 'find-file-other-frame
|
|
276 'default-dir-find-file-other-frame))
|
|
277 (efs-overwrite-fn "default-dir" 'find-file-read-only
|
|
278 'default-dir-find-file-read-only)
|
|
279 (if (fboundp 'find-file-read-only-other-window)
|
|
280 (efs-overwrite-fn "default-dir" 'find-file-read-only-other-window
|
|
281 'default-dir-find-file-read-only-other-window))
|
|
282 (if (fboundp 'find-file-read-only-other-frame)
|
|
283 (efs-overwrite-fn "default-dir" 'find-file-read-only-other-frame
|
|
284 'default-dir-find-file-read-only-other-frame))
|
|
285
|
|
286
|
|
287 (defun default-dir-load-file (file)
|
|
288 "Documented as original"
|
|
289 (interactive
|
|
290 (list
|
|
291 (expand-file-name
|
|
292 (read-file-name "Load file: " (default-directory) nil t))))
|
|
293 (default-dir-real-load-file file))
|
|
294
|
|
295 (efs-overwrite-fn "default-dir" 'load-file 'default-dir-load-file)
|
|
296
|
100
|
297 (condition-case nil
|
|
298 (require 'view-less)
|
|
299 (error (require 'view)))
|
98
|
300
|
|
301 (defun default-dir-view-file (file)
|
|
302 "Documented as original"
|
|
303 (interactive
|
|
304 (list
|
|
305 (expand-file-name
|
|
306 (read-file-name "View file: " (default-directory) nil t))))
|
|
307 (default-dir-real-view-file file))
|
|
308
|
|
309 (efs-overwrite-fn "default-dir" 'view-file 'default-dir-view-file)
|
|
310
|
|
311 (if (fboundp 'view-file-other-window)
|
|
312 (progn
|
|
313 (defun default-dir-view-file-other-window (file)
|
|
314 "Documented as original"
|
|
315 (interactive
|
|
316 (list
|
|
317 (expand-file-name
|
|
318 (read-file-name "View file in other window: "
|
|
319 (default-directory) nil t))))
|
|
320 (default-dir-real-view-file-other-window file))
|
|
321 (efs-overwrite-fn "default-dir" 'view-file-other-window
|
|
322 'default-dir-view-file-other-window)))
|
|
323
|
|
324 (if (fboundp 'view-file-other-frame)
|
|
325 (progn
|
|
326 (defun default-dir-view-file-other-frame (file)
|
|
327 "Documented as original"
|
|
328 (interactive
|
|
329 (list
|
|
330 (expand-file-name
|
|
331 (read-file-name "View file in other frame: "
|
|
332 (default-directory) nil t))))
|
|
333 (default-dir-real-view-file-other-frame file))
|
|
334 (efs-overwrite-fn "default-dir" 'view-file-other-frame
|
|
335 'default-dir-view-file-other-frame)))
|
|
336
|
|
337
|
|
338 (defun default-dir-shell-command (command &optional insert)
|
|
339 "Documented as original"
|
|
340 (interactive
|
|
341 (list
|
|
342 (let ((prompt (format "Shell command in %s: " (default-directory))))
|
|
343 (cond
|
|
344 ((memq default-dir-emacs-variant '(fsf-19 xemacs))
|
|
345 (read-from-minibuffer prompt nil nil nil
|
|
346 'shell-command-history))
|
|
347 ((featurep 'gmhist)
|
|
348 (let ((minibuffer-history-symbol 'shell-command-history))
|
|
349 (read-string prompt)))
|
|
350 (t (read-string prompt))))
|
|
351 current-prefix-arg))
|
|
352 (let ((default-directory (expand-file-name (default-directory))))
|
|
353 (default-dir-real-shell-command command insert)))
|
|
354
|
|
355 (efs-overwrite-fn "default-dir" 'shell-command 'default-dir-shell-command)
|
|
356
|
114
|
357 (defun default-dir-cd (dir)
|
|
358 "Documented as original"
|
|
359 (interactive
|
|
360 (list
|
|
361 (expand-file-name
|
|
362 (read-file-name "Change default directory: " (default-directory)))))
|
|
363 (default-dir-real-cd dir))
|
98
|
364
|
114
|
365 (efs-overwrite-fn "default-dir" 'cd 'default-dir-cd)
|
98
|
366
|
|
367 (defun default-dir-set-visited-file-name (filename)
|
|
368 "Documented as original"
|
|
369 (interactive
|
|
370 (list
|
|
371 (expand-file-name
|
|
372 (read-file-name "Set visited file name: " (default-directory)))))
|
|
373 (default-dir-real-set-visited-file-name filename))
|
|
374
|
|
375 (efs-overwrite-fn "default-dir" 'set-visited-file-name
|
|
376 'default-dir-set-visited-file-name)
|
|
377
|
|
378 (defun default-dir-insert-file (filename &rest args)
|
|
379 "Documented as original"
|
|
380 (interactive
|
|
381 (list
|
|
382 (expand-file-name
|
|
383 (read-file-name "Insert file: " (default-directory) nil t))))
|
|
384 (apply 'default-dir-real-insert-file filename args))
|
|
385
|
|
386 (efs-overwrite-fn "default-dir" 'insert-file 'default-dir-insert-file)
|
|
387
|
|
388 (defun default-dir-append-to-file (start end filename &rest args)
|
|
389 "Documented as original"
|
|
390 (interactive
|
|
391 (progn
|
|
392 (or (mark) (error "The mark is not set now"))
|
|
393 (list
|
|
394 (min (mark) (point))
|
|
395 (max (mark) (point))
|
|
396 (expand-file-name
|
|
397 (read-file-name "Append to file: " (default-directory))))))
|
|
398 (apply 'default-dir-real-append-to-file start end filename args))
|
|
399
|
|
400 (efs-overwrite-fn "default-dir" 'append-to-file 'default-dir-append-to-file)
|
|
401
|
|
402 (defun default-dir-delete-file (file)
|
|
403 "Documented as original"
|
|
404 (interactive
|
|
405 (list
|
|
406 (expand-file-name
|
|
407 (read-file-name "Delete file: " (default-directory) nil t))))
|
|
408 (default-dir-real-delete-file file))
|
|
409
|
|
410 (efs-overwrite-fn "default-dir" 'delete-file 'default-dir-delete-file)
|
|
411
|
|
412 ;;; end of default-dir.el
|