Subject: bug#29083: CC Mode 5.32.99 (C/l); M-x c-defun-mode doesn't show anything

From: Felip Moll <[email-masked]>
Date: Tue, 31 Oct 2017 18:54:01 +0100

Hi Alan,

This is great. It works and I understand the issue.

Just to know, is there any plan to change it to non-interactive and
provide such an interactive command in CC Mode?

BR
Felip M

--
Felip Moll Marquès
Computer Science Engineer
E-Mail - [email-masked]
WebPage - http://lipix.ciutadella.es

2017-10-31 18:38 GMT+01:00 Alan Mackenzie <[email-masked]>:
> Hello, Felip.
>
> On Tue, Oct 31, 2017 at 13:43:43 +0100, Felip Moll wrote:
>> When inspecting a C code file, I pressed M-x c-defun-mode in order emacs
>> to show me in which function I was, but nothing happened.
>
> Yes, thanks for the report.
>
> The bug here seems to be that c-defun-mode is interactive, when it
> merely returns the function name rather than displaying it.  You really
> need a function calling c-defun-name, which then displays it.  Here is
> what I use.  You're welcome to adapt it to do what you need:
>
> (eval-after-load "cc-mode"
>   '(progn
>      (defun c-display-defun-name (&optional arg)
>        "Display the name of the current CC mode defun and the position in it.
> With a prefix arg, push the name onto the kill ring too."
>        (interactive "P")
>        (save-restriction
>          (widen)
>          (c-save-buffer-state ((name (c-defun-name))
>                                (limits (c-declaration-limits t))
>                                (point-bol (c-point 'bol)))
>            (when name
>              (message "%s.  Line %s/%s." name
>                       (1+ (count-lines (car limits) point-bol))
>                       (count-lines (car limits) (cdr limits)))
>              (if arg (kill-new name))
>              (sit-for 3 t)))))
>      (define-key c-mode-base-map "\C-cn" 'c-display-defun-name)
>      (put 'c-display-defun-name 'isearch-scroll t)))
>
> [ Version information an CC Mode dump snipped, but appreciated. ]
>
> --
> Alan Mackenzie (Nuremberg, Germany).