spacemacs
M + /
: file name/ address auto completeC + c C + x C + v
display the image- org export to html css set
#+OPTIONS: tex:t
#+STARTUP: latexpreview
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://gongzhitaao.org/orgcss/org.css"/>
- 添加 python 自动补全
pip安装库
- jedi
- virtualenv
- elpy
- flycheck
在.spacemacs 文件中进行配置
(setq configuration-layer--elpa-archives
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:complete-on-dot t)
)
dotspacemacs-additional-packages '(
(jedi :location elpa)
elpy
flycheck
)
在编辑python文件时还需要
M+x run-python
运行python
C + c C+Z
C+C C+c
常用快捷键
alt + % 查找 询问替换
m + {a-z} 设置书签
` {a-z} 跳转至书签
#隐藏代码块
Hide Block C-c @ C-h
Show Block C-c @ C-s
Hide All C-c @ C-M-h
Show All C-c @ C-M-s
Hide Level C-c @ C-l
Toggle Hiding C-c @ C-c
Undo - C-/
Redo - C-?
g d 跳转至函数定义处
Ctr o 跳转回之前光标处
<spc> / 工程内查找
<spc> * 工程内查找当前光标所在文字
<spc> p R 工程内替换
<spc> p f 工程内定位文件
<spc> p p 多个工程切换
中文乱码
只需 C-x RET r ( M-x revert-buffer-with-coding-system) 来用指定的编码重新读入这个文件即可。一般乱码都是因为 emacs 下使用 latin 或者 utf8,而打开的文档是 gb2312 编码。如果不记得编码类型就试一下,基本上 gb2312 都能解决。
Emacs lisp
所有的 elisp 都是运行在 emacs 这个环境下。
用 M-x lisp-interaction-mode 先转换到 lisp-interaction-mode
(message "Hello world")
让 elisp 解释器执行一个 S-表达式可以用 C-x C-e,也可以在光标右括号处用C+j
- elisp 中定义一个函数是用这样的形式:
(defun function-name (arguments-list)
"document string"
body)
例子:
(defun hello-world (name)
"Say hello to user whose name is NAME."
(message "Hello, %s" name))
- 变量赋值
(setq foo "I'm foo") ; => "I'm foo"
(message foo) ; => "I'm foo"
- 局部作用域的变量
elisp 里可以用 let 和 let* 进行局部变量的绑定。
(let (bindings)
body)
例子:
(defun circle-area (radix)
(let ((pi 3.1415926)
area)
(setq area (* pi radix radix))
(message "直径为 %.2f 的圆面积是 %.2f" radix area)))
(circle-area 3)
let* 和 let 的使用形式完全相同,唯一的区别是在 let* 声明中就能使用前面声明的变量:
(defun circle-area (radix)
(let* ((pi 3.1415926)
(area (* pi radix radix)))
(message "直径为 %.2f 的圆面积是 %.2f" radix area)))
- 顺序执行
(progn A B C ...)
它的作用就是让表达式 A, B, C 顺序执行。比如:
(progn
(setq foo 3)
(message "Square of %d is %d" foo (* foo foo)))
- 条件判断
elisp 有两个最基本的条件判断表达式 if 和 cond。使用形式分别如下:
(if condition
then
else)
(cond (case1 do-when-case1)
(case2 do-when-case2)
...
(t do-when-none-meet))
使用的例子如下:
(defun my-max (a b)
(if (> a b)
a b))
(my-max 3 4) ; => 4
(defun fib (n)
(cond ((= n 0) 0)
((= n 1) 1)
(t (+ (fib (- n 1))
(fib (- n 2))))))
(fib 10) ; => 55
- 循环
循环使用的是 while 表达式。它的形式是:
(while condition
body)
比如:
(defun factorial (n)
(let ((res 1))
(while (> n 1)
(setq res (* res n)
n (- n 1)))
res))
(factorial 10) ; => 3628800
- 逻辑运算
条件的逻辑运算和其它语言都是很类似的,使用 and、or、not。and 和 or 也同样具有短路性质。很多人喜欢在表达式短时,用 and 代替 when,or 代替 unless。当然这时一般不关心它们的返回值,而是在于表达式其它子句的副作用。比如 or 经常用于设置函数的缺省值,而 and 常用于参数检查:
(defun hello-world (&optional name)
(or name (setq name "Emacser"))
(message "Hello, %s" name)) ; => hello-world
(hello-world) ; => "Hello, Emacser"
(hello-world "Ye") ; => "Hello, Ye"
(defun square-number-p (n)
(and (>= n 0)
(= (/ n (sqrt n)) (sqrt n))))
(square-number-p -1) ; => nil
(square-number-p 25) ; => t
- 字符和字符串
字符的读入语法是在字符前加上一个问号,比如 ?A 代表字符 ‘A’。
?A ; => 65
?a ; => 97
产生一个字符串可以用 make-string。这样生成的字符串包含的字符都是一样的。要生成不同的字符串可以用 string 函数。
(make-string 5 ?x) ; => "xxxxx"
(string ?a ?b ?c) ; => "abc"
在已有的字符串生成新的字符串的方法有 substring, concat。substring 的后两个参数是起点和终点的位置。如果终点越界或者终点比起点小都会产生一个错误。这个在使用 substring 时要特别小心。
(substring "0123456789" 3) ; => "3456789"
(substring "0123456789" 3 5) ; => "34"
(substring "0123456789" -3 -1) ; => "78"
concat 函数相对简单,就是把几个字符串连接起来。
数字和字符串之间的转换可以用 number-to-string 和 string-to-number。
大小写转换使用的是 downcase 和 upcase 两个函数。这两个函数的参数既可以字符串,也可以是字符。capitalize 可以使字符串中单词的第一个字符大写,其它字符小写。upcase-initials 只使第一个单词的第一个字符大写,其它字符小写。这两个函数的参数如果是一个字符,那么只让这个字符大写。比如:
(downcase "The cat in the hat") ; => "the cat in the hat"
(downcase ?X) ; => 120
(upcase "The cat in the hat") ; => "THE CAT IN THE HAT"
(upcase ?x) ; => 88
(capitalize "The CAT in tHe hat") ; => "The Cat In The Hat"
(upcase-initials "The CAT in the hAt") ; => "The CAT In The HAt"
格式化字符串
format 类似于 C 语言里的 printf 可以实现对象的字符串化。数字的格式化和 printf 的参数差不多,值得一提的是 “%S” 这个格式化形式,它可以把对象的输出形式转换成字符串,这在调试时是很有用的.
;; 测试函数
(stringp OBJECT)
(string-or-null-p OBJECT)
(char-or-string-p OBJECT)
;; 构建函数
(make-string LENGTH INIT)
(string &rest CHARACTERS)
(substring STRING FROM &optional TO)
(concat &rest SEQUENCES)
;; 比较函数
(char-equal C1 C2)
(string= S1 S2)
(string-equal S1 S2)
(string< S1 S2)
;; 转换函数
(char-to-string CHAR)
(string-to-char STRING)
(number-to-string NUMBER)
(string-to-number STRING &optional BASE)
(downcase OBJ)
(upcase OBJ)
(capitalize OBJ)
(upcase-initials OBJ)
(format STRING &rest OBJECTS)
;; 查找与替换
(string-match REGEXP STRING &optional START)
(replace-match NEWTEXT &optional FIXEDCASE LITERAL STRING SUBEXP)
(replace-regexp-in-string REGEXP REP STRING &optional FIXEDCASE LITERAL SUBEXP START)
(subst-char-in-string FROMCHAR TOCHAR STRING &optional INPLACE)
`符号的作用
告诉后面的符号不要执行,而是直接使用
(set 'numstr 'nine)
(message "%s" 'numstr) ; ===>输出numstr
(message "%s" numstr) ;===> 输出nine
spacemacs yasnippet
使用Doxygen简明注释自动补全
- 类注释
# -*- mode: snippet -*-
# name: cmclass
# key: cmclass
# --
/**
* @brief 类的简单概述
* 类的详细描述
*/
- 头文件注释
# -*- mode: snippet -*-
# name: cmfile
# key: cmfile
# --
/**
* @file ${1:`(file-name-nondirectory(buffer-file-name))`}
* @brief 简介
* @details 细节
* @author liudy
* @email deyin.liu@nscc-gz.cn
* @version 1.0.0
* @date `(format-time-string"%Y-%m-%d")`
*/
- 函数注释补全
# -*- mode: snippet -*-
# name: cmfuncb
# key: cmfuncb
# --
/**
* @brief 函数简介
*
* @param 形参 参数说明
* @param 形参 参数说明
* @return 返回说明
* @retval 返回值说明
*/
错误与解决办法
-
Error enabling Flyspell mode
解决: 终端安装 aspell -
Error enabling Flyspell mode:
(Error: No word lists can be found for the language “zh_CN”.)
解决: layer中加了(spell-checking :variables spell-checking-enable-by-default nil)
-
Failed to start an edit-server spacemacs
解决: 是因为chrome layer的问题,注释掉该layer即可 -
Spacemacs 启动速度特别慢
在你的.spacemacs 或者.spacemacs.d/init.el 文件中的 user-init 方法中添加下列代码后,重启 Spacemacs 即可:
(setq tramp-ssh-controlmaster-options "-o ControlMaster=auto -o ControlPath='tramp.%%C' -o ControlPersist=no")
-
Package company-tern is unavailable.
删除javascript layer即可