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 06:37:31 +0200 Message-ID: <5004EC0B.5070707@ubercode.de> References: <5004E847.2070000@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigF4FE1B54063CF8B158D19B0B" X-Trace: dough.gmane.org 1342499894 18210 80.91.229.3 (17 Jul 2012 04:38:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 17 Jul 2012 04:38:14 +0000 (UTC) Cc: 8576@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 17 06:38: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 1SqzY3-0000Ar-RH for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Jul 2012 06:38:12 +0200 Original-Received: from localhost ([::1]:58010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqzY2-0001gS-LF for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Jul 2012 00:38:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqzXz-0001gK-EL for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 00:38:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SqzXy-0006qX-2U for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 00:38:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqzXx-0006qJ-V5 for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 00:38:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Sqzdj-0007kG-H3 for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 00:44:03 -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 04:44:03 +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.134250023129745 (code B ref 8576); Tue, 17 Jul 2012 04:44:03 +0000 Original-Received: (at 8576) by debbugs.gnu.org; 17 Jul 2012 04:43:51 +0000 Original-Received: from localhost ([127.0.0.1]:45015 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SqzdW-0007ji-G9 for submit@debbugs.gnu.org; Tue, 17 Jul 2012 00:43:50 -0400 Original-Received: from vserver2179.vserver-on.de ([84.38.67.140]:37021) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SqzdS-0007jZ-Pg for 8576@debbugs.gnu.org; Tue, 17 Jul 2012 00:43:48 -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 019A01FF001; Tue, 17 Jul 2012 06:38:19 +0200 (CEST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 In-Reply-To: <5004E847.2070000@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:62019 Archived-At: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigF4FE1B54063CF8B158D19B0B Content-Type: multipart/mixed; boundary="------------000305030107070905020304" This is a multi-part message in MIME format. --------------000305030107070905020304 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 07/17/2012 06:21 AM, Dmitry Gutov wrote: > You shouldn't add the `js--indent-operator-re' constant, though, it's > already present in js-mode. Oh, you're right, thanks. I've updated the gists and attached a new patch= =2E >> 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. >=20 > I don't think this will be much of a problem. Probably not, but I fear it's going to be a lot of work - at least when I do it. > There is an alternative approach, though: one js2-mode user requested > that when the first value in the declaration is a function/object/array= , > it should always be indented: https://github.com/mooz/js2-mode/issues/3= >=20 > That option probably won't be very popular. Yes, I thought about suggesting that. But considering that that makes single variable declarations of functions/object literals look weird, I figured that wouldn't be desirable. I saw that you can configure this in j2-mode, perhaps that's an option. But I'd personally prefer the clever solution. --------------000305030107070905020304 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 04:29:06 +0000 @@ -1675,12 +1675,15 @@ "each")) "Regexp matching keywords optionally followed by an opening brace.") =20 +(defconst js--declaration-keyword-re + (regexp-opt '("var" "let" "const") 'words) + "Regular expression matching variable declaration keywords.") + (defconst js--indent-operator-re (concat "[-+*/%<>=3D&^|?:.]\\([^-+*/]\\|$\\)\\|" (js--regexp-opt-symbol '("in" "instanceof"))) "Regexp matching operators that affect indentation of continued expres= sions.") =20 - (defun js--looking-at-operator-p () "Return non-nil if point is on a JavaScript operator, other than a com= ma." (save-match-data @@ -1759,6 +1762,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 +1800,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) --------------000305030107070905020304-- --------------enigF4FE1B54063CF8B158D19B0B 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/ iEYEARECAAYFAlAE7BoACgkQJc3crOgfbuYJdACgniBslVvTK+f7F2+DEC/9uCzB vjgAoKhJ0cDzF8FfXMrCFzGcpJf+EL4p =s2ne -----END PGP SIGNATURE----- --------------enigF4FE1B54063CF8B158D19B0B--