gpt4 book ai didi

emacs - 微调: `set-process-sentinel` | `set-process-filter` | `start-process`

转载 作者:行者123 更新时间:2023-12-04 23:01:21 31 4
gpt4 key购买 nike

互联网上很少有例子涉及这个问题的所有三个问题——即 set-process-sentinel ; set-process-filter ;和 start-process .

我尝试了几种不同的方法来微调进程,以强制进程号 1 ( push ) 在进程号 2 ( push ) 开始之前完成。在我所有的尝试中,第二个进程总是在我为进程号 1 输入密码之前运行并完成。进程号 2 的密码存储在 osxkeychain 中。 .

我尝试的第一种方法是使用 Magit,同步和异步进程。我尝试的第二种方法是使用函数 while . . .在包含所述列表的缓冲区中搜索 Remote 列表。下面列出了第三次尝试——它使用了在函数开始时创建的 Remote 列表,然后是 mapcar。将列表向下移至 push与 Git。

任何关于如何更好地控制进程号 1 ( push ) 以便它在进程号 2 ( push ) 开始之前成功完成的想法将不胜感激。

2 号进程过早开始和结束并不是世界末日,而是学习如何控制 Emacs 进程——而不是进程控制我的问题。

编辑 (2014 年 4 月 23 日):添加了一个文档字符串。修改了缓冲区的处理 *REMOTES* -- 即 kill-local-variable 'git-remote-listerase-buffer现在使用 with-current-buffer ... 可以正常工作

(defvar git-remote-list nil
"List of remote locations -- e.g., lawlist_remote or github_remote.")
(make-variable-buffer-local 'git-remote-list)

(defvar git-commit-message (format "Committed -- %s" (current-time-string))
"The predetermined Git commit message.")
(make-variable-buffer-local 'git-commit-message)

(defun my-process-filter (proc string)
(when (string-match "password" string)
(process-send-string
proc
(concat (read-passwd "Password: ") "\n"))))

(defun my-process-sentinel (proc string)
(when (= 0 (process-exit-status proc))
(message "Process `%s` has finished." proc)))

(defun stage-commit-push-all ()
"This function does the following:
* Save the current working buffer if it has been modified.
* Gather a list of all remotes associated with working directory Git project.
* Stage all -- `/usr/local/git/bin/git add .`
* Commit all -- `/usr/local/git/bin/git commit -m [git-commit-message]`
* Push to all remotes: `/usr/local/git/bin/git push -v [remote] [current-branch]`
Obtaining the current branch presently requires installation of Magit."
(interactive)
(when (buffer-modified-p)
(save-buffer))
(when (get-buffer "*REMOTES*")
(with-current-buffer (get-buffer "*REMOTES*")
(kill-local-variable 'git-remote-list)
(erase-buffer)))
(set-process-sentinel
(start-process
"list-remotes"
"*REMOTES*"
"/usr/local/git/bin/git"
"remote"
"-v")
(lambda (p e) (when (= 0 (process-exit-status p))
(let* (
beg
end
git-remote-name)
(with-current-buffer (get-buffer "*REMOTES*")
(goto-char (point-max))
(while (re-search-backward "\(push\)" nil t)
(beginning-of-line 1)
(setq beg (point))
(re-search-forward "\t" nil t)
(setq end (- (point) 1))
(setq git-remote-name (buffer-substring-no-properties beg end))
(setq git-remote-list
(append (cons git-remote-name git-remote-list)))) ))
(set-process-sentinel
(start-process
"stage-all"
"*OUTPUT*"
"/usr/local/git/bin/git"
"add"
".")
(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process
"commit-all"
"*OUTPUT*"
"/usr/local/git/bin/git"
"commit"
"-m"
git-commit-message)
(lambda (p e) (when (= 0 (process-exit-status p))
(mapcar (lambda (x)
(let ((proc
(start-process
"push-process"
"*OUTPUT*"
"/usr/local/git/bin/git"
"push"
"-v"
(format "%s" x)
(magit-get-current-branch))))
(set-process-filter proc 'my-process-filter)
(set-process-sentinel proc 'my-process-sentinel) ))
(with-current-buffer (get-buffer "*REMOTES*") git-remote-list)
)))))))))))

最佳答案

想到的方法很简单,每次调用 start-process依赖于前一个进程的哨兵。

本质上,生成一个你想要做的事情的队列,触发对第一个队列项的处理,并让每个哨兵触发器在它自己的进程完成后启动下一个队列项(如果有的话)的进程。

关于emacs - 微调: `set-process-sentinel` | `set-process-filter` | `start-process` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23237869/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com