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
11 ** Setting loading Path
13 Set the emacs load path
15 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
17 (add-to-list 'load-path "~/.emacs.d/elisp")
21 ** Package Initialization
23 #+BEGIN_SRC emacs-lisp :tangle yes
27 (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/")
28 ("org" . "http://orgmode.org/elpa/")))
36 Disable scroll bar, tool-bar and menu-bar
38 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
44 (setq debug-on-error t)
45 (setq inhibit-startup-message t)
47 (defalias 'yes-or-no-p 'y-or-n-p)
54 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
56 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
58 (unless (package-installed-p 'use-package)
59 (package-refresh-contents)
60 (package-install 'use-package))
62 (require 'use-package)
66 * Color and Fonts Settings
68 ** highlight current line
70 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
78 [[https://github.com/paldepind/smart-comment][smart-comments]]
80 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
82 (use-package smart-comment
84 :bind ("M-;" . smart-conmment))
92 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
94 (global-font-lock-mode 1)
98 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
100 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
103 (defvar sd/fixed-font-family
104 (cond ((x-list-fonts "Hasklig") "Hasklig")
105 ((x-list-fonts "Source Code Pro") "Source Code Pro")
106 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
107 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
108 "The fixed width font based on what is installed, `nil' if not defined."))
114 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
117 (when sd/fixed-font-family
118 (set-frame-font sd/fixed-font-family)
119 (set-face-attribute 'default nil :font sd/fixed-font-family :height 140)
120 (set-face-font 'default sd/fixed-font-family)))
126 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
128 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
130 (setq vc-follow-symlinks t)
132 (use-package color-theme
134 :init (require 'color-theme)
135 :config (use-package color-theme-sanityinc-tomorrow
139 (load-theme 'sanityinc-tomorrow-bright t)))
141 ;(eval-after-load 'color-theme
142 ; (load-theme 'sanityinc-tomorrow-bright t))
146 Change the Org-mode colors
148 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
150 (defun org-src-color-blocks-light ()
151 "Colors the block headers and footers to make them stand out more for lighter themes"
154 '(org-block-begin-line
155 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
156 '(org-block-background
157 ((t (:background "#FFFFEA"))))
159 ((t (:background "#FFFFEA"))))
161 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
163 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
164 '(which-func ((t (:foreground "#008000"))))))
166 (defun org-src-color-blocks-dark ()
167 "Colors the block headers and footers to make them stand out more for dark themes"
170 '(org-block-begin-line
171 ((t (:foreground "#008ED1" :background "#002E41"))))
172 '(org-block-background
173 ((t (:background "#000000"))))
175 ((t (:background "#000000"))))
177 ((t (:foreground "#008ED1" :background "#002E41"))))
179 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
180 '(which-func ((t (:foreground "green"))))))
182 (org-src-color-blocks-dark)
186 improve color for org-mode
187 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
188 (deftheme ha/org-theme "Sub-theme to beautify org mode")
191 (defvar sd/variable-font-tuple
192 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
193 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
194 ((x-list-fonts "Verdana") '(:font "Verdana"))
195 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
196 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
197 "My variable width font available to org-mode files and whatnot."))
199 (defun sd/org-color ()
200 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
201 (base-font-color (face-foreground 'default nil 'default))
202 (background-color (face-background 'default nil 'default))
203 (primary-color (face-foreground 'mode-line nil))
204 (secondary-color (face-background 'secondary-selection nil 'region))
205 (base-height (face-attribute 'default :height))
206 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
207 (custom-theme-set-faces 'ha/org-theme
208 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
209 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
210 `(org-table ((t (:inherit 'fixed-pitched))))
211 `(org-block ((t (:inherit 'fixed-pitched))))
212 `(org-block-background ((t (:inherit 'fixed-pitched))))
213 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
214 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
215 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
216 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
217 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
218 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
219 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
220 :height ,(round (* 1.1 base-height))))))
221 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
222 :height ,(round (* 1.25 base-height))))))
223 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
224 :height ,(round (* 1.5 base-height))))))
225 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
226 :height ,(round (* 1.75 base-height))))))
227 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
234 ** Org-mode Basic setting
236 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
238 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
241 (setq org-startup-indented t)
242 (setq org-hide-leading-starts t)
243 (setq org-src-fontify-natively t)
244 (setq org-src-tab-acts-natively t)
245 (setq org-confirm-babel-evaluate nil)
247 (org-babel-do-load-languages
248 'org-babel-load-languages
261 (setq org-use-speed-commands t
262 org-completion-use-ido t)
269 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
271 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
273 (use-package org-bullets
276 (add-hook 'org-mode-hook
278 (org-bullets-mode t))))
284 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode
286 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
291 :init (add-hook 'org-mode-hook 'worf-mode))
301 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
303 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
307 :commands magit-status magit-blame)
316 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
320 :init (setq ido-enable-flex-matching t
321 ido-ignore-extensions t
322 ido-use-virtual-buffers t
327 (add-to-list 'completion-ignored-extensions ".pyc"))
333 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
337 :init (setq ido-enable-flex-matching t
339 :config (flx-ido-mode 1))
345 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
347 (use-package ido-vertical-mode
350 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
352 (ido-vertical-mode 1))
358 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
362 :init (smex-initialize)
365 ("M-X" . smex-major-mode-commands))
373 Enable linum mode on programming modes
375 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
377 (add-hook 'prog-mode-hook 'linum-mode)
381 Fix the font size of line number
383 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
385 (defun fix-linum-size ()
387 (set-face-attribute 'linum nil :height 110))
389 (add-hook 'linum-mode-hook 'fix-linum-size)
393 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
395 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
397 (use-package linum-relative
400 (defun linum-new-mode ()
401 "If line numbers aren't displayed, then display them.
402 Otherwise, toggle between absolute and relative numbers."
405 (linum-relative-toggle)
409 ("A-k" . linum-new-mode))
411 ;; auto enable linum-new-mode in programming modes
412 (add-hook 'prog-mode-hook 'linum-relative-mode)
416 ** Save File Position
418 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
421 (setq-default save-place t)
422 (setq save-place-forget-unreadable-files t)
423 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
429 Setting PATH environment variable
431 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
433 (setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
437 * Programming Languages
441 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
443 (use-package color-identifiers-mode
446 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
447 :diminish color-identifiers-mode)