forge
forge copied to clipboard
Browse file on remote
Optionally with selected region highlighted.
vermiculus/magithub#400
This will probably involve a new slot (or three) in forge-repository
:
- base URL of the file at a commit / on a branch
- above + anchor line
- above + start & end anchor lines
Browse file on remote
Yes, though I don't think that's urgent. I prefer viewing files in Emacs :-)
While I would probably not "browse" files much, I would still like to be able to quickly get the corresponding url so that I can paste them somewhere. Luckily you have added support for that recently ;-)
This will probably involve a new slot (or three) in
forge-repository
But those will just be class-allocated *-format
slots right? So not
a big deal.
Oh, and feel free to add issues such as this one, but please add the enhancement
label right away.
Also if you do intend on something yourself, then assign it to yourself. Hm, you probably are not allowed to do that yet. Time to give you some permissions.
Hm, you probably are not allowed to do that yet. Time to give you some permissions.
I would like that :-) I'm normally very diligent about labeling issues I create (at least in my repositories).
Any status on this one? Would be a really great feature!
There is a package with the same name which does the same thing https://github.com/rmuslimov/browse-at-remote.
There is a package with the same name which does the same thing https://github.com/rmuslimov/browse-at-remote.
Yeah I know. There are multiple, I am using git-link myself: https://github.com/sshaw/git-link
It would just be nice to have it in forge/magit instead :)
I created a snippet for this. I took inspiration for how forge-browse-commit
was implemented. Here's what I came up with:
(defun forge-browse-buffer-file ()
(interactive
(browse-url
(let
((rev (magit-get-current-branch))
(repo (forge-get-repository 'stub))
(file (file-relative-name buffer-file-name (projectile-project-root))))
(forge--format repo "https://%h/%o/%n/blob/%r/%f"
`((?r . ,rev) (?f . ,file)))))))
It requires projectile
for figuring out the project-relative path of currently visited file.
@fredefox's implementation is cool but projectile-project-root
is a little janky for me. It would be nice if magit just kept a variable referencing the relative path (from the base git directory) to the current buffer. I would think it wouldn't be hard, but my elisp-fu kinda sucks.
It would be nice if magit just kept a variable referencing the relative path (from the base git directory) to the current buffer.
(magit-file-relative-name buffer-file-name)
This feature would be really useful if you would like to send over a reference to a file or a highlighted couple of lines to somebody over chat or email.
This feature would be really useful if you would like to send over a reference to a file or a highlighted couple of lines to somebody over chat or email.
I suppose you could combine the snippet @tarsius shared with the snippet I wrote replacing browse-url
with kill-new
.
This feature would be really useful if you would like to send over a reference to a file or a highlighted couple of lines to somebody over chat or email.
I suppose you could combine the snippet @tarsius shared with the snippet I wrote replacing
browse-url
withkill-new
.
(defun forge-browse-buffer-file ()
(interactive)
(kill-new
(let
((rev (magit-get-current-branch))
(repo (forge-get-repository 'stub))
(file (magit-file-relative-name buffer-file-name)))
(forge--format repo "https://%h/%o/%n/blob/%r/%f"
`((?r . ,rev) (?f . ,file))))))
Thanks @bezirg I could understand and combine the two solutions. Actually I am working on a PR to add this functionality with line handling as well.
The solution is working so far but I am struggling with this issue.
I've created at PR #317
This version extends @fredefox 's to use the revision hash, rather than the branch name (so that the link is permanent), and adds highlighting from the region if applicable. (Only tested on GitHub so far)
(defun btv-forge-browse-buffer-file ()
(interactive)
(browse-url
(let
((rev (magit-rev-abbrev "HEAD"))
(repo (forge-get-repository 'stub))
(file (magit-file-relative-name buffer-file-name))
(highlight
(if
(use-region-p)
(let ((l1 (line-number-at-pos (region-beginning)))
(l2 (line-number-at-pos (- (region-end) 1))))
(format "#L%d-L%d" l1 l2))
""
)))
(forge--format repo "https://%h/%o/%n/blob/%r/%f%L"
`((?r . ,rev) (?f . ,file) (?L . ,highlight))))))
That's a very nice addition. It's nice to see people share their creativity. I would probably replace magit-rev-abbrev
with magit-rev-parse
. Also I would suggest defining it as a helper forge--buffer-file
so you can do e.g.:
(defun forge-browse-buffer-file ()
(interactive)
(browse-url (forge--buffer-file)))
(defun forge-buffer-file-as-kill ()
(interactive)
(kill-new (forge--buffer-file)))