ledger-mode icon indicating copy to clipboard operation
ledger-mode copied to clipboard

New 'ledger-indent-region' function

Open jdek opened this issue 1 year ago • 7 comments

  • ledger-mode.el (ledger-mode): Set indent-region-function.
  • ledger-post.el (ledger-indent-region): New function that indents the region by calling ledger-indent-line for each line.

Closes #197

jdek avatar Feb 24 '24 07:02 jdek

@purcell hi, possible to get a quick review on this? Would be quite nice to have this fixed in master.

jdek avatar Mar 08 '24 22:03 jdek

Probably @enderw88 would be better placed to comment on whether this is a desirable fix — I'm not sure about the history of indentation in ledger-mode

purcell avatar Mar 11 '24 10:03 purcell

Maybe @bcc32 could take a look?

jdek avatar Mar 31 '24 21:03 jdek

As far as I can tell, the default indent-region-functionindent-region-line-by-line – calls indent-line-function on each line. So what's the difference here, assuming that indent-line-function is set to ledger-indent-line?

purcell avatar Apr 01 '24 09:04 purcell

ie. what you've implemented feels the same as simply not setting indent-region-function in the first place.

purcell avatar Apr 01 '24 09:04 purcell

Good catch, I wasn't aware that indent-region worked like that by default. Just unsetting indent-region-function seems to work for me.

Test input:

    2017-06-26 Commonplace Coffee
         Expenses:Restaurants:Coffee                 3.00   ; Grande
    Assets:Cash:Wallet                         -3.00

2017-06-26 Commonplace Coffee
       Expenses:Restaurants:Coffee                 3.00   ; Grande
    Assets:Cash:Wallet                         -3.00

          2017-06-26 Commonplace Coffee
      Assets:Cash:Wallet
        Expenses:Restaurants:Coffee                 3.00

Current master:

    2017-06-26 Commonplace Coffee
   Expenses:Restaurants:Coffee                 3.00   ; Grande
   Assets:Cash:Wallet                         -3.00

2017-06-26 Commonplace Coffee
   Expenses:Restaurants:Coffee                 3.00   ; Grande
   Assets:Cash:Wallet                         -3.00

   2017-06-26 Commonplace Coffee
   Assets:Cash:Wallet
   Expenses:Restaurants:Coffee                 3.00

With (setq-local indent-region-function nil):

2017-06-26 Commonplace Coffee
   Expenses:Restaurants:Coffee                 3.00   ; Grande
   Assets:Cash:Wallet                         -3.00

2017-06-26 Commonplace Coffee
   Expenses:Restaurants:Coffee                 3.00   ; Grande
   Assets:Cash:Wallet                         -3.00

2017-06-26 Commonplace Coffee
   Assets:Cash:Wallet
   Expenses:Restaurants:Coffee                 3.00

ledger-post-align-postings is broken somehow I guess?

jdek avatar Apr 01 '24 11:04 jdek

ledger-post-align-postings is broken somehow I guess?

Hmmm... do we have any tests for that, perhaps? You could consider pushing a failing test to show what you'd expect.

purcell avatar Apr 01 '24 17:04 purcell