HOME | EDIT | RSS | ABOUT | GITHUB

Literal Programming Emacs Configure Literal Programming Emacs Configure

Install

安装这个config再容易不过了

cd ~
git clone git@github.com:jcouyang/.emacs.d.git
cd .emacs.d
cask install

打开 emacs, 问啥都说 yes, yeah

Theme

我的最爱 tomorrow theme eighties

https://github.com/purcell/color-theme-sanityinc-tomorrow

(require 'dracula-theme)
(load-theme 'dracula t)
  (add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
  (add-to-list 'default-frame-alist '(ns-appearance . dark))

also, there're several of popular themes of your choice

http://emacsthemes.caisah.info/installed-emacs-themes/

Fonts


;;; Fira code
(set-default-font "Fira Mono-14:width=condensed:weight=light")

;; https://gist.github.com/mordocai/50783defab3c3d1650e068b4d1c91495
;; This works when using emacs --daemon + emacsclient
(add-hook 'after-make-frame-functions (lambda (frame) (set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")))
;; This works when using emacs without server/client
(set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")
;; I haven't found one statement that makes both of the above situations work, so I use both for now

(defconst fira-code-font-lock-keywords-alist
  (mapcar (lambda (regex-char-pair)
            `(,(car regex-char-pair)
              (0 (prog1 ()
                   (compose-region (match-beginning 1)
                                   (match-end 1)
                                   ;; The first argument to concat is a string containing a literal tab
                                   ,(concat "   " (list (decode-char 'ucs (cadr regex-char-pair)))))))))
          '(("\\(www\\)"                   #Xe100)
            ("[^/]\\(\\*\\*\\)[^/]"        #Xe101)
            ("\\(\\*\\*\\*\\)"             #Xe102)
            ("\\(\\*\\*/\\)"               #Xe103)
            ("\\(\\*>\\)"                  #Xe104)
            ("[^*]\\(\\*/\\)"              #Xe105)
            ("\\(\\\\\\\\\\)"              #Xe106)
            ("\\(\\\\\\\\\\\\\\)"          #Xe107)
            ("\\({-\\)"                    #Xe108)
            ("\\(\\[\\]\\)"                #Xe109)
            ("\\(::\\)"                    #Xe10a)
            ("\\(:::\\)"                   #Xe10b)
            ("[^=]\\(:=\\)"                #Xe10c)
            ("\\(!!\\)"                    #Xe10d)
            ("\\(!=\\)"                    #Xe10e)
            ("\\(!==\\)"                   #Xe10f)
            ("\\(-}\\)"                    #Xe110)
            ("\\(--\\)"                    #Xe111)
            ("\\(---\\)"                   #Xe112)
            ("\\(-->\\)"                   #Xe113)
            ("[^-]\\(->\\)"                #Xe114)
            ("\\(->>\\)"                   #Xe115)
            ("\\(-<\\)"                    #Xe116)
            ("\\(-<<\\)"                   #Xe117)
            ("\\(-~\\)"                    #Xe118)
            ("\\(#{\\)"                    #Xe119)
            ("\\(#\\[\\)"                  #Xe11a)
            ("\\(##\\)"                    #Xe11b)
            ("\\(###\\)"                   #Xe11c)
            ("\\(####\\)"                  #Xe11d)
            ("\\(#(\\)"                    #Xe11e)
            ("\\(#\\?\\)"                  #Xe11f)
            ("\\(#_\\)"                    #Xe120)
            ("\\(#_(\\)"                   #Xe121)
            ("\\(\\.-\\)"                  #Xe122)
            ("\\(\\.=\\)"                  #Xe123)
            ("\\(\\.\\.\\)"                #Xe124)
            ("\\(\\.\\.<\\)"               #Xe125)
            ("\\(\\.\\.\\.\\)"             #Xe126)
            ("\\(\\?=\\)"                  #Xe127)
            ("\\(\\?\\?\\)"                #Xe128)
            ("\\(;;\\)"                    #Xe129)
            ("\\(/\\*\\)"                  #Xe12a)
            ("\\(/\\*\\*\\)"               #Xe12b)
            ("\\(/=\\)"                    #Xe12c)
            ("\\(/==\\)"                   #Xe12d)
            ("\\(/>\\)"                    #Xe12e)
            ("\\(//\\)"                    #Xe12f)
            ("\\(///\\)"                   #Xe130)
            ("\\(&&\\)"                    #Xe131)
            ("\\(||\\)"                    #Xe132)
            ("\\(||=\\)"                   #Xe133)
            ("[^|]\\(|=\\)"                #Xe134)
            ("\\(|>\\)"                    #Xe135)
            ("\\(\\^=\\)"                  #Xe136)
            ("\\(\\$>\\)"                  #Xe137)
            ("\\(\\+\\+\\)"                #Xe138)
            ("\\(\\+\\+\\+\\)"             #Xe139)
            ("\\(\\+>\\)"                  #Xe13a)
            ("\\(=:=\\)"                   #Xe13b)
            ("[^!/]\\(==\\)[^>]"           #Xe13c)
            ("\\(===\\)"                   #Xe13d)
            ("\\(==>\\)"                   #Xe13e)
            ("[^=]\\(=>\\)"                #Xe13f)
            ("\\(=>>\\)"                   #Xe140)
            ("\\(<=\\)"                    #Xe141)
            ("\\(=<<\\)"                   #Xe142)
            ("\\(=/=\\)"                   #Xe143)
            ("\\(>-\\)"                    #Xe144)
            ("\\(>=\\)"                    #Xe145)
            ("\\(>=>\\)"                   #Xe146)
            ("[^-=]\\(>>\\)"               #Xe147)
            ("\\(>>-\\)"                   #Xe148)
            ("\\(>>=\\)"                   #Xe149)
            ("\\(>>>\\)"                   #Xe14a)
            ("\\(<\\*\\)"                  #Xe14b)
            ("\\(<\\*>\\)"                 #Xe14c)
            ("\\(<|\\)"                    #Xe14d)
            ("\\(<|>\\)"                   #Xe14e)
            ("\\(<\\$\\)"                  #Xe14f)
            ("\\(<\\$>\\)"                 #Xe150)
            ("\\(<!--\\)"                  #Xe151)
            ("\\(<-\\)"                    #Xe152)
            ("\\(<--\\)"                   #Xe153)
            ("\\(<->\\)"                   #Xe154)
            ("\\(<\\+\\)"                  #Xe155)
            ("\\(<\\+>\\)"                 #Xe156)
            ("\\(<=\\)"                    #Xe157)
            ("\\(<==\\)"                   #Xe158)
            ("\\(<=>\\)"                   #Xe159)
            ("\\(<=<\\)"                   #Xe15a)
            ("\\(<>\\)"                    #Xe15b)
            ("[^-=]\\(<<\\)"               #Xe15c)
            ("\\(<<-\\)"                   #Xe15d)
            ("\\(<<=\\)"                   #Xe15e)
            ("\\(<<<\\)"                   #Xe15f)
            ("\\(<~\\)"                    #Xe160)
            ("\\(<~~\\)"                   #Xe161)
            ("\\(</\\)"                    #Xe162)
            ("\\(</>\\)"                   #Xe163)
            ("\\(~@\\)"                    #Xe164)
            ("\\(~-\\)"                    #Xe165)
            ("\\(~=\\)"                    #Xe166)
            ("\\(~>\\)"                    #Xe167)
            ("[^<]\\(~~\\)"                #Xe168)
            ("\\(~~>\\)"                   #Xe169)
            ("\\(%%\\)"                    #Xe16a)
            ;;("\\(x\\)"                     #Xe16b)
            ("[^:=]\\(:\\)[^:=]"           #Xe16c)
            ("[^\\+<>]\\(\\+\\)[^\\+<>]"   #Xe16d)
            ("[^\\*/<>]\\(\\*\\)[^\\*/<>]" #Xe16f))))

(defun add-fira-code-symbol-keywords ()
  (font-lock-add-keywords nil fira-code-font-lock-keywords-alist))

(add-hook 'prog-mode-hook
          #'add-fira-code-symbol-keywords)

(defun darwin-set-emoji-font (frame)
  "Adjust the font settings of FRAME so Emacs NS/Cocoa can display emoji properly."
  (if (eq system-type 'darwin)
      (set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji") frame 'prepend)))
;; For when emacs is started with Emacs.app
(darwin-set-emoji-font nil)
;; Hook for when a cocoa frame is created with emacsclient
;; see https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Frames.html
(add-hook 'after-make-frame-functions 'darwin-set-emoji-font)

(global-prettify-symbols-mode 1)

ENV

把fish中的path环境变量抄过来

(let ((path-from-shell (shell-command-to-string "/usr/local/bin/fish -c \"echo -n \\$PATH[1]; for val in \\$PATH[2..-1];echo -n \\\":\\$val\\\";end\"")))
  (setenv "PATH" path-from-shell)
  (setq exec-path (split-string path-from-shell ":")))

Global General Modes

有一些全局基本设置,可以让emacs能基本适应我的习惯

  • 开启server,方便从terminal使用 emacsclient 1
  • Meta key 设为 Command (我用的是mac)6
  • C-h 映射到 C-? ,因为帮助功能不是很有用,但是 C-h 这个unix系统下的默认是删除键,使用太频繁了。9
 1:   (server-start) ;
 2:   (global-superword-mode 1)
 3:   (when (eq system-type 'darwin)
 4:     (setq mac-option-modifier 'alt)
 5: (setq mac-option-modifier 'super) ; make opt key do Super
 6:     (setq mac-command-modifier 'meta));
 7:   (setq inhibit-startup-message t)
 8:   (delete-selection-mode 1) ; delete selection when paste
 9:   (keyboard-translate ?\C-h ?\C-?);
10:   (global-auto-revert-mode 1)  ;auto revert buffers when changed on dis
11:   (global-diff-hl-mode)
12:   (setq-default
13:    make-backup-files nil ; stop creating those backup~ file
14:    auto-save-default nil
15: 
16:    indent-tabs-mode nil                   ;use spaces instead of tabs
17:    electric-pair-mode nil
18:    )
19:   (electric-indent-mode t)
  • UI tweaks
(column-number-mode 1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

User Settings

(when (file-readable-p ".user.el") (load ".user.el"))

用户设置, 放一些密码或敏感内容

Modes [42%]

dot

(add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))

DONE company

  • State "DONE" from "" [2015-03-09 Mon 22:54]

company 是用来取代 autocomplete-mode的自动补全的插件,不要以为是单词 company 的意思,其实是 /comp lete any/。选择company是因为速度要快一些。根据他的比较可以看看 这里

company自带了一系列的 backend 你可以像 这样 enable。 Completion will start automatically after you type a few letters. Use M-n and M-p to select, <return> to complete or <tab> to complete the common part. Search through the completions with C-s, C-r and C-o. Press M-(digit) to quickly complete with one of the first 10 candidates.

When the completion candidates are shown, press <f1> to display the documentation for the selected candidate, or C-w to see its source. Not all back-ends support this.

document

 1: (require 'company)
 2: (require 'company-tern)
 3: ;; (require 'company-ispell)
 4: (add-to-list 'company-backends 'company-tern)  ;;
 5: (add-to-list 'company-backends 'company-yasnippet t)
 6: (add-to-list 'company-backends 'company-robe)
 7: ;; (add-to-list 'company-backends 'company-ispell)
 8: ;; not always down case
 9: (setq company-dabbrev-downcase nil)
10: (setq company-tooltip-align-annotations t)
11: (setq company-idle-delay 0.1)
12: (global-company-mode)
13: 

DONE deft

(setq
 deft-extension "org"
 deft-directory "~/Develop/blog/org"
 deft-text-mode 'org-mode
 deft-recursive t
 deft-use-filename-as-title nil
 deft-file-naming-rules
 '((noslash . "-")
   (nospace . "-")
   (case-fn . downcase))
 deft-use-filter-string-for-filename t
 deft-org-mode-title-prefix t
 )

elm

(add-to-list 'company-backends 'company-elm)

git

(require 'git-link)
(add-to-list 'git-link-remote-alist
      '("git\\.realestate\\.com\\.au" git-link-github))
(add-to-list 'git-link-commit-remote-alist
      '("git\\.realestate\\.com\\.au" git-link-commit-github))

haskell

(package-install 'intero)
(add-hook 'haskell-mode-hook 'intero-mode)

IN PROGRESS helm

  • State "IN PROGRESS" from "" [2015-03-09 Mon 21:46]

this is worth reading when you just start using helm http://tuhdo.github.io/helm-intro.html

helm 可以让你很方便的在项目里快速浏览文件

 1: (require 'helm-config)
 2: (require 'helm-git-grep)
 3: (helm-mode 1)
 4: (helm-autoresize-mode 1)
 5: (projectile-global-mode)
 6: (global-set-key (kbd "C-c h") 'helm-command-prefix)
 7: (global-unset-key (kbd "C-x c"))
 8: (setq projectile-completion-system 'helm
 9:       helm-M-x-fuzzy-match t
10:       helm-buffers-fuzzy-matching t
11:       helm-recentf-fuzzy-match t
12:       helm-ag-fuzzy-match t ;(ref: ag-fuzzy-match)
13:       projectile-enable-caching t;
14:       helm-locate-fuzzy-match t
15:       projectile-indexing-method 'alien);
16: (helm-projectile-on)
17: 

其中第1315两行能加速projectile index一个大的repo时的速度。如果需要重新index,可以 C-c p i.

iedit

(require 'iedit)
(setq iedit-unmatched-lines-invisible-default t)

flycheck

(require 'flycheck)
;;(add-hook 'after-init-hook #'global-flycheck-mode)
(setq-default flycheck-disabled-checkers
              (append flycheck-disabled-checkers
                      '(javascript-jshint)))
(setq-default flycheck-disabled-checkers
              (append flycheck-disabled-checkers
                      '(json-jsonlist)))

js2-mode

(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.sjs$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.es6$" . js2-mode))
(setq js2-allow-rhino-new-expr-initializer nil)
(setq js2-enter-indents-newline t)
(setq js2-global-externs '("module" "require" "buster" "sinon" "assert" "refute" "setTimeout" "clearTimeout" "setInterval" "clearInterval" "location" "__dirname" "console" "JSON"))
(setq js2-idle-timer-delay 0.1)
(setq js2-indent-on-enter-key nil)
(setq js2-mirror-mode nil)
(setq js2-strict-inconsistent-return-warning nil)
(setq js2-auto-indent-p t)
(setq js2-include-rhino-externs nil)
(setq js2-include-gears-externs nil)
(setq js2-concat-multiline-strings 'eol)
(setq js2-rebind-eol-bol-keys nil)
(setq js2-mode-show-parse-errors t)
(setq js2-mode-show-strict-warnings nil)

Got most of that from Magnars' .emacs.d.

ruby-mode

(add-hook 'ruby-mode-hook 'robe-mode)
;(setq rbenv-installation-dir "/usr/local/bin/")
(defadvice inf-ruby-console-auto (before activate-rbenv-for-robe activate)
 (rbenv-use-corresponding))

tide-mode

 (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
 (defun setup-tide-mode ()
   (interactive)
   (tide-setup)
   (flycheck-mode +1)
   (setq flycheck-check-syntax-automatically '(save mode-enabled))
   (eldoc-mode +1)
   (tide-hl-identifier-mode +1)
   ;; company is an optional dependency. You have to
   ;; install it separately via package-install
   ;; `M-x package-install [ret] company`
   (company-mode +1))

 ;; aligns annotation to the right hand side
 (setq company-tooltip-align-annotations t)

 ;; formats the buffer before saving
 (add-hook 'before-save-hook 'tide-format-before-save)

 (add-hook 'typescript-mode-hook #'setup-tide-mode)
 (require 'web-mode)
(add-hook 'web-mode-hook
         (lambda ()
           (when (and (buffer-file-name)
(string-equal "tsx" (file-name-extension buffer-file-name)))
             (setup-tide-mode))))
 ;; (add-hook 'web-mode-hook
 ;;           (lambda ()
 ;;             (when (string-equal "tsx" (file-name-extension buffer-file-name))
 ;;               (setup-tide-mode))))

json-mode

(add-to-list 'auto-mode-alist '("\\.json\\'" . json-mode))
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tag\\'" . web-mode))

json-mode adds a bit better syntax highlighting for .json files.

Magit


(bind-keys
 ("C-x g" . magit-status))

DONE Nyancati

彩虹猫滚动条,萌萌哒滚动条

(nyan-mode t)

latex

(setq tex-compile-commands '(("xelatex %r")))
(setq tex-command "xelatex")
(setq-default TeX-engine 'xelatex)

(setq org-latex-pdf-process
      '("xelatex -interaction nonstopmode -output-directory %o %f"
        "xelatex -interaction nonstopmode -output-directory %o %f"
        "xelatex -interaction nonstopmode -output-directory %o %f"))

(setq locate-command "mdfind")
(setenv "PATH" (concat (getenv "PATH") ":/usr/local/share/npm/bin:/usr/local/bin:/usr/texbin"))
(setq exec-path (append exec-path '("/usr/local/bin" "~/.rbenv/shims" "/usr/texbin")))

languagetool

(require 'langtool)
(setq langtool-language-tool-jar "/usr/local/Cellar/languagetool/4.0/libexec/languagetool-commandline.jar"
      langtool-disabled-rules '("WHITESPACE_RULE"
                                "EN_UNPAIRED_BRACKETS"
                                "COMMA_PARENTHESIS_WHITESPACE"
                                "EN_QUOTES")
      langtool-default-language "en-US")
(when (executable-find "hunspell")
  (setenv "DICTIONARY" "en_US")
  (setq ispell-program-name "hunspell")
  (setq ispell-really-hunspell t)
  )

on-screen

翻页的事后加一条小黑线,不然找不到翻哪了

(on-screen-global-mode 1)
(setq on-screen-highlight-method 'narrow-line)

key chord

(key-chord-mode 1)
(setq key-chord-two-keys-delay 0.03)

TODO org

  • latex
    (require 'ox-latex)
    (add-to-list 'org-latex-classes
                 '("tufte" "\\documentclass[11pt,twoside,openright]{tufte-book}"
                   ("\\chapter{%s}" . "\\chapter*{%s}")
                   ("\\section{%s}" . "\\section*{%s}")
                   ("\\subsection{%s}" . "\\subsection*{%s}")
                   ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
    
  • hooks
    (add-hook 'org-mode-hook 'turn-on-flyspell)
    
  • TODO Default Settings

    org-agenda-files 是很有意思的一个参数,agenda的todo list会扫描这里面的文件,并把所有的 TODO 列出来。 这个参数吃一个列表,所以我把所有的dropbox下的org文件都引进来了 9

    比如这篇博客中的所有TODO,就都会出现在我的agenda里面。

     1: (setq org-directory "~/Dropbox/org")
     2: 
     3: (setq org-confirm-babel-evaluate nil
     4:       org-src-fontify-natively t
     5:       org-src-tab-acts-natively t)
     6: 
     7: (let ((todo "~/Dropbox/org/todo.org"))
     8:   (when (file-readable-p todo)
     9:     (setq org-agenda-files (file-expand-wildcards "~/Dropbox/**/*.org")) ;
    10:     (setq initial-buffer-choice (lambda ()
    11:                                   (org-agenda nil "n")
    12:                                   (delete-other-windows)
    13:                                   (current-buffer)
    14:                                   ))
    15:     ))
    16: (setq org-default-notes-file "~/Dropbox/org/refile.org")
    17: (setq org-mobile-inbox-for-pull "~/Dropbox/org/flagged.org")
    18: (setq org-mobile-directory "~/Dropbox/org/mobile")
    19: 
    20: (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
    21: 
    22: (setq org-startup-folded 'nofold)
    23: (setq org-startup-indented t)
    24: (setq org-startup-with-inline-images t)
    25: (setq org-startup-truncated t)
    26: (setq org-refile-targets '((org-agenda-files :maxlevel . 5)))
    27: (setq org-src-tab-acts-natively t)
    28: (setq org-use-speed-commands t)
    29: (setq org-default-notes-file (concat org-directory "/todo.org"))
    30: (add-to-list 'org-src-lang-modes '("jsx" . web))
    31: (add-to-list 'org-src-lang-modes '("tsx" . web))
    32: (setq js-indent-level 2)
    
    • speed commnad
      (("Outline Navigation")
       ("n" org-speed-move-safe 'org-next-visible-heading)
       ("p" org-speed-move-safe 'org-previous-visible-heading)
       ("f" org-speed-move-safe 'org-forward-heading-same-level)
       ("b" org-speed-move-safe 'org-backward-heading-same-level)
       ("F" . org-next-block)
       ("B" . org-previous-block)
       ("u" org-speed-move-safe 'outline-up-heading)
       ("j" . org-goto)
       ("g" org-refile t)
       ("Outline Visibility")
       ("c" . org-cycle)
       ("C" . org-shifttab)
       (" " . org-display-outline-path)
       ("s" . org-narrow-to-subtree)
       ("=" . org-columns)
       ("Outline Structure Editing")
       ("U" . org-metaup)
       ("D" . org-metadown)
       ("r" . org-metaright)
       ("l" . org-metaleft)
       ("R" . org-shiftmetaright)
       ("L" . org-shiftmetaleft)
       ("i" progn
        (forward-char 1)
        (call-interactively 'org-insert-heading-respect-content))
       ("^" . org-sort)
       ("w" . org-refile)
       ("a" . org-archive-subtree-default-with-confirmation)
       ("@" . org-mark-subtree)
       ("#" . org-toggle-comment)
       ("Clock Commands")
       ("I" . org-clock-in)
       ("O" . org-clock-out)
       ("Meta Data Editing")
       ("t" . org-todo)
       ("," org-priority)
       ("0" org-priority 32)
       ("1" org-priority 65)
       ("2" org-priority 66)
       ("3" org-priority 67)
       (":" . org-set-tags-command)
       ("e" . org-set-effort)
       ("E" . org-inc-effort)
       ("W" lambda
        (m)
        (interactive "sMinutes before warning: ")
        (org-entry-put
         (point)
         "APPT_WARNTIME" m))
       ("Agenda Views etc")
       ("v" . org-agenda)
       ("/" . org-sparse-tree)
       ("Misc")
       ("o" . org-open-at-point)
       ("?" . org-speed-command-help)
       ("<" org-agenda-set-restriction-lock 'subtree)
       (">" org-agenda-remove-restriction-lock))
      
  • structure template
    (add-to-list 'org-structure-template-alist '("E" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC\n"))
    (add-to-list 'org-structure-template-alist '("S" "#+BEGIN_SRC shell-script\n?\n#+END_SRC\n"))
    (add-to-list 'org-structure-template-alist '("J" "#+BEGIN_SRC js\n?\n#+END_SRC\n"))
    (add-to-list 'org-structure-template-alist '("C" "#+BEGIN_SRC clojure\n?\n#+END_SRC\n"))
    (add-to-list 'org-structure-template-alist '("d" "#+BEGIN_SRC ditaa :file ? :exports results\n?#+END_SRC\n"))
    
  • Clocking
    (setq org-clock-persist 'history)
    (org-clock-persistence-insinuate)
    
  • DONE Capture
    (setq org-default-notes-file (concat org-directory "/todo.org"))
    
    (setq org-capture-templates
          '(
            ("t" "Todo" entry (file org-default-notes-file) "* TODO %?\n  %u\n  %a")
            ("s" "Simple Task" entry (file org-default-notes-file) "* TODO %?\n  %U\n")
            ))
    (setq org-todo-keywords
          '((sequence
             "TODO(t)"
             "IN PROGRESS(p!)"
             "HOLD(h!)"
             "WAITING(w)"
             "SOMEDAY(s)"
             "|"
             "DONE(d!)"
             "CANCELLED(c)"
             )))
    (setq org-todo-keyword-faces
          '(
            ("IN PROGRESS" . 'warning)
            ("DOING" . 'warning)
            ("HOLD" . 'font-lock-keyword-face)
            ("WAITING" . 'font-lock-builtin-face)
            ("SOMEDAY" . 'font-lock-doc-face)
            ))
    (setq org-log-into-drawer t)
    
  • DONE Publish
    (setq org-html-validation-link nil)
    
    (setq org-publish-project-alist
          '(("static"
             :base-directory "~/Develop/grokking-monad/org/images"
             :base-extension "png\\|jpg\\|jpeg\\|gif\\|svg"
             :publishing-directory "~/Develop/grokking-monad/book/images"
             :recursive t
             :publishing-function org-publish-attachment)
            ("text"
             :base-directory "~/Develop/grokking-monad/org"
             :base-extension "org"
             :publishing-directory "~/Develop/grokking-monad/book"
             :sub-superscript t
             :recursive t
             :publishing-function org-gfm-publish-to-gfm
             :html-extension "md"
             :body-only t)
            ("gitbook" :components ("static" "text"))))
    
  • org-deck
    (setq org-deck-base-url "https://blog.oyanglul.us/deck.js")
    (setq org-deck-theme "web-2.0.css")
    (setq org-deck-transition "horizontal-slide.css")
    (setq org-deck-postamble "<p>%t - %a</p>")
    
  • TODO Agenda
    ;; create the file for the agendas if it doesn't exist
    (appt-activate 1)              ; activate appt (appointment notification)
    
    (org-agenda-to-appt)           ; add appointments on startup
    
    ;; add new appointments when saving the org buffer, use 'refresh argument to do it properly
    (defun my-org-agenda-to-appt-refresh () (org-agenda-to-appt 'refresh))
    (defun my-org-mode-hook ()
      (add-hook 'after-save-hook 'my-org-agenda-to-appt-refresh nil 'make-it-local))
    (add-hook 'org-mode-hook 'my-org-mode-hook)
    (add-hook 'org-mode-hook (lambda ()
                               (visual-line-mode 1)))
    (require 'notifications)
    (defun my-appt-disp-window-function (min-to-app new-time msg)
      (notifications-notify :title (format "Appointment in %s min" min-to-app) :body msg))
    (setq appt-disp-window-function 'my-appt-disp-window-function)
    (setq appt-delete-window-function (lambda (&rest args)))
    
    ;; add state to the sorting strategy of todo
    (setcdr (assq 'todo org-agenda-sorting-strategy) '(todo-state-up priority-down category-keep))
    
  • babel
    (org-babel-do-load-languages
     'org-babel-load-languages
     '((js . t)
       (clojure . t)
       ))
    
  • pandoc
      (setq org-pandoc-options-for-revealjs '(
                                              (self-contained . t)
    (variable . "theme=solarized")
    (section-divs . t)
                                              (standalone . nil)))
    

pallet

pallet 可以让你在emacs里安装和卸载的插件同步到 Cask file

(require 'pallet)
(pallet-mode t)

purescript

(require 'psc-ide)

(add-hook 'purescript-mode-hook
  (lambda ()
    (psc-ide-mode)
    (company-mode)
    (flycheck-mode)
    (turn-on-purescript-indentation)))

smartparens

(require 'smartparens-config)
(smartparens-global-mode t)

(show-smartparens-global-mode t)

(add-hook 'clojure-mode-hook 'turn-on-smartparens-strict-mode)

sequential-command

(require 'sequential-command)
(define-sequential-command seq-home
  back-to-indentation beginning-of-line seq-return)
(define-sequential-command seq-end
  end-of-line end-of-buffer seq-return)
(global-set-key "\C-a" 'seq-home)
  (global-set-key "\C-e" 'seq-end)
(define-sequential-command seq-company-tab company-complete-common company-complete-selection)

(define-key company-active-map (kbd "TAB") 'seq-company-tab)
(define-key company-active-map [tab] 'seq-company-tab)

scala-mode

(require 'ensime)
  (add-to-list 'auto-mode-alist '("\\.sc$" . scala-mode))
  (add-to-list 'auto-mode-alist '("\\.scala$" . scala-mode))
  (add-hook 'scala-mode-hook 'ensime-mode)
(setq ensime-startup-notification nil)

TODO tern

A JavaScript code analyzer 非常给力的 javascript 编辑工具, 支持 auto completion, jump to definition, find type of, rename variable 等 这些 IDE 才能提供的语言向 的支持.

Needs the tern binary to be present, which can be installed with npm:

sudo npm install -g tern

这里完了要改 tern.el 的一行代码, 傻逼的居然用相对路径

(bin-file (expand-file-name "../bin/tern" (file-name-directory (file-truename script-file)))))
M-.
    Jump to the definition of the thing under the cursor.
M-,
    Brings you back to last place you were when you pressed M-..
C-c C-r
    Rename the variable under the cursor.
C-c C-c
    Find the type of the thing under the cursor.
C-c C-d
    Find docs of the thing under the cursor. Press again to open the associated URL (if any).
(add-hook 'js-mode-hook (lambda () (tern-mode t)))
(add-hook 'js2-mode-hook (lambda () (tern-mode t)))
(add-hook 'web-mode-hook (lambda () (tern-mode t)))

See the project homepage for more info.

textmate

(require 'textmate)
(textmate-mode)
(bind-keys
 :map *textmate-mode-map*
 ("M-}" . textmate-shift-right)
 ("M-{" . textmate-shift-left)
 ("M-/" . comment-or-uncomment-region-or-line)
 ("M-l" . textmate-select-line)
 )

Prompt Behavior

1: (defalias 'yes-or-no-p 'y-or-n-p)
2: (setq kill-buffer-query-functions
3:       (remq 'process-kill-buffer-query-function
4:             kill-buffer-query-functions))

all "yes" or "no" questions are aliased to "y" or "n". We don't really want to type a full word to answer a question from Emacs

Also Emacs should be able to kill processes without asking. Got that snippet from: http://www.masteringemacs.org/articles/2010/11/14/disabling-prompts-emacs/

Reason

(defun shell-cmd (cmd)
  "Returns the stdout output of a shell command or nil if the command returned
   an error"
  (car (ignore-errors (apply 'process-lines (split-string cmd)))))

(let* ((refmt-bin (or (shell-cmd "refmt ----where")
                      (shell-cmd "which refmt")))
       (merlin-bin (or (shell-cmd "ocamlmerlin ----where") (shell-cmd "which ocamlmerlin")))
       (merlin-base-dir (when merlin-bin
                          (replace-regexp-in-string "bin/ocamlmerlin$" "" merlin-bin))))
  ;; Add npm merlin.el to the emacs load path and tell emacs where to find ocamlmerlin
  (when merlin-bin
    (add-to-list 'load-path (concat merlin-base-dir "share/emacs/site-lisp/"))
    (setq merlin-command merlin-bin))

  (when refmt-bin
    (setq refmt-command refmt-bin)))

(require 'reason-mode)
(require 'merlin)
(add-hook 'reason-mode-hook (lambda ()
                              (add-hook 'before-save-hook 'refmt-before-save)
                              (merlin-mode)))

(setq merlin-ac-setup t)

web-mode

  (require 'editorconfig)
  (editorconfig-mode 1)
(setq web-mode-content-types-alist
  '(("jsx" . "\\.js[x]?\\'")))
  (add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
  (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))

yasnippet

(yas-global-mode 1)

ditaa

(setq org-ditaa-jar-path "/usr/local/Cellar/ditaa/0.9/libexec/ditaa0_9.jar")

Key Bindings

  • State "IN PROGRESS" from "" [2015-03-09 Mon 21:46]

emacs 最大亮点之一就是其快捷键众多, 当然用户都喜欢根据自身爱好定义最高效的 快捷键, 因此, 把这些定义都放到这里定义更方便与管理,更新,和查找.

smartparens

(bind-keys
 :map smartparens-mode-map
 ("C-M-f" . sp-forward-sexp)
 ("C-M-b" . sp-backward-sexp)
 ("C-S-i" . sp-down-sexp)
 ("C-S-o" . sp-up-sexp)
 ("M-A-i" . sp-backward-down-sexp)
 ("M-A-o" . sp-backward-up-sexp)
 ("C-M-a" . sp-beginning-of-sexp)
 ("C-M-e" . sp-end-of-sexp)
 ("C-M-n" . sp-next-sexp)
 ("C-M-p" . sp-previous-sexp)
 ("C-M-d" . sp-kill-sexp)
 ("C-M-<backspace>" . sp-backward-kill-sexp)
 ("C-M-k" . sp-kill-hybrid-sexp)
 ("C-M-w" . sp-copy-sexp)
 ("C-M-[" . sp-backward-unwrap-sexp)
 ("C-M-]" . sp-unwrap-sexp)
 ("C-<right>" . sp-forward-slurp-sexp)
 ("C-<left>" . sp-forward-barf-sexp)
 ("C-M-<left>" . sp-backward-slurp-sexp)
 ("C-M-<right>" . sp-backward-barf-sexp))

helm

(bind-keys
 ("C-c h o" . helm-occur)
 ("C-c h x" . helm-register)
 ("M-x" . helm-M-x)
 ("C-x b" . helm-mini)
 ("M-y" . helm-show-kill-ring))
(bind-keys
 :map helm-map
 ("<tab>" . helm-execute-persistent-action) ; rebind tab to run persistent action
 ("C-i" . helm-execute-persistent-action) ; make TAB works in terminal
 ("C-z" . helm-select-action) ; list actions using C-z
 )

multiple cursor

(bind-keys
 ("C-<" . mc/mark-previous-like-this)
 ("C->" . mc/mark-next-like-this)
 ("C-*" . mc/mark-all-like-this))

general

(bind-keys
 ("M-c" . kill-ring-save)
 ("C-8" . er/expand-region)
 ("M-8" . er/contract-region)
 ("C-x r" . vr/query-replace)
 ("M--" . text-scale-decrease)
 ("M-=" . text-scale-increase)
 ("C-c i" . (lambda () (interactive) (indent-region (point-min) (point-max))))
 ("M-<backspace>" . kill-whole-line)
 ("C-c r" . revert-buffer)
 ("C-3" . back-button-global-backward)
 ("C-4" . back-button-global-forward)
 ("C-c SPC" . ace-jump-mode)
 ("C-c h d" . howdoi-query-insert-code-snippet-at-point)
 ("M-k" . delete-other-windows)
 ("<f7>" . toggle-window-split)
 ("C-c c" . deft)
 ("C-x t" . org-capture)
 ("C-c a" (lambda () (interactive) (org-agenda nil "n"))))

keychord

(key-chord-define-global "vr" 'vr/replace)
(key-chord-define-global "ln" 'linum-mode)