magit调用git命令时间很长的时候, 怎么显示一个标识或者进度?

酷炫,期待分享

基于网上找的一个notify.el修改了一下, 增加了错误通知接口, 另外增加了一个通知后端, 在macos上使用osacript来发送系统通知:

然后再修改magit的进程结束处理函数, 我用的是magit 1.x, 修改比较简单:

--- a/.lisp/magit/magit.el
+++ b/.lisp/magit/magit.el
@@ -2170,7 +2170,16 @@ function can be enriched by magit extension like magit-topgit and magit-svn"
         (dired-uncache default-directory)))
     (setq magit-process nil)
     (magit-set-mode-line-process nil)
-    (magit-refresh-buffer magit-process-client-buffer)))
+    (magit-refresh-buffer magit-process-client-buffer)
+	;;+Added by zhanghj([email protected]) at 13:17 04/26/2019
+  	(unless (get-buffer-window magit-process-client-buffer)
+	  (let ((repo-dir (with-current-buffer magit-process-client-buffer
+						(magit-get-top-dir default-directory))))
+		(if successp
+			(my-notify "magit result: OK"
+					   (format "%s\n------\nrepo: %s" msg repo-dir))
+		  (my-notify-critical "magit result: failed"
+							  (format "%s\n------\nrepo: %s" msg repo-dir)))))))
 
 (defun magit-password (proc string)
   "Checks if git/ssh asks for a password and ask the user for it."

magit 2.x的没怎么用过, 看了一下, 可以尝试修改magit-process-finish函数.

1 个赞

你是基于 EmacsWiki: notify.el 这份源代码修改的吧?

大佬 @jwiegley 有个 alert.el 功能似乎不少(里边还有个基于 frame 的通知功能没实现完):

| Name          | Summary                                                            |
| ------------- | ------------------------------------------------------------------ |
| fringe        | Changes the current frame's fringe background color                |
| mode-line     | Changes the current frame's mode-line background color             |
| gntp          | Uses gntp, it requires [gntp.el](https://github.com/tekai/gntp.el) |
| growl         | Uses Growl on OS X, if growlnotify is on the PATH                  |
| ignore        | Ignores the alert entirely                                         |
| libnotify     | Uses libnotify if notify-send is on the PATH                       |
| log           | Logs the alert text to *Alerts*, with a timestamp                  |
| message       | Uses the Emacs `message` facility                                  |
| notifications | Uses notifications library via D-Bus                               |
| notifier      | Uses terminal-notifier on OS X, if it is on the PATH               |
| osx-notifier  | Native OSX notification using AppleScript                          |
| toaster       | Use the toast notification system                                  |
| x11           | Changes the urgency property of the window in the X Window System

Emacs 内置了一个 notifications.el 不过依赖 DBUS,在 macOS 下用不了。

还有 terminal-notifiernode-notifier 等命令行工具:eshell 一个命令完成时在modeline提醒 - #2,来自 twlz0ne

我觉得还是系统通知靠谱,emacs被最小化之后自己实现的通知很难被注意到。

terminal-notifier在tmux下不能用,装了另外一个跟他配合的插件,当时好像遇到了死机,所以这些外部非必须得工具都删了,感觉用系统自带的兼容比较好,也通用。

alert.el代码太多了,一百多行可以实现的功能用了一千行。我喜欢简单直接够用的。