How can I create an empty file from emacs, ideally from within a dired buffer?
For example, I've just opened a Python module in dired mode, created a new directory, opened that in dired, and now need to add an empty __init__.py
file in the directory.
If I use C-x C-f __init__.py RET C-x C-s
then emacs doesn't create the file because no changes have been made to it. I would have to type in the file, save it, delete my typing and then save it again for that to work.
Thanks
If you want Emacs to treat all new files as modified, you can automate the solution like this:
Emacs won't allow you to save a buffer unless it thinks the contents have changed. The quickest, though possibly not cleanest is to open the file using C-x C-f, then press (say) space and backspace, then you should be able to save a file with no contents.
There are other ways of changing the "buffer has been modified" flag, but I don't think there's any easier.
The best option would be:
You can use the touch command:
The shortest way
M-!
> __init__.py
RETI've modified answer from MrBones and created custom function with keybinding:
This is very useful to not spend time on recurring action of creating init.py everywhere in new Python project folder.