Add support for generating source hut links.

This commit is contained in:
Tom Alexander 2023-09-30 00:50:25 -04:00
parent c2a0f90b4f
commit 9d118078ae
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 37 additions and 2 deletions

View File

@ -53,7 +53,15 @@
(let ((load-it (lambda (f)
(load-file (concat (file-name-as-directory dir) f)))
))
(mapc load-it (directory-files dir nil "\\.el$"))))
(mapc load-it (directory-files dir nil "\\.el$"))))
(defun generate-vc-link ()
(interactive)
(or
(generate-github-link)
(generate-source-hut-link)
)
)
(defun generate-github-link ()
"Generate a permalink to the current line."
@ -73,6 +81,33 @@
)
(message "%s" full-url)
(kill-new full-url)
t
)
)
)
)
)
(defun generate-source-hut-link ()
"Generate a permalink to the current line."
(interactive)
(let (
(current-rev (vc-working-revision buffer-file-name))
(line-number (line-number-at-pos))
(repository-url (vc-git-repository-url buffer-file-name))
(relative-path (file-relative-name buffer-file-name (vc-root-dir)))
)
(message "Using repo url %s" repository-url)
(save-match-data
(and (string-match "https://git.sr.ht/\\([^/]+\\)/\\([^/]+\\)" repository-url)
(let* (
(sh-org (match-string 1 repository-url))
(sh-repo (match-string 2 repository-url))
(full-url (format "https://git.sr.ht/%s/%s/tree/%s/%s#L%s" sh-org sh-repo current-rev relative-path line-number))
)
(message "%s" full-url)
(kill-new full-url)
t
)
)
)

View File

@ -7,6 +7,6 @@
;; dabbrev-expand. Seems to be some sort of dumb-expand. Accidentally hitting it when trying to use M-?
(global-unset-key (kbd "M-/"))
(global-set-key (kbd "C-x g l") 'generate-github-link)
(global-set-key (kbd "C-x g l") 'generate-vc-link)
(provide 'base-global-keys)