sshaw / git-link

Emacs package to get the GitHub/Bitbucket/GitLab/... URL for a buffer location
394 stars 73 forks source link

Allow overriding git-link-use-commit when calling git-link #107

Closed nbarrientos closed 1 year ago

nbarrientos commented 1 year ago

Hi,

I personally tend to prefer setting git-link-use-commit to t globally, but in some cases, when calling git-link, I'd love to be able to temporarily change the value of git-link-use-commit to nil so the generated link points to the checked out branch instead of to the commit hash. I have a function like this in my config:

(defun my/git-link-branch ()
    "Create a URL representing the current buffer's location always
using the branch name."
    (interactive)
    (let ((git-link-use-commit nil))
      (call-interactively #'git-link)))

However it'd be cooler and more convenient if it was possible to "request" this behaviour when calling git-link.

This patch changes a little bit the semantics of the prefix argument, using a single prefix argument to select the remote (trying to make this interface change not hugely painful for users) and adding a double prefix argument to flip the current value of git-link-use-commit (only in the context of the current call to git-link, of course).

With this change applied, instead of having to maintain my own function like above, I'd only have to call:

C-u C-u M-x git-link RET

To generate a link to the file pointing to the current branch 😇

It'd be totally acceptable also to make this new feature cumulative with double prefix argument meaning then "select remote" and "invert git-link-use-commit".

Thanks for considering the patch.

sshaw commented 1 year ago

Yes in v1 git-link-use-commit will default to t. I also think C-u should toggle in v1 and C-u C-u should prompt for remote. In the meantime this will due. Thanks!

nbarrientos commented 1 year ago

Thanks for merging! Perfectly fine if the C-u semantics change in the future :smile:

liuyinz commented 1 year ago

Nice. but how to change both at the same time?

sshaw commented 1 year ago

Nice. but how to change both at the same time?

@liuyinz I don't know, suggestions?