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
243 (setq org-startup-indented t)
244 (setq org-hide-leading-starts t)
245 (setq org-src-fontify-natively t)
246 (setq org-src-tab-acts-natively t)
247 (setq org-confirm-babel-evaluate nil)
248 (setq org-use-speed-commands t)
249 (setq org-completion-use-ido t))
251 (org-babel-do-load-languages
252 'org-babel-load-languages
270 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
272 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
274 (use-package org-bullets
277 (add-hook 'org-mode-hook
279 (org-bullets-mode t))))
285 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
286 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
287 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
290 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
295 :init (add-hook 'org-mode-hook 'worf-mode)
297 (define-key worf-mode-map "[" nil)
298 (define-key worf-mode-map "]" nil)
299 (define-key worf-mode-map (kbd "M-[") 'worf-backward)
300 (define-key worf-mode-map (kbd "M-]") 'worf-forward))
310 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
312 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
316 :commands magit-status magit-blame)
325 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
329 :init (setq ido-enable-flex-matching t
330 ido-ignore-extensions t
331 ido-use-virtual-buffers t
336 (add-to-list 'completion-ignored-extensions ".pyc"))
342 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
346 :init (setq ido-enable-flex-matching t
348 :config (flx-ido-mode 1))
354 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
356 (use-package ido-vertical-mode
359 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
361 (ido-vertical-mode 1))
367 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
371 :init (smex-initialize)
374 ("M-X" . smex-major-mode-commands))
382 Enable linum mode on programming modes
384 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
386 (add-hook 'prog-mode-hook 'linum-mode)
390 Fix the font size of line number
392 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
394 (defun fix-linum-size ()
396 (set-face-attribute 'linum nil :height 110))
398 (add-hook 'linum-mode-hook 'fix-linum-size)
402 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
404 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
406 (use-package linum-relative
409 (defun linum-new-mode ()
410 "If line numbers aren't displayed, then display them.
411 Otherwise, toggle between absolute and relative numbers."
414 (linum-relative-toggle)
418 ("A-k" . linum-new-mode))
420 ;; auto enable linum-new-mode in programming modes
421 (add-hook 'prog-mode-hook 'linum-relative-mode)
425 ** Save File Position
427 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
430 (setq-default save-place t)
431 (setq save-place-forget-unreadable-files t)
432 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
438 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
440 (use-package multi-term
447 [[https://github.com/abo-abo/ace-link][ace-link]] is a package written by [[https://github.com/abo-abo][Oleh Krehel]]. It is convenient to jump to link in help mode, info-mode, etc
448 Type =o= to go to the link
450 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
452 (use-package ace-link
455 (ace-link-setup-default))
459 * Programming Languages
463 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
465 (use-package color-identifiers-mode
468 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
469 :diminish color-identifiers-mode)