unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Ivan Andrus <darthandrus@gmail.com>
Cc: 19134@debbugs.gnu.org
Subject: bug#19134: 24.4.51; Error using mark-defun in c++-mode
Date: 22 Nov 2014 22:04:13 -0000	[thread overview]
Message-ID: <20141122220413.75395.qmail@mail.muc.de> (raw)
In-Reply-To: <mailman.14214.1416532702.1147.bug-gnu-emacs@gnu.org>

Hello again, Ivan.

In article <mailman.14214.1416532702.1147.bug-gnu-emacs@gnu.org> you wrote:
> Starting from emacs -Q, create a buffer in `c++-mode' with contents below.

> class Bob
> {
> protected:

>    void fun()
>    {
>    }

> };


> Placing point on the line after "protected:" and running mark-defun gives
> the error:

> c-where-wrt-brace-construct: c-where-wrt-brace-construct: c-beginning-of-decl-1 returned label

Yes.  I've just pushed the following patch to the git repository:


diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 5fa3b25..50cdd78 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1417,12 +1417,15 @@ No indentation or other \"electric\" behavior is performed."
              (car (c-beginning-of-decl-1
                    ;; NOTE: If we're in a K&R region, this might be the start
                    ;; of a parameter declaration, not the actual function.
+                   ;; It might also leave us at a label or "label" like
+                   ;; "private:".
                    (and least-enclosing ; LIMIT for c-b-of-decl-1
                         (c-safe-position least-enclosing paren-state)))))

        ;; Has the declaration we've gone back to got braces?
-       (setq brace-decl-p
-             (save-excursion
+       (or (eq decl-result 'label)
+           (setq brace-decl-p
+                 (save-excursion
                    (and (c-syntactic-re-search-forward "[;{]" nil t t)
                         (or (eq (char-before) ?\{)
                             (and c-recognize-knr-p
@@ -1430,10 +1433,11 @@ No indentation or other \"electric\" behavior is performed."
                                  ;; ';' in a K&R argdecl.  In
                                  ;; that case the declaration
                                  ;; should contain a block.
-                                 (c-in-knr-argdecl))))))
+                                 (c-in-knr-argdecl)))))))

        (cond
-        ((= (point) kluge-start)       ; might be BOB or unbalanced parens.
+        ((or (eq decl-result 'label)   ; e.g. "private:" or invalid syntax.
+             (= (point) kluge-start))  ; might be BOB or unbalanced parens.
          'outwith-function)
         ((eq decl-result 'same)
          (if brace-decl-p


I think this should fix the problem.  Would you please test it with
`mark-defun' and confirm it works properly.  Thanks!

Incidentally, `c-mark-function' (the default binding for C-M-h in CC Mode)
doesn't do the right thing here.  I'll be looking into this.

> Ideally it would give no error, and IMO, it should mark fun(), though
> marking the class would be fine as well.

It marks the class, since it gives priority to defuns point is in, rather
than those which follow point.  There might be scope for some improvement
here.

Thanks for taking the trouble to distil the problem down to a nice, very
short piece of code, and for describing the problem so helpfully.

> -Ivan

-- 
Alan Mackenzie (Nuremberg, Germany).






  parent reply	other threads:[~2014-11-22 22:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 22:01 bug#19134: 24.4.51; Error using mark-defun in c++-mode Ivan Andrus
     [not found] ` <mailman.14214.1416532702.1147.bug-gnu-emacs@gnu.org>
2014-11-22 22:04   ` Alan Mackenzie [this message]
2014-11-25  3:00     ` Ivan Andrus

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=20141122220413.75395.qmail@mail.muc.de \
    --to=acm@muc.de \
    --cc=19134@debbugs.gnu.org \
    --cc=darthandrus@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).