feat(vc): add codeberg support to browse-at-remote

This should be PRed upstream later.
This commit is contained in:
Henrik Lissner 2023-02-18 16:45:14 -05:00
parent 81268cc5cf
commit 79736d832d
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 26 additions and 0 deletions

View file

@ -1,11 +1,33 @@
;;; emacs/vc/autoload/vc.el -*- lexical-binding: t; -*- ;;; emacs/vc/autoload/vc.el -*- lexical-binding: t; -*-
;;
;;; Helpers
(defun +vc--remote-homepage () (defun +vc--remote-homepage ()
(require 'browse-at-remote) (require 'browse-at-remote)
(or (let ((url (browse-at-remote--remote-ref))) (or (let ((url (browse-at-remote--remote-ref)))
(cdr (browse-at-remote--get-url-from-remote (car url)))) (cdr (browse-at-remote--get-url-from-remote (car url))))
(user-error "Can't find homepage for current project"))) (user-error "Can't find homepage for current project")))
;; TODO: PR these upstream?
;;;###autoload
(defun browse-at-remote--format-region-url-as-codeberg (repo-url location filename &optional linestart lineend)
"URL formatted for codeberg."
(cond
((and linestart lineend)
(format "%s/src/%s/%s#L%d-L%d" repo-url location filename linestart lineend))
(linestart (format "%s/src/%s/%s#L%d" repo-url location filename linestart))
(t (format "%s/src/%s/%s" repo-url location filename))))
;;;###autoload
(defun browse-at-remote--format-commit-url-as-codeberg (repo-url commithash)
"Commit URL formatted for codeberg"
(format "%s/src/commit/%s" repo-url commithash))
;;
;;; Commands
(defvar browse-at-remote-prefer-symbolic) (defvar browse-at-remote-prefer-symbolic)
;;;###autoload ;;;###autoload
(defun +vc/browse-at-remote (&optional arg) (defun +vc/browse-at-remote (&optional arg)

View file

@ -133,6 +133,10 @@ otherwise in default state."
;; using commit hashes rather than branch names. ;; using commit hashes rather than branch names.
(setq browse-at-remote-prefer-symbolic nil) (setq browse-at-remote-prefer-symbolic nil)
;; Add codeberg.org support
;; TODO: PR this upstream?
(add-to-list 'browse-at-remote-remote-type-regexps '("^codeberg\\.org$" . "codeberg"))
;; HACK `browse-at-remote' produces urls with `nil' in them, when the repo is ;; HACK `browse-at-remote' produces urls with `nil' in them, when the repo is
;; detached. This creates broken links. I think it is more sensible to ;; detached. This creates broken links. I think it is more sensible to
;; fall back to master in those cases. ;; fall back to master in those cases.