domingo, 14 de octubre de 2012

github -> emacs : org-protocol-github-lines

Hello emacsers,

Today I'd like to present a hack I've assembled after being tired of going from github page to emacs looking for a given file/line repeteadly.

Say you collaborate in a project that's hosted in github, and you issue a pull request. If the team is minimally careful, someone will look at your code, and comment on it, pointing conventions you didn't follow, or pointing to buggy code you didn't notice you were introducing. At work, we are continuously doing comments in others pull requests as its part of our workflow.

So, wouldn't it be nice to have a custom button that opens your favourite editor in the correct file and line you're just staring at, but in your browser? Ok, that's what this hack is for.  The puzzle has 3 parts:


 When you check the pull request someone commented, you normally see something like the following.

Then you normally look at the file name, the line and the comment, and try to remember the three pieces of info, go to your editor, fetch the file, line and do the appropiate modifications.

Well, with org-protocol-github-lines  (yeah, the name sucks), you'll be presented with this: 
And the new link will point to "org-protocol://github-comment://kidd/org-protocol-github-lines/org-protocol-github-lines.el/28" .  This is done via a simple chromium userscript. (Alert, I suck at js, it's a complete hack)

Operative System

The second part of the puzzle is teaching your OS that org-protocol:// URIs should be opened with emacsclient. After trying some methods I found on internet and being unable to make any of those working, I went for the naive approach of copying xdg-open to my ~/bin directory, and patch it accordingly to open org-protocol:// URIs with emacsclient.  The complete xdg-open is in the git repo.


And the last thing is the elisp part. when emacs receives an uri starting with org-protocol, you can use some org-protocol helpers to decode the parameters and such. The relevant info is in the org-mode page.

There's an alist called org-protocol-projects that you should modify to map "user/repo" -> "path/to/the/root/of/the/repo/(local)" .

And here's a video that shows the whole thing in action.

Demo of org-protocol-github-lines emacs plugin from Raimon Grau on Vimeo.

If you find more places where it makes sense to add those links, or have anything to coment, please use the comments here, or github issues, or find me in #emacs and #emacs-es as rgrau or rgc.

Clone it from

No hay comentarios: