How do I create an empty file in emacs?
Solution 1:
You can use the touch command:
M-! touch __init__.py RET
Solution 2:
The following works:
C-x b __init__.py RET C-x C-w RET
If you're in a dired buffer the file will be saved in the directory show here.
The trick is to first create an empty buffer by switching to a name that doesn't exist. Then write out the file.
Solution 3:
If you want Emacs to treat all new files as modified, you can automate the solution like this:
(add-hook 'find-file-hooks 'assume-new-is-modified)
(defun assume-new-is-modified ()
(when (not (file-exists-p (buffer-file-name)))
(set-buffer-modified-p t)))
Solution 4:
Programatically and without any dependency on touch
, it's quite easy:
(with-temp-buffer (write-file "path/to/empty/file/"))