-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.el
213 lines (163 loc) · 4.95 KB
/
test.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
;; Misc function
;; temp function
(provide 'test)
;; (dolist (i (delete-duplicates find-tag-history :from-end t))
;; (print i))
(defun revert-all-buffers ()
(interactive)
(save-current-buffer
(dolist (buf (buffer-list))
(set-buffer buf)
(condition-case nil
(revert-buffer nil t)
(error nil)))))
(defun del-dup-lines ()
(interactive)
(let (line ll)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(pushnew (buffer-substring-no-properties (line-beginning-position) (line-end-position))
ll
:test #'string=)
(forward-line)
)
(with-output-to-temp-buffer "*temp*"
(set-buffer standard-output)
(dolist (i (nreverse ll))
(insert i "\n")))
)))
(defadvice newline-and-indent (after newline-and-indent ())
(when (eq (char-after) ?\))
(save-excursion
(newline)
(indent-according-to-mode)
)))
(ad-activate 'newline-and-indent)
;;(defun delete-indentation (&optional arg)
(defadvice delete-indentation (before delete-indentation (&optional arg))
(forward-line))
(ad-activate 'delete-indentation)
(defvar mydiary-title-regex "* [0-9]\\{4\\}-[0-9]\\{1,2\\}-[0-9]\\{1,2\\}")
(defun mydiary-go-to-title-f ()
"MyDiary"
(interactive)
;; (save-match-data
;; (save-excursion
(if (not(re-search-forward mydiary-title-regex nil t))
(progn
(goto-char (point-min))
(re-search-forward mydiary-title-regex nil t)))
;; ))
)
(defun mydiary-go-to-title-b ()
"MyDiary"
(interactive)
;; (save-match-data
;; (save-excursion
(if (not(re-search-backward mydiary-title-regex nil t))
(progn
(goto-char (point-max))
(re-search-backward mydiary-title-regex nil t)))
;; ))
)
(defun mydiary-occur ()
""
(interactive)
(occur mydiary-title-regex))
(global-set-key [f12] 'mydiary-go-to-title-f)
(global-set-key [(shift f12)] 'mydiary-go-to-title-b)
;; (global-set-key [f11] 'mydiary-occur)
(defun mydiary-add-title ()
"Add * yyyy-mm-dd w string"
(interactive)
(insert (concat "* " (format-time-string "%Y-%m-%d %A") " Çç")))
(global-set-key [(f11)] 'mydiary-add-title)
(require 'xml)
(defun my-display-xml-tree ()
(interactive)
(let ((str "")
(start (point-min))
(end (point-max))
)
(if (and transient-mark-mode mark-active)
(setq start (region-beginning)))
(if (and transient-mark-mode mark-active)
(setq end (region-end)))
(setq str (xml-parse-region start end))
(with-output-to-temp-buffer "*XML*"
(save-excursion
(set-buffer standard-output)
(pp str)
(emacs-lisp-mode)
(hs-minor-mode 1)
))
)
)
(defun del-bufs-of-major-mode (maj-mode)
(dolist (buf (buffer-list))
(when (eq (with-current-buffer buf major-mode) maj-mode)
(dolist (win (get-buffer-window-list buf))
(delete-window win))
(kill-buffer buf))
))
(defun del-occur-bufs ()
(interactive)
(del-bufs-of-major-mode 'occur-mode))
(defun pop-occur-buf ()
""
(interactive)
(catch 'loop
(dolist (buf (buffer-list))
(if (eq (with-current-buffer buf major-mode) 'occur-mode)
(progn
(pop-to-buffer buf)
;(fit-window-to-buffer (get-buffer-window buf) (/ (frame-height) 2))
(shrink-window-if-larger-than-buffer (get-buffer-window buf))
(throw 'loop t)
)))))
(if (eq system-type 'windows-nt)
(defvar my-temp-dir "D:/brian-temp/")
(defvar my-temp-dir "~/.brian-temp/"))
;; open a new temp file for easily edit something temporarily.
(defun open-a-temp-file ()
""
(interactive)
(let ()
(unless (file-directory-p my-temp-dir)
(make-directory my-temp-dir)
)
(find-file (let ((temporary-file-directory my-temp-dir)) (make-temp-file "brian"))))
)
(global-set-key [f9] 'open-a-temp-file)
(defun my-ediff-temp-files ()
""
(interactive)
(let (file-A
file-B
)
(unless (file-directory-p my-temp-dir)
(make-directory my-temp-dir)
)
(let ((temporary-file-directory my-temp-dir))
(setq file-A (make-temp-file "brian"))
(setq file-B (make-temp-file "brian"))
)
(ediff-files file-A file-B)
))
(defun my-close-temp-files ()
(interactive)
(let ((temp-dir (file-name-as-directory (expand-file-name my-temp-dir)))
(fname "")
)
(dolist (buf (buffer-list))
(when (and (setq fname (buffer-file-name buf))
(string= (file-name-directory fname)
temp-dir
))
(dolist (win (get-buffer-window-list buf))
(ignore-errors
(delete-window win)))
(kill-buffer buf)
)))
)