Emacs tips

6.1

package-install not found

Run M-x package-refresh-contents first

Ivy

Shortcuts:

C-M-j ( ivy-immediate-done )

语法高亮

Font Lock Mode 实现语法高亮,主要有两种方式:

  • syntax table 高亮字符串和注释
  • 基于正则表达式的搜索高亮

Font Lock Basic 介绍了基本的函数和变量

font-lock-defaults

(keywords [keywords-only [case-fold
  [syntax-alist other-vars...]]])

定时运行任务

(run-at-time TIME REPEAT FUNCTION &rest ARGS)

(run-at-time "10 sec" nil 'show-paren-mode 'toggle)

Emacs regexp examples

  • 多个空行:"\\(^\n\\)\\{2,\\}"
  • word: "\\w+\\W*"
  • word or symbol:"\\(\\w\\|\\s_\\)+[^ \t\n]*[ \t\n]*"

String / List 转换

; split
(split-string "foo, bar" ", ")

; join
(string-join '("foo" "bar") ", ")
(mapconcat #'identity '("foo" "bar") ", ")

String / Symbol 转换

; Symbol to String
(symbol-name 'some-symbol)

; String to Symbol
(intern "some-string")

Install Emacs from source in MacOS

git clone git://git.sv.gnu.org/emacs.git
cd emacs

./autogen.sh
./configure
make
make install

emacs/nextstep/Emacs.App是最终的应用。

gnutls not found

brew install texinfo
export PATH=/usr/local/opt/texinfo/bin:$PATH

lib/xml not found

尝试先运行 ./configure 后再 make

./configure
make

或尝试安装 libxml2

brew install libxml2

Emacs 特殊符号索引

elisp/Index

字符串属性

#(: Text Props and Strings

#("foo bar" 0 3 (face bold) 3 4 nil 4 7 (face italic))

使用字面量作用域

Elisp 默认是动态作用域(调用时获取变量),可以在文件开头加声明设置成字面量作用域(定义时获取变量)。

;; -*- lexical-binding: t -*-

快速阅读代码

配置 MELPA 安装源

MELPA 是 emacs 扩展包(package)的一个安装源。

配置

init.el

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                (not (gnutls-available-p))))
        (proto (if no-ssl "http" "https")))
  (when no-ssl
  (warn "\
    Your version of Emacs does not support SSL connections,
    which is unsafe because it allows man-in-the-middle attacks.
    There are two things you can do about this warning:
    1. Install an Emacs version that does support SSL and be safe.
    2. Remove this warning from your init file so you won't see it again."))
  ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  (when (< emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)

使用

  • M-x package-refresh-contents or M-x package-list-packages
  • M-x package-install

Multiple cursor

配置

dotspacemacs-additional-packages '( evil-mc )

(global-evil-mc-mode 1)

选中文本后的快捷键:grm, grq

key map variables and look up order

Org mode 介绍

https://orgmode.org/worg/org-tutorials/org4beginners.html

查看 messages

  • SPC w p m

  • C-x C-b *Messages* Ret

报错 wrong argument type: commandp, ...

可以尝试在函数内调用(interactive)

(defun funname ()
  (interactive)
  ...
)
📖