How do I create an empty file in emacs?

前端 未结 15 543
轻奢々
轻奢々 2020-12-13 03:20

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,

相关标签:
15条回答
  • 2020-12-13 03:54

    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.

    0 讨论(0)
  • 2020-12-13 03:55

    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)))
    
    0 讨论(0)
  • 2020-12-13 03:56

    (shell-command (concat "touch " (buffer-file-name))) will do what you want, if you've already opened the empty file.

    0 讨论(0)
  • 2020-12-13 03:57

    You can mark an empty buffer as modified by running set-buffer-modified-p. Then when you save it, Emacs will write the file.

    M-;                         ; Eval
    (set-buffer-modified-p t)   ; Mark modified
    C-x C-s                     ; Save buffer
    
    0 讨论(0)
  • 2020-12-13 03:58

    You can use the touch command:

    M-! touch __init__.py RET
    
    0 讨论(0)
  • 2020-12-13 04:00

    Use touch command.

    M-! touch __init__.py RET
    
    0 讨论(0)
提交回复
热议问题