Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation and completion improvements #15

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ed0099e
Fix indentation of directives not preceeded by empty line
alexsmith1612 May 10, 2021
7017a94
Indent posting metadata lines an additional level
alexsmith1612 May 10, 2021
fdfa9c2
Align numbers in balance and price directives in addition to postings
alexsmith1612 May 10, 2021
b4f14e4
Align open directive currencies to number alignment + 1
alexsmith1612 May 10, 2021
80a3e8b
Add customizable variable for minimum number alignment separation
alexsmith1612 May 10, 2021
01c5a74
Add customizable variable to enable number alignment with tab-dwim
alexsmith1612 May 10, 2021
013e57a
Add more generic beancount-indent-directive function
alexsmith1612 May 10, 2021
90c54d4
Always call indent-region on TAB if the region is active
alexsmith1612 May 10, 2021
aff0255
Update indentation tests
alexsmith1612 May 10, 2021
c232302
Fix link-at-point-003 unit test
alexsmith1612 May 10, 2021
ee36fcc
Explicitly require imenu in beancount.el
alexsmith1612 May 10, 2021
2489f46
Require org for org-level-x faces
alexsmith1612 May 10, 2021
6df3934
Don't insert space after completions
alexsmith1612 May 10, 2021
7d07c48
Limit non-timestamped directives completions
alexsmith1612 May 10, 2021
2518f70
Allow completion of tags and links not on their own line
alexsmith1612 May 10, 2021
c9725e3
Move posting completions after tag and link completions
alexsmith1612 May 10, 2021
c880cf6
Don't attempt completion inside strings except for options
alexsmith1612 May 10, 2021
4102a12
Don't collect matches inside strings
alexsmith1612 May 10, 2021
a721f15
Add more completion tests
alexsmith1612 May 10, 2021
cc8ea35
Update copyright and author information
alexsmith1612 May 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions beancount.el
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,14 @@ With an argument move to the next non cleared transaction."
;; that begin with something that looks like a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this improves. If you don't want completion while editing a string, don't invoke the completion function. What am I missing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with "don't invoke the completion function" is that we use a tab-dwim function which either toggles outline sections, attempts to complete, or indents based on context.

My goal is to be able to hit TAB to indent while editing in strings regardless of their content (in particular if the string happens to have # or ^ in it), and IMO there's no case where a user would want beancount-mode to try to complete anything in a string (with the exception of options), since strings are more-or-less opaque to beancount.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where this is coming from now: you enabled completion of tags and links also now when on a dedicated line. Very welcome fix BTW, thank you! This enables completion of the sames in string literals too.

I admit I see advantages in permitting completion of tag and links in strings too. It is common to mention links or tags in strings for many different reasons, and account names too. Having auto completion for them in strings could be seen as an handy feature. If you don't want completion just put hit space or close the double quotes before pressing tab. I am almost tempted to open up account completion to more contexts rather to restrict existing completion contexts further.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about not completing in strings to fight you too hard here, but I don't personally see a need for any kind of completion in strings in Beancount. I could see it being more useful in comments than in strings.

I do, however, feel strongly that beancount-collect should not grab matches that occur in strings (at least not in the generic case, perhaps there may be some exceptions in the future). In fact, I think that it should probably also ignore matches that occur in comments.

;; non-timestamped directive--don't match the beginning of
;; complete transactions)
((beancount-looking-at "\\($\\|[a-z]+\\)" 0 pos)
((and (not (beancount-inside-string-p))
(beancount-looking-at "\\($\\|[a-z]+\\)" 0 pos))
(list (match-beginning 0) (match-end 0) beancount-directive-names))

;; poptag
((beancount-looking-at
(concat "poptag\\s-+\\(\\(?:#[" beancount-tag-chars "]*\\)\\)") 1 pos)
((and (not (beancount-inside-string-p))
(beancount-looking-at
(concat "poptag\\s-+\\(\\(?:#[" beancount-tag-chars "]*\\)\\)") 1 pos))
(list (match-beginning 1) (match-end 1)
(beancount-collect-pushed-tags (point-min) (point))))

Expand All @@ -506,15 +508,17 @@ With an argument move to the next non cleared transaction."
(mapcar (lambda (s) (concat "\"" s "\"")) beancount-option-names)))

;; timestamped directive
((beancount-looking-at
(concat beancount-date-regexp "\\s-+\\([[:alpha:]]*\\)") 1 pos)
((and (not (beancount-inside-string-p))
(beancount-looking-at
(concat beancount-date-regexp "\\s-+\\([[:alpha:]]*\\)") 1 pos))
(list (match-beginning 1) (match-end 1) beancount-timestamped-directive-names))

;; timestamped directives followed by account
((beancount-looking-at
(concat "^" beancount-date-regexp
"\\s-+" (regexp-opt beancount-account-directive-names)
"\\s-+\\([" beancount-account-chars "]*\\)") 1 pos)
((and (not (beancount-inside-string-p))
(beancount-looking-at
(concat "^" beancount-date-regexp
"\\s-+" (regexp-opt beancount-account-directive-names)
"\\s-+\\([" beancount-account-chars "]*\\)") 1 pos))
(setq beancount-accounts nil)
(list (match-beginning 1) (match-end 1) #'beancount-account-completion-table))

Expand Down Expand Up @@ -547,7 +551,8 @@ With an argument move to the next non cleared transaction."
(list (match-beginning 0) (match-end 0) completion-table)))

;; posting
((and (beancount-looking-at
((and (not (beancount-inside-string-p))
(beancount-looking-at
(concat "[ \t]+\\([" beancount-account-chars "]*\\)") 1 pos)
;; Do not force the account name to start with a
;; capital, so that it is possible to use substring
Expand Down