Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forge--msg: Make it more resilient to buffer kills #744

Closed

Conversation

LemonBreezes
Copy link

@LemonBreezes LemonBreezes commented Jan 21, 2025

Previously, if you killed the magit-status buffer while forge was
fetching the repository information, and ran magit-status again, the
forge status would be missing from the modeline. With this PR, we use
the buffer name as a backup to identify the status buffer in case it was
killed.

The reason why I want this change is that by default, Doom Emacs kills the
magit-status buffer when you quit magit "if the buried/killed magit buffer was
the last magit buffer open for this repo" (see https://github.com/doomemacs/doomemacs/blob/master/modules/tools/magit/autoload.el#L125).

@tarsius
Copy link
Member

tarsius commented Jan 21, 2025

Closes #633.

Previously, if you killed the `magit-status` buffer while forge was
fetching the repository information, and ran `magit-status` again, the
forge status would be missing from the modeline. With this PR, we use
the buffer name as a backup to identify the status buffer in case it was
killed.
@LemonBreezes LemonBreezes force-pushed the make-forge-msg-more-resilient branch from ff90605 to 67816ec Compare January 22, 2025 00:06
@LemonBreezes
Copy link
Author

Force-pushed because I realized I did not use buffer-live-p for buf.

@tarsius
Copy link
Member

tarsius commented Jan 23, 2025

The Fetching page N status updates are not put in place by this function, but by ghub--graphql-set-mode-line. That function does not have any concept or access to "that repository" (except maybe deeply nested inside an url-encoded tree.

Doing this properly would be much more involved and while it would be desirable, I still do not think it is work the effort. FWIW before I realized the above, I cam up with the following. I cannot test it, obviously, and it still is an idealized version that doesn't take enough circumstances into account, but I guess it would be an improvement, if it weren't for the above.

@ -506,6 +506,16 @@ (defun forge--msg (repo echo done format &rest args)
                  msg)))
     (when (and echo msg)
       (message "%s%s" msg (if done "...done" "...")))
+    (cond
+     ((or (not format)
+          (not (and (derived-mode-p 'magit-mode)
+                    (equal default-directory (oref repo worktree))))))
+     ((not (buffer-live-p forge--mode-line-buffer))
+      (setq forge--mode-line-buffer (current-buffer)))
+     ((not (eq (current-buffer) forge--mode-line-buffer))
+      (with-current-buffer forge--mode-line-buffer
+        (setq mode-line-process nil))
+      (setq forge--mode-line-buffer (current-buffer))))
     (when (buffer-live-p forge--mode-line-buffer)
       (with-current-buffer forge--mode-line-buffer
         (setq mode-line-process

Instead I have added a new variable ghub-graphql-message-progress. If you enable that, then the Fetching page N messages are shown in the echo area.

@tarsius tarsius closed this Jan 23, 2025
tarsius added a commit to magit/ghub that referenced this pull request Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants