-
Notifications
You must be signed in to change notification settings - Fork 2
/
.emacs
executable file
·239 lines (201 loc) · 7.68 KB
/
.emacs
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
;;--------------------------------------------------------------------------
;; .emacs
;; Settings for emacs
;; Copyright (c) 2010-2024, Michael Paquier
;;--------------------------------------------------------------------------
;;--------------------------------------------------------------------------
;; System configuration
;;--------------------------------------------------------------------------
;; Remove splash screen
(setq inhibit-splash-screen t)
;; enable visual feedback on selections
(setq-default transient-mark-mode t)
;; Remove annoying backup files, creating files like aa.txt~
(setq make-backup-files nil)
;; Disable auto save, creating files like #aa.txt#
(setq auto-save-default nil)
;; Stop at the end of the file, not just add lines
(setq next-line-add-newlines nil)
(setq c-tab-always-indent nil)
;; Delete complete TAB when using backward delete and not convert into spaces
(setq backward-delete-char-untabify-method nil)
;; Cursor color
(set-cursor-color "blue")
;; Remove menu bar
(menu-bar-mode -1)
;; Print column number
(column-number-mode 1)
;; Suppress startup verbosity.
(setq inhibit-startup-message t
initial-scratch-message nil)
;; Use the clipboard, pretty please, so that copy/paste "works"
(setq x-select-enable-clipboard t)
;; Highlight current line
(global-hl-line-mode)
;; Always follow soft links to real files when opening them
(setq vc-follow-symlinks t)
;; Disable Ctl-Z to prevent an unwanted exit
(global-unset-key (kbd "C-z"))
;; Enable region-wide upper-case switch.
(put 'upcase-region 'disabled nil)
;;--------------------------------------------------------------------------
;; Formatting
;;--------------------------------------------------------------------------
;; Shell scripting
(defun private-sh-mode ()
"Personal settings for shell scripting"
(interactive)
(setq tab-width 4)
;; Add personal settings here
)
(add-hook 'sh-mode-hook 'private-sh-mode)
;; PostgreSQL settings
;; Use of a named style makes it easy to use the style elsewhere
(c-add-style "pgsql"
'((c-file-style . "bsd")
(fill-column . 78)
(indent-tabs-mode . t)
(c-basic-offset . 4)
(c-auto-align-backslashes . nil)
(tab-width . 4)
(c-offsets-alist . ((case-label . +)
(label . -)
(statement-case-open . +)))))
(defun pgsql-c-mode ()
(c-mode)
(c-set-style "pgsql")
)
(setq auto-mode-alist
(cons '("\\(postgres\\|pgsql\\).*\\.[chyl]\\'" . pgsql-c-mode)
auto-mode-alist))
(setq auto-mode-alist
(cons '("\\(postgres\\|pgsql\\).*\\.cc\\'" . pgsql-c-mode)
auto-mode-alist))
;; SGML documentation
(add-hook 'sgml-mode-hook
(defun postgresql-sgml-mode-hook ()
(when (string-match "\\(postgres\\|pgsql\\).*\\.sgml\\'" buffer-file-name)
(setq fill-column 78)
(setq indent-tabs-mode nil)
(setq sgml-basic-offset 1))))
;; Perl settings
(defun pgsql-perl-mode ()
"Perl style adjusted for PostgreSQL project"
(tab-width . 4)
(perl-indent-level . 4)
(perl-continued-statement-offset . 4)
(perl-continued-brace-offset . 4)
(perl-brace-offset . 0)
(perl-brace-imaginary-offset . 0)
(perl-label-offset . -2)
(setq indent-tabs-mode t)
)
(add-hook 'perl-mode-hook
(lambda ()
(if (string-match "postgres" buffer-file-name)
(pgsql-perl-mode))))
;; Manage TAB entry to 4-width tabs
(defun private-build-tab-stop-list (width)
(let ((num-tab-stops (/ 80 width))
(counter 1)
(ls nil))
(while (<= counter num-tab-stops)
(setq ls (cons (* width counter) ls))
(setq counter (1+ counter)))
(set (make-local-variable 'tab-stop-list) (nreverse ls))))
;; This is essential to change the behaviour of backspace for a tab...
(defun c-tab-mode-common-hook ()
(setq tab-width 4)
(private-build-tab-stop-list tab-width)
(setq c-basic-offset tab-width))
(defun sh-tab-mode-common-hook ()
(setq tab-width 4)
(private-build-tab-stop-list tab-width)
(setq c-basic-offset tab-width))
;; Finally add this hook for necessary languages
(add-hook 'c-mode-common-hook 'c-tab-mode-common-hook) ;; C language
(add-hook 'sh-mode-hook 'sh-tab-mode-common-hook) ;; Shell-script
;; Delete trailing whitespaces for several languages
(add-hook 'c-mode-hook '(lambda ()
(add-hook 'write-contents-hooks 'delete-trailing-whitespace nil t)))
(add-hook 'c++-mode-hook '(lambda ()
(add-hook 'write-contents-hooks 'delete-trailing-whitespace nil t)))
(add-hook 'perl-mode-hook '(lambda ()
(add-hook 'write-contents-hooks 'delete-trailing-whitespace nil t)))
(add-hook 'python-mode-hook '(lambda ()
(add-hook 'write-contents-hooks 'delete-trailing-whitespace nil t)))
(add-hook 'sh-mode-hook '(lambda ()
(add-hook 'write-contents-hooks 'delete-trailing-whitespace nil t)))
;; Highlight lines with strictly more than 80 characters
(defun 80-col-limit nil
(defface line-overflow
'((t (:background "orange" :foreground "black")))
"Face to use for `hl-line-face'.")
(highlight-regexp "^.\\{81,\\}$" 'line-overflow)
)
(add-hook 'c-mode-hook '(lambda ()
(add-hook 'find-file-hook '80-col-limit)))
(add-hook 'c++-mode-hook '(lambda ()
(add-hook 'find-file-hook '80-col-limit)))
(add-hook 'perl-mode-hook '(lambda ()
(add-hook 'find-file-hook '80-col-limit)))
(add-hook 'python-mode-hook '(lambda ()
(add-hook 'find-file-hook '80-col-limit)))
(add-hook 'sh-mode-hook '(lambda ()
(add-hook 'find-file-hook '80-col-limit)))
(add-hook 'sgml-mode-hook '(lambda ()
(add-hook 'find-file-hook '80-col-limit)))
;; Display current function name in code
(which-function-mode 1)
;; Mutt settings to enable auto-fill-mode for messages.
;; Open mail-mode when emacs is invoked by mutt.
(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
;; Wrap email body.
(add-hook 'mail-mode-hook 'turn-on-auto-fill)
;; Git settings: auto-fill-mode for commits with dedicated mode.
(define-derived-mode git-commit-mode text-mode "GitCommit"
"Mode for writing git commit files."
(setq fill-column 72)
(auto-fill-mode +1)
(set (make-local-variable 'comment-start-skip) "#.*$"))
(add-to-list 'auto-mode-alist
'("/\\(?:COMMIT\\|NOTES\\|TAG\\|PULLREQ\\)_EDITMSG\\'"
. git-commit-mode))
;;--------------------------------------------------------------------------
;; Navigation
;;--------------------------------------------------------------------------
;; Scroll line by line
(setq scroll-step 1
scroll-conservatively 10000)
;; Turn on font-lock mode
(global-font-lock-mode t)
;;--------------------------------------------------------------------------
;; Controls
;;--------------------------------------------------------------------------
;; Under mac, have Command as Meta and keep Option for localized input
(when (string-match "apple-darwin" system-configuration)
(setq mac-allow-anti-aliasing t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier 'none))
;; Deletion key
(global-set-key [delete] 'delete-char)
(global-set-key [kp-delete] 'delete-char)
;; f4~f6 settings
(global-set-key [f4] 'goto-line)
(global-set-key [f5] 'query-replace)
(global-set-key [f6] 'switch-to-buffer)
;; Copy/Paste/Cut
(global-set-key "\C-t" 'copy-region-as-kill) ; Copy
(global-set-key "\C-w" 'kill-region) ; Cut
(global-set-key "\C-y" 'yank) ; Paste
;; Special handling for TAB
(global-set-key (kbd "TAB") 'tab-to-tab-stop)
;; Rectangular selection area, activate a mark to begin selection
(global-set-key "\C-u" 'set-mark-command)
;;--------------------------------------------------------------------------
;; Others
;;--------------------------------------------------------------------------
;; Private settings for emacs
;; Bypass if it does not exist.
(when (file-exists-p "~/.emacs_extra")
(load-file "~/.emacs_extra"))