我正在关注elisp的介绍.第一章.这是我从html书中复制/粘贴的两个例子.我已经评估了两种形式,在这里我复制/粘贴返回的值和输出作为*Messages*缓冲区的副作用(我不知道如何复制迷你缓冲区内容).
第一种形式
(let ((zebra 'stripes)
(tiger 'fierce))
(message "One kind of animal has %s and another is %s."
zebra tiger))
Run Code Online (Sandbox Code Playgroud)
来自*消息*的输出
One kind of animal has stripes and another is fierce.
#("One kind of animal has stripes and another is fierce." 23 30 (fontified t))
Run Code Online (Sandbox Code Playgroud)
第二种形式
(let ((birch 3)
pine
fir
(oak 'some))
(message "Here are %d variables with %s, %s and %s value."
birch pine fir oak))
Run Code Online (Sandbox Code Playgroud)
*Messages*的输出是:
Here are 3 variables with nil, nil and some value.
"Here are 3 variables with nil, nil and some value."
Run Code Online (Sandbox Code Playgroud)
为什么第一个表单返回lambda值?是什么让第一个表单如此特殊以至于返回的值不是字符串?
use*_*342 10
在message返回类型仅仅是一个字符串.在*Messages*缓冲区中,您可以看到返回值message(由评估命令在回显区域中显示在引号中),以及回显区域中显示的未加引号的字符串message.第一个结果不是lambda,而是带有text属性的字符串.
在Emacs中,字符串对象的可打印表示通常是双引号中的内容,如第二个示例中所示.但是,附加文本属性的字符串以更复杂的方式打印,如#("...string contents..." start end (property value...) ...).这种扩展语法是Lisp阅读器能够在从文本表示中读回字符串时重新创建属性.您可以通过M-: (insert #("foo" 0 3 (face (:foreground "yellow"))))在新缓冲区中进行评估来测试这一点- 文本将显示为黄色,因为字符串本身包含将其绘制为黄色的说明.(要看到这一点,你需要处于一个新的缓冲区中,比如说,C-x b randomname RET它不会在语法高亮的缓冲区中工作,例如*scratch*,因为它们会自己着色文本.)
因此,您打印的第一个字符串附带了属性,可能是复制和粘贴的工件,这就是为什么它被打印为#("..." ...).第二个字符串没有属性,可以打印为简单字符串.
该的Emacs Lisp手册包含文字属性更加信息.
| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |