From unknown Sat Jun 21 12:28:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#22717: 25.0.91; sh-mode indentation bug with opening parens at the beginnings of lines, and apostrophes Resent-From: Phil Sainty Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Feb 2016 13:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 22717 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 22717@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.145571531124016 (code B ref -1); Wed, 17 Feb 2016 13:22:01 +0000 Received: (at submit) by debbugs.gnu.org; 17 Feb 2016 13:21:51 +0000 Received: from localhost ([127.0.0.1]:38921 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aW239-0006FF-5q for submit@debbugs.gnu.org; Wed, 17 Feb 2016 08:21:51 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49024) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aW233-0006Ew-2r for submit@debbugs.gnu.org; Wed, 17 Feb 2016 08:21:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aW22t-0006tI-Cl for submit@debbugs.gnu.org; Wed, 17 Feb 2016 08:21:35 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:54402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW22t-0006tE-9A for submit@debbugs.gnu.org; Wed, 17 Feb 2016 08:21:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW22o-000709-RA for bug-gnu-emacs@gnu.org; Wed, 17 Feb 2016 08:21:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aW22j-0006rb-QE for bug-gnu-emacs@gnu.org; Wed, 17 Feb 2016 08:21:26 -0500 Received: from [219.88.242.59] (port=36598 helo=mail.orcon.net.nz) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW22j-0006po-97 for bug-gnu-emacs@gnu.org; Wed, 17 Feb 2016 08:21:21 -0500 Received: from [10.1.1.4] (default-rdns.callplus.co.nz [202.150.106.218] (may be forged)) (authenticated bits=0) by mail.orcon.net.nz (8.14.3/8.14.3/Debian-9.4) with ESMTP id u1HDIQso004881 for ; Thu, 18 Feb 2016 02:18:27 +1300 From: Phil Sainty Message-ID: <56C47322.8040404@orcon.net.nz> Date: Thu, 18 Feb 2016 02:18:26 +1300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Bayes-Prob: 0.0001 (Score 0: No Bayes scoring rules defined, tokens from: outbound) X-CanIt-Geo: ip=202.150.106.218; country=NZ; region=Wellington; city=Featherston; latitude=-41.1169; longitude=175.2937; http://maps.google.com/maps?q=-41.1169,175.2937&z=6 X-CanItPRO-Stream: base:outbound X-Canit-Stats-ID: 02Qjpir2t - 97c9af10a667 - 20160218 X-Scanned-By: CanIt (www . roaringpenguin . com) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) I've come up with the following test case: #!/bin/sh echo " (" # Opening parenthesis at the beginning of a line if true; then # Here's an apostrophe fi # ...and now this will be indented -- aligned with the apostrophe If you auto-indent that, the final line gets indented to align with the column containing the apostrophe in the preceding comment. I've been working through a very large shell script trying to eliminate indentation issues, and I discovered that quotes in comments could cause problems with the indentation of later lines of code. Balanced apostrophes 'like so' seem to be ok in general, but sometimes unbalanced quotes would cause subsequent issues. I noticed the opening parenthesis bit while trying to narrow this down to a small test case, and have subsequently confirmed that inserting a space before all such line-starting opening parens eliminates all of my problems with commented quotes. My initial workaround had been to convert unbalanced commented apostrophes into a unicode RIGHT SINGLE QUOTATION MARK, and that resolved most of the problems I was seeing. I found one instance in my large script where double quotes were an issue, such that changing "emacsclient -a ''" in a comment (including both types of quote) into just emacsclient -a '' (i.e. removing the double quotes) resolved the issue. I also saw occasional (but not consistent) issues with `symbol' style quotes, and I ended up replacing the backticks with normal apostrophes for all of those instances. (But again, the opening paren seems to be the trigger.) This was mostly with 24.5, but I've just checked my test case with the current emacs-25 branch from git, and replicated the problem. I found one other consistent indentation issue, which I'll post as a separate bug, as it seems like a different issue. -Phil In GNU Emacs 25.0.91.1 (x86_64-unknown-linux-gnu, X toolkit, Xaw3d scroll bars) of 2016-02-18 built on shodan Repository revision: 14aec913ac3f0dd408487c0e8327403e0f239964 Windowing system distributor 'The X.Org Foundation', version 11.0.11701000 System Description: Ubuntu 15.04 Configured using: 'configure --prefix=/home/phil/emacs/trunk/usr/local --with-x-toolkit=lucid --without-sound' Configured features: XAW3D XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK DBUS GSETTINGS NOTIFY GNUTLS LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 Important settings: value of $LANG: en_NZ.UTF-8 value of $XMODIFIERS: @im=ibus locale-coding-system: utf-8 Major mode: Shell-script Minor modes in effect: sh-electric-here-document-mode: t show-paren-mode: t minibuffer-depth-indicate-mode: t winner-mode: t global-hl-line-mode: t tooltip-mode: t global-eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Recent messages: For information about GNU Emacs and the GNU system, type C-h C-a. GNU Emacs 25.0.91.1 (x86_64-unknown-linux-gnu, X toolkit, Xaw3d scroll bars) of 2016-02-18 Mark set [5 times] Setting up indent for shell type sh Indentation variables are now local. Indentation setup for shell type sh Mark activated Indenting region...done Undo! funcall-interactively: End of buffer Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message dired-x dired format-spec rfc822 mml mml-sec epg epg-config gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util help-fns help-mode easymenu cl-loaddefs pcase cl-lib mail-prsvr mail-utils sh-script smie executable paren mb-depth winner ring hl-line time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote dbusbind inotify dynamic-setting system-font-setting font-render-setting x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 93900 8317) (symbols 48 20374 0) (miscs 40 79 221) (strings 32 17885 4311) (string-bytes 1 490436) (vectors 16 12632) (vector-slots 8 440791 5202) (floats 8 168 90) (intervals 56 264 0) (buffers 976 11) (heap 1024 24743 910)) From unknown Sat Jun 21 12:28:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#22717: 25.0.91; sh-mode / forward-comment bug with opening parens at the beginnings of lines, and quotes in comments Resent-From: Phil Sainty Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Apr 2017 10:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22717 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 22717@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.14925993723052 (code B ref -1); Wed, 19 Apr 2017 10:57:02 +0000 Received: (at submit) by debbugs.gnu.org; 19 Apr 2017 10:56:12 +0000 Received: from localhost ([127.0.0.1]:55595 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0nHQ-0000nA-7g for submit@debbugs.gnu.org; Wed, 19 Apr 2017 06:56:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57950) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0nHP-0000my-Dx for submit@debbugs.gnu.org; Wed, 19 Apr 2017 06:56:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0nHI-0003Vg-SZ for submit@debbugs.gnu.org; Wed, 19 Apr 2017 06:56:06 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:33258) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0nHI-0003VY-PV for submit@debbugs.gnu.org; Wed, 19 Apr 2017 06:56:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0nHH-00043p-Gv for bug-gnu-emacs@gnu.org; Wed, 19 Apr 2017 06:56:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0nHC-0003R7-IA for bug-gnu-emacs@gnu.org; Wed, 19 Apr 2017 06:56:03 -0400 Received: from [219.88.242.56] (port=34209 helo=mail.orcon.net.nz) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0nHC-0003PV-0H for bug-gnu-emacs@gnu.org; Wed, 19 Apr 2017 06:55:58 -0400 Received: from [192.168.20.102] ([150.107.175.195]) (authenticated bits=0) by mail.orcon.net.nz (8.14.3/8.14.3/Debian-9.4) with ESMTP id v3JAPMIr023342 for ; Wed, 19 Apr 2017 22:25:23 +1200 References: <56C47322.8040404@orcon.net.nz> From: Phil Sainty Message-ID: <82536383-60fe-1d11-db63-5c3a2a1c7d57@orcon.net.nz> Date: Wed, 19 Apr 2017 22:25:22 +1200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <56C47322.8040404@orcon.net.nz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Bayes-Prob: 0.0001 (Score 0: No Bayes scoring rules defined, tokens from: outbound) X-CanIt-Geo: ip=150.107.175.195; country=NZ; region=Bay of Plenty; city=Tauranga; latitude=-37.7146; longitude=176.3294; http://maps.google.com/maps?q=-37.7146,176.3294&z=6 X-CanItPRO-Stream: base:outbound X-Canit-Stats-ID: 01TaapnUx - fbc086e2557d - 20170419 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.4 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.4 (----) On 18/02/16 02:18, Phil Sainty wrote: > I've come up with the following test case: > > #!/bin/sh > echo " > (" # Opening parenthesis at the beginning of a line > > if true; then > # Here's an apostrophe > fi # ...and now this will be indented -- aligned with the apostrophe > > > If you auto-indent that, the final line gets indented to align > with the column containing the apostrophe in the preceding comment. Taking another look at this, I've narrowed it down to the behaviour of `forward-comment': With point at the beginning of the "fi" line, running (forward-comment -1) moves point to the end of the preceding line, after the word "apostrophe". If any of the following changes are made, the (forward-comment -1) call will move point to the "#" at the beginning of the comment: * Remove the ' from the comment * Add an additional ' to the comment line (i.e. a balanced quantity) * Change the line with the opening parenthesis so that the lines does not begin with the paren. I note that adding a closing paren (so they are balanced) does not make a difference. The issue occurs with double-quote and back-quote characters as well as apostrophes. Any of: ' " ` Similarly, we can substitute a square or curly opening parenthesis for the round opening paren. Any of ( [ { I've tested this with version 24.5, 25.2rc2, and master. -Phil p.s. The actual indentation code is presumably irrelevant, but the sequence of events for that was: smie-indent-line calls smie-indent-calculate which runs smie-indent-functions until a non-nil value is found. In this instance it is smie-indent-keyword which returns a value, and the key part is (let* ((parent (smie-backward-sexp token))) token here is "fi" and calling (smie-backward-sexp "fi") manually with point at the beginning of that line, we can observe that point moves to the apostrophe inside the comment. If we remove the apostrophe, point moves to the start of the corresponding "if" instead. smie-backward-sexp returns (t 96 "'") in the (t POS TOKEN) format. Ultimately it is smie-next-sexp which produces the value, apparently failing to skip comments during its processing. The docstring says "NEXT-TOKEN is a function of no argument that moves forward by one token (after skipping comments if needed)". NEXT-TOKEN is compiled elisp produced by (indirect-function smie-backward-token-function) where smie-backward-token-function is sh-smie-sh-backward-token. About the first thing to happen in sh-smie-sh-backward-token is (forward-comment (- (point))) to skip backwards over as many comments as possible. From unknown Sat Jun 21 12:28:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#22717: 25.0.91; sh-mode indentation bug with opening parens at the beginnings of lines, and apostrophes Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 20 Jun 2019 11:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22717 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Phil Sainty Cc: 22717@debbugs.gnu.org Received: via spool by 22717-submit@debbugs.gnu.org id=B22717.156102972632421 (code B ref 22717); Thu, 20 Jun 2019 11:23:02 +0000 Received: (at 22717) by debbugs.gnu.org; 20 Jun 2019 11:22:06 +0000 Received: from localhost ([127.0.0.1]:47941 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hdv8o-0008Qm-8s for submit@debbugs.gnu.org; Thu, 20 Jun 2019 07:22:06 -0400 Received: from mail-io1-f52.google.com ([209.85.166.52]:34270) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hdv8l-0008Q6-Nq; Thu, 20 Jun 2019 07:22:04 -0400 Received: by mail-io1-f52.google.com with SMTP id k8so550286iot.1; Thu, 20 Jun 2019 04:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=M+s7JMgwhJTuT/JihQ4MqMzqAc4UQO1Usvj+XrilUPM=; b=JQHAQ22QGaiOqz9eM/SYRr1/OU3hCOjIAkPdkouX3MvNpsGHU/T2MPqrT8uWbdMCiM n8mYi+guMq5ceE3gjGKjlDEptsBLfvNVahySys4v+x6tjXg2Qo/TSZ2aHMqJEDq3mAVW pSZLy+sPlwfCQMWJut0ipK7fOKG2xouJDU+JPKXaBqfFFhejbprOpdTJv4eiIqf0irT0 5PTOMqv8XdDU+BL3AWUEoTAl9pED3xynW4xKczVnlMMJ7HQIKSItlkt+SzGEq26P8hxU jsf7kCAzBi649gQMm8WkoMAPeuArJA+xQnIJAcw24HsB3sH+cpSMEyCZTdVMdEHdQRrP SIfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=M+s7JMgwhJTuT/JihQ4MqMzqAc4UQO1Usvj+XrilUPM=; b=cSIpkkhhjKmDaK2F7kOmSDbRf9FgXQgQSqMB4r+qQZregbmQgp6nYAfrsvzDEp+QKY g4FLQHPY7EkgJr1bIeqauvyioY/wXXdmYfP1mN+0g2Fl3YnASiLCMSWl4a7MEtYdzcWK bkxLRLViQTQXfE85BENF0tBR2YrGX2eXTQ2r6crnX/oHtL7fGpjGE1YnDaWIH2dFTqbg jY2pphhyPW31kYC0aXqjN3jEA6yzL+hgnCgrkdFCZwPrxyoXsyeT5esALaFLYy1KpBd4 wX++x+deYBtDDCpncLwRBh9iFfV6mnhA3qmeVmTiUR41Jcup+1RdXkxs+ewbyw5rIAfg LMVw== X-Gm-Message-State: APjAAAVlchqq10FIJO9JdHC0q05/kOYeL81mMz63A+/7j8v/00c4MzID 3GOhNl+Tyf+aryKqrV9qlFD0m6rI X-Google-Smtp-Source: APXvYqwfrZzpoEOKVdi/0YhhilWMEqg4Pl5ztQmn0+hJkbKek3WVmX+S9T8EJnXzfxgBv/mL1w1ZeA== X-Received: by 2002:a6b:ee15:: with SMTP id i21mr4968298ioh.281.1561029717958; Thu, 20 Jun 2019 04:21:57 -0700 (PDT) Received: from minid (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.gmail.com with ESMTPSA id p3sm16157927iog.70.2019.06.20.04.21.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jun 2019 04:21:57 -0700 (PDT) From: Noam Postavsky References: <56C47322.8040404@orcon.net.nz> Date: Thu, 20 Jun 2019 07:21:56 -0400 In-Reply-To: <56C47322.8040404@orcon.net.nz> (Phil Sainty's message of "Thu, 18 Feb 2016 02:18:26 +1300") Message-ID: <87fto4wlgr.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 22717 fixed close 22717 27.1 quit Phil Sainty writes: > I've come up with the following test case: > > #!/bin/sh > echo " > (" # Opening parenthesis at the beginning of a line > > if true; then > # Here's an apostrophe > fi # ...and now this will be indented -- aligned with the apostrophe > > > If you auto-indent that, the final line gets indented to align > with the column containing the apostrophe in the preceding comment. This is fixed in master, probably by [1: 14b9558752]. [1: 14b9558752]: 2017-12-12 23:03:00 -0500 * src/syntax.c (find_defun_start): Use syntax-ppss https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=14b95587520959c5b54356547a0a69932a9bb480