如何通过elisp创建一个空文件?

hbi*_*bin 11 lisp emacs elisp

我将显式文件设置为通过UI创建的自定义.它被命名了custom.el.目前,我使用以下代码段创建此文件(如果不存在).

(defconst custom-file (expand-file-name "custom.el" user-emacs-directory))
(unless (file-exists-p custom-file)
  (shell-command (concat "touch " custom-file)))
Run Code Online (Sandbox Code Playgroud)

有一个丑陋的shell命令touch,任何其他elisp函数都可以做到这一点?

mat*_*thk 15

您可以使用(write-region "" nil custom-file)不确定这是理想的解决方案.

  • 如果你将第一个'nil`改为``"`,那么我认为你有理想的解决方案. (3认同)