使用 gnus 上新闻组
Elisp 入门2 - 语言概览

Elisp 入门1 - 打印

皮贝贝 posted @ 2010年12月29日 08:35 in emacs with tags elisp emacs , 4585 阅读

 

决定重新看遍 Elisp, 毕竟 Emacs 是用的最多的东西。

 

1 学习环境

Emacs 里的 scratch buffer 是最好的学习环境,而且默认是一直存在在 Emacs 内存中。进入 scratch buffer:

M-x switch-to-buffer <RET> *scratch* <RET>

在 scratch* buffer 中,默认的模式是 lisp-interaction-mode, 如果不是,先设定此模式:

M-x lisp-interaction-mode

而后,便可以进行lisp学习了。一个简单的 Hello World:

 

(message "Hello, World!")

在右括号后面按 C-j 会在新行打印结果:

 

(message "Hello, World!") <C-j>
 => "Hello, World!"

在 *message* buffer 中也会输出结果。 另外 Emacs 有一个全局按键: C-x C-e. 在任意模式下都可使用,在 *message* buffer 中输出表求值结果。

2 打印: message 函数

message 函数,可以输入 C-h f <RET> message 来查询函数的文档说明:

 

(message FORMAT-STRING &rest ARGS)
 将一条信息输出到 *scratch* buffer 中。
 函数返回此字符串。

这里, 符号 & 是说明后面的参数是可选的。 message 后面第一个参数是一个格式化字符串,然后是格式化字符串中格式符要替换的数据列表。例如:

 

(message "Hello, %d" 12)

第一个参数 "Hello, %d" 是格式化字符串, 后面的参数 12 会替换其中的格式符 %d, 从而函数的返回值是:

 

"Hello, Li Xiaoni"

@note: Li Xiaoni 是我不小心打校内网址不小心少打了个 e 发现的。

2.1 格式化字符串中的格式符

以 % 开头,所以如果要打印一个 % 号,必须这样 %%:

 

(message "%%")
 => "%"

一些常用的格式符:

 
%s 字符串
%d 十进制整数
%o 八进制整数
%x 十六进制整数
%X 同 %x, 大写形式输出
%c 字符
%S
%f 小数点形式的浮点数
%e 指数形式的浮点数
%g %f或%e, 自动选择一个最少输出字符的格式

 

 

(message "Hello, World") 
 => "Hello, World"
(message "Hello, %s" "Li Xiaoni") 
 => "Hello, Li Xiaoni"
(message "num: %d" 12) 
 => "num: 12"
(message "num: %X" 12)
 => "num: C"
(message "list: %S" '(apple orange pair)) 
 => "list: (apple orange pair)"
(message "list: %S" ()) ;; 空表
 => "list: nil"
(message "char: %c" ?a)
 => "a"

 

Avatar_small
zoro 说:
2011年4月11日 17:07

o(∩∩)o...哈哈这www.xiaoni.com就一张照片阿……

Head_small
皮贝贝 说:
2011年5月04日 14:01

@zoro: 强大吧,这个千年不死的域名呦!

Avatar_small
Grade 5 Result dinaj 说:
2022年8月27日 20:55

Primary School Certificate Students of Dinajpur Board can get their PSC Result 2022 with full mark sheet available from the last week of December 2022 at DPE official website for November Primary Certificate Exams 2022, Grade 5 Result dinajpur Board there are lacks of students who are participated in the terminal exams in the country along with Dinajpur Division also.Directorate of Primary Education (DPE) has successfully conducted those class 5th grade exams between 17th to 24th November 2022 across in the country for all education boards, and they have conduct answer sheet evaluation process to announce PSC Result 2022 Dinajpur Board with full mark sheet, Minister of Education has announced this is a very tuff process to complete on time for this DPE new GPA grading system of PEC Marking scheme.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter