98
|
1 ;; -*-Emacs-Lisp-*-
|
|
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3 ;;
|
|
4 ;; File: default-dir.el
|
|
5 ;; RCS:
|
100
|
6 ;; Version: $Revision: 1.3 $
|
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
|
|
61 (if (or (featurep 'mule)
|
|
62 (boundp 'MULE))
|
|
63 (progn
|
|
64
|
|
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))
|
|
84
|
|
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))
|
|
94
|
|
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))))
|
|
125
|
|
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 (defun default-dir-find-file (file)
|
|
142 "Documented as original"
|
|
143 (interactive
|
|
144 (list
|
|
145 (expand-file-name
|
|
146 (read-file-name "Find file: " (default-directory)))))
|
|
147 (default-dir-real-find-file file))
|
|
148
|
|
149 (defun default-dir-find-file-other-window (file)
|
|
150 "Documented as original"
|
|
151 (interactive
|
|
152 (list
|
|
153 (expand-file-name
|
|
154 (read-file-name "Find file in other window: " (default-directory)))))
|
|
155 (default-dir-real-find-file-other-window file))
|
|
156
|
|
157 (defun default-dir-find-file-read-only (file)
|
|
158 "Documented as original"
|
|
159 (interactive
|
|
160 (list
|
|
161 (expand-file-name
|
|
162 (read-file-name "Find file read-only: " (default-directory) nil t))))
|
|
163 (default-dir-real-find-file-read-only file))
|
|
164
|
|
165 (if (fboundp 'find-file-read-only-other-window)
|
|
166 (progn
|
|
167 (defun default-dir-find-file-read-only-other-window (file)
|
|
168 "Documented as original"
|
|
169 (interactive
|
|
170 (list
|
|
171 (expand-file-name
|
|
172 (read-file-name
|
|
173 "Find file read-only in other window: "
|
|
174 (default-directory) nil t))))
|
|
175 (default-dir-real-find-file-read-only-other-window file))))
|
|
176
|
|
177 (if (fboundp 'find-file-other-frame)
|
|
178 (progn
|
|
179 (defun default-dir-find-file-other-frame (file)
|
|
180 "Documented as original"
|
|
181 (interactive
|
|
182 (list
|
|
183 (expand-file-name
|
|
184 (read-file-name "Find file in other frame: "
|
|
185 (default-directory)))))
|
|
186 (default-dir-real-find-file-other-frame file))))
|
|
187
|
|
188 (if (fboundp 'find-file-read-only-other-frame)
|
|
189 (progn
|
|
190 (defun default-dir-find-file-read-only-other-frame (file)
|
|
191 "Documented as original"
|
|
192 (interactive
|
|
193 (list
|
|
194 (expand-file-name
|
|
195 (read-file-name "Find file read-only in other frame: "
|
|
196 (default-directory) nil t))))
|
|
197 (default-dir-real-find-file-read-only-other-frame file)))))
|
|
198
|
|
199 (efs-overwrite-fn "default-dir" 'find-file 'default-dir-find-file)
|
|
200 (efs-overwrite-fn "default-dir" 'find-file-other-window
|
|
201 'default-dir-find-file-other-window)
|
|
202 (if (fboundp 'find-file-other-frame)
|
|
203 (efs-overwrite-fn "default-dir" 'find-file-other-frame
|
|
204 'default-dir-find-file-other-frame))
|
|
205 (efs-overwrite-fn "default-dir" 'find-file-read-only
|
|
206 'default-dir-find-file-read-only)
|
|
207 (if (fboundp 'find-file-read-only-other-window)
|
|
208 (efs-overwrite-fn "default-dir" 'find-file-read-only-other-window
|
|
209 'default-dir-find-file-read-only-other-window))
|
|
210 (if (fboundp 'find-file-read-only-other-frame)
|
|
211 (efs-overwrite-fn "default-dir" 'find-file-read-only-other-frame
|
|
212 'default-dir-find-file-read-only-other-frame))
|
|
213
|
|
214
|
|
215 (defun default-dir-load-file (file)
|
|
216 "Documented as original"
|
|
217 (interactive
|
|
218 (list
|
|
219 (expand-file-name
|
|
220 (read-file-name "Load file: " (default-directory) nil t))))
|
|
221 (default-dir-real-load-file file))
|
|
222
|
|
223 (efs-overwrite-fn "default-dir" 'load-file 'default-dir-load-file)
|
|
224
|
100
|
225 (condition-case nil
|
|
226 (require 'view-less)
|
|
227 (error (require 'view)))
|
98
|
228
|
|
229 (defun default-dir-view-file (file)
|
|
230 "Documented as original"
|
|
231 (interactive
|
|
232 (list
|
|
233 (expand-file-name
|
|
234 (read-file-name "View file: " (default-directory) nil t))))
|
|
235 (default-dir-real-view-file file))
|
|
236
|
|
237 (efs-overwrite-fn "default-dir" 'view-file 'default-dir-view-file)
|
|
238
|
|
239 (if (fboundp 'view-file-other-window)
|
|
240 (progn
|
|
241 (defun default-dir-view-file-other-window (file)
|
|
242 "Documented as original"
|
|
243 (interactive
|
|
244 (list
|
|
245 (expand-file-name
|
|
246 (read-file-name "View file in other window: "
|
|
247 (default-directory) nil t))))
|
|
248 (default-dir-real-view-file-other-window file))
|
|
249 (efs-overwrite-fn "default-dir" 'view-file-other-window
|
|
250 'default-dir-view-file-other-window)))
|
|
251
|
|
252 (if (fboundp 'view-file-other-frame)
|
|
253 (progn
|
|
254 (defun default-dir-view-file-other-frame (file)
|
|
255 "Documented as original"
|
|
256 (interactive
|
|
257 (list
|
|
258 (expand-file-name
|
|
259 (read-file-name "View file in other frame: "
|
|
260 (default-directory) nil t))))
|
|
261 (default-dir-real-view-file-other-frame file))
|
|
262 (efs-overwrite-fn "default-dir" 'view-file-other-frame
|
|
263 'default-dir-view-file-other-frame)))
|
|
264
|
|
265
|
|
266 (defun default-dir-shell-command (command &optional insert)
|
|
267 "Documented as original"
|
|
268 (interactive
|
|
269 (list
|
|
270 (let ((prompt (format "Shell command in %s: " (default-directory))))
|
|
271 (cond
|
|
272 ((memq default-dir-emacs-variant '(fsf-19 xemacs))
|
|
273 (read-from-minibuffer prompt nil nil nil
|
|
274 'shell-command-history))
|
|
275 ((featurep 'gmhist)
|
|
276 (let ((minibuffer-history-symbol 'shell-command-history))
|
|
277 (read-string prompt)))
|
|
278 (t (read-string prompt))))
|
|
279 current-prefix-arg))
|
|
280 (let ((default-directory (expand-file-name (default-directory))))
|
|
281 (default-dir-real-shell-command command insert)))
|
|
282
|
|
283 (efs-overwrite-fn "default-dir" 'shell-command 'default-dir-shell-command)
|
|
284
|
|
285 ;; Is advice about?
|
|
286 (if (featurep 'advice)
|
|
287 (defadvice cd (before default-dir-cd activate compile)
|
|
288 (interactive
|
|
289 (list
|
|
290 (expand-file-name
|
|
291 (read-file-name "Change default directory: " (default-directory))))))
|
|
292
|
|
293 (defun default-dir-cd (dir)
|
|
294 "Documented as original"
|
|
295 (interactive
|
|
296 (list
|
|
297 (expand-file-name
|
|
298 (read-file-name "Change default directory: " (default-directory)))))
|
|
299 (default-dir-real-cd dir))
|
|
300
|
|
301 (efs-overwrite-fn "default-dir" 'cd 'default-dir-cd))
|
|
302
|
|
303 (defun default-dir-set-visited-file-name (filename)
|
|
304 "Documented as original"
|
|
305 (interactive
|
|
306 (list
|
|
307 (expand-file-name
|
|
308 (read-file-name "Set visited file name: " (default-directory)))))
|
|
309 (default-dir-real-set-visited-file-name filename))
|
|
310
|
|
311 (efs-overwrite-fn "default-dir" 'set-visited-file-name
|
|
312 'default-dir-set-visited-file-name)
|
|
313
|
|
314 (defun default-dir-insert-file (filename &rest args)
|
|
315 "Documented as original"
|
|
316 (interactive
|
|
317 (list
|
|
318 (expand-file-name
|
|
319 (read-file-name "Insert file: " (default-directory) nil t))))
|
|
320 (apply 'default-dir-real-insert-file filename args))
|
|
321
|
|
322 (efs-overwrite-fn "default-dir" 'insert-file 'default-dir-insert-file)
|
|
323
|
|
324 (defun default-dir-append-to-file (start end filename &rest args)
|
|
325 "Documented as original"
|
|
326 (interactive
|
|
327 (progn
|
|
328 (or (mark) (error "The mark is not set now"))
|
|
329 (list
|
|
330 (min (mark) (point))
|
|
331 (max (mark) (point))
|
|
332 (expand-file-name
|
|
333 (read-file-name "Append to file: " (default-directory))))))
|
|
334 (apply 'default-dir-real-append-to-file start end filename args))
|
|
335
|
|
336 (efs-overwrite-fn "default-dir" 'append-to-file 'default-dir-append-to-file)
|
|
337
|
|
338 (defun default-dir-delete-file (file)
|
|
339 "Documented as original"
|
|
340 (interactive
|
|
341 (list
|
|
342 (expand-file-name
|
|
343 (read-file-name "Delete file: " (default-directory) nil t))))
|
|
344 (default-dir-real-delete-file file))
|
|
345
|
|
346 (efs-overwrite-fn "default-dir" 'delete-file 'default-dir-delete-file)
|
|
347
|
|
348 ;;; end of default-dir.el
|