Emacs workflow to edit Bash scripts while they run

后端 未结 4 775
夕颜
夕颜 2020-12-06 18:15

Bash can give unexpected results if one edits a script while the script is running. But it would often be very convenient to be able to edit a temporary copy of a script tha

4条回答
  •  鱼传尺愫
    2020-12-06 18:50

    M-x delete-file, press down to insert obtain the path to the file you're editing, and RET to delete the file. When you next save your buffer, this will create a new file. Bash will keep executing the old, deleted file.

    By the way, in most cases, you don't even need to take this precaution. Emacs usually saves to a temporary file, then renames that temporary file to the proper file name (which deletes the old file, unless it's being kept as a backup). Emacs only overwrites the file in place if it detects that it can't recreate the file properly: if the file has hard links, or if you don't have write permission on the directory. (I'm simplifying a little; the details are in the basic-save-buffer-2 function in files.el.) As long as the file has a single directory entry and you have write permissions on the directory containing the script, just press C-x C-s.

提交回复
热议问题