gpt4 book ai didi

Emacs Lisp 打印输出

转载 作者:太空宇宙 更新时间:2023-11-03 18:51:09 25 4
gpt4 key购买 nike

我运行了以下代码,在暂存缓冲区和 ielm repl 中打印了 i 的 15 个连续值:

    (defvar i 0)
(while (< i 15)
(print i)
(setq i (+ i 1)))`

我在临时缓冲区和 repl 中注意到的是,它们都只显示 sexp 的结果值。 i 的打印值然后被发送到 Messages 缓冲区。

  1. 至少对于 repl,我怎样才能得到打印在 repl 中的 i 的值?
  2. 如果您有其他适合您的解决方案,请告诉我!

请注意,我通过终端和 Ubuntu 12.04 LTS 使用 emacs 24.3。感谢所有的帮助!

另外,从 print 的文档我们有:

print is a built-in function in `C source code'.

(print OBJECT &optional PRINTCHARFUN)

Output the printed representation of OBJECT, with newlines around it.
Quoting characters are printed when needed to make output that `read'
can handle, whenever this is possible. For complex objects, the behavior
is controlled by `print-level' and `print-length', which see.

OBJECT is any of the Lisp data types: a number, a string, a symbol,
a list, a buffer, a window, a frame, etc.

A printed representation of an object is text which describes that object.

Optional argument PRINTCHARFUN is the output stream, which can be one
of these:

- a buffer, in which case output is inserted into that buffer at point;
- a marker, in which case output is inserted at marker's position;
- a function, in which case that function is called once for each
character of OBJECT's printed representation;
- a symbol, in which case that symbol's function definition is called; or
- t, in which case the output is displayed in the echo area.

If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
is used instead.
  1. 由于我不熟悉 lisp 的实用方面,我该如何打印到不同的缓冲区?

最佳答案

这是我编写的 Emacs Lisp format 的一个小扩展,其执行类似于 Common Lisp format,但使用 % 作为控件字符:

http://code.google.com/p/formatting-el/source/browse/trunk/formatting.el

因此,例如,如果您想将带有换行符的数字列表打印成字符串,您可以这样做:

(cl-format "%{%s%^\n%}" (cl-loop for i from 0 below 10 collect i))
"0
1
2
3
4
5
6
7
8
9"

实现此目的的另一种方法是使用如下内容:

(mapconcat #'number-to-string (cl-loop for i from 0 below 10 collect i) "\n")
"0
1
2
3
4
5
6
7
8
9"

关于Emacs Lisp 打印输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18418685/

25 4 0
文章推荐: html - Twitter Bootstrap 居中响应式导航栏
文章推荐: css - 我的简单 CSS 画廊在 Firefox 中工作,但在 safari 或 chrome 中不工作
文章推荐: css - 将

限制在带有 CSS 的 Angular

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com