all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Yasushi SHOJI <yasushi.shoji@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: c-indent-line-or-region with 500 char
Date: Sat, 8 Dec 2018 13:53:51 +0000	[thread overview]
Message-ID: <20181208135351.GA17410@ACM> (raw)
In-Reply-To: <CAELBRW+0FWryNLenhNB2eX1qxe0vSk=46Us=fsOs-uHaiy+QeA@mail.gmail.com>

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 <tab> 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 <expression>:"?
       (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).



  reply	other threads:[~2018-12-08 13:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26 13:19 c-indent-line-or-region with 500 char Yasushi SHOJI
2018-12-08 13:53 ` Alan Mackenzie [this message]
2019-01-28 11:11   ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181208135351.GA17410@ACM \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=yasushi.shoji@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.