Useful keybinding

Buffer and window

  • SPC f s Save a buffer
  • SPC f S Save all opened buffers
  • SPC f f Open the buffer in now directory
  • SPC f r Open the buffer and search in recently files
  • SPC b b Open or switch a buffer with helm
  • SPC b d Delete a buffer
  • SPC b K Delete other buffer but this
  • SPC w v/s split v or s
  • SPC h/l/j/k switch window
  • SPC h d f 对一个功能提示并显示其文档。
  • SPC h d k 对一个快捷键提示并显示其绑定的内容。
  • SPC h d v 对一个变量提示并显示其文档和当前值。
  • SPC h SPC 搜索一个命令,功能,变量或接口,并显示其文档
  • SPC f e * Search configuration
  • SPC ? 列出所有快捷键。
  • SPC : M-x 列出可执行的所有命令

Others

  • SPC f e R Reload the init.el
  • SPC T h Select a theme using a helm buffer
  • SPC f/p t To toggle the Neotree buffer press (project)
  • SPC h b Open the bookmark
  • SPC h T evil-tutor-start
  • SPC h l Resume the last helm buffers
  • SPC s L Focus the last converted search buffer
  • F3 In a helm buffer, convert a helm search buffer into a regular buffer

The Emacs Evil Tutor

LESSON 1

  1. The cursor is moved using either the arrow keys or the hjkl keys. h (left) j (down) k (up) l (right)

  2. To exit Emacs type: :qa! to trash all changes. OR type: :wqa to save the changes.

  3. Ctrl + f Page Down Ctrl + b Page Up

  4. 0 Cursor to the beginging of the line $ Cursor to the end of the line

  5. G Cursor to the last of the file nG Cursor to the n line of the file gg Cursor to the begin of the file, like 1G :[Enter] followed by a line number and moves to that line number. N[Enter] Curosr to the N line

NOTE: Pressing will place you in normal state or will cancel an unwanted and partially completed command.

LESSON 2

  1. x/X To delete a character under/before the cursor in normal state type

  2. To delete a whole line type: dd

  3. The format for a command in normal state is:

    [number] command object OR command [number] object where: number - is how many times to repeat the command command - is what to do, such as d for delete object - is what the command should act upon, such as w for word, $ for “to the end of line”, etc.

  4. d1G, dG, d0, d$

  5. yy Copy the line of cursokr nyy Copy the n line data

  6. y1G, yG, y0, y$

  7. p/P Paste the data from the next/before line

  8. To undo previous actions, type: u To undo the undo’s type: CTRL-R Repeat the last opeartion: .

LESSON 3

  1. To replace text that has already been deleted, type p this puts the deleted text AFTER the cursor (if a line was deleted it will go on the line below the cursor).

  2. To replace the character under the cursor, type r and then the character which will replace the original.

  3. The change command allows you to change the specified object from the cursor to the end of the object. eg. Type cw to change from the cursor to the end of the word, c$ to change to the end of a line.

  4. The format for change is: [number] c object OR c [number] object

LESSON 4

  1. Typing / followed by a phrase searches FORWARD for the phrase. Typing ? followed by a phrase searches BACKWARD for the phrase. After a search type n to find the next occurrence in the same direction or N to search in the opposite direction.

  2. Typing % while the cursor is on a (,),[,],{, or } locates its matching pair.

  3. To substitute new for the first old on a line type :s/old/new To substitute new for all ‘old’s on a line type :s/old/new/g To substitute phrases between two line #’s type :#,#s/old/new/g To substitute all occurrences in the file type :%s/old/new/g To ask for confirmation each time add ‘c’ :%s/old/new/gc

LESSON 5

  1. :!command executes an external command.

    Some useful examples are: :!ls or :!dir - shows a directory listing. :!rm or :!del FILENAME - removes file FILENAME.

  2. :w FILENAME writes the current buffer to disk with file name FILENAME.

  3. :#,#w FILENAME saves the lines # through # in file FILENAME.

  4. :r FILENAME retrieves disk file FILENAME and inserts it into the current buffer following the cursor position.

LESSON 6

  1. Typing o opens a line BELOW the cursor and places the cursor on the open line in insert state. Typing a capital O opens the line ABOVE the line the cursor is on.

  2. Type an a to insert text AFTER the character the cursor is on. Typing a capital A automatically appends text to the end of the line.

  3. i/I Insert text at the character/Not blank

Tips

Not understand: 12.1.4 Additional text objects 12.3.3 Helm micro-state 12.7 Searching

Spacemacs Rocks

Spacemacs Rocks Season 2 ( Day one)

Install Emacs

  • Mac
  • Windows
  • Linux(apt get install emacs)

Go over the Emacs tutorial at least once

  • C-h t to open the tutorial.
  • You need be familiar with cursor movement(C-f/C-b/C-n/C-p/C-a/C-e) and basic editing (C-k)
  • You should be familiar with M(eta), s(uper, command key), S(hift), C(trl) M-x s-p S-p C-p
  • Prefix key(c-h is a prefix key) and C-g (C-x c-f)

Learn to active some built-in functionality (org-mode)

  • linum-mode to display line numbers (M-x linum-mode)
  • C-x C-f(find/file) to open files, C-x C-s(ave) to save files. (You could also use your mouse to do all the file operations.)
  • you should always ask Emacs the right question
  • C-h k/ C-h v / C-h f (Emacs is a self document, extensiable editor.)
  • The key bindings are actually a quick way to command Emacs.

Learn some elisp(emacs lisp)

  • use learnxinyminutes website to learn emacs lisp.
  • at least you know how to define variable, functions
  • You should know how to make a function callable and how to set a key binding for the function.

Start to hacking Emacs from the day one!

  • turn off tool-bar
  • turn off scroll-bar
  • show linum-mode
  • turn off splash screen
  • save your config
  • define a function to quickly open your config file.

Emacs package system in the first glance.

  • How to use the built-in Package system of Emacs.
  • Install company mode and active it.
  • Major mode and minor mode (C-h m)
  • Happy hacking. :)

Bonus(org-mode basics)

3rd level
  • use * to define headings
  • C-c C-t to toggle TODO states

GTD(getting things done)* Day1 C-h t help model

Spacemacs Rocks Season 2 ( Day two )

Fixes some annoying stuff

  1. make cursor style to bar

  2. disable backup file

1
(setq make-backup-files nil)

use C-’ to open another buffer to edit source code. Make source code fancy in the org file.

1
2
(require 'org)
(setq org-src-fontify-natively t)
  1. enable recentf-mode
1
2
3
4
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
  1. bring electric-indent-mode back

  2. add delete selection mode

1
(delete-selection-mode t)

Make Emacs more fancy

  1. Open with full screen
1
(setq  initial-frame-alist (quote ((fullscreen . maximized))))
  1. show match parents
1
(add-hook 'emacs-lisp-mode-hook 'show-paren-mode)

It has a flaw, we will use more powerful package in the future.

  1. Highlight current line (global-hl-line-mode)
1
(global-hl-line-mode t)

Improve built-in package system

  1. make package system more powerful with Melpa
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(when (>= emacs-major-version 24)
  (require 'package)
  (package-initialize)
  (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
  )
(require 'cl)

;;add whatever packages you want here
(defvar zilongshanren/packages '(
                          company

              )  "Default packages")

(defun zilongshanren/packages-installed-p ()
  (loop for pkg in zilongshanren/packages
        when (not (package-installed-p pkg)) do (return nil)
        finally (return t)))

(unless (zilongshanren/packages-installed-p)
  (message "%s" "Refreshing package database...")
  (package-refresh-contents)
  (dolist (pkg zilongshanren/packages)
    (when (not (package-installed-p pkg))
      (package-install pkg))))
  1. install a theme (monokai)
  2. install hungry delete mode
  3. package-list-packages (add/delete/update packages)
  4. install and configure smex and ivy mode
  5. use customize-group to customize the package settings
  6. install and configure smartparens mode
  7. Don’t try to update the package daily, the updating process might failed.

(tips: press M-RET to fix the order, you could also use M-RET to add new headings, cheers!)

Setup a javascript IDE

  1. Install js2-mode and start to write javascript
  2. Install nodejs-repl to execute code inside Emacs

Learn more from Emacs itself

  1. c-h c-f(find-function), c-h c-v(find-variable), c-h c-k(find-function-on-key)
  2. Tell users to learn more about elisp(M-x info)

Org-mode(Bonus Time)

Agenda files and agenda view
  1. one gtd.org file
1
2
(setq org-agenda-files '("~/org"))
(global-set-key (kbd "C-c a") 'org-agenda)
Learn how to schedule items and set deadline
  1. c-c c-s to schedule item
  2. c-c c-d to set deadline of item.

Excercise

the difference between .emacs and .emacs.d/init.el file
try to configure company mode via customize-group

Spacemacs Rocks Season 2 ( Day three )

Split your configs into multiple files

  1. use Git to management your init file

  2. help window is anoyying..

1
2
3
4
5
;; add popwin mode
;; why this line is needed
(require 'popwin) (require 'init-packages)
   ;;when require, wh(setq company-minimum-prefix-length 1)en not require
(popwin-mode t)
  1. load-file, load-path and load
  2. features, provide and require, autoload
  3. naming conventions

zilongshanren/xxxx minor mode or major mode. niubi-mode niubi-xxx

all of the names should have a prefix, such that the naming conflicts could be minimal.

  1. define your abbrevs
1
2
3
4
5
6
7
8
  (abbrev-mode t)

(define-abbrev-table 'global-abbrev-table '(
                                            ;; signature
                                            ("8zl" "zilongshanren")
                                            ;; emacs regex

                                            ))
  1. how to organize your configs
  2. init-packages.el
  3. init-ui.el
  4. init-better-defaults.el
  5. init-keybindings.el
  6. custom.el
1
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  1. use `counsel-git` to find file in git managed project.
1
(global-set-key (kbd "C-c p f") 'counsel-git)

Major mode and minor mode in details

  1. conventions

text-mode/special-mode/prog-mode naming: xxx-mode, xxx-mode-key-map xxx-mode-hook

  1. mode key map and mode hook

  2. let’s take a look at a pacakge in elpa (company)

Better Defaults

  1. disable audio bell
1
(setq ring-bell-function 'ignore)
  1. auto revert file when they are changed outside the editor
1
(global-auto-revert-mode t)

Exercise

  1. Only turn on Linum-mode when doing programming (tips: use prog-mode-hook)

Spacemacs Rocks Season 2 (Day 4)

Talk more about load, load-file, require, provide and auto-load

Better defaults

  1. Indent-region or buffer
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  (defun indent-buffer ()
    "Indent the currently visited buffer."
    (interactive)
 reveal-in-osx-finder   It is bound to RET, a.
(indent-rSpacemacsegion (point-min) (point-max)))

  (defun indent-region-or-buffer ()
    "Indent a region if selected, otherwise the whole buffer."
    (interactive)
    (save-excursion
      (if (region-active-p)
          (progn
            (indent-region (region-beginning) (region-end))
            (message "Indented selected region."))
        (progn
          (indent-buffer)
          (message "Indented buffer.")))))

  (global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)
  1. another way to complete things in Emacs.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  (global-set-key (kbd "s-/") 'hippie-expand)

;; hippie expand is dabbrev expand on steroids
(setq hippie-expand-try-functions-list '(try-expand-dabbrev
                                         try-expand-dabbrev-all-buffers
                                         try-expand-dabbrev-from-kill
                                         try-complete-file-name-partially
                                         try-complete-file-name
                                         try-expand-all-abbrevs
                                         try-expand-list
                                         try-expand-line
                                         try-complete-lisp-symbol-partially
                                         try-complete-lisp-symbol))
  1. copy, delete and rename file

Copy/Delete/Rname files and folders

+: to create directory C-x C-f: to create file g: to refersh dired buffer C: copy file d: delete file D: delete after confirm R: rename files

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
  ;; dired - reuse current buffer by pressing 'a'
  (put 'dired-find-alternate-file 'disabled nil)

  ;; always delete and copy recursively
  (setq dired-recursive-deletes 'always)
  (setq dired-recursive-copies 'always)

  ;; if there is a dired buffer displayed in the next window, use its
  ;; current subdir, instead of the current subdir of this dired buffer
  (setq dired-dwim-target t)

  (put 'dired-find-alternate-file 'disabled nil)

  (define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file)

;; less typing when Emacs ask you yes or no
  (fset 'yes-or-no-p 'y-or-n-p)
  1. add new file and folder

  2. for adding new folders,

C-x C-f to create a new file.

  1. open dired of current buffer
1
(require 'dired-x)

after applying this setting, we could press `C-x C-j` to jump to the dired buffer of current file.

  1. open finder on Mac. (optional)

Packages:

reveal-in-osx-finder for openning the finder of the current file.

Bonus Time. Use Org-mode literate programming to organize your Emacs configurations.

1
2
3
(require 'org-install)
(require 'ob-tangle)
(org-babel-load-file (expand-file-name "zilongshanren.org" user-emacs-directory))

Exercise

  1. define C-x C-e in Js2-mode to eval js expression after node-repl mode is actived.

Spacemacs Rocks Season 2 (Day 5)

Fix smartparen quote issue

1
2
3
4
5
6
7
8
(define-advice show-paren-function (:around (fn) fix-show-paren-function)
  "Highlight enclosing parens."
  (cond ((looking-at-p "\\s(") (funcall fn))
        (t (save-excursion
             (ignore-errors (backward-up-list))
             (funcall fn)))))

  (sp-local-pair 'emacs-lisp-mode "'" nil :actions nil)

Editing large web page

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(defun remove-dos-eol ()
  "Replace DOS eolns CR LF with Unix eolns CR"
  (interactive)
  (goto-char (point-min))
  (while (search-forward "\r" nil t) (replace-match "")))

(defun hidden-dos-eol ()
  "Do not show ^M in files containing mixed UNIX and DOS line endings."
  (interactive)
  (setq buffer-display-table (make-display-table))
  (aset buffer-display-table ?\^M []))

Add more useful packages for web development

web-mode

toggle indent in web-mode

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(defun my-web-mode-indent-setup ()
  (setq web-mode-markup-indent-offset 2) ; web-mode, html tag in html file
  (setq web-mode-css-indent-offset 2)    ; web-mode, css in html file
  (setq web-mode-code-indent-offset 2)   ; web-mode, js code in html file
  )

(add-hook 'web-mode-hook 'my-web-mode-indent-setup)

(defun my-toggle-web-indent ()
  (interactive)
  ;; web development
  (if (or (eq major-mode 'js-mode) (eq major-mode 'js2-mode))
      (progn
        (setq js-indent-level (if (= js-indent-level 2) 4 2))
        (setq js2-basic-offset (if (= js2-basic-offset 2) 4 2))))

  (if (eq major-mode 'web-mode)
      (progn (setq web-mode-markup-indent-offset (if (= web-mode-markup-indent-offset 2) 4 2))
             (setq web-mode-css-indent-offset (if (= web-mode-css-indent-offset 2) 4 2))
             (setq web-mode-code-indent-offset (if (= web-mode-code-indent-offset 2) 4 2))))
  (if (eq major-mode 'css-mode)
      (setq css-indent-offset (if (= css-indent-offset 2) 4 2)))

  (setq indent-tabs-mode nil))

(global-set-key (kbd "C-c t i") 'my-toggle-web-indent)
js2-refactor
  • extract method
  • extract function

occur and imenu

  1. improve occur
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(defun occur-dwim ()
  "Call `occur' with a sane default."
  (interactive)
  (push (if (region-active-p)
            (buffer-substring-no-properties
             (region-beginning)
             (region-end))
          (let ((sym (thing-at-point 'symbol)))
            (when (stringp sym)
              (regexp-quote sym))))
        regexp-history)
  (call-interactively 'occur))
(global-set-key "M-s o" 'occur-dwim)
  1. improve imenu
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
(defun js2-imenu-make-index ()
      (interactive)
      (save-excursion
        ;; (setq imenu-generic-expression '((nil "describe\\(\"\\(.+\\)\"" 1)))
        (imenu--generic-function '(("describe" "\\s-*describe\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1)
                                   ("it" "\\s-*it\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1)
                                   ("test" "\\s-*test\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1)
                                   ("before" "\\s-*before\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1)
                                   ("after" "\\s-*after\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1)
                                   ("Function" "function[ \t]+\\([a-zA-Z0-9_$.]+\\)[ \t]*(" 1)
                                   ("Function" "^[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*=[ \t]*function[ \t]*(" 1)
                                   ("Function" "^var[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*=[ \t]*function[ \t]*(" 1)
                                   ("Function" "^[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*()[ \t]*{" 1)
                                   ("Function" "^[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*:[ \t]*function[ \t]*(" 1)
                                   ("Task" "[. \t]task([ \t]*['\"]\\([^'\"]+\\)" 1)))))
(add-hook 'js2-mode-hook
              (lambda ()
                (setq imenu-create-index-function 'js2-imenu-make-index)))

(global-set-key (kbd "M-s i") 'counsel-imenu)

expand-region and iedit mode

Bonus Time. Org export

export to html, you could also export to pdf

C-x C-e

Exercises

  1. Learn how to use emmet-mode to do zen coding: https://github.com/smihica/emmet-mode
  2. configure your system to export org file to pdf file
  3. install multiple cursor mode and compare it with iedit mode

Spacemacs Rocks Season 2 (Day 6)

Bonus Time: Org-mdoe

Use org-capture to take notes

1
2
3
4
(setq org-capture-templates
      '(("t" "Todo" entry (file+headline "~/.emacs.d/gtd.org" "工作安排")
         "* TODO [#B] %?\n  %i\n"
         :empty-lines 1)))

Further reading: http://orgmode.org/manual/Capture.html

Install Org pomodoro to track my time

clean up configs

  1. move keybindings into one place
  2. make c-n and c-p to select company condicate

Batch rename files

  1. press `C-x C-q` in dired mode
  2. use expand-region and iedit to batch change files

search and replace

install helm-ag
  1. at first, you should install ag

search speed: ag > pt > ack > grep

1
2
brew install the_silver_searcher
apt-get install silversearcher-ag

Show javascript errors with flycheck

  1. flycheck-checkers
  2. eslint

Snippets and auto snippet

exercises

  1. give `helm-swoop` package a try: https://github.com/ShingoFukuyama/helm-swoop
  2. Give `org-mac-link` package a try: http://melpa.org/#/org-mac-link

Spacemacs Rocks Season 2 (Day 7)

Tweak C-w to delete backward

Evil (It’s not Baidu!) Turn Emacs into Vim in one second

  1. install Evil plugin

  2. tell the different between Evil and Vim Universal args

  3. Evil state = Vim mode

evil normal state evil insert state evil visual state evil motion state evil emacs state evil operator state (diw)

  1. configure Evil leader key

  2. press `C-z` to toggle between Normal and Emacs state ??

  3. Made some modes to use emacs-state

1
2
3
4
(dolist (mode '(ag-mode
                 flycheck-error-list-mode
                 git-rebase-mode))
   (add-to-list 'evil-emacs-state-modes mode))
  1. binding h/j/k/l key
1
2
3
4
5
6
7
8
9
(add-hook 'occur-mode-hook
          (lambda ()
            (evil-add-hjkl-bindings occur-mode-map 'emacs
              (kbd "/")       'evil-search-forward
              (kbd "n")       'evil-search-next
              (kbd "N")       'evil-search-previous
              (kbd "C-d")     'evil-scroll-down
              (kbd "C-u")     'evil-scroll-up
              ))

Add this to Dired mode, ibuffer mode?

Which key

Design your own key bindings

  1. Use SPC as the leader key
  2. Use comma as the major mode leader key
  3. Use SPC : to list all available commands
  4. Use which key to group key bindings
  5. Yeah! You got a minimal Spacemacs!

Bonus Time: Search Org notes

References

Exercises

  • Install hydra and begin to add your own hydras!

Spacemacs Rocks Season 2 (Day 8)

elpa mirros

Cask and pallet

You can’t start different versions of Emacs with the single config
Troubleshootings
  • Emacs 24.5: Dependency flycheck failed to install: Package `let-alist-1.0.4’ is unavailable
  • define-advice is not defined for Emacs 24.5
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
(if (>= emacs-major-version 25)
(define-advice show-paren-function (:around (fn) fix-show-paren-function)
  "Highlight enclosing parens."
  (cond ((looking-at-p "\\s(") (funcall fn))
  (t (save-excursion
       (ignore-errors (backward-up-list))
       (funcall fn))))
  )
(defadvice show-paren-function (around fix-show-paren-function activate)
  (cond ((looking-at-p "\\s(") ad-do-it)
  (t (save-excursion
       (ignore-errors (backward-up-list))
       ad-do-it)))
  )
)

Spacemacs Rocks Season 2 (Day 9)

Topic: Macro and Use-package

What is macro?

Code which generate code?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(setq my-var 1)
(setq my-var (+ 1 my-var))

(defmacro inc (var)
  (list 'setq var (list '1+ var)))

(inc my-var) ;;add a new language

(macroexpand '(inc my-var))

(defun inc-v2 (var)
  (setq var (1+ var)))

(inc-v2 my-var)
1
2
(setq my-var 1)
(macroexpand '(inc my-var))

Write macro is almost the same as writing function in elisp.

What’s the different betwwen function and macro?

Evaluation: the macro arguments are the actual expressions appearing in the macro call.
Expansion: the value returned by the macro body is an alternate Lisp expression, also known as the expansion of the macro
examples:

back quote matters.

1
(sp-local-pair 'emacs-lisp-mode "`" nil :actions nil)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(defun my-print (number)
  (message "This is a number: %d" number))

(my-print 2)

(my-print (+ 2 3))

(quote (+ 1 1))
;; return a list


(defmacro my-print-2 (number)
  `(message "This is a number; %d" ,number))

(my-print-2 2)

(my-print-2 (+ 2 3))

(setq my-var 2)
(inc my-var)

(defmacro inc2 (var1 var2)
  (list 'progn (list 'inc var1) (list 'inc var2)))


(macroexpand '(inc2 my-var my-var))
(macroexpand-all '(inc2 my-var my-var))

Why Macro?

A more useful example of Elisp macro
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(defun prelude-search (query-url prompt)
  "Open the search url constructed with the QUERY-URL.
PROMPT sets the `read-string prompt."
  (browse-url
   (concat query-url
           (url-hexify-string
            (if mark-active
                (buffer-substring (region-beginning) (region-end))
              (read-string prompt))))))

(defmacro prelude-install-search-engine (search-engine-name search-engine-url search-engine-prompt)
  "Given some information regarding a search engine, install the interactive command to search through them"
  `(defun ,(intern (format "prelude-%s" search-engine-name)) ()
       ,(format "Search %s with a query or region if any." search-engine-name)
       (interactive)
       (prelude-search ,search-engine-url ,search-engine-prompt)))



(prelude-install-search-engine "google"     "http://www.google.com/search?q="              "Google: ")
(prelude-install-search-engine "youtube"    "http://www.youtube.com/results?search_query=" "Search YouTube: ")
(prelude-install-search-engine "github"     "https://github.com/search?q="                 "Search GitHub: ")
(prelude-install-search-engine "duckduckgo" "https://duckduckgo.com/?t=lm&q="              "Search DuckDuckGo: ")
Use-package and basic usage
  • a more safe require

  • group config into one place

  • autoload and bind keys easily

  • make your config load faster

  • and more? Spacemacs use it a lot.

Bonus Time

  • pretty print the lisp Object

(pp (macroexpand ‘(use-package company-mode)))

  • fuck your brain?
1
2
3
(defmacro defsynonym (old-name new-name)
  `(defmacro ,new-name (&rest args)
     `(, ',old-name ,@args)))

more discussion: https://emacs-china.org/t/lisp/357

Reference

Readme more about macro: https://www.gnu.org/software/emacs/manual/html%5Fnode/elisp/Macros.html#Macros

Spacemacs Rocks Season 2 (Day 10)

Topic: Company-mode and auto-completion Cask and macro/use-package

Fix previous issues

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
(use-package exec-path-from-shell
  :ensure t
  :if (and (eq system-type 'darwin) (display-graphic-p))
  :config
  (progn
     (when (string-match-p "/zsh$" (getenv "SHELL"))
      ;; Use a non-interactive login shell.  A login shell, because my
      ;; environment variables are mostly set in `.zprofile'.
       (setq exec-path-from-shell-arguments '("-l")))

     (exec-path-from-shell-initialize)
    )
  )

;; (use-package monokai-theme
;; :ensure t)

How company-mode works?

  1. backend for the completion sources and front end to display the candidates
  2. C-h v company-backends
  3. try company-file and company-ispell, M-x
  4. C-h C-f to view the backend implementation

Why my company sucks?

  1. Python anaconda-mode not works
  2. some backend require build with a server-client architecture: company-anaconda, company-jedi, company-ycmd, company-tern etc
  3. At first, you should make sure the server side is working properly and then you want to make sure you use the right backend
  4. how to fix anaconda on Mac

Group backend

Write a Simple company backend

http://sixty-north.com/blog/writing-the-simplest-emacs-company-mode-backend

reference

  1. http://sixty-north.com/blog/series/how-to-write-company-mode-backends
  2. https://www.emacswiki.org/emacs/CompanyMode

ACUTEX 编译 PATH 配置

spacemacs does not use PATH from nix-shell · Issue #2294 · syl20bnr/spacemacs Spacemacs 默认用 exec-path-from-shell,屏蔽了 PATH 路径,因此将其去除即可

1
dotspacemacs-excluded-packages '(exec-path-from-shell)