From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#28598: 25.3; Errors in narrowed buffers in CC-mode Date: Sun, 1 Oct 2017 18:55:49 +0000 Message-ID: <20171001185548.GC3461@ACM> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1506884712 13875 195.159.176.226 (1 Oct 2017 19:05:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 1 Oct 2017 19:05:12 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: 28598@debbugs.gnu.org To: George Plymale II , John Wiegley Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 01 21:05:06 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1dyjY1-0002yb-DI for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Oct 2017 21:05:05 +0200 Original-Received: from localhost ([::1]:49555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dyjY8-0005tk-Ef for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Oct 2017 15:05:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dyjY2-0005rM-F3 for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2017 15:05:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dyjXy-00051g-Sa for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2017 15:05:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34441) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dyjXy-00051Y-Pq; Sun, 01 Oct 2017 15:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dyjXy-0003Vx-FB; Sun, 01 Oct 2017 15:05:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Sun, 01 Oct 2017 19:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28598 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 28598-submit@debbugs.gnu.org id=B28598.150688467713466 (code B ref 28598); Sun, 01 Oct 2017 19:05:02 +0000 Original-Received: (at 28598) by debbugs.gnu.org; 1 Oct 2017 19:04:37 +0000 Original-Received: from localhost ([127.0.0.1]:43122 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyjXZ-0003V7-9I for submit@debbugs.gnu.org; Sun, 01 Oct 2017 15:04:37 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:37406 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1dyjXX-0003Uz-HX for 28598@debbugs.gnu.org; Sun, 01 Oct 2017 15:04:36 -0400 Original-Received: (qmail 77831 invoked by uid 3782); 1 Oct 2017 19:04:32 -0000 Original-Received: from acm.muc.de (p548C6954.dip0.t-ipconnect.de [84.140.105.84]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 01 Oct 2017 21:04:31 +0200 Original-Received: (qmail 4157 invoked by uid 1000); 1 Oct 2017 18:55:49 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:137756 Archived-At: Hello, George and John. On Mon, Sep 25, 2017 at 10:51:00 -0700, John Wiegley wrote: > >>>>> "GP" == George Plymale 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: #, 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).