1327aa07d0486ca9ad246526e0cdec979b759d6a
[dotfiles.git] / emacs / emacs
1
2 (setq debug-on-error t)
3
4 (scroll-bar-mode -1)
5 (tool-bar-mode -1)
6 (menu-bar-mode -1)
7 (add-to-list 'default-frame-alist '(width  . 120))
8 (add-to-list 'default-frame-alist '(height . 40))
9 ;(add-to-list 'default-frame-alist '(font . "Source Code Pro for Powerline-12:weight:light" ))
10 (add-to-list 'default-frame-alist '(font . "Source Code Pro for Powerline-14" ))
11 (load-theme 'tango-dark)
12
13 (put 'set-goal-column 'disabled nil)
14 (setq vc-follow-symlinks t)
15 (setq visible-bell 1)
16 (setq ring-bell-function 'ignore)
17 (setq resize-mini-windows t)
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;http://y.tsutsumi.io/emacs-from-scratch-part-2-package-management.html
20 (require 'package)
21 (add-to-list 'package-archives
22              '("melpa" . "http://melpa.milkbox.net/packages/") t)
23 (package-initialize)
24
25 (defvar required-packages
26   '(
27     magit
28     helm
29     ido-ubiquitous
30     yasnippet
31     evil
32     ido-vertical-mode
33     smex
34     color-theme
35     color-theme-sanityinc-tomorrow
36     key-chord
37 ;    powerline-evil
38     powerline
39     evil-leader
40     flx-ido
41     flx
42     auto-complete
43     fiplr
44     w3m
45     ace-jump-mode
46     el-get
47     color-identifiers-mode
48   ) "a list of packages to ensure are installed at launch.")
49
50 (require 'cl)
51 (defun packages-installed-p ()
52   (loop for p in required-packages
53         when (not (package-installed-p p)) do (return nil)
54         finally (return t)))
55
56 (unless (packages-installed-p)
57   (message "%s" "Emacs is now refreshing its package database...")
58   (package-refresh-contents)
59   (message "%s" " done.")
60   (dolist (p required-packages)
61     (when (not (package-installed-p p))
62       (package-install p))))
63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64
65 (setq fiplr-root-markers '(".git" ".svn" "*.DS_Store"))
66 (setq fiplr-ignored-globs '((directories (".git" ".svn"))
67                             (files ("*.jpg" "*.png" "*.zip" "*~" "*.o" ".obj" "*.swp" "*.hg" ".pyc" ".*" ))))
68
69
70 ;(setq mac-right-option-modifier 'control)
71
72 (global-set-key (kbd "C-x f") 'fiplr-find-file)
73 ;;;; ------------------------------------ Ido ---------------------------------------------
74 (ido-mode 1)
75 (ido-everywhere 1)
76 (flx-ido-mode 1)
77 (setq ido-use-faces nil)
78 (setq ido-enable-flex-matching t)
79 (require 'ido-vertical-mode)
80 (setq ido-use-faces t)
81 (set-face-attribute 'ido-vertical-first-match-face nil
82                     :background "#e5b7c0")
83 (set-face-attribute 'ido-vertical-only-match-face nil
84                     :background "#e52b50"
85                     :foreground "white")
86 (set-face-attribute 'ido-vertical-match-face nil
87                     :foreground "#b00000")
88 (ido-vertical-mode 1)
89
90 ;; smex
91 (require 'smex) 
92 (global-set-key (kbd "M-x") 'smex)
93 (global-set-key (kbd "M-X") 'smex-major-mode-commands)
94 ;;;; ----------------------------------------------------------------------------------------
95
96 ;;;; ---------------------------------- evil ------------------------------------------------
97 (global-evil-leader-mode)
98 (evil-leader/set-leader ";")
99 (evil-leader/set-key "e" 'find-file)
100 (evil-leader/set-key "b" 'switch-to-buffer)
101 (require 'evil)
102 ;;Exit insert mode by pressing j and then j quickly
103 ;(setq key-chord-two-keys-delay 0.5)
104 ;(key-chord-define evil-normal-state-map "jj" 'evil-force-normal-state)
105 (key-chord-define evil-visual-state-map "jj" 'evil-change-to-previous-state)
106 (key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
107 (key-chord-define evil-replace-state-map "jj" 'evil-normal-state)
108 (key-chord-mode 1)
109
110 ;; change mode-line color by evil state
111 (lexical-let ((default-color (cons (face-background 'mode-line)
112                                    (face-foreground 'mode-line))))
113   (add-hook 'post-command-hook
114             (lambda ()
115               (let ((color (cond ((minibufferp) default-color)
116                                  ((evil-insert-state-p) '("#e80000" . "#ffffff"))
117                                  ((evil-emacs-state-p)  '("#444488" . "#ffffff"))
118                                  ((buffer-modified-p)   '("#006fa0" . "#ffffff"))
119                                  (t default-color))))
120                 (set-face-background 'mode-line (car color))
121                            (set-face-foreground 'mode-line (cdr color))))))
122 ;(evil-mode 1)
123 ;;(require 'powerline-evil)
124 ;; TODO: enter emacs mode in eshll rather then evil mode
125 ;;
126 ;;;; ---------------------------------- evil ------------------------------------------------
127
128 ;;;; ------------------------------------ helm ---------------------------------------------
129 ;;;;;;;;;;; helm configuration https://github.com/emacs-helm/helm http://tuhdo.github.io/helm-intro.html
130 ;;(require 'helm-config)
131 ;;(global-set-key (kbd "M-x") 'helm-M-x)
132 ;;(helm-mode 1)
133 ;;(setq helm-M-x-fuzzy-match t)
134 ;;(global-set-key (kbd "C-x b") 'helm-mini)
135 ;;(setq helm-buffers-fuzzy-matching t
136 ;;      helm-recentf-fuzzy-match    t)
137 ;;(global-set-key (kbd "C-x C-f") 'helm-find-files)
138 ;;(when (executable-find "ack-grep")
139 ;;  (setq helm-grep-default-command "ack-grep -Hn --no-group --no-color %e %p %f"
140 ;;        helm-grep-default-recurse-command "ack-grep -H --no-group --no-color %e %p %f"))
141 ;;(setq helm-ff-skip-boring-files t)
142 ;;;(require 'helm-config)
143 ;;;(require 'helm-themes)
144 ;;;(set-face-attribute 'helm-selection nil :background "#441100")
145 ;;;; ----------------------------------------------------------------------------------------
146
147 ;; magit
148 ;; will get ad-handle-definition:  got redefined
149 (require 'magit)
150 ;(setq magit-auto-revert-mode nil)
151 (setq magit-last-seen-setup-instructions "1.4.0")
152
153 (require 'auto-complete)
154 (auto-complete-mode 1)
155
156
157 ;;; ---------------------------------------- el-get -----------------------------------------
158 ;(require 'el-get)
159 ;(add-to-list 'el-get-recipe-path "~/.emacs.d/el-get-user/recipes")
160
161 ;(el-get-bundle packages/sm-package-powerline
162 ;  :url "https://github.com/laynor/emacs-conf.git"
163 ;  )
164
165
166 ;;; -----------------------------------------------------------------------------------------
167 ;(add-to-list 'load-path "~/.emacs.d/test/powerline")
168 (require 'powerline)
169
170 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
171 (global-font-lock-mode 1)
172 (setq my/font-family "Source Code Pro")
173 (set-frame-font my/font-family)
174 (set-face-attribute 'default nil :font my/font-family :height 120)
175 (set-face-font 'default my/font-family)
176
177
178
179 ;;;;;;;;;;;;;;;; color theme 
180 (require 'color-theme)
181 (defun org-src-color-blocks-light ()
182   "Colors the block headers and footers to make them stand out more for lighter themes"
183   (interactive)
184   (custom-set-faces
185    '(org-block-begin-line
186     ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
187    '(org-block-background
188      ((t (:background "#FFFFEA"))))
189    '(org-block-end-line
190      ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
191
192    '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
193    '(which-func ((t (:foreground "#008000")))))
194
195    ;; Looks like the minibuffer issues are only for v23
196    ; (set-face-foreground 'minibuffer "black")
197    ; (set-face-foreground 'minibuffer-prompt "red")
198 )
199
200 (defun org-src-color-blocks-dark ()
201   "Colors the block headers and footers to make them stand out more for dark themes"
202   (interactive)
203   (custom-set-faces
204    '(org-block-begin-line
205      ((t (:foreground "#008ED1" :background "#002E41"))))
206    '(org-block-background
207      ((t (:background "#111111"))))
208    '(org-block-end-line
209      ((t (:foreground "#008ED1" :background "#002E41"))))
210
211    '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
212    '(which-func ((t (:foreground "green")))))
213
214    ;; Looks like the minibuffer issues are only for v23
215    ;; (set-face-foreground 'minibuffer "white")
216    ;; (set-face-foreground 'minibuffer-prompt "white")
217 )
218
219 (deftheme ha/org-theme "Sub-theme to beautify org mode")
220
221
222 (defun ha/change-theme (theme org-block-style)
223   "Changes the color scheme and reset the mode line."
224   (funcall theme)
225   (powerline-reset)
226   (funcall org-block-style)
227
228   (let* ((sans-font (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
229                           ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
230                           ((x-list-fonts "Verdana")         '(:font "Verdana"))
231                           ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
232                           (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro."))))
233          (base-font-color  (face-foreground 'default nil 'default))
234          (background-color (face-background 'default nil 'default))
235          (primary-color    (face-foreground 'mode-line nil))
236          (secondary-color  (face-background 'secondary-selection nil 'region))
237          (headline        `(:inherit default :weight bold :foreground ,base-font-color)))
238     (custom-theme-set-faces 'ha/org-theme
239                             `(org-agenda-structure ((t (:inherit default ,@sans-font :height 2.0 :underline nil))))
240                             `(org-level-8 ((t (,@headline ,@sans-font))))
241                             `(org-level-7 ((t (,@headline ,@sans-font))))
242                             `(org-level-6 ((t (,@headline ,@sans-font))))
243                             `(org-level-5 ((t (,@headline ,@sans-font))))
244                             `(org-level-4 ((t (,@headline ,@sans-font :height 1.1))))
245                             `(org-level-3 ((t (,@headline ,@sans-font :height 1.25))))
246                             `(org-level-2 ((t (,@headline ,@sans-font :height 1.5))))
247                             `(org-level-1 ((t (,@headline ,@sans-font :height 1.75))))
248                             `(org-document-title ((t (,@headline ,@sans-font :height 1.5 :underline nil)))))))
249
250
251 (if (equal "howard.abrams" user-login-name)
252 ;(if (equal "peli3" user-login-name)
253   (ha/change-theme 'color-theme-sanityinc-tomorrow-day
254                    'org-src-color-blocks-light)
255   (ha/change-theme 'color-theme-sanityinc-tomorrow-night
256                    'org-src-color-blocks-dark))
257
258
259 ;(define-sequence 'personal-theme-map "<f9> d" 'ha/change-theme
260 ;  (list (list "d" 'color-theme-sanityinc-tomorrow-day      'org-src-color-blocks-light)  ; White on Black
261 ;        (list "l" 'color-theme-sanityinc-tomorrow-eighties 'org-src-color-blocks-dark)   ; Lt. Gray on Gray
262 ;        (list "m" 'color-theme-sanityinc-tomorrow-bright   'org-src-color-blocks-dark)   ; Bright on Black
263 ;        (list "n" 'color-theme-sanityinc-tomorrow-night    'org-src-color-blocks-dark))) ; White on Gray
264
265 ;;;;;;;;; mode line
266 (setq which-func-unknown "")
267 (which-function-mode 1)
268
269 (setq which-func-format
270       `(" "
271         (:propertize which-func-current local-map
272                      (keymap
273                       (mode-line keymap
274                                  (mouse-3 . end-of-defun)
275                                  (mouse-2 . narrow-to-defun)
276                                  (mouse-1 . beginning-of-defun)))
277                      face which-func
278                      mouse-face mode-line-highlight
279                      help-echo "mouse-1: go to beginning\n\
280 mouse-2: toggle rest visibility\n\
281 mouse-3: go to end")
282         " "))
283
284
285 (defun powerline-simpler-vc-mode (s)
286   (if s
287       (replace-regexp-in-string "Git:" "" s)
288     s))
289
290 (defun powerline-simpler-minor-display (s)
291   (replace-regexp-in-string
292    (concat " "
293            (mapconcat 'identity '("Undo-Tree" "GitGutter" "Projectile"
294                                   "Abbrev" "ColorIds" "MRev" "ElDoc" "Paredit"
295                                   "+1" "+2" "FlyC" "Fly" ;; ":1/0"
296                                   "Fill" "AC" "FIC") "\\|")) "" s))
297
298 (defun powerline-ha-theme ()
299   "A powerline theme that removes many minor-modes that don't serve much purpose on the mode-line."
300   (interactive)
301   (setq-default mode-line-format
302                 '("%e"
303                   (:eval
304                    (let*
305                        ((active
306                          (powerline-selected-window-active))
307                         (mode-line
308                          (if active 'mode-line 'mode-line-inactive))
309                         (face1
310                          (if active 'powerline-active1 'powerline-inactive1))
311                         (face2
312                          (if active 'powerline-active2 'powerline-inactive2))
313                         (separator-left
314                          (intern
315                           (format "powerline-%s-%s" powerline-default-separator
316                                   (car powerline-default-separator-dir))))
317                         (separator-right
318                          (intern
319                           (format "powerline-%s-%s" powerline-default-separator
320                                   (cdr powerline-default-separator-dir))))
321                         (lhs
322                          (list
323                           (powerline-raw "%*" nil 'l)
324                           ;; (powerline-buffer-size nil 'l)
325                           (powerline-buffer-id nil 'l)
326                           (powerline-raw " ")
327                           (funcall separator-left mode-line face1)
328                           (powerline-narrow face1 'l)
329                           (powerline-simpler-vc-mode (powerline-vc face1))))
330                         (rhs
331                          (list
332                           (powerline-raw mode-line-misc-info face1 'r)
333                           (powerline-raw global-mode-string face1 'r)
334                           (powerline-raw "%4l" face1 'r)
335                           (powerline-raw ":" face1)
336                           (powerline-raw "%3c" face1 'r)
337                           (funcall separator-right face1 mode-line)
338                           (powerline-raw " ")
339                           (powerline-raw "%6p" nil 'r)
340                           (powerline-hud face2 face1)))
341                         (center
342                          (list
343                           (powerline-raw " " face1)
344                           (funcall separator-left face1 face2)
345                           (when
346                               (boundp 'erc-modified-channels-object)
347                             (powerline-raw erc-modified-channels-object face2 'l))
348                           (powerline-major-mode face2 'l)
349                           (powerline-process face2)
350                           (powerline-raw " :" face2)
351
352                           (powerline-simpler-minor-display (powerline-minor-modes face2 'l))
353
354                           (powerline-raw " " face2)
355                           (funcall separator-right face2 face1))))
356                      (concat
357                       (powerline-render lhs)
358                       (powerline-fill-center face1
359                                              (/
360                                               (powerline-width center)
361                                               2.0))
362                       (powerline-render center)
363                       (powerline-fill face1
364                                       (powerline-width rhs))
365                       (powerline-render rhs)))))))
366
367 (powerline-ha-theme)
368
369
370 (provide 'init-mode-line)
371 (fringe-mode -1)