在magit-revision-mode buffer打開形如 `#1234` 的github issue頁面

我經常:

  1. (magit-blame-addition)
  2. 打開一個hunk進入magit-revision-mode
  3. 看到commit description第一行含有(#1234)字樣,想要打開 github.com/foo/bar/issues/1234查看相關討論

如何快速打開這個連結呢?對於一般形如https://的URI,可以用git-link。

最好能跳過Parent:行,比如對於如下description,不要跳轉到#30702

Parent:     d821a111a3 restrict second argument of `size` and `axes` to Integer for most types (#30702)
Contained:  _Static_assert master
Follows:    v1.0.0 (1082)
Precedes:   v1.2.0-rc1 (539)

separate Base and sysimg, and put less code in top-level files (#30782)

暫時採用這個方案:

(cl-defun +my/open-issue-in-browser ()
  "In magit-revision-mode, open the issue page if something like `(#123)' is in the commit message."
  (interactive)
  (let ((pos 1))
    (while (setq pos (next-property-change pos))
      (when-let* ((section (get-text-property pos 'magit-section))
                  (_ (eq (oref section type) 'commit-message)))
        (goto-char pos)
        (when (re-search-forward "#[0-9]+" (line-end-position) t)
          (browse-url (format "%s/issues/%s"
                              (shell-command-to-string "git ls-remote --get-url")
                              (substring (match-string 0) 1)))
          (shell-command "wmctrl -a chrome")
          (return-from +my/open-issue-in-browser))))))

可以用forge,会把Github的#xx转换为一个text button

可用 Emacs 自带的 Bug-Reference mode,甚至 Magit 默认就开启了它,magit-revision-mode-hook 默认就添加了 bug-reference-mode,只是你需要设置下 Bug-Reference mode,告诉它项目信息,比如以前 Magit 项目自己的设置:

现在 Magit 删掉了这个,貌似因为 Forge 会自动设置 Bug-Reference mode,不用一个一个项目写了。

謝謝。我doom-emacs裏的forge沒有初始化好。

  • 設定~/.emacs.d/.local/etc/authinfo.gpg (添加username^ghubusername^forge)
  • (emacsql-sqlite-compile 2編譯emacsql-sqlite
  • M-x forge-add-repository

之後就能看到 (#12345) 變成button了(Forge自動設置bug-reference-bug-regexpbug-reference-url-format)。怎麼用avy之類打開button呢?

ace-link可以一键打开button

还有link-hint。melpa你个浓眉大眼的,说好不上架功能类似的package的呢?