[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/typescript-mode 444aa36ec2 169/222: Fix the indentation of
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/typescript-mode 444aa36ec2 169/222: Fix the indentation of member expressions and continued expressions. |
Date: |
Sun, 6 Feb 2022 16:59:29 -0500 (EST) |
branch: elpa/typescript-mode
commit 444aa36ec272d0fcb9c5066ce4513d377a78dda7
Author: Louis-Dominique Dubeau <ldd@lddubeau.com>
Commit: Louis-Dominique Dubeau <ldd@lddubeau.com>
Fix the indentation of member expressions and continued expressions.
---
typescript-mode.el | 143 ++++++++++++++++++++++++++++++++---------------------
1 file changed, 88 insertions(+), 55 deletions(-)
diff --git a/typescript-mode.el b/typescript-mode.el
index 3ae8e16ae0..7806053db4 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -2258,6 +2258,23 @@ Searches specifically for any of \"=\", \"}\", and
\"type\"."
(and (progn (backward-char)
(not (looking-at "++\\|--\\|/[/*]")))))))))))
+(cl-defun typescript--compute-member-expression-indent ()
+ "Determine the indent of a member expression.
+
+This function must be called with point located at the dot that
+starts the member expression.
+"
+ ;; Find the line that has the object from which we are getting thismember.
+ ;; And set an indent relative to that.
+ (while (looking-at "\\.")
+ (typescript--backward-syntactic-ws)
+ (while (memq (char-before) '(?\] ?} ?\)))
+ (backward-list)
+ (typescript--backward-syntactic-ws))
+ (if (looking-back typescript--dotted-name-re nil)
+ (back-to-indentation)
+ (typescript--forward-syntactic-ws)))
+ (+ (current-column) typescript-indent-level))
(defun typescript--end-of-do-while-loop-p ()
"Return non-nil if point is on the \"while\" of a do-while statement.
@@ -2424,61 +2441,77 @@ moved on success."
"Return the proper indentation for the current line."
(save-excursion
(back-to-indentation)
- (cond ((nth 4 parse-status)
- (typescript--get-c-offset 'c (nth 8 parse-status)))
- ((nth 8 parse-status) 0) ; inside string
- ((typescript--ctrl-statement-indentation))
- ((eq (char-after) ?#) 0)
- ((nth 1 parse-status)
- (let ((same-indent-p (looking-at "[]})]"))
- (switch-keyword-p (looking-at
"\\_<default\\_>\\|\\_<case\\_>[^:]"))
- (continued-expr-p (typescript--continued-expression-p))
- (list-start (nth 1 parse-status)))
- (goto-char list-start)
- (if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
- (progn
- (skip-syntax-backward " ")
- (cond
- ((or (typescript--backward-to-parameter-list)
- (eq (char-before) ?\)))
- ;; Take the curly brace as marking off the body of a
function.
- ;; In that case, we want the code that follows to see the
indentation
- ;; that was in effect at the beginning of the function
declaration, and thus
- ;; we want to move back over the list of function
parameters.
- (backward-list))
- ((looking-back "," nil)
- ;; If we get here, we have a comma, spaces and an opening
curly brace. (And
- ;; (point) is just after the comma.) We don't want to
move from the current position
- ;; so that object literals in parameter lists are
properly indented.
- nil)
- (t
- ;; In all other cases, we don't want to move from the
curly brace.
- (goto-char list-start)))
- (back-to-indentation)
- (let* ((in-switch-p (unless same-indent-p
- (looking-at "\\_<switch\\_>")))
- (same-indent-p (or same-indent-p
- (and switch-keyword-p
- in-switch-p)))
- (indent
- (cond (same-indent-p
- (current-column))
- (continued-expr-p
- (+ (current-column) (* 2
typescript-indent-level)
- typescript-expr-indent-offset))
- (t
- (+ (current-column)
typescript-indent-level)))))
- (if (and in-switch-p typescript-indent-switch-clauses)
- (+ indent typescript-indent-level)
- indent)))
- (unless same-indent-p
- (forward-char)
- (skip-chars-forward " \t"))
- (current-column))))
-
- ((typescript--continued-expression-p)
- (+ typescript-indent-level typescript-expr-indent-offset))
- (t 0))))
+ (let ((member-expr-p (looking-at "\\.")))
+ (cond ((nth 4 parse-status) ;; Inside a comment.
+ (typescript--get-c-offset 'c (nth 8 parse-status)))
+ ((nth 8 parse-status) 0) ;; Inside a string.
+ ((typescript--ctrl-statement-indentation)) ;; Control statements.
+ ((eq (char-after) ?#) 0) ;; Looking at a pragma.
+ ;; Inside a list of things. Note that in the TS contents, the
curly braces
+ ;; marking code blocks are "list of things".
+ ((nth 1 parse-status)
+ (let ((indent-start (point))
+ (same-indent-p (looking-at "[]})]"))
+ (switch-keyword-p (looking-at
"\\_<default\\_>\\|\\_<case\\_>[^:]"))
+ (continued-expr-p (typescript--continued-expression-p))
+ (list-start (nth 1 parse-status)))
+ (goto-char list-start)
+ (if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
+ (progn
+ (skip-syntax-backward " ")
+ (cond
+ ((or (typescript--backward-to-parameter-list)
+ (eq (char-before) ?\)))
+ ;; Take the curly brace as marking off the body of a
function.
+ ;; In that case, we want the code that follows to see
the indentation
+ ;; that was in effect at the beginning of the function
declaration, and thus
+ ;; we want to move back over the list of function
parameters.
+ (backward-list))
+ ((looking-back "," nil)
+ ;; If we get here, we have a comma, spaces and an
opening curly brace. (And
+ ;; (point) is just after the comma.) We don't want to
move from the current position
+ ;; so that object literals in parameter lists are
properly indented.
+ nil)
+ (t
+ ;; In all other cases, we don't want to move from the
curly brace.
+ (goto-char list-start)))
+ (back-to-indentation)
+ (let* ((in-switch-p (unless same-indent-p
+ (looking-at "\\_<switch\\_>")))
+ (same-indent-p (or same-indent-p
+ (and switch-keyword-p
+ in-switch-p)))
+ (indent
+ (cond (same-indent-p
+ (current-column))
+ (continued-expr-p
+ (if (not member-expr-p)
+ (+ (current-column) (* 2
typescript-indent-level)
+ typescript-expr-indent-offset)
+ (goto-char indent-start)
+
(typescript--compute-member-expression-indent)))
+ (t
+ (+ (current-column)
typescript-indent-level)))))
+ (if (and in-switch-p typescript-indent-switch-clauses)
+ (+ indent typescript-indent-level)
+ indent)))
+ (unless same-indent-p
+ (forward-char)
+ (skip-chars-forward " \t"))
+ (if continued-expr-p
+ (if (not member-expr-p)
+ (progn (back-to-indentation)
+ (+ (current-column) typescript-indent-level
+ typescript-expr-indent-offset))
+ (goto-char indent-start)
+ (typescript--compute-member-expression-indent))
+ (current-column)))))
+
+ ((typescript--continued-expression-p) ;; Inside a continued
expression.
+ (if member-expr-p
+ (typescript--compute-member-expression-indent)
+ (+ typescript-indent-level typescript-expr-indent-offset)))
+ (t 0)))))
(defun typescript-indent-line ()
"Indent the current line as typescript."
- [nongnu] elpa/typescript-mode 7a5c74d88e 109/222: Merge pull request #72 from Wilfred/remove_cpp, (continued)
- [nongnu] elpa/typescript-mode 7a5c74d88e 109/222: Merge pull request #72 from Wilfred/remove_cpp, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode c2d72b7d81 116/222: Fix unwanted indentation after non-keyword "each", ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 0d32c85bfb 110/222: Drop typescript-parent-mode., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 5b6d60a2b2 118/222: Fix indentation after keyword-lookalike methods., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 6a6c63ad5e 126/222: Extract test utilities, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 72ec0f93aa 125/222: Merge pull request #90 from jack-williams/add-never, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 69607202bc 139/222: Make GPL license discoverable by Github., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f20103a448 154/222: Add `delete-selection` hints, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode fe63c579b5 158/222: Merge pull request #120 from emacs-typescript/tsx-tests, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode bd15f212a7 165/222: Implement support type-highlighting in some basic declarations, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 444aa36ec2 169/222: Fix the indentation of member expressions and continued expressions.,
ELPA Syncer <=
- [nongnu] elpa/typescript-mode a8b7e76e85 171/222: Fix infinite loop in indentation., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 62e0366b46 181/222: Remove debugging code, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a504b6f571 182/222: Merge pull request #1 from jkdufair/jkdufair-remove-debugging-code, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f36fddeb54 186/222: Merge pull request #136 from phst/dup, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 178ceca2d4 188/222: Add option for list items indenting, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 2b1f04a166 191/222: Use ‘(should-not …)’ instead of ‘(should (not …))’., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode daded219e6 199/222: Create initial GitHub actions build-definition, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode ab9c2e4fd0 209/222: Merge pull request #153 from emacs-typescript/feature/build-fix, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 67fd5fe4f2 200/222: Delete .travis.yml, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 1043025d42 204/222: Merge pull request #143 from jcs-PR/badge, ELPA Syncer, 2022/02/06