From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: c-indent-line-or-region with 500 char Date: Sat, 8 Dec 2018 13:53:51 +0000 Message-ID: <20181208135351.GA17410@ACM> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1544277464 32536 195.159.176.226 (8 Dec 2018 13:57:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 8 Dec 2018 13:57:44 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) Cc: emacs-devel@gnu.org To: Yasushi SHOJI Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 08 14:57:39 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gVd6v-0008GH-IU for ged-emacs-devel@m.gmane.org; Sat, 08 Dec 2018 14:57:37 +0100 Original-Received: from localhost ([::1]:51006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVd92-0000kR-AN for ged-emacs-devel@m.gmane.org; Sat, 08 Dec 2018 08:59:48 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVd8C-0000jZ-8D for emacs-devel@gnu.org; Sat, 08 Dec 2018 08:59:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gVd88-00010W-53 for emacs-devel@gnu.org; Sat, 08 Dec 2018 08:58:56 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:55255 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1gVd87-000102-QT for emacs-devel@gnu.org; Sat, 08 Dec 2018 08:58:52 -0500 Original-Received: (qmail 73964 invoked by uid 3782); 8 Dec 2018 13:58:50 -0000 Original-Received: from acm.muc.de (p2E5D5926.dip0.t-ipconnect.de [46.93.89.38]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 08 Dec 2018 14:58:48 +0100 Original-Received: (qmail 17592 invoked by uid 1000); 8 Dec 2018 13:53:51 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:231722 Archived-At: Hello, Yashi. On Mon, Nov 26, 2018 at 22:19:15 +0900, Yasushi SHOJI wrote: > Hello, > I just found this odd behavior on my Emacs and I'd like to ask how to > fix it. I'm attaching a.c with 500 chars in. Go to the very bottom of > the file and hitting the tab will move the cursors to the right. hitting the > tab key again moves it again. It just keeps going. > If you delete some char from the file, it stop behaving. > I can reproduce this with the following Emacs with `-q`. > - Debian Sid's Emacs 1:25.2+1-11 > - The current tip of emacs-26 branch (ea624626) > Does anyone see the behavior? Yes, this was one of these bugs which was fairly easy to diagnose, but difficult to decide how to fix. Thanks for taking the trouble to report this. Your file is actually 502 bytes long. At some place in CC Mode, there was a call to (c-beginning-of-statement-1 ...) with a search limit of 500 bytes. This just failed to reach the # of the #define at the beginning of the buffer, hence mis-analysed the text, leading to the strange behaviour. When a random byte is removed, this 500 limit was just big enough to reach that # at the beginning of the buffer, hence analysed it correctly, and the key worked properly. The fix in the patch below amends c-beginning-of-statement-1 to detect hitting the limit. It should apply cleanly to the emacs-26 branch. Could you please try out this patch (to emacs/lisp/progmodes/cc-engine.el), byte compile cc-engine.el, try it out on your real code, and confirm to me that it fixes the bug, or tell me what's still not working. If you want any help applying the patch or byte compiling the file, feel free to send me private email. Thanks again for the report! diff -r 021672422937 cc-engine.el --- a/cc-engine.el Sat Nov 24 10:18:12 2018 +0000 +++ b/cc-engine.el Sat Dec 08 13:41:22 2018 +0000 @@ -698,7 +698,7 @@ (c-point 'bol (elt saved-pos 0)))))))) (defun c-beginning-of-statement-1 (&optional lim ignore-labels - noerror comma-delim) + noerror comma-delim hit-lim) "Move to the start of the current statement or declaration, or to the previous one if already at the beginning of one. Only statements/declarations on the same level are considered, i.e. don't @@ -1271,6 +1272,17 @@ ;; Might have jumped over several labels. Go to the last one. (setq pos last-label-pos))))) + ;; Have we hit LIM without finding a beginning of statement? + (when (and hit-lim + (bobp) + (>= pos start)) + (unless + (and (eq (point) 1) + (not (looking-at c-comment-start-regexp)) + (not (and c-anchored-cpp-prefix + (looking-at c-anchored-cpp-prefix)))) + (setq ret nil))) + ;; Have we got "case :"? (goto-char pos) (when (and after-case:-pos @@ -9656,7 +9668,7 @@ (let ((beg (point)) id-start) (and - (eq (c-beginning-of-statement-1 lim) 'same) + (eq (c-beginning-of-statement-1 lim nil nil nil t) 'same) (not (and (c-major-mode-is 'objc-mode) (c-forward-objc-directive))) > Thanks, > -- > yashi -- Alan Mackenzie (Nuremberg, Germany).