Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an empty file by elisp?

Tags:

emacs

lisp

elisp

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?

like image 955
hbin Avatar asked Dec 28 '12 15:12

hbin


People also ask

How do I create a file in Emacs?

To create a new file, use Control-X-Control-F, just as if the file already existed. When emacs asks you for the file name, type in the name you want your new file to have, and emacs will create the file, and display an empty buffer for you to type in. Emacs will perform file name completion for you.

What is the command to open a file from within Emacs?

Use Ctrl-x f to open a file from within Emacs. Create a new file in the same way as opening a file by specifying the new filename. The new file will not be saved unless specified. Save a file that is currently open by entering the Ctrl-x Ctrl-s command.

How do I navigate to a folder in Emacs?

To start dired: In Emacs, type M-x dired. You will be prompted for the directory to open. Type in the directory to display, or press Return to open the default directory.


1 Answers

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

like image 194
mathk Avatar answered Oct 01 '22 16:10

mathk