English 中文(简体)
Emacs lisp; 如何从任何类型的变量中创建字符串?
原标题:Emacs lisp; how to make a string from a variable of any type?
  • 时间:2012-05-25 13:56:10
  •  标签:
  • elisp

错误调用函数显示的错误消息, 例如 :

(message (file-attributes "."))

发出讯息:

"eval: Wrong type argument: stringp, ("/home14/tjones" 1 0 0 (20415 35598) (20211 19255) (20211 19255) 14 "lrwxrwxrwx" t ...)"

您如何故意进行这种翻译,例如:

(message (thing-to-string (file-attributes ".")))

给一些信息,比如:

("/home14/tjones" 1 0 0 (20415 35598) (20211 19255) (20211 19255) 14 "lrwxrwxrwx" t ...)

仅用于调试/ 信息 。 我假设有一条方法, 信息正在做, 但是这是否暴露给我们的用户?

最佳回答

查看 prin1-to-string 及相关功能 ( prin1 , , princ , 等) 并尝试手册! > > http://www.gnu.org/ software/emacs/manual/html_node/elisp/Output-Functions.html

问题回答

message 的第一个参数应该是一个格式字符串(与您传递到 format 函数的字符串相同。如果您给它“%s”格式(或“%S”与 https://stackoverflow.com/a/10766741/35881) > Stefan s 答案。 ),它将会将您给它的任何字符串字符串作为下一个参数 。

首都 S 版本将排除字符串中的字符, 以便重读为表达式。 在这种情况下, 我认为这就是你想要的。 因此, 您不需要更改您的代码来获取您想要的 :

(message "%S" (file-attributes "."))

In your example, message did not do anything (it just refused to run), so the translation to string was done by the read-eval-print loop which caught the error and turned it into a text message. But yes, message can also do that, and it does that by calling format, which internally uses things like prin1-to-string. So (format "%S" <foo>) would do your thing-to-string.





相关问题
How to determine operating system in elisp?

How do I programmatically determine which OS Emacs is running under in ELisp? I would like to run different code in .emacs depending on the OS.

Emacs, Zen-Coding mode, and Putty

I use emacs via Putty and since Putty doesn t send certain key combinations to the remote console I generally need to re-bind them to other key combinations. After installing the amazing Zen-Coding ...

Emacs23 php-mode problem

I keep getting this error and similar errors while using php-mode on Emacs23 on Ubuntu: Debugger entered--Lisp error: (void-function php-template-if-hook) php-template-if-hook() abbrev-insert(if #...

Emacs Setting which-function-mode

I would like to have which-function-mode on by default when I open up Emacs. I ve added the following lines to my .emacs file. (setq which-func-mode t) (setq which-function-mode t) When I open ...

eval during emacs lisp macro expansion

How can I fix the simple macro foo in (elisp)Eval During Expansion? None of the followings work: (defmacro foo1 (a) `(setq (eval ,a) t)) (defmacro foo2 (a) `(setq ,(eval a) t)) (defmacro foo3 (...

Get local cvs comment history when committing file/s in emacs

I often commit files with similar cvs comment but not in a single operation. I would like to able to bring up previous comments I ve used in a previous commit when I am in the process of writing a ...

热门标签