How to create an empty file by elisp?

2019-04-04 22:59发布

问题:

I set an explicit file to customization created via the UI. It's named custom.el. Currently, I use the followed snippets to create this file if not exist.

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

There is an ugly shell-command touch in, any other elisp functions can do this?

回答1:

You can use (write-region "" nil custom-file) not sure that is the ideal solution.



标签: emacs lisp elisp