New feature request: web link to edit file

138 views
Skip to first unread message

redst...@gmail.com

unread,
Jan 25, 2015, 12:09:51 AM1/25/15
to bean...@googlegroups.com
When clicking on a date on the web display, it displays the parsed raw text like so:
Location: accounts/full.beancount:29564
...


This would be a great place to add a link to the source file and line, so one could click on it and have that particular line open up in their favorite editor. I'm not sure if this will work without some client-side configuration or hack, but the idea occurred to me, so I thought I'd write it here to save it.

Nathan Grigg

unread,
Jan 25, 2015, 12:37:31 AM1/25/15
to redst...@gmail.com, bean...@googlegroups.com
Seems like a protocol handler would be the best way to handle it, for example http://www.tkalin.com/blog_posts/using-console-vim-as-vim-protocol-handler-in-ubuntu/.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/36491544-a70d-4671-a79d-b3c711566e36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Blais

unread,
Jan 25, 2015, 12:46:26 AM1/25/15
to redst...@gmail.com, bean...@googlegroups.com
Clicking on the date already sends you to a page with the context (same as bean-doctor context), like this:



I used to have it send you to the source code as served from the web interface, more similar to what you suggest, e.g.:


I'm not particularly swayed either way, they both seem like good options.
Regarding directing an external program to do this (e.g. an editor), I've done that before but it requires some non-trivial setup and there are many different ways to do this, I'd prefer it to be something you have to turn on with a command-line option, and perhaps configure the method from that option.



redst...@gmail.com

unread,
Jan 25, 2015, 3:19:18 PM1/25/15
to bean...@googlegroups.com, redst...@gmail.com
Yes, seems like the best way to handle it. Thanks for the pointer!

redst...@gmail.com

unread,
Jan 25, 2015, 3:24:11 PM1/25/15
to bean...@googlegroups.com, redst...@gmail.com
I used to have it send you to the source code as served from the web interface, more similar to what you suggest, e.g.:


Good to know.
 
I'm not particularly swayed either way, they both seem like good options.
Regarding directing an external program to do this (e.g. an editor), I've done that before but it requires some non-trivial setup and there are many different ways to do this, I'd prefer it to be something you have to turn on with a command-line option, and perhaps configure the method from that option.

 Yes, and I'd be happy to look into how to have this configurable etc. some time soon, especially because it helps me fix things as I try to move all my journal over to Beancount. However, this doesn't help me currently because this will simple take me to the concatenated file, and not the actual source file. So I'll hold off in it until you're able to get around to supporting includes.

redst...@gmail.com

unread,
May 12, 2015, 8:01:32 PM5/12/15
to bean...@googlegroups.com, redst...@gmail.com
Hi Martin,
So I have this working: the transaction's info page contains a link which upon clicking opens up my editor directly to the source line. This has hugely sped up my data entry and fixing. This is the one feature I've missed ever since I moved to command-line accounting: the ability to make fixes "on the spot."

It's a minor change to the source code since as you pointed out, you had most of the code in there already. Client side configuration and a script is required, and since I use Windows quite a bit, I registered a new 'beancount:' URI handler on my Windows box as shown in [1], and this works flawlessly from any browser. Nathan Grigg pointed out a Linux solution earlier in this thread. Don't know about other platforms.

Would you be interested in merging in my patch for this, and associated documentation? If so, I'd be happy to get it into place. It would be nice to have the handler's string (I use 'beancount:') configurable, but I haven't yet figured out how to pass in the arguments from bean-web into render_entry_context(), but this isn't strictly needed.

Martin Blais

unread,
May 12, 2015, 11:23:36 PM5/12/15
to redst...@gmail.com, bean...@googlegroups.com
On Tue, May 12, 2015 at 8:01 PM, <redst...@gmail.com> wrote:
Hi Martin,
So I have this working: the transaction's info page contains a link which upon clicking opens up my editor directly to the source line. This has hugely sped up my data entry and fixing. This is the one feature I've missed ever since I moved to command-line accounting: the ability to make fixes "on the spot."

It's a minor change to the source code since as you pointed out, you had most of the code in there already. Client side configuration and a script is required, and since I use Windows quite a bit, I registered a new 'beancount:' URI handler on my Windows box as shown in [1], and this works flawlessly from any browser. Nathan Grigg pointed out a Linux solution earlier in this thread. Don't know about other platforms.

Great stuff. I love it when people just go ahead and build stuff that they need. This is great :-)


Would you be interested in merging in my patch for this, and associated documentation? If so, I'd be happy to get it into place. It would be nice to have the handler's string (I use 'beancount:') configurable, but I haven't yet figured out how to pass in the arguments from bean-web into render_entry_context(), but this isn't strictly needed.

Yes, only pending the copyright situation (I need to figure this out). The best for now would be if you want to clone my repo and share your changes with the list, send a pointer to it. I can have a look at what you need and see if I can integrate something that would work on all platforms.

Let me know.
Thanks!






--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.

redst...@gmail.com

unread,
Sep 6, 2015, 3:30:54 PM9/6/15
to Beancount, redst...@gmail.com
On Wednesday, May 13, 2015 at 8:53:36 AM UTC+5:30, Martin Blais wrote:
On Tue, May 12, 2015 at 8:01 PM, <redst...@gmail.com> wrote:
Hi Martin,
So I have this working: the transaction's info page contains a link which upon clicking opens up my editor directly to the source line. This has hugely sped up my data entry and fixing. This is the one feature I've missed ever since I moved to command-line accounting: the ability to make fixes "on the spot."

It's a minor change to the source code since as you pointed out, you had most of the code in there already. Client side configuration and a script is required, and since I use Windows quite a bit, I registered a new 'beancount:' URI handler on my Windows box as shown in [1], and this works flawlessly from any browser. Nathan Grigg pointed out a Linux solution earlier in this thread. Don't know about other platforms.

Great stuff. I love it when people just go ahead and build stuff that they need. This is great :-)


Would you be interested in merging in my patch for this, and associated documentation? If so, I'd be happy to get it into place. It would be nice to have the handler's string (I use 'beancount:') configurable, but I haven't yet figured out how to pass in the arguments from bean-web into render_entry_context(), but this isn't strictly needed.

Yes, only pending the copyright situation (I need to figure this out). The best for now would be if you want to clone my repo and share your changes with the list, send a pointer to it. I can have a look at what you need and see if I can integrate something that would work on all platforms.

The patch to existing code is simple:

------------
diff -r 90b86338538b src/python/beancount/reports/context.py
--- a/src/python/beancount/reports/context.py
+++ b/src/python/beancount/reports/context.py
@@ -34,7 +34,14 @@
         raise SystemExit("No entry could be found before {}:{}".format(filename, lineno))
     meta = closest_entry.meta
     print("Hash:{}".format(compare.hash_entry(closest_entry)), file=oss)
-    print("Location: {}:{}".format(meta.filename, meta.lineno), file=oss)
+
+    filelink_protocol_str = "beancount://"
+
+    filelink_display = "{}:{}".format(meta.filename, meta.lineno)
+    filelink_link    = "beancount://{}:lineno:{}".format(meta.filename, str(lineno))
+
+    print('Location: <a href="{}">{}</a>'.format(filelink_link, filelink_display), file=oss)
+
 
     # Get the entry's accounts and accumulate the balances of these accounts up
     # to the entry.
------------

This simply linkifies the filename shown, in the format: "beancount:///your/file/path/filename.beancount:lineno:97".

The OS would need a handler for the beancount:// protocol. I'd share mine, but it's a) only for cygwin-on-Windows, and b) has personal file paths, etc. I'll clean it up and share it some time, once you figure out the copyright situation.

This has been invaluable for me in being able to quickly fix things after updating transactions. I wasn't looking for a web interface, but because beancount came with bean-web, I took a look at it, and have been using it extensively ever since. bean-web has been simple and highly useful already!

 

Let me know.
Thanks!

Martin Blais

unread,
Sep 6, 2015, 4:24:34 PM9/6/15
to Beancount
Another idea would be to avoid the OS-wide registration of a URL handler and instead put a url to the locally running web server that would run a "open in editor at line X" shell command.


--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.

redst...@gmail.com

unread,
Dec 6, 2015, 11:31:58 PM12/6/15
to Beancount, redst...@gmail.com

Martin Blais

unread,
Dec 7, 2015, 12:38:04 AM12/7/15
to Beancount
Thank you redstreet0!


--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.

Dominik Aumayr

unread,
Dec 7, 2015, 1:58:17 AM12/7/15
to Beancount, redst...@gmail.com
Sounds like a great feature! 

One suggestion: The code generates URLs like "beancount:///Volumes/Ledger/example.ledger:lineno:123". Wouldn't it be cleaner to append the lineno as a GET-parameter like "beancount:///Volumes/Ledger/example.ledger?line=123" ?

Another variant would be to specify it like so: "beancount://open?url=file:///Volumes/Ledger/example.ledger&line=123&column=45" in order to preserve the "file://" and specifying what should happen ("open") when clicking the link. (The second variant would also make it easier to create applications, for example for the Mac, that handle the "beancount://"-scheme.)

redst...@gmail.com

unread,
Dec 7, 2015, 2:48:17 AM12/7/15
to Beancount, redst...@gmail.com
On Sunday, December 6, 2015 at 10:58:17 PM UTC-8, Dominik Aumayr wrote:
Sounds like a great feature! 

One suggestion: The code generates URLs like "beancount:///Volumes/Ledger/example.ledger:lineno:123". Wouldn't it be cleaner to append the lineno as a GET-parameter like "beancount:///Volumes/Ledger/example.ledger?line=123" ?

Another variant would be to specify it like so: "beancount://open?url=file:///Volumes/Ledger/example.ledger&line=123&column=45" in order to preserve the "file://" and specifying what should happen ("open") when clicking the link. (The second variant would also make it easier to create applications, for example for the Mac, that handle the "beancount://"-scheme.)

Thanks, those sound like good ideas. The second one sounds good, but my web-related knowledge is minimal, so I'll leave it up to your expertise to decide which is better. I'll be happy to make the change or let you make it if Martin decides to merge this in. Until then, the commit log shows how to use this on Windows. I use this feature a *lot* and have done so almost ever since I started using beancount.

Dominik Aumayr

unread,
Dec 7, 2015, 7:54:20 AM12/7/15
to bean...@googlegroups.com, redst...@gmail.com
If I were to choose I would go with the following variant:

beancount://open?url=file:///Volumes/Ledger/example.ledger&line=123&column=45

I have put together a set of tools to make this work on a Mac (https://github.com/aumayr/beancount-web/commit/f1e954df9c4a2ad8c491a3b08f6e05b49f2f74fd). It's an AppleScript-App for registering the URL scheme and intercept it, then forward it to a Python script which in turn reads the editor-command from a conf-file and starts the specified editor. See https://github.com/aumayr/beancount-web/tree/url-scheme#beancount-urlscheme for how it could be used.

We could join forces and combine your Windows-version (the BAT-script you mentioned) and the Mac-version to make it work on both platforms before making a new PR!?
> --
> You received this message because you are subscribed to the Google Groups "Beancount" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
> To post to this group, send email to bean...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/7d112bb1-1e49-4a42-a1c4-89cb6104ceca%40googlegroups.com.

redst...@gmail.com

unread,
Dec 7, 2015, 3:07:52 PM12/7/15
to Beancount, redst...@gmail.com

On Monday, December 7, 2015 at 4:54:20 AM UTC-8, Dominik Aumayr wrote:
If I were to choose I would go with the following variant:

    beancount://open?url=file:///Volumes/Ledger/example.ledger&line=123&column=45

I have put together a set of tools to make this work on a Mac (https://github.com/aumayr/beancount-web/commit/f1e954df9c4a2ad8c491a3b08f6e05b49f2f74fd). It's an AppleScript-App for registering the URL scheme and intercept it, then forward it to a Python script which in turn reads the editor-command from a conf-file and starts the specified editor. See https://github.com/aumayr/beancount-web/tree/url-scheme#beancount-urlscheme for how it could be used.

We could join forces and combine your Windows-version (the BAT-script you mentioned) and the Mac-version to make it work on both platforms before making a new PR!?

Sounds good - in fact, this was exactly what I was hoping for! I'll update my script to follow your scheme. This might take a me a few days since I'm in the middle of data updates at my end, but I'll post when I have it ready, and we can combine it into a new PR.

Martin Blais

unread,
Dec 11, 2015, 8:11:40 PM12/11/15
to Beancount, redst...@gmail.com

redst...@gmail.com

unread,
Dec 12, 2015, 8:35:17 PM12/12/15
to Beancount, redst...@gmail.com
Great, thanks! Would you consider moving the "Open" link to be left aligned? I ask because with wide-screen monitors being the norm these days, clicking on the right end of the screen generally involves way more effort. I can do it locally, but I'm hoping this makes sense for everyone

Martin Blais

unread,
Dec 12, 2015, 11:24:30 PM12/12/15
to Beancount

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.

redst...@gmail.com

unread,
Dec 13, 2015, 9:39:04 PM12/13/15
to Beancount
Thank you!
Reply all
Reply to author
Forward
0 new messages