【问题标题】:How to create an empty file by elisp?如何通过elisp创建一个空文件?
【发布时间】:2012-12-13 20:46:02
【问题描述】:

我为通过 UI 创建的自定义设置了一个显式文件。它被命名为custom.el。目前,如果不存在,我使用以下 sn-ps 创建此文件。

(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函数可以做到吗?

【问题讨论】:

标签: emacs lisp elisp


【解决方案1】:

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

【讨论】:

  • 如果您将第一个 nil 更改为 "",那么您将拥有理想的解决方案。
【解决方案2】:

我在这篇文章中基于 Joao Tavara anwser 在下面编写了这个函数:How do I create an empty file in 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))))

【讨论】:

    猜你喜欢
    • 2017-12-02
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多