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

Fix issue in keyword indentation with compound keywords #159

Closed

Conversation

ajhalme
Copy link
Contributor

@ajhalme ajhalme commented Aug 21, 2021

While playing around with Julia macros, I noticed that abstract type definitions inside a begin-end block were breaking the indentation in my Emacs.

I've never written anything in Emacs Lisp before, but the broken indentation was annoying me enough that I figured out how to fix it.

On closer inspection, I determined that the issue is with julia-last-open-block-pos and julia-at-keyword. The block position function determines the nesting level by scanning code preceding point one s-expressions at a time, keeping count of matched block starting and ending keywords. The julia-at-keyword function tries to match on keywords listed in julia-block-start-keywords, but unfortunately the matching doesn't quite work with compound keywords made up of more than one word.

Because julia-at-keyword uses (current-word), and because abstract and type are parsed as separate words, the matching misses the compound keyword abstract type (and primitive type and mutable struct). This results in the begin/end counting algorithm missing the compound keyword block beginnings, breaking the indentation.

This PR fixes this issue by introducing a new matching function specifically for compound keywords, julia-at-compound-keyword. This function looks at the current word and the one preceding it, and determines whether point is on the second word of a compound keyword. To make use of this function, I propose splitting the keyword list in two parts, with the compound words in their own list. The new function is applied as an additional clause in the block begin/end counting function.

I've included two tests that demonstrate the desired behaviour.

The performance cost from running the extra function should be negligible, though it is called for every s-expression step inside the matching algorithm.

Copy link
Collaborator

@tpapp tpapp left a comment

Choose a reason for hiding this comment

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

LGTM.

@tpapp
Copy link
Collaborator

tpapp commented Aug 22, 2021

@giordano @non-Jedi @FelipeLema If you have time a review would be appreciated.

Currently CI is not running, I ran the tests locally and the two font-lock failures seem unrelated.

@tpapp
Copy link
Collaborator

tpapp commented Aug 22, 2021

CI failure was local to a quirk my setup, sorry for the noise. Tests actually run clean.

@tpapp
Copy link
Collaborator

tpapp commented Aug 22, 2021

Closing and reopening to trigger CI.

@tpapp tpapp closed this Aug 22, 2021
@tpapp tpapp reopened this Aug 22, 2021
@tpapp
Copy link
Collaborator

tpapp commented Aug 22, 2021

Incidentally, even if you have

never written anything in Emacs Lisp before

you write nice and clean code, so if you would be willing to review PRs, just comment in #97.

@ajhalme ajhalme closed this Oct 28, 2021
@ajhalme ajhalme deleted the compound-keyword-match branch October 28, 2021 22:15
@tpapp
Copy link
Collaborator

tpapp commented Oct 29, 2021

@ajhalme: why did you close this?

@FelipeLema
Copy link
Contributor

FelipeLema commented Oct 31, 2021

ohmydays I was looking forward to this... do you need any help to complete this?

      ∧_∧ 
 /\(`・ω・)/\ 
( ● ⊂   ⊃● ) 
 \//   < \/ 
 ∧_∧/⌒\)∧_∧ 
( ・ω・∩ ∩・ω・ ) 
⊂   ノ ヽ   つ 
`/  /   |  < 
(_ノヽ)   (_ノ\_)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants