-
Notifications
You must be signed in to change notification settings - Fork 8
/
essentialpackage-setting.el
executable file
·343 lines (339 loc) · 15.4 KB
/
essentialpackage-setting.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
;; -*- coding: utf-8 -*-
;; File: essentialpackage-setting.el
;;
;; Author: Denny Zhang(https://www.dennyzhang.com/contact)
;; Copyright 2020, https://DennyZhang.com
;; Created:2008-10-01
;; Updated: Time-stamp: <2020-02-03 15:37:48>
;; --8<-------------------------- separator ------------------------>8--
;;show recent files
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-saved-items 100)
;; (setq recentf-auto-cleanup 300)
(defun recentf-open-files-compl ()
(interactive)
(let* ((all-files recentf-list)
(tocpl (mapcar (function
(lambda (x) (cons (file-name-nondirectory x) x))) all-files))
(prompt (append '("File name: ") tocpl))
(fname (completing-read (car prompt) (cdr prompt) nil nil)))
(find-file (cdr (assoc-string fname tocpl)))))
(global-set-key [(control x)(control r)] 'recentf-open-files-compl)
;; ;; --8<-------------------------- separator ------------------------>8--
;;remember where you were in a file
(setq save-place-file (concat CONF-EMACS-DATA "/filebat.saveplace"))
(setq-default save-place t) ;; activate it for all buffers
(require 'saveplace) ;; get the package
;; ;; --8<-------------------------- separator ------------------------>8--
; on duplicate filenames, show path names, not foo.x<2>, foo.x<3>, etc.
(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse
uniquify-separator " • "
uniquify-after-kill-buffer-p t
uniquify-ignore-buffers-re "^\\*")
;; ;; --8<-------------------------- separator ------------------------>8--
;;(add-to-list 'load-path (concat CONF-EMACS-VENDOR "/frame"))
;;(require 'frame-fns)
;; (require 'frame-cmds)
;; (global-set-key [(control up)] 'move-frame-up)
;; (global-set-key [(control down)] 'move-frame-down)
;; (global-set-key [(control left)] 'move-frame-left)
;; (global-set-key [(control right)] 'move-frame-right)
;; ;; ;; --8<-------------------------- separator ------------------------>8--
(if window-system
(progn
(require 'bm)
(setq bm-repository-file (concat CONF-EMACS-VENDOR "/data/out_of_svn/filebat.bm"))
;; make bookmarks persistent as default
(setq-default bm-buffer-persistence t)
;; Loading the repository from file when on start up.
;;(add-hook 'after-init-hook 'bm-repository-load) ;; TODO denny
;; Restoring bookmarks when on file find.
;;(add-hook 'find-file-hook 'bm-buffer-restore) ;; TODO
;; Saving bookmark data on killing a buffer
;; (add-hook 'kill-buffer-hook 'bm-buffer-save) ;; TODO
(defadvice bm-buffer-save (before if activate) (widen))
;; Saving the repository to file when on exit.
;; kill-buffer-hook is not called when emacs is killed, so we
;; must save all bookmarks first.
;;(add-hook 'kill-emacs-hook #'(lambda nil ;; TODO denny
;; (bm-buffer-save-all) ;; TODO denny
;; (bm-repository-save))) ;; TODO denny
;; Update bookmark repository when saving the file.
;;(add-hook 'after-save-hook 'bm-buffer-save)
;; Restore bookmarks when buffer is reverted.
;;(add-hook 'after-revert-hook 'bm-buffer-restore)
;; make sure bookmarks is saved before check-in (and revert-buffer)
(add-hook 'vc-before-checkin-hook 'bm-buffer-save)
(global-set-key (kbd "<C-f2>") 'bm-toggle)
(global-set-key (kbd "<f2>") 'bm-next)
(global-set-key (kbd "<S-f2>") 'bm-previous)
))
;; ;; --8<-------------------------- separator ------------------------>8--
(require 'highlight-symbol)
(global-set-key (kbd "<C-f5>") 'highlight-symbol-at-point)
(global-set-key (kbd "<f5>") 'highlight-symbol-next)
(global-set-key (kbd "<S-f5>") 'highlight-symbol-prev)
;; ;; --8<-------------------------- separator ------------------------>8--
;; rect-mark
;; (load-file (concat CONF-EMACS-VENDOR "/rect-mark/rect-mark.el")) ;; TODO
;; Support for marking a rectangle of text with highlighting.
;;(define-key ctl-x-map "r\C-M-\ " 'rm-set-mark)
;;(define-key ctl-x-map [?r ?\C-\ ] 'rm-set-mark)
(global-set-key (kbd "C-x r C-M-SPC") 'rm-set-mark)
(define-key ctl-x-map "r\C-x" 'rm-exchange-point-and-mark)
(define-key ctl-x-map "r\C-w" 'rm-kill-region)
(define-key ctl-x-map "r\M-w" 'rm-kill-ring-save)
(define-key global-map [S-down-mouse-1] 'rm-mouse-drag-region)
(autoload 'rm-set-mark "rect-mark"
"Set mark for rectangle." t)
(autoload 'rm-exchange-point-and-mark "rect-mark"
"Exchange point and mark for rectangle." t)
(autoload 'rm-kill-region "rect-mark"
"Kill a rectangular region and save it in the kill ring." t)
(autoload 'rm-kill-ring-save "rect-mark"
"Copy a rectangular region to the kill ring." t)
(autoload 'rm-mouse-drag-region "rect-mark"
"Drag out a rectangular region with the mouse." t)
;; ;; --8<-------------------------- separator ------------------------>8--
(require 'whitespace)
(setq whitespace-display-mappings
'((space-mark ?\ [?.])
(newline-mark ?\n [?$ ?\n])
(tab-mark ?\t [?\\ ?\t])))
;; ;; --8<-------------------------- separator ------------------------>8--
(require 'boxquote)
(setq boxquote-top-and-tail "-----------")
;; ;; --8<-------------------------- separator ------------------------>8--
(require 'cal-china-x)
;; TODO
;; show lunar calendar
;;(add-hook 'diary-nongregorian-listing-hook 'diary-chinese-list-entries)
;;(add-hook 'diary-nongregorian-marking-hook 'diary-chinese-mark-entries)
;;highlights all the days that are holidays
(setq calendar-mark-holidays-flag 't)
;; ;; --8<-------------------------- separator ------------------------>8--
(require 'loccur)
;; defines shortcut for loccur of the current word
(define-key global-map [(control meta o)] 'loccur-current)
(set-face-background 'isearch "#537182")
(set-face-foreground 'isearch "AntiqueWhite2")
(define-key global-map [(control meta u)] 'loccur-skeleton)
(defun loccur-skeleton ()
"Call `loccur' for code skeleton with the same leading whitespace."
(interactive)
(let ((point-orig (point)) leading-str (whitespace-count 0))
(save-excursion
(move-beginning-of-line nil)
(if (eq (point) point-orig)
;; pressing in the head of the line
(loccur (format "^[^ %c]" 9))
(progn
(setq leading-str (buffer-substring-no-properties point-orig (point)))
(dolist (ch (string-to-list leading-str))
(if (eq ch 32)
(setq whitespace-count (+ 1 whitespace-count))
)))
(if (eq 0 whitespace-count)
(loccur (format "^[^ ]" whitespace-count))
(loccur (format "^ \\{1,%d\\}[^ ]\\|^[^ ]" whitespace-count)))
))
)
)
;; (defun loccur-skeleton ()
;; "Call `loccur' for code skeleton with the same leading whitespace."
;; (interactive)
;; (let ((point-orig (point)) leading-str (whitespace-count 0))
;; (save-excursion
;; (move-beginning-of-line nil)
;; (setq leading-str (buffer-substring-no-properties point-orig (point)))
;; (dolist (ch (string-to-list leading-str))
;; (if (eq ch 32)
;; (setq whitespace-count (+ 1 whitespace-count))
;; )))
;; (if (not (eq 0 whitespace-count))
;; (loccur (format "^ \\{1,%d\\}[^ ]\\|^[^ ]" whitespace-count))
;; (loccur (format "^[^ ]" whitespace-count)))
;; ))
;; --8<-------------------------- separator ------------------------>8--
;; (require 'cursor-chg)
;; (change-cursor-mode 1) ; On for overwrite/read-only/input mode
;; (toggle-cursor-type-when-idle 1) ; On when idle
;; (setq curchg-default-cursor-color "green")
;; ;; --8<-------------------------- separator ------------------------>8--
(setq abbrev-file-name (concat CONF-EMACS-DATA "/filebat.abbrev"))
(setq save-abbrevs t) ;; save abbrevs when files are saved
(quietly-read-abbrev-file) ;; reads the abbreviations file on startup
;;(setq abbrev-mode 1) ;; always enable abbrev
(setq default-abbrev-mode 1)
;; ;; --8<-------------------------- separator ------------------------>8--
(require 'color-moccur)
;; ;; --8<-------------------------- separator ------------------------>8--
;; (require 'hide-region)
;; (defun hide-region-settings ()
;; "Settings for `hide-region'."
;; (setq hide-region-before-string "[======================该区域已")
;; (setq hide-region-after-string "被折叠======================]\n"))
;; (eval-after-load 'hide-region '(hide-region-settings))
;; (global-set-key (kbd "C-x M-r") 'hide-region-hide)
;; (global-set-key (kbd "C-x M-R") 'hide-region-unhide)
;; ;; --8<-------------------------- separator ------------------------>8--
(require 'ido)
(ido-mode t)
(ido-everywhere t)
(setq ido-enable-flex-matching t)
;; ;; --8<-------------------------- separator ------------------------>8--
(require 'thumbs)
(auto-image-file-mode t)
(setq thumbs-geometry "80x80")
(setq thumbs-per-line 3)
(setq thumbs-max-image-number 8)
;; ;; --8<-------------------------- separator ------------------------>8--
;;(add-to-list 'load-path (concat CONF-EMACS-VENDOR "/company-0.5/"))
(autoload 'company-mode "company" nil t)
(setq company-backends '(company-elisp
;;company-ropemacs
company-gtags
company-dabbrev-code
company-keywords
company-files
company-dabbrev))
(setq company-idle-delay 0.2) ;延迟时间
(setq company-minimum-prefix-length 2) ;触发补全的字符数量
(setq company-show-numbers nil) ;不显示数字
(dolist (hook programming-hook-list)
(add-hook hook 'company-mode))
;; ;; --8<-------------------------- separator ------------------------>8--
;; TODO: use community one
(load-file (concat CONF-EMACS-VENDOR "/highlight-tail/highlight-tail.el"))
(require 'highlight-tail)
(setq highlight-tail-colors
'(("#696969" . 0)
("white" . 100)))
(setq highlight-tail-steps 14
highlight-tail-timer 2)
(setq highlight-tail-posterior-type 'const)
(highlight-tail-mode 1)
;; --8<-------------------------- separator ------------------------>8--
(require 'rainbow-mode)
(dolist (hook programming-hook-list)
(add-hook hook #'(lambda () (rainbow-mode 1 ))))
;; --8<-------------------------- separator ------------------------>8--
(load-file (concat CONF-EMACS-VENDOR "/momentary/momentary.el"))
;; (load-file (concat CONF-EMACS-VENDOR "/proced/proced.el"))
;;(require 'proced) ;; TODO denny
(setq proced-sort "pmem")
;; --8<-------------------------- separator ------------------------>8--
;;(load-file (concat CONF-EMACS-VENDOR "/keep-buffers/keep-buffers.el"));; TODO
;;(setq keep-buffers-protected-list '("tmp" "*Messages*" "current.org" "pkm.org"))
;;(keep-buffers-erase-on-kill nil)
;; --8<-------------------------- separator ------------------------>8--
(require 'hilit-chg)
;; TODO: disable this
;;(add-hook 'find-file-hook 'enable-highlight-changes-mode)
(defun enable-highlight-changes-mode ()
"Enable highlight-changes-mode, with several modes excluded"
(let ((prohibit-mode-list '("Org" "Erlang" "DocView" (sgml-xml-mode "XHTML" "HTML"))))
(make-local-variable 'highlight-changes-mode)
(if (member mode-name prohibit-mode-list)
(highlight-changes-mode 0)
(progn
(highlight-changes-mode 0)
(global-highlight-changes-mode 'passive);;record changes in passive way
(local-set-key [(control c) (control p)] 'highlight-changes-previous-change)
(local-set-key [(control c) (control n)] 'highlight-changes-next-change)
(set-face-foreground 'highlight-changes nil)
;; set highlight-changes's background color slightly different with the editor's background color(DarkSlateGray)
(set-face-background 'highlight-changes "#382f2f")
(set-face-foreground 'highlight-changes-delete nil)
(set-face-background 'highlight-changes-delete "#916868")
)
)
)
)
;; (global-set-key (kbd "<f6>") 'highlight-changes-visible-mode) ;; changes
;; --8<-------------------------- separator ------------------------>8--
(require 'hide-lines)
(load-file (concat CONF-EMACS-VENDOR "/hide-lines/hidesearch.el"))
(require 'hidesearch)
(global-set-key (kbd "C-c C-s") 'hidesearch)
(global-set-key (kbd "C-c C-a") 'show-all-invisible)
;; --8<-------------------------- separator ------------------------>8--
(load-file (concat CONF-EMACS-VENDOR "/cn-weather/cn-weather.el"))
(require 'cn-weather)
(setq cn-weather-city "上海")
;; --8<-------------------------- separator ------------------------>8--
(require 'kill-ring-search)
;; --8<-------------------------- separator ------------------------>8--
;;(add-to-list 'load-path (concat CONF-EMACS-VENDOR "/elscreen/elscreen-1.4.6/elscreen.el"))
(require 'elscreen)
(eval-after-load 'elscreen
'(progn
;; Disable tab by default, try M-x elscreen-toggle-display-tab to show tab
(setq elscreen-display-tab nil)
;; default prefix key(C-z), is hard to invoke
(elscreen-set-prefix-key (kbd "M-s"))))
;; create screen automatically when there is only one screen
(defmacro elscreen-create-automatically (ad-do-it)
` (if (not (elscreen-one-screen-p))
,ad-do-it
(elscreen-create)
(elscreen-notify-screen-modification 'force-immediately)
(elscreen-message "New screen is automatically created")))
(defadvice elscreen-next (around elscreen-create-automatically activate)
(elscreen-create-automatically ad-do-it))
(defadvice elscreen-previous (around elscreen-create-automatically activate)
(elscreen-create-automatically ad-do-it))
(defadvice elscreen-toggle (around elscreen-create-automatically activate)
(elscreen-create-automatically ad-do-it))
;; --8<-------------------------- separator ------------------------>8--
(load-file (concat CONF-EMACS-VENDOR "/gse-number-rect/gse-number-rect.el"))
(require 'gse-number-rect)
;; --8<-------------------------- separator ------------------------>8--
(require 'fold-dwim)
(global-set-key [f7] 'lucky_try)
(global-set-key (kbd "<C-f7>") 'fold-dwim-hide-all)
(global-set-key (kbd "<M-S-f7>") 'fold-dwim-show-all)
(defun lucky_try ()
(interactive)
(cond
((string= mode-name "Diff")
(dos2unix))
((member mode-name '("Fundamental" "w3m"))
(toggle-truncate-lines))
((string= mode-name "Org")
(toggle-truncate-lines))
(t (fold-dwim-toggle))
))
;; --8<-------------------------- separator ------------------------>8--
;; (load-file (concat CONF-EMACS-VENDOR "/sr-speedbar/sr-speedbar.el")) ;; TODO
;; (setq sr-speedbar-skip-other-window-p t)
;; (setq speedbar-show-unknown-files t)
;; ;; (setq 'outline-view-change-hook nil) ;; TODO
;; ;; when pressing prefix of C-u, we will use speedbar, instead of minimap
;; (defun my-file-toogle (use-speedbar-p)
;; (interactive "P")
;; (if (null use-speedbar-p)
;; (minimap-toggle)
;; (sr-speedbar-toggle))
;; )
;; (global-set-key (kbd "<f3>") 'my-file-toogle)
;; --8<-------------------------- separator ------------------------>8--
(load-file (concat CONF-EMACS-VENDOR "/recent-jump/recent-jump.el"))
(require 'recent-jump)
(setq recent-jump-threshold 8)
(setq recent-jump-ring-length 20)
(global-set-key (kbd "C-c <") 'recent-jump-jump-backward)
(global-set-key (kbd "C-c >") 'recent-jump-jump-forward)
;; --8<-------------------------- separator ------------------------>8--
(require 'goto-last-change)
(global-set-key "\C-x\C-\\" 'goto-last-change)
(autoload 'goto-last-change
"goto-last-change" "Set point to the position of the last change." t)
(defadvice goto-last-change-with-auto-marks (before mav-goto-last-change activate)
"Split the window beforehand to retain the current view"
(unless (eq last-command 'goto-last-change-with-auto-marks)
(split-window-vertically)))
;; --8<-------------------------- separator ------------------------>8--
(load-file (concat CONF-EMACS-VENDOR "/yaml-mode/yaml-mode.el"))