从命令行运行 emacs 并处理锁定的文件

发布于 2024-11-29 02:00:41 字数 1713 浏览 1 评论 0 原文

我正在使用组织模式,并希望导出我的议程(示例议程)到一个文本文件,以便我可以用 conky 显示它。 org-mode 手册提供了这个命令行示例这样做:

emacs -batch -l ~/.emacs -eval '(org-batch-agenda "t")' | lpr

我已经这样修改了:

emacs -batch -l ~/.emacs -eval '(org-batch-agenda "e")' \
> ~/org/aux/agenda-export.txt

我将其设置为每 5 分钟运行一次的 cron 作业。除非我确实打开了 emacs,否则它效果很好。然后我注意到文件 agenda-export.txt 是空的。在从 coammand 行与通过 cron 手动运行此命令时,我收到此错误(或类似的错误,具体取决于我打开的文件):

...~/org/file.org locked by jwhendy (pid 10935): (s, q, p, ?)?

我打算编写一个脚本来导出到agenda-export-test.txt ,然后也许检查是否有空文件或没有行(wc -l == 0 也许?)。如果为 true,则保留现有文件并删除 agenda-export-test.txt。如果没有,请将 agenda-export-test.txt 移至 agenda-export.txt

但是......当我尝试运行这样的脚本时,我遇到了相同的 emacs 查询,询问是否窃取锁、继续或退出。我同意继续,因为我不认为 org-agenda 对文件做任何事情,因此它不会损害任何东西......但我不知道如何告诉 emacs“强制”或选择“继续” “如果遇到问题。我需要一些非交互式的东西。

所以,总而言之,我的想法是尝试:

  • 传递一个 --force 选项或类似于 emacs 的选项,使其在暂停时继续,
  • 查看导出的 tmp 文件是否有任何行并相应地处理它,
  • 告诉 emacs 以“只读”运行模式”(但我认为它不存在)

主要问题是,对于 cron,我不在那里告诉进程要做什么,所以它只是创建一个空文件作为导出的结果。如何用像cron这样无法响应的“盲”进程来处理这个锁定文件的业务呢?

我也尝试询问邮件列表,但没有任何结果。 [1] 我想知道这里是否有人有想法。

[1] http://www.mail-archive.com/ [电子邮件受保护]/msg45056.html

I'm using org-mode and am looking to export my agenda (example of an agenda) to a text file so that I can display it with conky. The org-mode manual features this command line example to do this:

emacs -batch -l ~/.emacs -eval '(org-batch-agenda "t")' | lpr

I've modified this like so:

emacs -batch -l ~/.emacs -eval '(org-batch-agenda "e")' \
> ~/org/aux/agenda-export.txt

I have this set as a cron job to run every 5 minutes. It works great unless I actually have emacs open. Then I noticed that the file agenda-export.txt was empty. In running this manually from the coammand line vs. through cron, I get this error (or similar depending on the files I have open):

...~/org/file.org locked by jwhendy (pid 10935): (s, q, p, ?)?

I was going to write a script to perhaps export to agenda-export-test.txt, then perhaps check for an empty file or no lines (wc -l == 0 maybe?). If true, leave the existing file alone and delete agenda-export-test.txt. If not, then move agenda-export-test.txt to agenda-export.txt.

But... when I try to run such a script, I'm met with the same emacs inquiry about whether to steal the lock, proceed, or quit. I'm fine with proceeding, as I don't think org-agenda does anything to the files and thus it wouldn't harm anything... but I don't know how to tell emacs to "force" or choose "proceed" if problems are encountered. I need something non-interactive.

So, to summarize, my thoughts were to try:

  • passing a --force option or similar to emacs to make it proceed at the pause
  • see if the exported tmp file has any lines and deal with it accordingly
  • tell emacs to run in "read only mode" (but I don't think it exists)

The main issue is that with cron, I'm not there to tell the process what to do, and so it just just make an empty file as the exported results. How can I handle this locked file business with a "blind" process like cron that can't respond?

I've tried asking the mailing list as well without a working outcome. [1] I wondered if someone here might have ideas.

[1] http://www.mail-archive.com/[email protected]/msg45056.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榆西 2024-12-06 02:00:41

您是否尝试过不使用 emacs 来复制文件?
放入你的 crontab 中:

cp ~/org/file.org /tmp/export.org && emacs -batch .... /tmp/export.org ..

常规的“cp”命令不应复制 emacs 锁。当然,如果您只是在 cp 命令期间保存议程,偶尔您可能会收到损坏的文件,但这应该不会太糟糕。

Have you tried copying file without using emacs?
put in your crontab:

cp ~/org/file.org /tmp/export.org && emacs -batch .... /tmp/export.org ..

A regular "cp" command should not copy emacs locks. Of course, once in a while you might get a damaged file if you save agenda just during cp command, but this should not be too bad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文