From: Ivan Andrus <darthandrus@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: 19134@debbugs.gnu.org
Subject: bug#19134: 24.4.51; Error using mark-defun in c++-mode
Date: Mon, 24 Nov 2014 20:00:36 -0700 [thread overview]
Message-ID: <9D48252F-D43B-44BA-A698-6C6C14E373BC@gmail.com> (raw)
In-Reply-To: <20141122220413.75395.qmail@mail.muc.de>
On Nov 22, 2014, at 3:04 PM, Alan Mackenzie <acm@muc.de> wrote:
> 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!
Yes, I confirm that it works.
> 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.
I didn’t notice that. I have C-M-h bound to a wrapper around mark-defun in my .emacs, so I don’t actually run c-mark-function. Thanks for pointing me to it.
>> 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.
That’s fine. It could probably be better but, hey, what couldn’t? :-)
> 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.
And thank you for the very fast fix. I should have taken the time a while since I have run into it occasionally.
-Ivan
prev parent reply other threads:[~2014-11-25 3:00 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
2014-11-25 3:00 ` Ivan Andrus [this message]
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=9D48252F-D43B-44BA-A698-6C6C14E373BC@gmail.com \
--to=darthandrus@gmail.com \
--cc=19134@debbugs.gnu.org \
--cc=acm@muc.de \
/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.