From 171bccba73acf8eaed772de8bcece1577b03b05d Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Fri, 17 Jul 2020 17:04:39 -0700 Subject: emacs: add git-link / support for sourcegraph We're moving from go/cs (twitter's own code search) to sourcegraph. I'm adding git-link and the configuration to go from emacs to our sourcegraph instance. Doing `git-link` in a file will take me to the file in sg, and doing `git-link-commit` on a commit in magit will take me to the commit in sg. --- emacs.d/custom/fcuny-git.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'emacs.d/custom') diff --git a/emacs.d/custom/fcuny-git.el b/emacs.d/custom/fcuny-git.el index 48409a7..e3b8c45 100644 --- a/emacs.d/custom/fcuny-git.el +++ b/emacs.d/custom/fcuny-git.el @@ -28,6 +28,37 @@ (setq-local fill-column 72) (setq-local comment-auto-fill-only-comments nil))) +;; from https://sideshowcoder.com/2020/07/02/opening-sourcegraph-from-emacs/ +;; in a repo, add the following in .git/config: +;; +;; [git-link] +;; remote = mysourcegraph.sourcegraph +;; [remote "mysourcegraph.sourcegraph"] +;; url = https://sourcegraph.twitter.biz/gitpuppet.twitter.biz/puppet-twitter +;; +(use-package git-link + :ensure t + :config + (defun git-link-sourcegraph (hostname dirname filename _branch commit start end) + (let ((line-or-range (if end (format "%s-%s" start end) start))) + (format "https://%s/%s@%s/-/blob/%s#L%s" + hostname + dirname + commit + filename + line-or-range))) + + (defun git-link-commit-sourcegraph (hostname dirname commit) + (format "https://%s/%s/-/commit/%s" + hostname + dirname + commit)) + + (add-to-list 'git-link-remote-alist '("sourcegraph" git-link-sourcegraph)) + (add-to-list 'git-link-commit-remote-alist '("sourcegraph" git-link-commit-sourcegraph)) + + (setq git-link-open-in-browser 't)) + ;; https://magit.vc/manual/magit/Per_002dRepository-Configuration.html ;; we don't want to refresh buffers in source. This should help with ;; performances. -- cgit 1.4.1