Mercurial > emacs
annotate lisp/eshell/em-dirs.el @ 30779:aa097d8d4f1a
(xml-parse-tag, xml-parse-attlist): Do not downcase
identifiers, since XML is case sensitive
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 14 Aug 2000 12:43:55 +0000 |
parents | 34b1ab9d583d |
children | 10b1c85c0bbe |
rev | line source |
---|---|
29876 | 1 ;;; em-dirs --- directory navigation commands |
2 | |
29934
34b1ab9d583d
Change spelling of the Free Software Foundation.
Gerd Moellmann <gerd@gnu.org>
parents:
29876
diff
changeset
|
3 ;; Copyright (C) 1999, 2000 Free Software Foundation |
29876 | 4 |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 2, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 ;; Boston, MA 02111-1307, USA. | |
21 | |
22 (provide 'em-dirs) | |
23 | |
24 (eval-when-compile (require 'esh-maint)) | |
25 | |
26 (defgroup eshell-dirs nil | |
27 "Directory navigation involves changing directories, examining the | |
28 current directory, maintaining a directory stack, and also keeping | |
29 track of a history of the last directory locations the user was in. | |
30 Emacs does provide standard Lisp definitions of `pwd' and `cd', but | |
31 they lack somewhat in feel from the typical shell equivalents." | |
32 :tag "Directory navigation" | |
33 :group 'eshell-module) | |
34 | |
35 ;;; Commentary: | |
36 | |
37 ;; The only special feature that Eshell offers in the last-dir-ring. | |
38 ;; To view the ring, enter: | |
39 ;; | |
40 ;; cd = | |
41 ;; | |
42 ;; Changing to an index within the ring is done using: | |
43 ;; | |
44 ;; cd - ; same as cd -0 | |
45 ;; cd -4 | |
46 ;; | |
47 ;; Or, it is possible to change the first member in the ring which | |
48 ;; matches a regexp: | |
49 ;; | |
50 ;; cd =bcc ; change to the last directory visited containing "bcc" | |
51 ;; | |
52 ;; This ring is maintained automatically, and is persisted across | |
53 ;; Eshell sessions. It is a separate mechanism from `pushd' and | |
54 ;; `popd', and the two may be used at the same time. | |
55 | |
56 (require 'ring) | |
57 (require 'esh-opt) | |
58 | |
59 ;;; User Variables: | |
60 | |
61 (defcustom eshell-dirs-load-hook '(eshell-dirs-initialize) | |
62 "*A hook that gets run when `eshell-dirs' is loaded." | |
63 :type 'hook | |
64 :group 'eshell-dirs) | |
65 | |
66 (defcustom eshell-pwd-convert-function (if (eshell-under-windows-p) | |
67 'expand-file-name | |
68 'identity) | |
69 "*The function used to normalize the value of Eshell's `pwd'. | |
70 The value returned by `pwd' is also used when recording the | |
71 last-visited directory in the last-dir-ring, so it will affect the | |
72 form of the list used by 'cd ='." | |
73 :type '(radio (function-item file-truename) | |
74 (function-item expand-file-name) | |
75 (function-item identity) | |
76 (function :tag "Other")) | |
77 :group 'eshell-dirs) | |
78 | |
79 (defcustom eshell-ask-to-save-last-dir 'always | |
80 "*Determine if the last-dir-ring should be automatically saved. | |
81 The last-dir-ring is always preserved when exiting an Eshell buffer. | |
82 However, when Emacs is being shut down, this variable determines | |
83 whether to prompt the user, or just save the ring. | |
84 If set to nil, it means never ask whether to save the last-dir-ring. | |
85 If set to t, always ask if any Eshell buffers are open at exit time. | |
86 If set to `always', the list-dir-ring will always be saved, silently." | |
87 :type '(choice (const :tag "Never" nil) | |
88 (const :tag "Ask" t) | |
89 (const :tag "Always save" always)) | |
90 :group 'eshell-dirs) | |
91 | |
92 (defcustom eshell-cd-shows-directory nil | |
93 "*If non-nil, using `cd' will report the directory it changes to." | |
94 :type 'boolean | |
95 :group 'eshell-dirs) | |
96 | |
97 (defcustom eshell-cd-on-directory t | |
98 "*If non-nil, do a cd if a directory is in command position." | |
99 :type 'boolean | |
100 :group 'eshell-dirs) | |
101 | |
102 (defcustom eshell-directory-change-hook nil | |
103 "*A hook to run when the current directory changes." | |
104 :type 'hook | |
105 :group 'eshell-dirs) | |
106 | |
107 (defcustom eshell-list-files-after-cd nil | |
108 "*If non-nil, call \"ls\" with any remaining args after doing a cd. | |
109 This is provided for convenience, since the same effect is easily | |
110 achieved by adding a function to `eshell-directory-change-hook' that | |
111 calls \"ls\" and references `eshell-last-arguments'." | |
112 :type 'boolean | |
113 :group 'eshell-dirs) | |
114 | |
115 (defcustom eshell-pushd-tohome nil | |
116 "*If non-nil, make pushd with no arg behave as 'pushd ~' (like `cd'). | |
117 This mirrors the optional behavior of tcsh." | |
118 :type 'boolean | |
119 :group 'eshell-dirs) | |
120 | |
121 (defcustom eshell-pushd-dextract nil | |
122 "*If non-nil, make \"pushd +n\" pop the nth dir to the stack top. | |
123 This mirrors the optional behavior of tcsh." | |
124 :type 'boolean | |
125 :group 'eshell-dirs) | |
126 | |
127 (defcustom eshell-pushd-dunique nil | |
128 "*If non-nil, make pushd only add unique directories to the stack. | |
129 This mirrors the optional behavior of tcsh." | |
130 :type 'boolean | |
131 :group 'eshell-dirs) | |
132 | |
133 (defcustom eshell-dirtrack-verbose t | |
134 "*If non-nil, show the directory stack following directory change. | |
135 This is effective only if directory tracking is enabled." | |
136 :type 'boolean | |
137 :group 'eshell-dirs) | |
138 | |
139 (defcustom eshell-last-dir-ring-file-name | |
140 (concat eshell-directory-name "lastdir") | |
141 "*If non-nil, name of the file to read/write the last-dir-ring. | |
142 See also `eshell-read-last-dir-ring' and `eshell-write-last-dir-ring'. | |
143 If it is nil, the last-dir-ring will not be written to disk." | |
144 :type 'file | |
145 :group 'eshell-dirs) | |
146 | |
147 (defcustom eshell-last-dir-ring-size 32 | |
148 "*If non-nil, the size of the directory history ring. | |
149 This ring is added to every time `cd' or `pushd' is used. It simply | |
150 stores the most recent directory locations Eshell has been in. To | |
151 return to the most recent entry, use 'cd -' (equivalent to 'cd -0'). | |
152 To return to an older entry, use 'cd -N', where N is an integer less | |
153 than `eshell-last-dir-ring-size'. To return to the last directory | |
154 matching a particular regexp, use 'cd =REGEXP'. To display the | |
155 directory history list, use 'cd ='. | |
156 | |
157 This mechanism is very similar to that provided by `pushd', except | |
158 it's far more automatic. `pushd' allows the user to decide which | |
159 directories gets pushed, and its size is unlimited. | |
160 | |
161 `eshell-last-dir-ring' is meant for users who don't use `pushd' | |
162 explicity very much, but every once in a while would like to return to | |
163 a previously visited directory without having to type in the whole | |
164 thing again." | |
165 :type 'integer | |
166 :group 'eshell-dirs) | |
167 | |
168 (defcustom eshell-last-dir-unique t | |
169 "*If non-nil, `eshell-last-dir-ring' contains only unique entries." | |
170 :type 'boolean | |
171 :group 'eshell-dirs) | |
172 | |
173 ;;; Internal Variables: | |
174 | |
175 (defvar eshell-dirstack nil | |
176 "List of directories saved by pushd in the Eshell buffer. | |
177 Thus, this does not include the current directory.") | |
178 | |
179 (defvar eshell-last-dir-ring nil | |
180 "The last directory that eshell was in.") | |
181 | |
182 ;;; Functions: | |
183 | |
184 (defun eshell-dirs-initialize () | |
185 "Initialize the builtin functions for Eshell." | |
186 (make-local-variable 'eshell-variable-aliases-list) | |
187 (setq eshell-variable-aliases-list | |
188 (append | |
189 eshell-variable-aliases-list | |
190 '(("-" (lambda (indices) | |
191 (if (not indices) | |
192 (unless (ring-empty-p eshell-last-dir-ring) | |
193 (expand-file-name | |
194 (ring-ref eshell-last-dir-ring 0))) | |
195 (expand-file-name | |
196 (eshell-apply-indices eshell-last-dir-ring indices))))) | |
197 ("+" "PWD") | |
198 ("PWD" (lambda (indices) | |
199 (expand-file-name (eshell/pwd))) t) | |
200 ("OLDPWD" (lambda (indices) | |
201 (unless (ring-empty-p eshell-last-dir-ring) | |
202 (expand-file-name | |
203 (ring-ref eshell-last-dir-ring 0)))) t)))) | |
204 | |
205 (when eshell-cd-on-directory | |
206 (make-local-variable 'eshell-interpreter-alist) | |
207 (setq eshell-interpreter-alist | |
208 (cons (cons 'eshell-lone-directory-p | |
209 'eshell-dirs-substitute-cd) | |
210 eshell-interpreter-alist))) | |
211 | |
212 (make-local-hook 'eshell-parse-argument-hook) | |
213 (add-hook 'eshell-parse-argument-hook | |
214 'eshell-parse-user-reference nil t) | |
215 (if (eshell-under-windows-p) | |
216 (add-hook 'eshell-parse-argument-hook | |
217 'eshell-parse-drive-letter nil t)) | |
218 | |
219 (when (eshell-using-module 'eshell-cmpl) | |
220 (make-local-hook 'pcomplete-try-first-hook) | |
221 (add-hook 'pcomplete-try-first-hook | |
222 'eshell-complete-user-reference nil t)) | |
223 | |
224 (make-local-variable 'eshell-dirstack) | |
225 (make-local-variable 'eshell-last-dir-ring) | |
226 | |
227 (if eshell-last-dir-ring-file-name | |
228 (eshell-read-last-dir-ring)) | |
229 (unless eshell-last-dir-ring | |
230 (setq eshell-last-dir-ring (make-ring eshell-last-dir-ring-size))) | |
231 | |
232 (make-local-hook 'eshell-exit-hook) | |
233 (add-hook 'eshell-exit-hook 'eshell-write-last-dir-ring nil t) | |
234 | |
235 (add-hook 'kill-emacs-hook 'eshell-save-some-last-dir)) | |
236 | |
237 (defun eshell-save-some-last-dir () | |
238 "Save the list-dir-ring for any open Eshell buffers." | |
239 (eshell-for buf (buffer-list) | |
240 (if (buffer-live-p buf) | |
241 (with-current-buffer buf | |
242 (if (and eshell-mode | |
243 eshell-ask-to-save-last-dir | |
244 (or (eq eshell-ask-to-save-last-dir 'always) | |
245 (y-or-n-p | |
246 (format "Save last dir ring for Eshell buffer `%s'? " | |
247 (buffer-name buf))))) | |
248 (eshell-write-last-dir-ring)))))) | |
249 | |
250 (defun eshell-lone-directory-p (file) | |
251 "Test whether FILE is just a directory name, and not a command name." | |
252 (and (file-directory-p file) | |
253 (or (file-name-directory file) | |
254 (not (eshell-search-path file))))) | |
255 | |
256 (defun eshell-dirs-substitute-cd (&rest args) | |
257 "Substitute the given command for a call to `cd' on that name." | |
258 (if (> (length args) 1) | |
259 (error "%s: command not found" (car args)) | |
260 (throw 'eshell-replace-command | |
261 (eshell-parse-command "cd" args)))) | |
262 | |
263 (defun eshell-parse-user-reference () | |
264 "An argument beginning with ~ is a filename to be expanded." | |
265 (when (and (not eshell-current-argument) | |
266 (eq (char-after) ?~)) | |
267 (add-to-list 'eshell-current-modifiers 'expand-file-name) | |
268 (forward-char) | |
269 (char-to-string (char-before)))) | |
270 | |
271 (defun eshell-parse-drive-letter () | |
272 "An argument beginning X:[^/] is a drive letter reference." | |
273 (when (and (not eshell-current-argument) | |
274 (looking-at "\\([A-Za-z]:\\)\\([^/\\\\]\\|\\'\\)")) | |
275 (goto-char (match-end 1)) | |
276 (let* ((letter (match-string 1)) | |
277 (regexp (concat "\\`" letter)) | |
278 (path (eshell-find-previous-directory regexp))) | |
279 (concat (or path letter) | |
280 (char-to-string directory-sep-char))))) | |
281 | |
282 (defun eshell-complete-user-reference () | |
283 "If there is a user reference, complete it." | |
284 (let ((arg (pcomplete-actual-arg))) | |
285 (when (string-match "\\`~[a-z]*\\'" arg) | |
286 (setq pcomplete-stub (substring arg 1) | |
287 pcomplete-last-completion-raw t) | |
288 (throw 'pcomplete-completions | |
289 (progn | |
290 (eshell-read-user-names) | |
291 (pcomplete-uniqify-list | |
292 (mapcar | |
293 (function | |
294 (lambda (user) | |
295 (file-name-as-directory (cdr user)))) | |
296 eshell-user-names))))))) | |
297 | |
298 (defun eshell/pwd (&rest args) ; ignored | |
299 "Change output from `pwd` to be cleaner." | |
300 (let* ((path default-directory) | |
301 (len (length path))) | |
302 (if (and (> len 1) | |
303 (eq (aref path (1- len)) directory-sep-char) | |
304 (not (and (eshell-under-windows-p) | |
305 (string-match "\\`[A-Za-z]:[\\\\/]\\'" path)))) | |
306 (setq path (substring path 0 (1- (length path))))) | |
307 (if eshell-pwd-convert-function | |
308 (setq path (funcall eshell-pwd-convert-function path))) | |
309 path)) | |
310 | |
311 (defun eshell-expand-multiple-dots (path) | |
312 "Convert '...' to '../..', '....' to '../../..', etc.. | |
313 | |
314 With the following piece of advice, you can make this functionality | |
315 available in most of Emacs, with the exception of filename completion | |
316 in the minibuffer: | |
317 | |
318 (defadvice expand-file-name | |
319 (before translate-multiple-dots | |
320 (filename &optional directory) activate) | |
321 (setq filename (eshell-expand-multiple-dots filename)))" | |
322 (while (string-match "\\.\\.\\(\\.+\\)" path) | |
323 (let* ((extra-dots (match-string 1 path)) | |
324 (len (length extra-dots)) | |
325 replace-text) | |
326 (while (> len 0) | |
327 (setq replace-text | |
328 (concat replace-text | |
329 (char-to-string directory-sep-char) "..") | |
330 len (1- len))) | |
331 (setq path | |
332 (replace-match replace-text t t path 1)))) | |
333 path) | |
334 | |
335 (defun eshell-find-previous-directory (regexp) | |
336 "Find the most recent last-dir matching REGEXP." | |
337 (let ((index 0) | |
338 (len (ring-length eshell-last-dir-ring)) | |
339 oldpath) | |
340 (if (> (length regexp) 0) | |
341 (while (< index len) | |
342 (setq oldpath (ring-ref eshell-last-dir-ring index)) | |
343 (if (string-match regexp oldpath) | |
344 (setq index len) | |
345 (setq oldpath nil | |
346 index (1+ index))))) | |
347 oldpath)) | |
348 | |
349 (eval-when-compile | |
350 (defvar dired-directory)) | |
351 | |
352 (defun eshell/cd (&rest args) ; all but first ignored | |
353 "Alias to extend the behavior of `cd'." | |
354 (let ((path (car args)) | |
355 (subpath (car (cdr args))) | |
356 handled) | |
357 (if (numberp path) | |
358 (setq path (number-to-string path))) | |
359 (if (numberp subpath) | |
360 (setq subpath (number-to-string subpath))) | |
361 (cond | |
362 (subpath | |
363 (let ((curdir (eshell/pwd))) | |
364 (if (string-match path curdir) | |
365 (setq path (replace-match subpath nil nil curdir)) | |
366 (error "Path substring '%s' not found" path)))) | |
367 ((and path (string-match "^-\\([0-9]*\\)$" path)) | |
368 (let ((index (match-string 1 path))) | |
369 (setq path | |
370 (ring-remove eshell-last-dir-ring | |
371 (if index | |
372 (string-to-int index) | |
373 0))))) | |
374 ((and path (string-match "^=\\(.*\\)$" path)) | |
375 (let ((oldpath (eshell-find-previous-directory | |
376 (match-string 1 path)))) | |
377 (if oldpath | |
378 (setq path oldpath) | |
379 (let ((len (ring-length eshell-last-dir-ring)) | |
380 (index 0)) | |
381 (if (= len 0) | |
382 (error "Directory ring empty")) | |
383 (while (< index len) | |
384 (eshell-printn | |
385 (concat (number-to-string index) ": " | |
386 (ring-ref eshell-last-dir-ring index))) | |
387 (setq index (1+ index))) | |
388 (setq handled t))))) | |
389 (path | |
390 (setq path (eshell-expand-multiple-dots path)))) | |
391 (unless handled | |
392 (setq dired-directory (or path "~")) | |
393 (let ((curdir (eshell/pwd))) | |
394 (unless (equal curdir dired-directory) | |
395 (eshell-add-to-dir-ring curdir)) | |
396 (let ((result (cd dired-directory))) | |
397 (and eshell-cd-shows-directory | |
398 (eshell-printn result))) | |
399 (run-hooks 'eshell-directory-change-hook) | |
400 (if eshell-list-files-after-cd | |
401 (throw 'eshell-replace-command | |
402 (eshell-parse-command "ls" (cdr args)))) | |
403 nil)))) | |
404 | |
405 (defun eshell-add-to-dir-ring (path) | |
406 "Add PATH to the last-dir-ring, if applicable." | |
407 (unless (and (not (ring-empty-p eshell-last-dir-ring)) | |
408 (equal path (ring-ref eshell-last-dir-ring 0))) | |
409 (if eshell-last-dir-unique | |
410 (let ((index 0) | |
411 (len (ring-length eshell-last-dir-ring))) | |
412 (while (< index len) | |
413 (if (equal (ring-ref eshell-last-dir-ring index) path) | |
414 (ring-remove eshell-last-dir-ring index) | |
415 (setq index (1+ index)))))) | |
416 (ring-insert eshell-last-dir-ring path))) | |
417 | |
418 ;;; pushd [+n | dir] | |
419 (defun eshell/pushd (&rest args) ; all but first ignored | |
420 "Implementation of pushd in Lisp." | |
421 (let ((path (car args))) | |
422 (cond | |
423 ((null path) | |
424 ;; no arg -- swap pwd and car of stack unless eshell-pushd-tohome | |
425 (cond (eshell-pushd-tohome | |
426 (eshell/pushd "~")) | |
427 (eshell-dirstack | |
428 (let ((old (eshell/pwd))) | |
429 (eshell/cd (car eshell-dirstack)) | |
430 (setq eshell-dirstack (cons old (cdr eshell-dirstack))) | |
431 (eshell/dirs t))) | |
432 (t | |
433 (error "pushd: No other directory")))) | |
434 ((string-match "^\\+\\([0-9]\\)" path) | |
435 ;; pushd +n | |
436 (setq path (string-to-number (match-string 1 path))) | |
437 (cond ((> path (length eshell-dirstack)) | |
438 (error "Directory stack not that deep")) | |
439 ((= path 0) | |
440 (error "Couldn't cd")) | |
441 (eshell-pushd-dextract | |
442 (let ((dir (nth (1- path) eshell-dirstack))) | |
443 (eshell/popd path) | |
444 (eshell/pushd (eshell/pwd)) | |
445 (eshell/cd dir) | |
446 (eshell/dirs t))) | |
447 (t | |
448 (let* ((ds (cons (eshell/pwd) eshell-dirstack)) | |
449 (dslen (length ds)) | |
450 (front (nthcdr path ds)) | |
451 (back (nreverse (nthcdr (- dslen path) (reverse ds)))) | |
452 (new-ds (append front back))) | |
453 (eshell/cd (car new-ds)) | |
454 (setq eshell-dirstack (cdr new-ds)) | |
455 (eshell/dirs t))))) | |
456 (t | |
457 ;; pushd <dir> | |
458 (let ((old-wd (eshell/pwd))) | |
459 (eshell/cd path) | |
460 (if (or (null eshell-pushd-dunique) | |
461 (not (member old-wd eshell-dirstack))) | |
462 (setq eshell-dirstack (cons old-wd eshell-dirstack))) | |
463 (eshell/dirs t))))) | |
464 nil) | |
465 | |
466 ;;; popd [+n] | |
467 (defun eshell/popd (&rest args) | |
468 "Implementation of popd in Lisp." | |
469 (let ((ref (or (car args) "+0"))) | |
470 (unless (and (stringp ref) | |
471 (string-match "\\`\\([+-][0-9]+\\)\\'" ref)) | |
472 (error "popd: bad arg `%s'" ref)) | |
473 (setq ref (string-to-number (match-string 1 ref))) | |
474 (cond ((= ref 0) | |
475 (unless eshell-dirstack | |
476 (error "popd: Directory stack empty")) | |
477 (eshell/cd (car eshell-dirstack)) | |
478 (setq eshell-dirstack (cdr eshell-dirstack)) | |
479 (eshell/dirs t)) | |
480 ((<= (abs ref) (length eshell-dirstack)) | |
481 (let* ((ds (cons nil eshell-dirstack)) | |
482 (cell (nthcdr (if (> ref 0) | |
483 (1- ref) | |
484 (+ (length eshell-dirstack) ref)) ds)) | |
485 (dir (cadr cell))) | |
486 (eshell/cd dir) | |
487 (setcdr cell (cdr (cdr cell))) | |
488 (setq eshell-dirstack (cdr ds)) | |
489 (eshell/dirs t))) | |
490 (t | |
491 (error "Couldn't popd")))) | |
492 nil) | |
493 | |
494 (defun eshell/dirs (&optional if-verbose) | |
495 "Implementation of dirs in Lisp." | |
496 (when (or (not if-verbose) eshell-dirtrack-verbose) | |
497 (let* ((msg "") | |
498 (ds (cons (eshell/pwd) eshell-dirstack)) | |
499 (home (expand-file-name "~/")) | |
500 (homelen (length home))) | |
501 (while ds | |
502 (let ((dir (car ds))) | |
503 (and (>= (length dir) homelen) | |
504 (string= home (substring dir 0 homelen)) | |
505 (setq dir (concat "~/" (substring dir homelen)))) | |
506 (setq msg (concat msg (directory-file-name dir) " ")) | |
507 (setq ds (cdr ds)))) | |
508 msg))) | |
509 | |
510 (defun eshell-read-last-dir-ring () | |
511 "Sets the buffer's `eshell-last-dir-ring' from a history file." | |
512 (let ((file eshell-last-dir-ring-file-name)) | |
513 (cond | |
514 ((or (null file) | |
515 (equal file "") | |
516 (not (file-readable-p file))) | |
517 nil) | |
518 (t | |
519 (let* ((count 0) | |
520 (size eshell-last-dir-ring-size) | |
521 (ring (make-ring size))) | |
522 (with-temp-buffer | |
523 (insert-file-contents file) | |
524 ;; Save restriction in case file is already visited... | |
525 ;; Watch for those date stamps in history files! | |
526 (goto-char (point-max)) | |
527 (while (and (< count size) | |
528 (re-search-backward "^\\([^\n].*\\)$" nil t)) | |
529 (ring-insert-at-beginning ring (match-string 1)) | |
530 (setq count (1+ count))) | |
531 ;; never allow the top element to equal the current | |
532 ;; directory | |
533 (while (and (not (ring-empty-p ring)) | |
534 (equal (ring-ref ring 0) (eshell/pwd))) | |
535 (ring-remove ring 0))) | |
536 (setq eshell-last-dir-ring ring)))))) | |
537 | |
538 (defun eshell-write-last-dir-ring () | |
539 "Writes the buffer's `eshell-last-dir-ring' to a history file." | |
540 (let ((file eshell-last-dir-ring-file-name)) | |
541 (cond | |
542 ((or (null file) | |
543 (equal file "") | |
544 (null eshell-last-dir-ring) | |
545 (ring-empty-p eshell-last-dir-ring)) | |
546 nil) | |
547 ((not (file-writable-p file)) | |
548 (message "Cannot write last-dir-ring file %s" file)) | |
549 (t | |
550 (let* ((ring eshell-last-dir-ring) | |
551 (index (ring-length ring))) | |
552 (with-temp-buffer | |
553 (while (> index 0) | |
554 (setq index (1- index)) | |
555 (insert (ring-ref ring index) ?\n)) | |
556 (insert (eshell/pwd) ?\n) | |
557 (eshell-with-private-file-modes | |
558 (write-region (point-min) (point-max) file nil | |
559 'no-message)))))))) | |
560 | |
561 ;;; Code: | |
562 | |
563 ;;; em-dirs.el ends here |