-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave-continue-file.el
124 lines (114 loc) · 2.9 KB
/
save-continue-file.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
;;;
;;; continue-file
;;;
;;;
;;; save filenames and restore from it.
;;;
(defvar continue-file "~/.continue.el"
"*filename of continue-file"
)
(defun old-save-continue-file ()
(interactive)
(set-buffer (generate-new-buffer continue-file))
(insert (format "(mapcar 'find-file '%S)\n"
(nreverse (delq nil (mapcar 'buffer-file-name (buffer-list))))))
(write-file continue-file)
(kill-buffer (current-buffer))
)
(defun old2-save-continue-file ()
(interactive)
(save-some-buffers t)
(let ((l (reverse (buffer-list)))
(continue-buf (generate-new-buffer continue-file))
buf
file)
(set-buffer continue-buf)
(while l
(setq buf (car l)
file (buffer-file-name buf))
(if (continue-file-no-save-p file)
(insert (format "(find-file %S)\n (goto-char %d)\n"
file
(save-excursion
(set-buffer buf)
(point))))
)
(setq l (cdr l))
)
(write-file continue-file)
(kill-buffer continue-buf)
)
)
(defun save-continue-file ()
"backup version not tested"
(interactive)
(save-some-buffers t)
(save-excursion
(let ((cf-visited (get-file-buffer continue-file))
(continue-buf (find-file continue-file))
;; never save continue-file itself because
;; during loading, (goto-char) changes the (point) and get into the infinite loop
(l (reverse (cdr (buffer-list))))
buf
file
history-files
(make-backup-files t)
(version-control t)
(kept-new-versions 10)
(delete-old-versions t)
)
(set-buffer continue-buf)
(erase-buffer)
(while l
(setq buf (car l)
file (save-continue-buffer-file-name buf))
(if (and file
(not (continue-file-no-save-p file))
)
(progn
(insert (format "(find-file %S)\n (goto-char %d)\n"
file
(save-excursion
(set-buffer buf)
(point))))
(setq history-files (cons file history-files))
)
)
(setq l (cdr l))
)
(insert "(add-hook 'kill-emacs-hook 'save-continue-file)\n")
; ここに visit-file の mini-buffer用の file-name-history 向けに、上のfileとして保存したリストを設定する
(insert (format "(setq file-name-history '%S)\n" history-files))
; save-continue-file hook is started only when loaded!
(save-buffer '(3))
(if cf-visited
(revert-buffer t t)
(kill-buffer continue-buf)
)
)
)
)
(defun save-continue-buffer-file-name (buf)
(or (buffer-file-name buf)
(save-excursion
(set-buffer buf)
(and (boundp 'list-buffers-directory)
list-buffers-directory))))
(defun restore-continue-file ()
(if (file-readable-p continue-file)
(progn
(load-file continue-file)
(add-hook 'kill-emacs-hook
'save-continue-file)
)
)
)
(defun continue-file-no-save-p (file)
(cond
((null file)
nil)
((string-match continue-file-no-save-regexp file)
file)
(t
nil)))
(defvar continue-file-no-save-regexp "^/[-a-zA-Z0-9_.@]*:")