From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#8576: 23.2; , js-mode doesn't support multi-line variable declarations Date: Fri, 06 Jul 2012 04:52:23 +0400 Message-ID: <4FF636C7.6020604@yandex.ru> References: <4DB915B0.7010605@ubercode.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030702010803050105030100" X-Trace: dough.gmane.org 1341536774 23068 80.91.229.3 (6 Jul 2012 01:06:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 6 Jul 2012 01:06:14 +0000 (UTC) To: 8576@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jul 06 03:06:14 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Smwzn-0002Hp-GT for geb-bug-gnu-emacs@m.gmane.org; Fri, 06 Jul 2012 03:06:07 +0200 Original-Received: from localhost ([::1]:41766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Smwzm-0001WS-EG for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 Jul 2012 21:06:06 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Smwzh-0001U4-RT for bug-gnu-emacs@gnu.org; Thu, 05 Jul 2012 21:06:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SmwnE-0003Pn-32 for bug-gnu-emacs@gnu.org; Thu, 05 Jul 2012 20:53:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41611) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SmwnD-0003Pg-OR for bug-gnu-emacs@gnu.org; Thu, 05 Jul 2012 20:53:08 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Smwry-0002a6-B6 for bug-gnu-emacs@gnu.org; Thu, 05 Jul 2012 20:58:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <4DB915B0.7010605@ubercode.de> Resent-From: Dmitry Gutov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 06 Jul 2012 00:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8576 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 8576-submit@debbugs.gnu.org id=B8576.13415362419864 (code B ref 8576); Fri, 06 Jul 2012 00:58:02 +0000 Original-Received: (at 8576) by debbugs.gnu.org; 6 Jul 2012 00:57:21 +0000 Original-Received: from localhost ([127.0.0.1]:51157 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SmwrJ-0002Z3-B1 for submit@debbugs.gnu.org; Thu, 05 Jul 2012 20:57:21 -0400 Original-Received: from forward15.mail.yandex.net ([95.108.130.119]:41487) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SmwrE-0002Yr-Sg for 8576@debbugs.gnu.org; Thu, 05 Jul 2012 20:57:19 -0400 Original-Received: from smtp12.mail.yandex.net (smtp12.mail.yandex.net [95.108.131.191]) by forward15.mail.yandex.net (Yandex) with ESMTP id 977C89E2D19 for <8576@debbugs.gnu.org>; Fri, 6 Jul 2012 04:52:19 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1341535939; bh=yf6TXYMNZEjRKQ6GuUhO4lHu0CdQ6i6aJFSCiEhPfp4=; h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type; b=aPIGr19AmZuLFH7P2cX2/fzr1LA201ke4wXeWAp1RosYu7nRbha5wq07ZaPd1iuqf 4QK7IfRFd/A1cK1In/o+Vg74GSpGP0Xeu2KeNgXoQnVzk4MmydRJ4ogtQV3V4OxKln rW7Rf7PZlpbn10EjgAYl92mt13i5NLOIkh/isGmE= Original-Received: from smtp12.mail.yandex.net (localhost [127.0.0.1]) by smtp12.mail.yandex.net (Yandex) with ESMTP id 84F7116A05D8 for <8576@debbugs.gnu.org>; Fri, 6 Jul 2012 04:52:19 +0400 (MSK) Original-Received: from 98-87.nwlink.spb.ru (98-87.nwlink.spb.ru [178.252.98.87]) by smtp12.mail.yandex.net (nwsmtp/Yandex) with ESMTP id qJOKpAIf-qJOuVlcJ; Fri, 6 Jul 2012 04:52:19 +0400 X-Yandex-Rcpt-Suid: 8576@debbugs.gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1341535939; bh=yf6TXYMNZEjRKQ6GuUhO4lHu0CdQ6i6aJFSCiEhPfp4=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type; b=pkjv1oUCNtv4zletkqAPjnVmmrRcC9LoJcMi1oq7DjVkl074UrVreGP3zWTlHuET+ 2MunA5St3RpvtPRu5VW6hucIBx3OUBkVtzceOvJoZF2qCYNELVtnQ3BtgUqaZcmLsb m5hUnscG29tjKsJQT9LSLdd/4LpvZHjkD9LoPgSc= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:61632 Archived-At: This is a multi-part message in MIME format. --------------030702010803050105030100 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > 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 --------------030702010803050105030100 Content-Type: text/plain; charset=windows-1251; name="js-multiline-decls.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="js-multiline-decls.diff" 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 --------------030702010803050105030100--