14

我将显式文件设置为通过 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)))

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

4

2 回答 2

22

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

于 2012-12-28T16:07:39.123 回答
0

我在这篇文章中基于 Joao Tavara anwser 在下面编写了这个函数:如何在 emacs 中创建一个空文件?

(defun fzl-create-empty-file-if-no-exists(filePath)
   "Create a file with FILEPATH parameter."
   (if (file-exists-p filePath)
       (message (concat  "File " (concat filePath " already exists")))
     (with-temp-buffer (write-file filePath))))
于 2020-11-16T15:14:54.940 回答