Emacs 記錄

什麼是 Emacs

Emacs

An extensible, customizable, free/libre text editor — and more.

Emacs 是...

  • 學會了Emacs,你就能夠:linux

    1. 一個快速、好用、高度自定義的編輯器。
    2. 天哪,不知不覺就也會寫一點Lisp了。
    3. 認識不少朋友。
GNU Emacs

Emacs 能夠寫什麼

  • 直接說說不能寫什麼吧。

殘酷的事實

  • 並不能完成除了編輯器以外全部的事情。
  • 你願意用鼠標的話,沒有人攔住你。
  • 學不會是不可能的。

怎麼介紹 Emacs 給你們

  • 常規功能: 成爲一個好的編輯器和 IDE
  • 大殺器: 別人都沒有的我有
  • 花哨功能: 有點想知道是那個淡散的人寫的

IDE: 平常介紹

  • 快速編輯 C-p/f/w/n ;; 系列
  • 窗口分割 C-x 123 ;; 系列
  • 工程瀏覽 projectile 和 neo-tree
  • M-x shell
  • 任意綁定按鍵

IDE: 查找替換

  • I-search
  • query-replace-regexp query-\([a-z]*\)-regexp xx-\1-yy
  • regex-builder
  • rgrep
  • projectile-find-file

IDE: tramp 編輯遠端文件/切換權限編輯

例如,直接經過 ssh 編輯遠端文件,sudo 身份編輯本地文件。git

C-x f /ssh:user@host:path
C-x f /sudo::/etc/hosts

參考:github

Tramp Mode

IDE: git 和 ediff

  • magit
  • ediff

IDE: 代碼跳轉和識別

  • TAGS 跳轉:

生成 TAGSweb

etags `find . -name "*.[chS]"`
etags `find . -name "*.h" -o "*.cpp"`
etags `find . -name "*.[he]rl"`

載入 TAGS:shell

M-x visit-tags-table

通常用法:數組

M-. %% 跳轉
M-* %% 返回跳轉
C-u M-. %% 下一個位置

IDE: 對 Go 特別友好的支持

在 go-mode, auto-complete, go-autocomplete,同時安裝好 gofmt 和 gocode。bash

(require 'go-mode)
(add-hook 'before-save-hook 'gofmt-before-save)

(require 'auto-complete-config)
(require 'go-autocomplete)

(add-hook 'go-mode-hook
          '(lambda() (setq tab-width 4)
         (linum-mode 1)
         (auto-complete-mode t)))
提示: Emacs 對代碼的跳轉補全依賴第三方語法分析工具,若是有工具,就可以很好的接入。

COOL: ELPA

Emacs > 24加入了本身的包管理,絕對是炫酷)。ssh

記得首先設置路徑。編輯器

(add-to-list 'package-archives
  '("popkit" . "http://elpa.popkit.org/packages/"))

而後 M-x list-package 函數

COOL: Emacs Lisp

只要你能數清括號,就能學會 Lisp :D

  • Lisp的7個公理
  • 數據類型: 數字/字符串/列表/數組/符號
  • 求值
  • 函數
  • 特有操做對象: 緩衝區/窗口/文件/文本

ELisp: 爲何說 Emacs 是 ELisp 寫的。

ELisp 是一門的語言。而且支持 GC。
豐富的庫。
幾乎全部的擴展程序都是純 ELisp 程序。

ELisp: 配置即代碼

(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

(defconst *is-a-mac* (eq system-type 'darwin))

ELisp: 大文件處理

(defun large-file-hook ()
  "If the size of given file is lager than 2 MB, to make the buffer read only."
  (when (> (buffer-size) (* 2 1024 1024))
(setq buffer-read-only t)
(buffer-disable-undo)
(buffer-disable-undo)
(linum-mode 0)
(font-lock-mode 0)
(fundamental-mode)))

COOL: 字體配置

針對不一樣的字符配置不一樣的字體。
(when (and (eq system-type 'gnu/linux))
  (set-face-attribute 'default nil :family "Ubuntu mono" :height 160)

  (dolist (charset '(kana han symbol cjk-misc bopomofo))
    (set-fontset-font (frame-parameter nil 'font)
      charset (font-spec :family "Noto Sans CJK TC light"
      :height 160))))

無聊小玩意兒

  • info/woman 閱讀文檔
  • web/圖片/pdf/word (eww)
  • tetris/snake/pong cd /usr/share/emacs/*/lisp/play
  • doctor

還在等什麼,趕忙開始學習吧。

C-x h, t ;; 查看自帶的教程。

推薦

一個很是好的參考資料。

A reasonable Emacs config
Emacs Lisp 簡明教程
相關文章
相關標籤/搜索