问题描述
如果在脚本运行时编辑脚本,Bash 可能会产生意外的结果.但是,能够编辑我在 shell 中运行的脚本的临时副本通常会非常方便,但在再次运行之前请确保它回到原始位置.有没有人对 Emacs 的工作流程或自定义有建议以促进这一点?
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 that I run within a shell, but make sure it is back in the original location before I run it again. Does anyone have suggestions for a workflow or customizations to Emacs to facilitate this?
推荐答案
Mx delete-file
, press down
to insert 获取你正在编辑的文件的路径, 和 RET
删除文件.下次保存缓冲区时,这将创建一个新文件.Bash 将继续执行已删除的旧文件.
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.
顺便说一句,在大多数情况下,您甚至不需要采取这种预防措施.Emacs 通常保存到一个临时文件,然后将该临时文件重命名为正确的文件名(这会删除旧文件,除非它作为备份保留).Emacs 仅在检测到无法正确重新创建文件时才覆盖该文件:如果文件具有硬链接,或者您没有对该目录的写权限.(我简化了一点;细节在 files.el
中的 basic-save-buffer-2
函数中.)只要文件有一个目录条目并且您对包含脚本的目录具有写入权限,只需按 Cx Cs
.
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
.
这篇关于Emacs 工作流在运行时编辑 Bash 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!