From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: sand Newsgroups: gmane.emacs.bugs Subject: Indentation bug in function INDENT-SEXP (from CVS sources) Date: Tue, 30 Jan 2007 11:12:32 -0800 Message-ID: <74edf1b42a57241cff49d9b1b3734674@www.avvantamail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1170194499 2805 80.91.229.12 (30 Jan 2007 22:01:39 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 30 Jan 2007 22:01:39 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 30 23:01:31 2007 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HC12g-00058l-7E for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Jan 2007 23:01:30 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HC12f-0000vn-PO for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Jan 2007 17:01:29 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HByPE-0002P3-P6 for bug-gnu-emacs@gnu.org; Tue, 30 Jan 2007 14:12:36 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HByPE-0002On-4I for bug-gnu-emacs@gnu.org; Tue, 30 Jan 2007 14:12:36 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HByPD-0002Oj-UN for bug-gnu-emacs@gnu.org; Tue, 30 Jan 2007 14:12:35 -0500 Original-Received: from smtp61.avvanta.com ([206.124.128.61] helo=mail.blarg.net) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HByPD-0000a1-G1 for bug-gnu-emacs@gnu.org; Tue, 30 Jan 2007 14:12:35 -0500 Original-Received: from mail.blarg.net (localhost.janice.p.blarg.net [127.0.0.1]) by mail.blarg.net (Postfix) with ESMTP id 6C99C21B110 for ; Tue, 30 Jan 2007 11:12:32 -0800 (PST) Original-Received: by mail.blarg.net (Postfix, from userid 48) id 5A39121B10D; Tue, 30 Jan 2007 11:12:32 -0800 (PST) Original-Received: from phpmailer ([207.171.180.101]) by www.avvantamail.com with HTTPS (PHPMailer); Tue, 30 Jan 2007 11:12:32 -0800 X-Priority: 3 X-Mailer: Avvanta's Communications Control Center v5.2.2 X-Mailer-Info: http://www.avvanta.com/ X-CCCUser: sand X-BlargAV-Status: No viruses detected, BlargAV v1.1 on localhost.drteeth.p.blarg.net X-detected-kernel: Linux 2.4-2.6 X-Mailman-Approved-At: Tue, 30 Jan 2007 17:01:27 -0500 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:15566 Archived-At: This is with a version of GNU Emacs compiled from the CVS mainline source= s of (roughly) August 11th, 2006. I have applied the multi-tty patch, so= I'm limited in the CVS versions I can use. I'm confident that the probl= em has not been fixed since, as I describe below. Here's an Emacs Lisp definition with bad indentation: (defadvice yank (after after-yank-indent-region activate) (when (memq major-mode '(c++-mode c-mode emacs-lisp-mode erlang-mode java-mode lisp-mode scheme-mode scheme48-mode)) (let ((mark-even-if-inactive t)) (indent-region (region-beginning) (region-end) nil)))) Place mark at the beginning of the "erlang-mode" line and point at the be= ginning of the "lisp-mode" line and run the "indent-region" command. The= erlang, java *and* lisp lines get indented. The "scheme-mode" line does= not: (defadvice yank (after after-yank-indent-region activate) (when (memq major-mode '(c++-mode c-mode emacs-lisp-mode erlang-mode java-mode lisp-mode scheme-mode scheme48-mode)) (let ((mark-even-if-inactive t)) (indent-region (region-beginning) (region-end) nil)))) I would expect the "lisp-mode" line to not move, based on the chosen regi= on. One can argue that the seen behavior is the correct behavior, as poi= nt is on the beginning of the "lisp-mode" line. However, the same three = lines change if you put mark at the beginning of the "erlang-mode" line a= nd point at the *end* of the "java-mode" line (before the newline). No p= art of the "lisp-mode" line is part of the region, so that is definitely = the wrong behavior. And in any case, I belive that the "lisp-mode" line = should not have changed in the first case, following the principle of lea= st surprise. [WARNING: Description ends, analysis and patch follow!] The bug is in the underlying INDENT-SEXP function. It does test against = the ENDPOS argument (marking the end of the region), but this test occurs= at the top of the loop, before we have advanced to the following line, s= o we get the off-by-one error we see above. There have been two revision= s to lisp-mode.el since I compiled from CVS, neither of which deal with I= NDENT-SEXP, so the problem should still be in the most recent sources. I have attached a patch that appears to fix the problem. With it, both t= ests indent only the erlang and java lines. The change hoists the FORWAR= D-LINE call up and earlier in the code, and compares ENDPOS against point= immediately afterwards, setting OUTER-LOOP-DONE to true if we have reach= ed ENDPOS. (Whether or not this is the right solution long-term is anoth= er matter; INDENT-SEXP is already rather hairy.) Derek -- sand@blarg.net ------------------------------ cut here ------------------------------ --- lisp-mode.el 2007-01-30 10:37:45.000000000 -0800 +++ mod-lisp-mode.el 2007-01-30 10:37:39.000000000 -0800 @@ -1128,8 +1128,11 @@ next-depth 0))) (or outer-loop-done endpos (setq outer-loop-done (<=3D next-depth 0))) + (forward-line 1) + (if (and endpos (<=3D endpos (point))) + (setq outer-loop-done t)) (if outer-loop-done - (forward-line 1) + nil (while (> last-depth next-depth) (setq indent-stack (cdr indent-stack) last-depth (1- last-depth))) @@ -1138,7 +1141,6 @@ last-depth (1+ last-depth))) ;; Now go to the next line and indent it according ;; to what we learned from parsing the previous one. - (forward-line 1) (setq bol (point)) (skip-chars-forward " t") ;; But not if the line is blank, or just a comment