Writing “Hello World” in Emacs?

拜拜、爱过 提交于 2019-12-02 19:16:43

Seems like you want princ instead of print. So, basically:

(princ "Hello world! I'm writing to STDOUT but I'm not in quotes!")

However, one caveat is that princ does not automatically terminate the output with \n.

As David Antaramian says, you probably want princ.

Also, message supports a format control string (akin to printf in C) that is adapted from format. So, you may eventually want to do something like

(princ (format "Hello, %s!\n" "World"))

As a couple of functions plus demonstration:

(defun fmt-stdout (&rest args)
  (princ (apply 'format args)))
(defun fmtln-stdout (&rest args)
  (princ (apply 'format
                (if (and args (stringp (car args)))
                    (cons (concat (car args) "\n") (cdr args))
                  args))))

(defun test-fmt ()
  (message "Hello, %s!" "message to stderr")
  (fmt-stdout "Hello, %s!\n" "fmt-stdout, explict newline")
  (fmtln-stdout "Hello, %s!" "fmtln-stdout, implicit newline"))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!