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

From: Alan Mackenzie <[email-masked]>
Date: Tue, 31 Oct 2017 17:38:24 +0000

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).