forked from blastura/dot-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-generic.el
236 lines (203 loc) · 8.47 KB
/
my-generic.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
;; Generics
;; Time-stamp: "2009-07-17 15:47:50 anton"
(server-start)
(set-variable 'inhibit-startup-message t)
(set-variable 'user-mail-address "anton\.johansson@gmail\.com")
(set-variable 'user-full-name "Anton Johansson")
(setq truncate-lines t)
(prefer-coding-system 'utf-8)
(global-font-lock-mode t)
(show-paren-mode t)
(setq fill-column 80)
(column-number-mode t)
(add-hook 'before-save-hook 'time-stamp) ;; insert time-stamp before saves
(setq visible-bell t) ;; disable audible bell
(setq-default indent-tabs-mode nil) ;; TAB ger mellanslag
(setq default-tab-width 3) ;; set tabs to 3 spaces
(setq speedbar-show-unknown-files t) ;;show all files in speedbar
(set-face-background (quote cursor) "red")
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(setq sentence-end-double-space nil)
(setq dabbrev-abbrev-skip-leading-regexp "[^ ]*[<>=*]") ;; script <tags> when expanding
;; Add color to a shell running in emacs ‘M-x shell’
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(setq exec-path (cons "/opt/local/bin" exec-path))
(setenv "PATH" (concat "/opt/local/bin:/opt/local/sbin:"
(getenv "PATH")))
(set-variable 'vc-path '("/opt/local/bin"))
;; Regex-tool
(set-variable 'regex-tool-backend (quote perl))
;; Mouse-scroll amount
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1) ((control))))
;; Frame-title shows filename
(setq frame-title-format '(multiple-frames "%b" "%b"))
;; Compilation ;;;;;;;;;;;;;;;;;;;;;;;;;
(setq compilation-scroll-output t)
(setq compilation-window-height 8)
;; (setq compilation-finish-function
;; (lambda (buf str)
;; (let (comp-saved-window-configuration (current-window-configuration))
;; (if (string-match "exited abnormally" str)
;; ;;there were errors
;; (message "compilation errors, press C-x ` to visit")
;; ;;no errors, make the compilation window go away in 0.5 seconds
;; (run-at-time 0.5 nil '(set-window-configuration
;; comp-saved-window-configuration))
;; (message "NO COMPILATION ERRORS!")))))
;; Skeletons
(global-set-key "'" 'skeleton-pair-insert-maybe)
(global-set-key "\"" 'skeleton-pair-insert-maybe)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)
(set-variable 'skeleton-pair t)
;; Keybindings
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings)) ;; allows window move with shift-arrowkeys
(global-set-key "\M-1" 'beginning-of-buffer)
(global-set-key "\M-2" 'end-of-buffer)
(global-set-key (kbd "C-M-SPC") 'anything)
(global-set-key "\M-n" 'just-one-space)
(global-set-key "\M-p" 'mark-paragraph)
(global-set-key "\M-j" 'hippie-expand) ;dabbrev-expand)
(setq hippie-expand-dabbrev-as-symbol nil)
(setq hippie-expand-try-functions-list
'(yas/hippie-try-expand
try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name
try-complete-file-name-partially
;;try-expand-all-abbrevs
;;try-expand-list
;;try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol
))
(global-set-key "\C-w" 'backward-kill-word) ;; erases standard kill-region
(global-set-key "\C-x\C-k" 'kill-region) ;; replace standard kill-region
(global-set-key "\M-y" 'anything-show-kill-ring) ;; replace standard yank-pop
(global-set-key (kbd "C-x C-b") #'ibuffer) ;; removes standard list-buffers
(global-set-key "\C-c\C-o" 'ffap)
(global-set-key "\C-x\C-m" 'execute-extended-command) ;; M-x
(global-set-key "\C-c\C-m" 'execute-extended-command) ;; M-x
(global-set-key "\C-xO" (lambda () (interactive) (other-window -1)))
(global-set-key (kbd "C-<tab>") 'other-window)
(global-set-key (kbd "C-S-<tab>") (lambda () (interactive) (other-window -1)))
(global-set-key "\C-o" (lambda() (interactive)
(save-excursion (newline-and-indent))
(indent-according-to-mode)))
(global-set-key (kbd "C-7") 'indent-region)
(global-set-key (kbd "C-8") 'comment-region)
(global-set-key (kbd "C-9") 'uncomment-region)
(global-set-key (kbd "C-s") 'isearch-forward-regexp)
(global-set-key (kbd "C-r") 'isearch-backward-regexp)
(global-set-key "\M-s" 'speedbar-get-focus)
(global-set-key [f5] 'call-last-kbd-macro) ;; bind key for calling last macro
(global-set-key "\M-\"" 'shell-command-on-region)
;; Alias
(defalias 'qrr 'query-replace-regexp)
;; GDB
(setq gdb-many-windows t)
;; Autosaves ;;;;;;;;;;;;;;;;;;;;
;; Put autosave files (ie #foo#) in one place, *not* scattered all over the
;; file system! (The make-autosave-file-name function is invoked to determine
;; the filename of an autosave file.)
(defvar autosave-dir "~/.emacs.d/autosave")
(make-directory autosave-dir t)
(defun auto-save-file-name-p (filename)
(string-match "^#.*#$" (file-name-nondirectory filename)))
(defun make-auto-save-file-name ()
(concat autosave-dir
(if buffer-file-name
(concat "/#" (file-name-nondirectory buffer-file-name) "#")
(expand-file-name
(concat "#%" (buffer-name) "#")))))
;; Put backup files (ie foo~) in one place too. (The backup-directory-alist
;; list contains regexp=>directory mappings; filenames matching a regexp are
;; backed up in the corresponding directory. Emacs will mkdir it if necessary.)
(defvar backup-dir (concat "~/.emacs.d/autosave/backup"))
(setq backup-directory-alist (list (cons "." backup-dir)))
;; Style ;;;;;;;;;;;;;;;;;;;;;;;;;
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;;(when window-system
;; (if (fboundp 'menu-bar-mode) (menu-bar-mode -1)))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;; Functions
(defun insert-date-time()
"Inserts standard date time string."
(interactive)
(insert (format-time-string "%c")))
(defun indent-whole-buffer()
"indent whole buffer"
(interactive)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max))
(delete-trailing-whitespace))
(defalias 'iwb 'indent-whole-buffer)
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "*sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)
(progn
(rename-file name new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil))))))
(defun move-buffer-file (dir)
"Moves both current buffer and file it's visiting to DIR."
(interactive "*DNew directory: ")
(let* ((name (buffer-name))
(filename (buffer-file-name))
(dir
(if (string-match dir "\\(?:/\\|\\\\)$")
(substring dir 0 -1) dir))
(newname (concat dir "/" name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(progn
(copy-file filename newname 1)
(delete-file filename)
(set-visited-file-name newname)
(set-buffer-modified-p nil)
t))))
(defun tidy-buffer ()
"Run Tidy HTML parser on current buffer."
(interactive)
(if (get-buffer "tidy-errs") (kill-buffer "tidy-errs"))
(shell-command-on-region (point-min) (point-max)
"tidy -f /tmp/tidy-errs -q -i -utf8 -asxhtml -wrap 0 -c" t)
(find-file-other-window "/tmp/tidy-errs")
(other-window 1)
(delete-file "/tmp/tidy-errs")
(message "buffer tidy'ed"))
(defun google-region (beg end)
"Google the selected region."
(interactive "r")
(browse-url (concat "http://www.google.com/search?ie=utf-8&oe=utf-8&q=" (buffer-substring beg end))))
;; Open all existing files read-only
;; (defun my-find-file-hook()
;; (toggle-read-only t))
;; (add-hook 'find-file-hook 'my-find-file-hook)
;; Make switching better with completions
(ido-mode 1)
(setq ido-enable-flex-matching t) ; fuzzy matching
(setq ido-create-new-buffer 'always)
;; Log-edit
(add-hook 'log-edit-mode-hook 'flyspell-mode)
;; Buffers/files identical names
;; TODO : move
(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator "|")
(setq uniquify-after-kill-buffer-p t)
(setq uniquify-ignore-buffers-re "^\\*")
(provide 'my-generic)