[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: which-function => DEFUN?
From: |
Lennart Borgman |
Subject: |
Re: which-function => DEFUN? |
Date: |
Mon, 10 May 2010 16:39:13 +0200 |
On Mon, May 10, 2010 at 4:22 PM, Juanma Barranquero <address@hidden> wrote:
> On Mon, May 10, 2010 at 15:58, Lennart Borgman
> <address@hidden> wrote:
>
>> It is a bit annoying to see DEFUN as the function shown by
>> which-function-mode.
>>
>> I am sure someone here has written an
>> imenu-extract-index-name-function for use in Emacs C sources... ;-)
>
> (defun which-func-identify-DEFUN ()
> (save-excursion
> (save-match-data
> (beginning-of-defun)
> (and (looking-at "DEFUN +(\"[^\"]+\",[ \n]+\\(F[^,]+\\),")
> (match-string-no-properties 1)))))
>
> Likely the `save-match-data' is not required, but I tend to err on the
> side of saving it on my code.
>
>> Where is it? How do you set it up?
>
> (add-hook 'which-func-functions 'which-func-identify-DEFUN nil t)
>
> on the required buffers (I set it through `c-mode-hook').
Thanks Juanma, here is my slightly modified version built from your version:
(defun my-which-func-identify-DEFUN ()
(let ((here (point)))
(save-match-data
;; Check if we are at the beginning of the function already
(unless (eobp) (forward-char))
(beginning-of-defun)
(when (< here (point)) (beginning-of-defun))
(prog1
(and (looking-at "DEFUN +(\"[^\"]+\",[ \n]+\\(F[^,]+\\),")
(match-string-no-properties 1))
(goto-char here)))))
(defun my-add-DEFUN ()
(add-hook 'which-func-functions 'my-which-func-identify-DEFUN nil t))
(add-hook 'c-mode-hook 'my-add-DEFUN)
- which-function => DEFUN?, Lennart Borgman, 2010/05/10
- Re: which-function => DEFUN?, Stefan Monnier, 2010/05/10
- Re: which-function => DEFUN?, Juanma Barranquero, 2010/05/10
- Global match data considered harmful, Stephen J. Turnbull, 2010/05/10
- Re: Global match data considered harmful, Stefan Monnier, 2010/05/11
- Re: Global match data considered harmful, Stephen J. Turnbull, 2010/05/11