From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#17842: sh-script's indentation gets confused by \; Date: Tue, 24 Jun 2014 16:10:00 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1403640687 22129 80.91.229.3 (24 Jun 2014 20:11:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Jun 2014 20:11:27 +0000 (UTC) Cc: Reiner Steib To: 17842@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 24 22:11:21 2014 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 1WzX3o-0005bS-EF for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Jun 2014 22:11:20 +0200 Original-Received: from localhost ([::1]:33643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzX3n-0007Uo-Tz for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Jun 2014 16:11:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzX3d-0007Tj-Kz for bug-gnu-emacs@gnu.org; Tue, 24 Jun 2014 16:11:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzX3W-0006cU-Ok for bug-gnu-emacs@gnu.org; Tue, 24 Jun 2014 16:11:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40251) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzX3W-0006cQ-LH for bug-gnu-emacs@gnu.org; Tue, 24 Jun 2014 16:11:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WzX3V-0003lE-Nj; Tue, 24 Jun 2014 16:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: reiner.steib@gmx.de, bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Jun 2014 20:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17842 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-Xcc: Reiner Steib Original-Received: via spool by 17842-submit@debbugs.gnu.org id=B17842.140364061114384 (code B ref 17842); Tue, 24 Jun 2014 20:11:01 +0000 Original-Received: (at 17842) by debbugs.gnu.org; 24 Jun 2014 20:10:11 +0000 Original-Received: from localhost ([127.0.0.1]:59632 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WzX2f-0003jt-JR for submit@debbugs.gnu.org; Tue, 24 Jun 2014 16:10:10 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:29714) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WzX2d-0003jN-1L for 17842@debbugs.gnu.org; Tue, 24 Jun 2014 16:10:08 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArYGAIDvNVNLd+D9/2dsb2JhbABZgwY7gw/APYEXF3SCJQEBAQECAVYoCws0EhQYDYgoCNIZF48BhDgEqRmBaoNMIQ X-IPAS-Result: ArYGAIDvNVNLd+D9/2dsb2JhbABZgwY7gw/APYEXF3SCJQEBAQECAVYoCws0EhQYDYgoCNIZF48BhDgEqRmBaoNMIQ X-IronPort-AV: E=Sophos;i="4.97,753,1389762000"; d="scan'208";a="69432629" Original-Received: from 75-119-224-253.dsl.teksavvy.com (HELO ceviche.home) ([75.119.224.253]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 24 Jun 2014 16:10:00 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 85A8266167; Tue, 24 Jun 2014 16:10:00 -0400 (EDT) In-Reply-To: (Stefan Monnier's message of "Tue, 24 Jun 2014 09:49:28 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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:90754 Archived-At: > However, I tested[1] the new code with the following script and found > some incorrect indents (see diff below, hope the whitespace doesn't > get changed). These are due to the new indentation code. > --- shell-script-test.sh > +++ # > @@ -12,21 +12,21 @@ > filter_1 () > { > tr -d '"' | > - awk -F\; '{ if ($7 == 0 || $7 == 1) { print $7 } ; \ > +awk -F\; '{ if ($7 == 0 || $7 == 1) { print $7 } ; \ > print $5 "," $1 }' | > - grep -v "^," > +grep -v "^," > } > filter_3 () > { > tr -d '"`' | tr ' ' ' ' | \ > - awk -F\; -f filter.awk | \ > - grep -v "^," | sort -t, -k2,2 > + awk -F\; -f filter.awk | \ > +grep -v "^," | sort -t, -k2,2 > } > tail -q -n+2 assets-ws.csv | awk -F \; -f merge.awk \ > - <( cat file1.csv file2.csv ) - | \ > - filter_2 | $conv | \ > - sed -f a.sed | sort -t\; -k3,3 -k1,1 > w.csv > + <( cat file1.csv file2.csv ) - | \ > + filter_2 | $conv | \ > + sed -f a.sed | sort -t\; -k3,3 -k1,1 > w.csv I installed the patch below which fixes the problem with \; and also with the indentation after "a | b |". The "<(cat...)" line is still not indented as you want it because you expect a different logic from the one followed by the current indentation code (the current code indents multi-line elements connected by \ as multi line constructs rather than "one long wrapped line", so the <(...) gets aligned with the other arguments to the "sort" command). Stefan === modified file 'lisp/progmodes/sh-script.el' --- lisp/progmodes/sh-script.el 2014-06-20 14:23:30 +0000 +++ lisp/progmodes/sh-script.el 2014-06-24 19:55:01 +0000 @@ -466,6 +466,9 @@ ?~ "_" ?, "_" ?= "." + ?\; "." + ?| "." + ?& "." ?< "." ?> ".") "The syntax table to use for Shell-Script mode. @@ -1837,6 +1840,40 @@ ((equal tok "in") (sh-smie--sh-keyword-in-p)) (t (sh-smie--keyword-p)))) +(defun sh-smie--default-forward-token () + (forward-comment (point-max)) + (buffer-substring-no-properties + (point) + (progn (if (zerop (skip-syntax-forward ".")) + (while (progn (skip-syntax-forward "w_'") + (looking-at "\\\\")) + (forward-char 2))) + (point)))) + +(defun sh-smie--default-backward-token () + (forward-comment (- (point))) + (let ((pos (point)) + (n (skip-syntax-backward "."))) + (if (or (zerop n) + (and (eq n -1) + (let ((p (point))) + (if (eq -1 (% (skip-syntax-backward "\\") 2)) + t + (goto-char p) + nil)))) + (while + (progn (skip-syntax-backward "w_'") + (or (not (zerop (skip-syntax-backward "\\"))) + (when (eq ?\\ (char-before (1- (point)))) + (let ((p (point))) + (forward-char -1) + (if (eq -1 (% (skip-syntax-backward "\\") 2)) + t + (goto-char p) + nil)))))) + (goto-char (- (point) (% (skip-syntax-backward "\\") 2)))) + (buffer-substring-no-properties (point) pos))) + (defun sh-smie-sh-forward-token () (if (and (looking-at "[ \t]*\\(?:#\\|\\(\\s|\\)\\|$\\)") (save-excursion @@ -1865,7 +1902,7 @@ tok)) (t (let* ((pos (point)) - (tok (smie-default-forward-token))) + (tok (sh-smie--default-forward-token))) (cond ((equal tok ")") "case-)") ((equal tok "(") "case-(") @@ -1909,7 +1946,7 @@ (goto-char (match-beginning 1)) (match-string-no-properties 1)) (t - (let ((tok (smie-default-backward-token))) + (let ((tok (sh-smie--default-backward-token))) (cond ((equal tok ")") "case-)") ((equal tok "(") "case-(") @@ -1939,18 +1976,18 @@ (`(:after . "case-)") (- (sh-var-value 'sh-indent-for-case-alt) (sh-var-value 'sh-indent-for-case-label))) ((and `(:before . ,_) - (guard (when sh-indent-after-continuation - (save-excursion + ;; After a line-continuation, make sure the rest is indented. + (guard sh-indent-after-continuation) + (guard (save-excursion (ignore-errors (skip-chars-backward " \t") - (sh-smie--looking-back-at-continuation-p)))))) - ;; After a line-continuation, make sure the rest is indented. - (let* ((sh-indent-after-continuation nil) - (indent (smie-indent-calculate)) - (initial (sh-smie--continuation-start-indent))) - (when (and (numberp indent) (numberp initial) - (<= indent initial)) - `(column . ,(+ initial sh-indentation))))) + (sh-smie--looking-back-at-continuation-p)))) + (let initial (sh-smie--continuation-start-indent)) + (guard (let* ((sh-indent-after-continuation nil) + (indent (smie-indent-calculate))) + (and (numberp indent) (numberp initial) + (<= indent initial))))) + `(column . ,(+ initial sh-indentation))) (`(:before . ,(or `"(" `"{" `"[")) (when (smie-rule-hanging-p) (if (not (smie-rule-prev-p "&&" "||" "|")) @@ -1974,7 +2011,12 @@ (smie-rule-bolp)))) (current-column) (smie-indent-calculate))))) - (`(:after . ,(or `"|" `"&&" `"||")) (if (smie-rule-parent-p token) nil 4)) + (`(:before . ,(or `"|" `"&&" `"||")) + (unless (smie-rule-parent-p token) + (smie-backward-sexp token) + `(column . ,(+ (funcall smie-rules-function :elem 'basic) + (smie-indent-virtual))))) + ;; Attempt at backward compatibility with the old config variables. (`(:before . "fi") (sh-var-value 'sh-indent-for-fi)) (`(:before . "done") (sh-var-value 'sh-indent-for-done)) @@ -2095,7 +2137,7 @@ ;; tok)) (t (let* ((pos (point)) - (tok (smie-default-forward-token))) + (tok (sh-smie--default-forward-token))) (cond ;; ((equal tok ")") "case-)") ((and tok (string-match "\\`[a-z]" tok) @@ -2136,7 +2178,7 @@ ;; (goto-char (match-beginning 1)) ;; (match-string-no-properties 1)) (t - (let ((tok (smie-default-backward-token))) + (let ((tok (sh-smie--default-backward-token))) (cond ;; ((equal tok ")") "case-)") ((and tok (string-match "\\`[a-z]" tok)