Emacs工作流在编辑Bash脚本时运行 [英] Emacs workflow to edit Bash scripts while they run

查看:116
本文介绍了Emacs工作流在编辑Bash脚本时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在脚本运行时编辑脚本,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删除文件,按下来插入获取要编辑的文件的路径, 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检测到该文件无法正确重新创建文件,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脚本时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆