bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#8576: 23.2; , js-mode doesn't support multi-line variable declaratio


From: jaseemabid
Subject: bug#8576: 23.2; , js-mode doesn't support multi-line variable declarations
Date: Thu, 5 Jul 2012 18:23:07 -0700 (PDT)
User-agent: G2/1.0

On Friday, 6 July 2012 06:22:23 UTC+5:30, Dmitry Gutov  wrote:
> > When the first var is staring with an offset, like inside a nested
> > function or something, this is failing. It feels like the second line
> > is indented wrt to coloumn 0 and not wrt to the "var" statement.
> 
> Reproduced when `indent-tabs-mode' is t.
> 
> Here's the updated patch for trunk.
> 
> -- Dmitry
> 
> 
> diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
> index 2e943be..98883a9 100644
> --- a/lisp/progmodes/js.el
> +++ b/lisp/progmodes/js.el
> @@ -1680,6 +1680,9 @@ This performs fontification according to 
> `js--class-styles'."
>            (js--regexp-opt-symbol '("in" "instanceof")))
>    "Regexp matching operators that affect indentation of continued 
> expressions.")
>  
> +(defconst js--declaration-keyword-re
> +  (regexp-opt '("var" "let" "const") 'words)
> +  "Regular matching variable declaration keywords.")
>  
>  (defun js--looking-at-operator-p ()
>    "Return non-nil if point is on a JavaScript operator, other than a comma."
> @@ -1759,6 +1762,42 @@ nil."
>           (list (cons 'c js-comment-lineup-func))))
>      (c-get-syntactic-indentation (list (cons symbol anchor)))))
>  
> +(defun js--multiline-decl-indentation ()
> +  "Returns the declaration indentation column if the current line belongs
> +to a multiline declaration statement.  All declarations are lined up 
> vertically:
> +
> +var a = 10,
> +    b = 20,
> +    c = 30;
> +"
> +  (let (at-opening-bracket)
> +    (save-excursion
> +      (back-to-indentation)
> +      (when (not (looking-at js--declaration-keyword-re))
> +        (when (looking-at js--indent-operator-re)
> +          (goto-char (match-end 0)))
> +        (while (and (not at-opening-bracket)
> +                    (not (bobp))
> +                    (let ((pos (point)))
> +                      (save-excursion
> +                        (js--backward-syntactic-ws)
> +                        (or (eq (char-before) ?,)
> +                            (and (not (eq (char-before) ?\;))
> +                                 (and
> +                                  (prog2
> +                                      (skip-chars-backward "[[:punct:]]")
> +                                      (looking-at js--indent-operator-re)
> +                                    (js--backward-syntactic-ws))
> +                                  (not (eq (char-before) ?\;))))
> +                            (and (>= pos (point-at-bol))
> +                                 (<= pos (point-at-eol)))))))
> +          (condition-case err
> +              (backward-sexp)
> +            (scan-error (setq at-opening-bracket t))))
> +        (when (looking-at js--declaration-keyword-re)
> +          (goto-char (match-end 0))
> +          (1+ (current-column)))))))
> +
>  (defun js--proper-indentation (parse-status)
>    "Return the proper indentation for the current line."
>    (save-excursion
> @@ -1769,6 +1808,7 @@ nil."
>            ((js--ctrl-statement-indentation))
>            ((eq (char-after) ?#) 0)
>            ((save-excursion (js--beginning-of-macro)) 4)
> +          ((js--multiline-decl-indentation))
>            ((nth 1 parse-status)
>          ;; A single closing paren/bracket should be indented at the
>          ;; same level as the opening statement. Same goes for

In the mean while, I tried js2-mode. Reported the same issue there. 
Fixed it here : 
https://github.com/mooz/js2-mode/commit/3ee849316253121ec4ee51268bc814ab60d63b2f





reply via email to

[Prev in Thread] Current Thread [Next in Thread]