File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3434 (line-number-at-pos ))))))
3535
3636 (defun meain/github-url (&optional use-master )
37- " Link to the currently selected code in GitHub. Pass `USE-MASTER' to use master branch."
37+ " Link to the currently selected code in GitHub. Pass `USE-MASTER' to use master branch.
38+ If region is active, link covers the region."
3839 (interactive " P" )
3940 (save-restriction
4041 (widen )
4950 1 )
5051 (user-error " Current latest commit not available upstream" )))
5152
52-
5353 (let* ((git-url (replace-regexp-in-string
5454 " ^git@github.com:\\ (.*\\ )\\ .git$" " https://github.com/\\ 1"
5555 (meain/cmd-head " git config --get remote.origin.url" )))
6060 (meain/cmd-head " git log --format='%H' -n 1" )))
6161 (file-path (file-relative-name (or buffer-file-name default-directory)
6262 (car (project-roots (project-current )))))
63- (line-frag (unless (equal major-mode 'dired-mode )
64- (format " #L%s " (line-number-at-pos ))))
63+ (line-frag
64+ (unless (equal major-mode 'dired-mode )
65+ (if (use-region-p )
66+ (let* ((start (line-number-at-pos (region-beginning )))
67+ (end (1- (line-number-at-pos (region-end )))))
68+ (if (= start end)
69+ (format " #L%s " start)
70+ (format " #L%s -L%s " start end)))
71+ (format " #L%s " (line-number-at-pos )))))
6572 (web-url (concat git-url " /blob/" git-ref " /" file-path (or line-frag " " ))))
6673 (message " %s copied to clipboard." web-url)
6774 (meain/copy-to-clipboard web-url))))
You can’t perform that action at this time.
0 commit comments