Giter Club home page Giter Club logo

Comments (5)

mhansen avatar mhansen commented on June 23, 2024 1

What's wrong with piping through hledger print (and handling inter transaction content
separately) ?

I suppose I'd want to be very careful not to lose data. So I'd want to be very confident that I'm not going to lose data before releasing anything like this.

I just tried hledger print on a file, and it complained about a balance assertion, which I could silence with -I. So that's one problem fixed.

I assumed hledger print wouldn't show comments inside transactions, or comments at the end of a transaction line. But it appears it does?

Let's try a test for a few language features:

$ cat test.hledger
; Comment
alias X = Y
commodity 1000.00 AUD
include /dev/null

; Comment after newline
2021-01-01 Description ; end of line comment
  ; Inside transaction comment
  Expenses:Post  200 AUD = 300 AUD ; End of post comment
  Assets:Bank  ; end of bank comment
  ; End of transaction comment
; Post transaction comment

Let's see how much it preserves:

$ hledger print -f test.hledger -I
2021-01-01 Description  ; end of line comment
    ; Inside transaction comment
    Expenses:Post      200.00 AUD = 300 AUD  ; End of post comment
    Assets:Bank                    ; end of bank comment
    ; End of transaction comment

It's good that some of the comments are preserved! But statements for alias, commodity, include, and inter-transaction comments have all gone missing. And I imagine the include will pull other files in during autoformatting. There's probably a bunch of other more esoteric language features that I don't use (timedot?) that I'd want to be confident in handling correctly before offering an autoformatter. I don't really feel confident in building a parser that will mirror what hledger does precisely (and as hledger changes in future too).

I believe these autoformatters best live alongside the canonical parser: that is, in hledger core, so that the autoformatter parser evolves along with the autoformatter (cf gofmt, rustfmt, clang-format).

from hledger-vscode.

mhansen avatar mhansen commented on June 23, 2024

from hledger-vscode.

simonmichael avatar simonmichael commented on June 23, 2024

from hledger-vscode.

the-solipsist avatar the-solipsist commented on June 23, 2024

What's wrong with piping through hledger print (and handling inter transaction content separately) ?

Nothing at all. It's just that doing so requires a separate script[1]. So it's just a matter of laziness vs. convenience.

At one point, I was using the vim-ledger plugin solely for reformatting of my file, since it made it very easy. Now that I've moved to vscode, I was hoping I could use hledger-vscode for the same purpose.

[1]: Here's a script that does the job for me, at least wrt to the include and default commands I use at the beginning of a file:

#!/bin/bash
sed '/^20[0-9][0-9]/Q' $1 > /tmp/j
tail -n +2 $1 | hledger -f- print -x -I >> /tmp/j
mv $1{,.bak}
mv /tmp/j $1

from hledger-vscode.

the-solipsist avatar the-solipsist commented on June 23, 2024

Ah. I misunderstood what @simonmichael meant. I mistakenly thought his question was aimed at me, rather than at @mhansen.

The things that hledger print (currently) doesn't handle are clearly defined:

  1. Directives (like alias, commodity, include, account, etc.)
  2. Inter-transaction comments

So intra-transaction comments (those attached to transactions and postings) are handled just fine. What aren't handled are inter-transaction comments.

And I imagine the include will pull other files in during autoformatting

Yes, hledger print respects include directives. That's why in my short script, I omit the include and default directives (which are in the top 2 lines of my file) before passing it on to hledger: tail -n +2 $1 | hledger -f- print -x -I.

from hledger-vscode.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.