all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: George Plymale II <georgedp@orbitalimpact.com>,
	John Wiegley <jwiegley@gmail.com>
Cc: 28598@debbugs.gnu.org
Subject: bug#28598: 25.3; Errors in narrowed buffers in CC-mode
Date: Sun, 1 Oct 2017 18:55:49 +0000	[thread overview]
Message-ID: <20171001185548.GC3461@ACM> (raw)
In-Reply-To: <m27ewmsm4b.fsf@newartisans.com>

Hello, George and John.

On Mon, Sep 25, 2017 at 10:51:00 -0700, John Wiegley wrote:
> >>>>> "GP" == George Plymale <georgedp@orbitalimpact.com> writes:

> GP> For those too lazy to follow the link, here's the gist: When I press `RET'
> GP> at the beginning or end of a narrowed buffer in CC-mode, I see errors like
> GP> this:

> GP> c-determine-limit: Args out of range: #<buffer dired.c>, 1, 1564

> Alan, do you have any thoughts on this one?

George, would you try the following patch, please?  The file
cc-engine.el is in ..../emacs-25.3/lisp/progmodes.  After applying the
patch, it is sufficient merely to recompile cc-engine.el.  If you want
any help with the patching/recompiling process, feel free to send me
private email.

The bug which you tripped over is already (almost) fixed in the emacs-26
branch of the git repository.  It is expected to be released some months
from now.

In the meantime, this patch should solve the problems in Emacs 25.3.
Please let me know if it doesn't.



--- cc-engine.20171001.eeel	2017-04-14 15:02:47.000000000 +0000
+++ cc-engine.el	2017-10-01 17:14:49.185254672 +0000
@@ -4682,18 +4682,29 @@
   ;; This doesn't preserve point.
   (let* ((pos (max (- start try-size) (point-min)))
 	 (base (c-state-semi-safe-place pos))
-	 (s (parse-partial-sexp base pos)))
-    (if (or (nth 4 s) (nth 3 s))	; comment or string
-	(nth 8 s)
+	 (s (save-restriction
+	      (widen)
+	      (parse-partial-sexp base pos)))
+	 (cand (if (or (nth 4 s) (nth 3 s)) ; comment or string
+		   (nth 8 s)
+		 pos)))
+    (if (>= cand (point-min))
+	cand
+      (parse-partial-sexp pos start nil nil s 'syntax-table)
       (point))))
 
 (defun c-determine-limit (how-far-back &optional start try-size)
-  ;; Return a buffer position HOW-FAR-BACK non-literal characters from START
-  ;; (default point).  This is done by going back further in the buffer then
-  ;; searching forward for literals.  The position found won't be in a
-  ;; literal.  We start searching for the sought position TRY-SIZE (default
-  ;; twice HOW-FAR-BACK) bytes back from START.  This function must be fast.
-  ;; :-)
+  ;; Return a buffer position HOW-FAR-BACK non-literal characters from
+  ;; START (default point).  The starting position, either point or
+  ;; START may not be in a comment or string.
+  ;;
+  ;; The position found will not be before POINT-MIN and won't be in a
+  ;; literal.
+  ;;
+  ;; We start searching for the sought position TRY-SIZE (default
+  ;; twice HOW-FAR-BACK) bytes back from START.
+  ;;
+  ;; This function must be fast.  :-)
   (save-excursion
     (let* ((start (or start (point)))
 	   (try-size (or try-size (* 2 how-far-back)))
@@ -4715,7 +4726,8 @@
 		 'syntax-table))	; stop-comment
 
 	;; Gather details of the non-literal-bit - starting pos and size.
-	(setq size (- (if (or (nth 4 s) (nth 3 s))
+	(setq size (- (if (or (and (nth 4 s) (not (eq (nth 7 s) 'syntax-table)))
+			      (nth 3 s))
 			  (nth 8 s)
 			(point))
 		      pos))
@@ -4723,7 +4735,8 @@
 	    (setq stack (cons (cons pos size) stack)))
 
 	;; Move forward to the end of the comment/string.
-	(if (or (nth 4 s) (nth 3 s))
+	(if (or (and (nth 4 s) (not (eq (nth 7 s) 'syntax-table)))
+		(nth 3 s))
 	    (setq s (parse-partial-sexp
 		     (point)
 		     start
@@ -4747,6 +4760,8 @@
 	(+ (car elt) (- count how-far-back)))
        ((eq base (point-min))
 	(point-min))
+       ((> base (- start try-size)) ; Can only happen if we hit point-min.
+	(car elt))
        (t
 	(c-determine-limit (- how-far-back count) base try-size))))))
 

> -- 
> John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
> http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2

-- 
Alan Mackenzie (Nuremberg, Germany).





  parent reply	other threads:[~2017-10-01 18:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-25  6:21 bug#28598: 25.3; Errors in narrowed buffers in CC-mode George Plymale II
2017-09-25 17:51 ` John Wiegley
2017-09-25 20:50   ` Alan Mackenzie
2017-09-26  1:14     ` George Plymale II
2017-10-01 18:55   ` Alan Mackenzie [this message]
2017-10-02 19:02     ` George Plymale II
2017-10-30 17:37       ` 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=20171001185548.GC3461@ACM \
    --to=acm@muc.de \
    --cc=28598@debbugs.gnu.org \
    --cc=georgedp@orbitalimpact.com \
    --cc=jwiegley@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.