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)
52 * Package Management Tools
56 Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages
58 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
60 (unless (package-installed-p 'use-package)
61 (package-refresh-contents)
62 (package-install 'use-package))
64 (require 'use-package)
70 [[https://github.com/dimitri/el-get][El-get]] is package management tool, whicl allows to install external elisp package from any git repository not in mepla.
71 Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
73 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
78 (add-to-list 'load-path "~/.emacs.d/el-get"))
82 * Color and Fonts Settings
84 ** highlight current line
86 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
94 [[https://github.com/paldepind/smart-comment][smart-comments]]
96 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
98 (use-package smart-comment
100 :bind ("M-;" . smart-conmment))
108 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
110 (global-font-lock-mode 1)
114 [[https://github.com/i-tu/Hasklig][Hasklig]] and Source Code Pro, defined fonts family
116 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
119 (defvar sd/fixed-font-family
120 (cond ((x-list-fonts "Hasklig") "Hasklig")
121 ((x-list-fonts "Source Code Pro") "Source Code Pro")
122 ((x-list-fonts "Anonymous Pro") "Anonymous Pro")
123 ((x-list-fonts "M+ 1mn") "M+ 1mn"))
124 "The fixed width font based on what is installed, `nil' if not defined."))
130 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
133 (when sd/fixed-font-family
134 (set-frame-font sd/fixed-font-family)
135 (set-face-attribute 'default nil :font sd/fixed-font-family :height 140)
136 (set-face-font 'default sd/fixed-font-family)))
142 Loading theme should be after all required loaded, refere [[https://github.com/jwiegley/use-package][:defer]] in =use-package=
144 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
146 (setq vc-follow-symlinks t)
148 (use-package color-theme
150 :init (require 'color-theme)
151 :config (use-package color-theme-sanityinc-tomorrow
155 (load-theme 'sanityinc-tomorrow-bright t)))
157 ;(eval-after-load 'color-theme
158 ; (load-theme 'sanityinc-tomorrow-bright t))
162 Change the Org-mode colors
164 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
166 (defun org-src-color-blocks-light ()
167 "Colors the block headers and footers to make them stand out more for lighter themes"
170 '(org-block-begin-line
171 ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
172 '(org-block-background
173 ((t (:background "#FFFFEA"))))
175 ((t (:background "#FFFFEA"))))
177 ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
179 '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
180 '(which-func ((t (:foreground "#008000"))))))
182 (defun org-src-color-blocks-dark ()
183 "Colors the block headers and footers to make them stand out more for dark themes"
186 '(org-block-begin-line
187 ((t (:foreground "#008ED1" :background "#002E41"))))
188 '(org-block-background
189 ((t (:background "#000000"))))
191 ((t (:background "#000000"))))
193 ((t (:foreground "#008ED1" :background "#002E41"))))
195 '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
196 '(which-func ((t (:foreground "green"))))))
198 (org-src-color-blocks-dark)
202 improve color for org-mode
203 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
204 (deftheme ha/org-theme "Sub-theme to beautify org mode")
207 (defvar sd/variable-font-tuple
208 (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
209 ((x-list-fonts "Lucida Grande") '(:font "Lucida Grande"))
210 ((x-list-fonts "Verdana") '(:font "Verdana"))
211 ((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
212 (nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro.")))
213 "My variable width font available to org-mode files and whatnot."))
215 (defun sd/org-color ()
216 (let* ((sd/fixed-font-tuple (list :font sd/fixed-font-family))
217 (base-font-color (face-foreground 'default nil 'default))
218 (background-color (face-background 'default nil 'default))
219 (primary-color (face-foreground 'mode-line nil))
220 (secondary-color (face-background 'secondary-selection nil 'region))
221 (base-height (face-attribute 'default :height))
222 (headline `(:inherit default :weight bold :foreground ,base-font-color)))
223 (custom-theme-set-faces 'ha/org-theme
224 `(org-agenda-structure ((t (:inherit default :height 2.0 :underline nil))))
225 `(org-verbatim ((t (:inherit 'fixed-pitched :foreground "#aef"))))
226 `(org-table ((t (:inherit 'fixed-pitched))))
227 `(org-block ((t (:inherit 'fixed-pitched))))
228 `(org-block-background ((t (:inherit 'fixed-pitched))))
229 `(org-block-begin-line ((t (:inherit 'fixed-pitched))))
230 `(org-block-end-line ((t (:inherit 'fixed-pitched))))
231 `(org-level-8 ((t (,@headline ,@sd/variable-font-tuple))))
232 `(org-level-7 ((t (,@headline ,@sd/variable-font-tuple))))
233 `(org-level-6 ((t (,@headline ,@sd/variable-font-tuple))))
234 `(org-level-5 ((t (,@headline ,@sd/variable-font-tuple))))
235 `(org-level-4 ((t (,@headline ,@sd/variable-font-tuple
236 :height ,(round (* 1.1 base-height))))))
237 `(org-level-3 ((t (,@headline ,@sd/variable-font-tuple
238 :height ,(round (* 1.25 base-height))))))
239 `(org-level-2 ((t (,@headline ,@sd/variable-font-tuple
240 :height ,(round (* 1.5 base-height))))))
241 `(org-level-1 ((t (,@headline ,@sd/variable-font-tuple
242 :height ,(round (* 1.75 base-height))))))
243 `(org-document-title ((t (,@headline ,@sd/variable-font-tuple :height 1.5 :underline nil)))))))
250 ** Org-mode Basic setting
252 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent=
254 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
259 (setq org-startup-indented t)
260 (setq org-hide-leading-starts t)
261 (setq org-src-fontify-natively t)
262 (setq org-src-tab-acts-natively t)
263 (setq org-confirm-babel-evaluate nil)
264 (setq org-use-speed-commands t)
265 (setq org-completion-use-ido t))
267 (org-babel-do-load-languages
268 'org-babel-load-languages
286 use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8 charactes
288 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
290 (use-package org-bullets
293 (add-hook 'org-mode-hook
295 (org-bullets-mode t))))
301 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode.
302 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
303 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
306 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
311 :init (add-hook 'org-mode-hook 'worf-mode)
313 (define-key worf-mode-map "[" nil)
314 (define-key worf-mode-map "]" nil)
315 (define-key worf-mode-map (kbd "M-[") 'worf-backward)
316 (define-key worf-mode-map (kbd "M-]") 'worf-forward))
326 [[https://github.com/magit/magit][Magit]] is a very cool git interface on Emacs.
328 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
332 :commands magit-status magit-blame)
341 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
345 :init (setq ido-enable-flex-matching t
346 ido-ignore-extensions t
347 ido-use-virtual-buffers t
352 (add-to-list 'completion-ignored-extensions ".pyc"))
358 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
362 :init (setq ido-enable-flex-matching t
364 :config (flx-ido-mode 1))
370 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
372 (use-package ido-vertical-mode
375 (setq ido-vertical-define-keys 'C-n-C-p-up-and-down)
377 (ido-vertical-mode 1))
383 #+BEGIN_SRC emacs-lisp :tangle yes :result silent
387 :init (smex-initialize)
390 ("M-X" . smex-major-mode-commands))
398 Enable linum mode on programming modes
400 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
402 (add-hook 'prog-mode-hook 'linum-mode)
406 Fix the font size of line number
408 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
410 (defun fix-linum-size ()
412 (set-face-attribute 'linum nil :height 110))
414 (add-hook 'linum-mode-hook 'fix-linum-size)
418 I like [[https://github.com/coldnew/linum-relative][linum-relative]], just like the =set relativenumber= on =vim=
420 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
422 (use-package linum-relative
425 (defun linum-new-mode ()
426 "If line numbers aren't displayed, then display them.
427 Otherwise, toggle between absolute and relative numbers."
430 (linum-relative-toggle)
434 ("A-k" . linum-new-mode))
436 ;; auto enable linum-new-mode in programming modes
437 (add-hook 'prog-mode-hook 'linum-relative-mode)
441 ** Save File Position
443 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
446 (setq-default save-place t)
447 (setq save-place-forget-unreadable-files t)
448 (setq save-place-skip-check-regexp "\\`/\\(?:cdrom\\|floppy\\|mnt\\|/[0-9]\\|\\(?:[^@/:]*@\\)?[^@/:]*[^@/:.]:\\)")
454 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
456 (use-package multi-term
463 [[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
464 Type =o= to go to the link
466 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
468 (use-package ace-link
471 (ace-link-setup-default))
475 * Programming Languages
479 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
481 (use-package color-identifiers-mode
484 (add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
486 :diminish color-identifiers-mode)
492 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
494 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
496 (defalias 'perl-mode 'cperl-mode)
498 (setq cperl-hairy t) ;; Turns on most of the CPerlMode options
499 (setq cperl-auto-newline t)
500 (setq cperl-highlight-variables-indiscriminately t)
502 ;(add-to-list 'load-path "~/.emacs.d/elisp/")
504 ;(template-initialize)