Article View: comp.emacs
Article #3262Re: help on searching for function name
From: Kai Grossjohann
Date: Tue, 22 Dec 1992 11:28
Date: Tue, 22 Dec 1992 11:28
56 lines
2512 bytes
2512 bytes
>>>>> On Thu, 10 Dec 1992 16:13:19 GMT,
>>>>> elton@cbnewsb.cb.att.com (elton.huang) said:
> Dear Folks,
> I would like to have something like that in emacs, my cursor is somewhere
> in a C file I am editing but since the nae of the function that the
> cursor is in can not be shown unless I scroll up though sometime it's
> long, I hope I can press a key and the name of the function can be shown
> in the mini-buffer.
> I have to know how to do searches and regular expression in elisp. The
> algorithm I have in mind is
> search backward for "^{" and on success,
> search backward for "(" and on success,
> print out the word immediate before "(" found.
> Would some kind soul knowing how to do this give me a solution or a hint ?
> Thanks in advance,
> Elton
(defun c-display-function-name ()
"your own documentation goes here"
(interactive)
(save-excursion
(if (re-search-backward "^{" (point-min) t)
(if (re-search-backward "(" (point-min) t)
(progn
(backward-word 1)
(mark-word 1)
(message (buffer-substring (region-beginning) (region-end)))
(sit-for 2) ))))
) ; defun
You need to bind this to a key, of course.
Minimal testing has been done on this. It works as it should. However, I'm not
so sure that this is what you really want, because it depends on the fact that
the beginning opening brace of a C function is always on the beginning of a
line, and that no other opening brace is on the beginning of any line. Maybe
we should use something like backward-sexp? I'll leave that to you to think
about.
Good luck,
Kai
--
Kai Grossjohann Phone (voice): 49 231 75 30 15
Baroper Str. 331 App. 510 E-Mail:
W-4600 Dortmund 50 grossjoh@ls6.informatik.uni-dortmund.de
Germany
Technical Details
Message-ID:
<GROSSJOH.92Dec22112841@linus.ls6.informatik.uni-dortmund.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!Informatik.Uni-Dortmund.DE!fbi-news!grossjohReferences:
<1992Dec10.161319.7660@cbfsb.cb.att.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!Informatik.Uni-Dortmund.DE!fbi-news!grossjoh From: grossjoh@linus.ls6.informatik.uni-dortmund.de (Kai Grossjohann) Newsgroups: comp.emacs Subject: Re: help on searching for function name Date: 22 Dec 92 11:28:41 Organization: Universitaet Dortmund, Lehrstuhl Informatik VI Lines: 56 Message-ID: <GROSSJOH.92Dec22112841@linus.ls6.informatik.uni-dortmund.de> References: <1992Dec10.161319.7660@cbfsb.cb.att.com> Reply-To: Kai Grossjohann <grossjoh@ls6.informatik.uni-dortmund.de> NNTP-Posting-Host: linus.informatik.uni-dortmund.de In-reply-to: elton@cbnewsb.cb.att.com's message of Thu, 10 Dec 1992 16:13:19 GMT