Fix issue in keyword indentation with compound keywords #159
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andjulia-at-keyword
. The block position function determines the nesting level by scanning code precedingpoint
one s-expressions at a time, keeping count of matched block starting and ending keywords. Thejulia-at-keyword
function tries to match on keywords listed injulia-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 becauseabstract
andtype
are parsed as separate words, the matching misses the compound keywordabstract type
(andprimitive type
andmutable 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 whetherpoint
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.