diff options
| author | Thomas Voss <thomas.voss@humanwave.nl> | 2025-12-11 14:09:13 +0100 |
|---|---|---|
| committer | Thomas Voss <thomas.voss@humanwave.nl> | 2025-12-11 14:09:13 +0100 |
| commit | 6200092afe794866017a87db2c4b0967e1135b19 (patch) | |
| tree | 646412b80650bed30c9218c30168bfef7f2bfb5c /.config/emacs | |
| parent | 48c0bcb851f67589ed922c87b8caa74252afc779 (diff) | |
emacs: Add ‘gh-open-previous-pr’
Diffstat (limited to '.config/emacs')
| -rw-r--r-- | .config/emacs/modules/mm-projects.el | 3 | ||||
| -rw-r--r-- | .config/emacs/site-lisp/gh.el | 22 |
2 files changed, 23 insertions, 2 deletions
diff --git a/.config/emacs/modules/mm-projects.el b/.config/emacs/modules/mm-projects.el index 720cea3..02d7af4 100644 --- a/.config/emacs/modules/mm-projects.el +++ b/.config/emacs/modules/mm-projects.el @@ -108,6 +108,7 @@ This is intended to be called interactively via ;;; GitHub Pull Requests (require 'gh) -(keymap-global-set "C-c p" #'gh-create-pr) +(keymap-global-set "C-c p c" #'gh-create-pr) +(keymap-global-set "C-c p o" #'gh-open-previous-pr) (provide 'mm-projects) diff --git a/.config/emacs/site-lisp/gh.el b/.config/emacs/site-lisp/gh.el index 0461b18..23086e5 100644 --- a/.config/emacs/site-lisp/gh.el +++ b/.config/emacs/site-lisp/gh.el @@ -36,4 +36,24 @@ via `gh-get-labels'." (apply #'call-process "gh" nil t nil "pr" "create" flags) (message (buffer-string))))) -(provide 'gh)
\ No newline at end of file +(defvar gh-pr-regexp + "\\`https://\\(?:www\\.\\)?github\\.com/[^/]+/[^/]+/pull/[[:digit:]]+\\'") + +(defun gh--pr-link-p (s) + (declare (pure t) (side-effect-free t)) + (string-match-p gh-pr-regexp s)) + +(defun gh-open-previous-pr () + "Open the previous GitHub pull request. +Opens the previous pull request created by `gh-create-pr' by searching +for the echoed URL in the `*Messages*' buffer." + (interactive) + (with-current-buffer "*Messages*" + (goto-char (point-max)) + (while (not (gh--pr-link-p (buffer-substring-no-properties + (pos-bol) (pos-eol)))) + (unless (line-move -1 :noerror) + (user-error "No previous pull request found."))) + (browse-url-at-point))) + +(provide 'gh) |