1 #+TITLE: Emacs Configuration file
3 #+EMAIL: seudut@gmail.com
7 Most config are just copied from [[https://github.com/howardabrams/dot-files][howardabrams]]'s dotfiles
13 Set the system PATH environment
15 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
17 (setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
21 Set the emacs load path
23 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
25 (add-to-list 'load-path "~/.emacs.d/elisp")
29 ** Package Initialization
31 #+BEGIN_SRC emacs-lisp :tangle yes
35 (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
36 ("org" . "http://orgmode.org/elpa/")))
44 Disable scroll bar, tool-bar and menu-bar
46 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
52 (setq debug-on-error t)
53 (setq inhibit-startup-message t)
55 (defalias 'yes-or-no-p 'y-or-n-p)
62 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
64 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
66 (unless (package-installed-p 'use-package)
67 (package-refresh-contents)
68 (package-install 'use-package))
70 (require 'use-package)
74 * Color and Fonts Settings
76 ** highlight current line
78 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
86 [[https://github.com/paldepind/smart-comment][smart-comments]]
88 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
90 (use-package smart-comment
92 :bind ("M-;" . smart-conmment))
100 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
102 (global-font-lock-mode 1)
106 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
108 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
111 (defvar sd/fixed-font-family
112 (cond ((x-list-fonts "Hasklig") "Hasklig")
113 ((x-list-fonts "Source Code Pro") "Source Code Pro")
114 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
115 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
116 "The fixed width font based on what is installed, `nil' if not defined."))
122 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
125 (when sd/fixed-font-family
126 (set-frame-font sd/fixed-font-family)
127 (set-face-attribute 'default nil :font sd/fixed-font-family :height 140)
128 (set-face-font 'default sd/fixed-font-family)))
134 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
136 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
138 (setq vc-follow-symlinks t)
140 (use-package color-theme
142 :init (require 'color-theme)
143 :config (use-package color-theme-sanityinc-tomorrow
147 (load-theme 'sanityinc-tomorrow-bright t)))
149 ;(eval-after-load 'color-theme
150 ; (load-theme 'sanityinc-tomorrow-bright t))
154 Change the Org-mode colors
156 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
158 (defun org-src-color-blocks-light ()
159 "Colors the block headers and footers to make them stand out more for lighter themes"
162 '(org-block-begin-line
163 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
164 '(org-block-background
165 ((t (:background "#FFFFEA"))))
167 ((t (:background "#FFFFEA"))))
169 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
171 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
172 '(which-func ((t (:foreground "#008000"))))))
174 (defun org-src-color-blocks-dark ()
175 "Colors the block headers and footers to make them stand out more for dark themes"
178 '(org-block-begin-line
179 ((t (:foreground "#008ED1" :background "#002E41"))))
180 '(org-block-background
181 ((t (:background "#000000"))))
183 ((t (:background "#000000"))))
185 ((t (:foreground "#008ED1" :background "#002E41"))))
187 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
188 '(which-func ((t (:foreground "green"))))))
190 (org-src-color-blocks-dark)
194 improve color for org-mode
195 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
196 (deftheme ha/org-theme "Sub-theme to beautify org mode")
199 (defvar sd/variable-font-tuple
200 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
201 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
202 ((x-list-fonts "Verdana") '(:font "Verdana"))
203 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
204 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
205 "My variable width font available to org-mode files and whatnot."))
207 (defun sd/org-color ()
208 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
209 (base-font-color (face-foreground 'default nil 'default))
210 (background-color (face-background 'default nil 'default))
211 (primary-color (face-foreground 'mode-line nil))
212 (secondary-color (face-background 'secondary-selection nil 'region))
213 (base-height (face-attribute 'default :height))
214 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
215 (custom-theme-set-faces 'ha/org-theme
216 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
217 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
218 `(org-table ((t (:inherit 'fixed-pitched))))
219 `(org-block ((t (:inherit 'fixed-pitched))))
220 `(org-block-background ((t (:inherit 'fixed-pitched))))
221 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
222 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
223 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
224 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
225 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
226 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
227 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
228 :height ,(round (* 1.1 base-height))))))
229 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
230 :height ,(round (* 1.25 base-height))))))
231 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
232 :height ,(round (* 1.5 base-height))))))
233 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
234 :height ,(round (* 1.75 base-height))))))
235 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
245 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
247 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
249 (use-package org-bullets
252 (add-hook 'org-mode-hook
254 (org-bullets-mode t))))
258 ** Org-mode Basic setting
260 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
262 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
264 (setq org-startup-indented t)
265 (setq org-hide-leading-starts t)
266 ;(setq org-src-fontify-natively t)
267 (setq org-src-tab-acts-natively t)
268 (setq org-confirm-babel-evaluate nil)
270 (org-babel-do-load-languages
271 'org-babel-load-languages
292 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
294 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
298 :commands magit-status magit-blame)
307 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
311 :init (setq ido-enable-flex-matching t
312 ido-ignore-extensions t
313 ido-use-virtual-buffers t
318 (add-to-list 'completion-ignored-extensions ".pyc"))
324 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
328 :init (setq ido-enable-flex-matching t
330 :config (flx-ido-mode 1))
336 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
338 (use-package ido-vertical-mode
341 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
343 (ido-vertical-mode 1))
349 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
353 :init (smex-initialize)
356 ("M-X" . smex-major-mode-commands))
364 Enable linum mode on programming modes
366 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
368 (add-hook 'prog-mode-hook 'linum-mode)
372 Fix the font size of line number
374 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
376 (defun fix-linum-size ()
378 (set-face-attribute 'linum nil :height 110))
380 (add-hook 'linum-mode-hook 'fix-linum-size)
384 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
386 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
388 (use-package linum-relative
391 (defun linum-new-mode ()
392 "If line numbers aren't displayed, then display them.
393 Otherwise, toggle between absolute and relative numbers."
396 (linum-relative-toggle)
400 ("A-k" . linum-new-mode))
402 ;; auto enable linum-new-mode in programming modes
403 (add-hook 'prog-mode-hook 'linum-relative-mode)
407 ** Save File Position
409 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
412 (setq-default save-place t)
413 (setq save-place-forget-unreadable-files t)
414 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
418 * Programming Languages
422 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
424 (use-package color-identifiers-mode
427 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
428 :diminish color-identifiers-mode)