-
Notifications
You must be signed in to change notification settings - Fork 78
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 multiline variable declarations. #56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2120,6 +2120,26 @@ moved on success." | |
(when location | ||
(goto-char location)))) | ||
|
||
(defun typescript--multiline-declaration-indentation () | ||
"Returns the proper indentation for lines which are continuations of | ||
multiline var/let/const declarations. If the point is not on such a line, | ||
returns nil." | ||
(save-excursion | ||
(beginning-of-line) | ||
(let ((decl-re "^ *\\(var\\|const\\|let\\)\\_> *") | ||
(is-looking-at-decl-keyword nil)) | ||
(save-match-data | ||
(while (and (looking-back ",[[:space:]\n]+" nil) | ||
(= (forward-line -1) 0) | ||
(not (setq is-looking-at-decl-keyword (looking-at decl-re))))) | ||
(when is-looking-at-decl-keyword | ||
;; Found the var/let/const declaration of which the initial line was a | ||
;; continuation of. The correct indentation is therefore the relative | ||
;; offset of the word following the var keyword. | ||
(let ((bol-pos (point))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. |
||
(re-search-forward decl-re) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
or something of that order. |
||
(- (point) bol-pos))))))) | ||
|
||
(defun typescript--proper-indentation (parse-status) | ||
"Return the proper indentation for the current line." | ||
(save-excursion | ||
|
@@ -2130,6 +2150,7 @@ moved on success." | |
((typescript--ctrl-statement-indentation)) | ||
((eq (char-after) ?#) 0) | ||
((save-excursion (typescript--beginning-of-macro)) 4) | ||
((typescript--multiline-declaration-indentation)) | ||
((nth 1 parse-status) | ||
(let ((same-indent-p (looking-at | ||
"[]})]\\|\\_<case\\_>\\|\\_<default\\_>")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see another regex searching for
var
,const
,let
elsewhere intypescript--font-lock-keywords-3
. Can we perhaps combine the two regexes into a singledefconst
and refer to the new constant, so as to avoid duplication?