From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Felix H. Dahlke" Newsgroups: gmane.emacs.bugs Subject: bug#8576: 23.2; js-mode doesn't support multi-line variable declarations Date: Tue, 17 Jul 2012 05:16:23 +0200 Message-ID: <5004D907.5050908@ubercode.de> References: <4FD13370.8000406@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig79D455A1C5E0438E67B2340C" X-Trace: dough.gmane.org 1342495033 21647 80.91.229.3 (17 Jul 2012 03:17:13 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 17 Jul 2012 03:17:13 +0000 (UTC) Cc: 8576@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 17 05:17:13 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 1SqyHd-0005aR-5o for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Jul 2012 05:17:09 +0200 Original-Received: from localhost ([::1]:54795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqyHc-0004Qm-F2 for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Jul 2012 23:17:08 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqyHZ-0004Qc-Ed for bug-gnu-emacs@gnu.org; Mon, 16 Jul 2012 23:17:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SqyHY-0003AG-9y for bug-gnu-emacs@gnu.org; Mon, 16 Jul 2012 23:17:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35415) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqyHY-0003AB-6T for bug-gnu-emacs@gnu.org; Mon, 16 Jul 2012 23:17:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SqyNJ-0005t6-K7 for bug-gnu-emacs@gnu.org; Mon, 16 Jul 2012 23:23:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Felix H. Dahlke" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Jul 2012 03:23:01 +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.134249535322593 (code B ref 8576); Tue, 17 Jul 2012 03:23:01 +0000 Original-Received: (at 8576) by debbugs.gnu.org; 17 Jul 2012 03:22:33 +0000 Original-Received: from localhost ([127.0.0.1]:44961 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SqyMq-0005sM-0B for submit@debbugs.gnu.org; Mon, 16 Jul 2012 23:22:32 -0400 Original-Received: from vserver2179.vserver-on.de ([84.38.67.140]:48922) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SqyMn-0005sD-C2 for 8576@debbugs.gnu.org; Mon, 16 Jul 2012 23:22:30 -0400 Original-Received: from [192.168.1.6] (xdsl-78-35-166-67.netcologne.de [78.35.166.67]) (Authenticated sender: fhd@ubercode.de) by vserver2179.vserver-on.de (Postfix) with ESMTPSA id 28FAA1FF001 for <8576@debbugs.gnu.org>; Tue, 17 Jul 2012 05:17:02 +0200 (CEST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 In-Reply-To: <4FD13370.8000406@yandex.ru> X-Enigmail-Version: 1.4.2 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:62016 Archived-At: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig79D455A1C5E0438E67B2340C Content-Type: multipart/mixed; boundary="------------010803040501010904090305" This is a multi-part message in MIME format. --------------010803040501010904090305 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I tried some things but couldn't really make it work like I wanted. So I decided to just improve the patch a bit. I am now using the proper indentation which also fixes the issue reported by jaseemabid. I've attached the patch for Emacs 24 and updated the Gists: https://gist.github.com/2849595 (Emacs 24) https://gist.github.com/2849799 (Emacs 23) The problem with my desired behaviour is indeed that it requires forward parsing. So when you're indenting a full statement like this, it works: var x =3D { num: 5 }, y =3D 6; However, when you're initially typing this (pressing TAB on each line), it ends up like this: var x =3D { num: 5 }, y =3D 6; You'd have to go back and indent the whole thing again after adding the closing brace followed by a comma. That's actually pretty annoying in practice and would probably lead to highly inconsistent indendation, so I decided to leave it out for now. The only solution I can think of would be to go back up after typing a closing brace followed by a comma and indent the preceeding lines. Some modes do that, but it would require drastic changes to js.el. I'd rather get this patch in first and see if the issue annoys me (or anyone else) enough to work further on this. --------------010803040501010904090305 Content-Type: text/x-patch; name="indent-multi-line-var-statements.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="indent-multi-line-var-statements.patch" =3D=3D=3D modified file 'lisp/progmodes/js.el' --- lisp/progmodes/js.el 2012-07-11 23:13:41 +0000 +++ lisp/progmodes/js.el 2012-07-17 03:08:57 +0000 @@ -416,6 +416,16 @@ :paren-depth most-negative-fixnum :type 'toplevel)) =20 +(defconst js--indent-operator-re + (concat "[-+*/%<>=3D&^|?:.]\\([^-+*/]\\|$\\)\\|" + (regexp-opt '("in" "instanceof") 'words)) + "Regular expression matching operators that affect indentation +of continued expressions.") + +(defconst js--declaration-keyword-re + (regexp-opt '("var" "let" "const") 'words) + "Regular expression matching variable declaration keywords.") + ;;; User Customization =20 (defgroup js nil @@ -1759,6 +1769,36 @@ (list (cons 'c js-comment-lineup-func)))) (c-get-syntactic-indentation (list (cons symbol anchor))))) =20 +(defun js--multi-line-declaration-indentation () + "Helper function for `js--proper-indentation'. +Return the proper indentation of the current line if it belongs to a dec= laration +statement spanning multiple lines; otherwise, return nil." + (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) ?\;)) + (prog2 + (skip-chars-backward "[[:punct:]]")= + (looking-at js--indent-operator-re)= + (js--backward-syntactic-ws)) + (not (eq (char-before) ?\;))) + (and (>=3D pos (point-at-bol)) + (<=3D pos (point-at-eol))))))) + (condition-case err + (backward-sexp) + (scan-error (setq at-opening-bracket t)))) + (when (looking-at js--declaration-keyword-re) + (+ (current-indentation) js-indent-level)))))) + (defun js--proper-indentation (parse-status) "Return the proper indentation for the current line." (save-excursion @@ -1767,6 +1807,7 @@ (js--get-c-offset 'c (nth 8 parse-status))) ((nth 8 parse-status) 0) ; inside string ((js--ctrl-statement-indentation)) + ((js--multi-line-declaration-indentation)) ((eq (char-after) ?#) 0) ((save-excursion (js--beginning-of-macro)) 4) ((nth 1 parse-status) --------------010803040501010904090305-- --------------enig79D455A1C5E0438E67B2340C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlAE2QoACgkQJc3crOgfbuZUkwCglobyld8pGcwJS8I/wa5tYUqn c2QAn06joqTSV3a8ZQgmpOxFG6i1J7tM =CkjU -----END PGP SIGNATURE----- --------------enig79D455A1C5E0438E67B2340C--