summaryrefslogtreecommitdiffstats
path: root/.emacs.d/init.el
blob: aac7344b904eaed80ef24195969c069e1da59a98 (plain)
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
;; -*- mode: Emacs-Lisp; -*-
(load "~/.emacs.d/ryuslash-load-path")
(load "~/.emacs.d/functions")
;;; Theme
(require 'naquadah-theme)
(eval-after-load 'naquadah-theme
  (naquadah-theme-set-faces
   'naquadah

   ;; markdown-mode
   '(markdown-link-face (:inherit 'link))
   '(markdown-header-face-1 (:inherit 'org-level-1))
   '(markdown-header-face-2 (:inherit 'org-level-2))
   '(markdown-header-face-3 (:inherit 'org-level-3))
   '(markdown-header-face-4 (:inherit 'org-level-4))
   '(markdown-header-face-5 (:inherit 'org-level-5))
   '(markdown-header-face-6 (:inherit 'org-level-6))))

;;; Autopair
(require 'autopair)
(autopair-global-mode t)       ; automatically add the other delimiter
(setq autopair-skip-criteria 'always
      autopair-autowrap      t
      autopair-blink         nil)
(setq-default autopair-dont-pair '(:string (?\' ?\") :comment (?\')))

;; Column marker
(defun set-column-markers (cm1 cm2)
  (column-marker-1 cm1)
  (column-marker-2 cm2))

(require 'column-marker)

(dolist (hook '(prog-mode-hook html-mode-hook))
  (add-hook hook
            (lambda ()
              (set-column-markers 73 81))))

(add-hook 'php-mode-hook
          (lambda ()
            (set-column-markers 76 81)))

;;; Org mode
(require 'org-crypt)
(require 'org-publish)
(setq
 org-tags-exclude-from-inheritance  '("crypt")
 org-crypt-key                      "33E8CC1CC4"
 org-use-fast-todo-selection        t
 org-default-notes-file             (concat org-directory
                                            "/notes.org")
 org-outline-path-complete-in-steps t
 org-return-follows-link            t
 org-log-into-drawer                t
 org-todo-keywords                  '((sequence "TODO(t)"
                                                "IN PROGRESS(p)"
                                                "WAITING(w@/!)"
                                                "|"
                                                "DONE(d!/!)"
                                                "CANCELLED(c@/!)"))
 org-refile-targets                 '((org-agenda-files :maxlevel . 5)
                                      (nil              :maxlevel . 5))
 org-todo-keyword-faces
 '(("TODO"        :foreground "red"          :weight bold)
   ("IN PROGRESS" :foreground "yellow"       :weight bold)
   ("DONE"        :foreground "forest green" :weight bold)
   ("WAITING"     :foreground "orange"       :weight bold)
   ("CANCELLED"   :foreground "orangered"    :weight bold)))
(add-to-list 'auto-mode-alist '("\\.commitmsg$" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-ca" 'org-agenda)
(add-hook 'org-mode-hook
          (lambda ()
            (flyspell-mode t)
            (auto-fill-mode t)))
(org-crypt-use-before-save-magic)

;;; Rainbow delimiters
(require 'rainbow-delimiters)
(setq rainbow-delimiters-max-face-count 8)

;;; Uniquify
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward)

;;; Go
(autoload 'go-mode            "go-mode" "Major mode for google go" t)
(autoload 'gofmt              "go-mode"                         "" t)
(autoload 'go-fmt-before-save "go-mode"                         "" t)
(add-to-list 'auto-mode-alist '("\\.go$" . go-mode))
(add-hook 'go-mode-hook
          (lambda ()
            (turn-off-auto-fill)
            (column-marker-1 -1)))

;;; Htmlize
(require 'htmlize)
(setq htmlize-output-type 'inline-css)

;;; Git
(require 'git)

;;; Markdown mode
(autoload 'markdown-mode "markdown-mode" "Major mode for Markdown" t)
(setq whitespace-style '(face trailing)) ; For use with markdown mode
(add-to-list 'auto-mode-alist '("\\.m\\(ark\\)?do?wn$". markdown-mode))
(add-hook 'markdown-mode-hook
          (lambda ()
            (whitespace-mode 1)
            (turn-on-auto-fill)))

;;; Xmodmap mode
(autoload 'xmodmap-mode "xmodmap-mode" "Major mode for xmodmap" t)
(add-to-list 'auto-mode-alist '("\\.[xX]modmap\\(rc\\)?$" . xmodmap-mode))

;;; Gtags
(autoload 'gtags-mode "gtags" "Minor mode for using gtags" t)
(add-hook 'gtags-mode-hook
          (lambda ()
            (local-set-key (kbd "M-,") 'gtags-find-tag) ; find a tag,
                                        ; also M-.
            (local-set-key (kbd "M-.") 'gtags-find-rtag))) ; reverse
                                        ; tag

(add-hook 'c-mode-common-hook
          (lambda ()
            (gtags-mode t)
            (djcb-gtags-create-or-update)))

;;; PHP
(defun oni-php-show-outline ()
  (interactive)
  (occur "\\(function .*(\\|\\(public\\|private\\|protected\\)\\( static\\)? \\$\\|class \\sw\\)"))

(autoload 'php-mode "php-mode" "Major mode for PHP" t)
(setq-default php-mode-warn-if-mumamo-off nil) ; don't warn me about this
(setq php-mode-force-pear t)
(add-to-list 'auto-mode-alist '("\\.php[345]?$" . php-mode))
(add-hook 'php-mode-hook
          (lambda ()
            (c-set-offset 'arglist-intro '+)
            (c-set-offset 'arglist-close '0)
            (local-set-key [f6] 'comment-line)
            (local-set-key [f7] 'oni-php-show-outline)))
(add-php-keywords)

;;; bidi
(setq-default bidi-display-reordering nil)

;;; Message
(add-hook 'message-mode-hook
          (lambda ()
            (turn-on-auto-fill)
            (turn-on-flyspell)))

;;; Gnus
(setq gnus-init-file "~/.emacs.d/gnus")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                         AUTOLOADS                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload 'vala-mode         "vala-mode"         "Major mode for Vala" t)
(autoload 'csharp-mode       "csharp-mode"         "Major mode for C#" t)
(autoload 'sqlplus-mode      "sqlplus"         "Major mode for PL/SQL" t)
(autoload 'batch-mode        "batch-mode"       "Major mode for Batch" t)
(autoload 'lua-mode          "lua-mode"         "A Major mode for Lua" t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode"  "Major mode for dot" t)
(autoload 'cmake-mode        "cmake-mode"       "Major mode for CMake" t)
(autoload 'rainbow-mode      "rainbow-mode"    "Minor mode for colors" t)
(autoload 'stumpwm-mode      "stumpwm-mode"   "Major mode for stumpwm" t)
(autoload 'git-commit-mode    "git-commit"                      "" t)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                         VARIABLES                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar font-lock-operator-face 'font-lock-operator-face)
(defvar font-lock-end-statement 'font-lock-end-statement)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                          SETTINGS                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq-default indent-tabs-mode nil)       ; spaces, no tabs
(setq-default truncate-lines t)           ; don't wrap
(setq-default tab-width 4)

(setq inhibit-startup-message t)        ; Don't show welcome screen
(setq require-final-newline t)          ; Always put final newline
(setq inhibit-default-init t)           ; Don't load default library
(setq scroll-conservatively 101)        ; scroll only one line
(setq browse-url-browser-function 'browse-url-generic)
(setq browse-url-generic-program (getenv "BROWSER"))
(setq uniquify-buffer-name-style 'reverse)
(setq jit-lock-defer-time 0.2)          ; Don't fontlock immediately
(setq ido-save-directory-list-file nil)
(setq ido-auto-merge-delay-time 2)      ; Wait before fixing names
(setq mouse-autoselect-window t)
(setq pop-up-windows nil)

(setq frame-title-format ; I don't like emacs@cloud, must have file
 '(:eval                 ; name
   (concat "emacs: " (buffer-name))))

(setq backup-directory-alist            ; backup file location
 `((".*" . ,temporary-file-directory)))

(setq auto-save-file-name-transforms    ; autosave file location
 `((".*" ,temporary-file-directory t)))

(setq default-frame-alist               ; default frame settings
      (append '((font . "DejaVu Sans Mono-11:antialias=true"))))
(setq initial-frame-alist               ; initial frame settings
      (append '((font . "DejaVu Sans Mono-11:antialias=true"))))

(if window-system
    (x-init)
  (cli-init))

(fset 'yes-or-no-p 'y-or-n-p)           ; switch yes or no to y or n

(tool-bar-mode -1)                ; no toolbar
(menu-bar-mode -1)                ; no menubar
(line-number-mode -1)             ; don't show line number in splitter
(global-linum-mode t)             ; Show line numbers in gutter
(column-number-mode t)            ; show column number in splitter
(global-font-lock-mode t)         ; show syntax highlighting, old
(delete-selection-mode t)         ; delete selection upon typing
(show-paren-mode t)               ; show the opposite paren
(ido-mode t)

(add-to-list 'compilation-finish-functions 'my-comp-finish-function)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                     FILE ASSOCIATIONS                      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist '("\\.vala$"            . vala-mode))
(add-to-list 'auto-mode-alist '("\\.vapi$"            . vala-mode))
(add-to-list 'auto-mode-alist '("\\.cs$"              . csharp-mode))
(add-to-list 'auto-mode-alist '("\\.bat$"             . batch-mode))
(add-to-list 'auto-mode-alist '("\\.lua$"             . lua-mode))
(add-to-list 'auto-mode-alist '("\\.js\\(on\\)?$"     . js-mode))
(add-to-list 'auto-mode-alist '("CMakeLists\\.txt$"   . cmake-mode))
(add-to-list 'auto-mode-alist '("\\.cmake$"           . cmake-mode))
(add-to-list 'auto-mode-alist '("\\.css$"             . css-mode))
(add-to-list 'auto-mode-alist '("stumpwmrc"           . stumpwm-mode))
(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG$"     . git-commit-mode))
(add-to-list 'auto-mode-alist '("\\.tpl$"             . html-mode))

(add-to-list 'file-coding-system-alist '("\\.vala$" . utf-8))
(add-to-list 'file-coding-system-alist '("\\.vapi$" . utf-8))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                          KEYBINDS                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(global-set-key "\C-m" 'newline-and-indent)
(global-set-key (kbd "C-x n r") 'narrow-to-region)
(global-set-key [f5] '(lambda ()
                        (interactive)
                        (revert-buffer nil t nil)))
(global-set-key [M-left]  'windmove-left)
(global-set-key [M-right] 'windmove-right)
(global-set-key [M-up]    'windmove-up)
(global-set-key [M-down]  'windmove-down)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                           HOOKS                            ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'before-save-hook 'on-before-save)
(add-hook 'after-save-hook  'on-after-save)

(if (>= emacs-major-version 24)
    (add-hook 'prog-mode-hook             'on-prog-mode)
  (progn
    (add-hook 'c-mode-common-hook   'on-prog-mode)
    (add-hook 'go-mode-hook         'on-prog-mode)
    (add-hook 'emacs-lisp-mode-hook 'on-prog-mode)))

(add-hook 'c-mode-hook                'on-c-mode)
(add-hook 'html-mode-hook             'on-html-mode)
(add-hook 'git-commit-mode-hook       'auto-fill-mode)
(add-hook 'css-mode-hook              'rainbow-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                         SKELETONS                          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-skeleton cmake-project-skeleton
  "A cmake project template file"
  "Name: "
  "cmake_minimum_required(VERSION 2.6)\n"
  "project(" str ")\n"
  "\n"
  "set(" str "_VERSION_MAJOR 0)\n"
  "set(" str "_VERSION_MINOR 0)\n"
  "set(" str "_VERSION_PATCH 0)\n"
  "\n"
  "set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})\n"
  "add_subdirectory(src)")

(define-skeleton myaethon-set-varchar-docstring
  "A docstring for a varchar setter"
  ""
  "\/* Setter for the "
  (skeleton-read "name: ")
  " column\n"
  "\n"
  '(indent-according-to-mode)
  "$value: string, no longer than "
  (skeleton-read "len: ")
  " characters */"
  '(fill-paragraph))

(define-skeleton myaethon-set-array-varchar-docstring
  "A docstring for an array/varchar setter"
  ""
  '(setq name (skeleton-read "name: "))
  '(setq len (string-to-number (skeleton-read "length: ")))
  '(setq size (floor (/ (- len 1) 2)))
  "/* Setter for the "
  name
  " column\n"
  "\n"
  '(indent-according-to-mode)
  "$value: array, with no more than "
  (number-to-string size)
  " elements; string, no langer than "
  (number-to-string len)
  " characters */"
  '(fill-paragraph))

(define-skeleton myaethon-simple-entity
  "A basic database entity"
  ""
  '(setq name (skeleton-read "Name: "))
  "<?php\n"
  "require_once('classes/dbobject.php');\n"
  "\n"
  "/* Entity for the " (downcase name) " table */\n"
  "class " name " extends DB_Object\n"
  "{\n"
  "/* Table to select data from */\n"
  "protected static $tables = '" (downcase name) "';\n"
  "\n"
  "/* Get the name of this class\n"
  "--\n"
  "ret: __CLASS__ */\n"
  "protected static function get_class_name()\n"
  "{\n"
  "return __CLASS__;\n"
  "}\n"
  "\n"
  "public function update()\n"
  "{\n"
  "throw new Exception('Not Implemented.');\n"
  "}\n"
  "\n"
  "public function insert()\n"
  "{\n"
  "throw new Exception('Not Implemented.');\n"
  "}\n"
  "}\n"
  "\n"
  "?>\n"
  '(indent-region (point-min) (point-max)))

(add-html-keywords)
(make-face 'font-lock-operator-face)
(make-face 'font-lock-end-statement)
(set-face-foreground 'font-lock-operator-face "#EDD400")
(set-face-foreground 'font-lock-end-statement "#888A85")

;; Custom file
(setq custom-file "~/.emacs.d/custom.el")
(if (file-exists-p custom-file)
    (load custom-file))
(defvar home-file "~/wiki.info" "File to open when starting")
(if (file-exists-p home-file)
    (info home-file))