home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / emacs / 3846 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.4 KB  |  70 lines

  1. Path: sparky!uunet!mcsun!Germany.EU.net!Informatik.Uni-Dortmund.DE!fbi-news!grossjoh
  2. From: grossjoh@linus.ls6.informatik.uni-dortmund.de (Kai Grossjohann)
  3. Newsgroups: comp.emacs
  4. Subject: Re: help on searching for function name
  5. Date: 22 Dec 92 11:28:41
  6. Organization: Universitaet Dortmund, Lehrstuhl Informatik VI
  7. Lines: 56
  8. Message-ID: <GROSSJOH.92Dec22112841@linus.ls6.informatik.uni-dortmund.de>
  9. References: <1992Dec10.161319.7660@cbfsb.cb.att.com>
  10. Reply-To: Kai Grossjohann <grossjoh@ls6.informatik.uni-dortmund.de>
  11. NNTP-Posting-Host: linus.informatik.uni-dortmund.de
  12. In-reply-to: elton@cbnewsb.cb.att.com's message of Thu, 10 Dec 1992 16:13:19 GMT
  13.  
  14. >>>>> On Thu, 10 Dec 1992 16:13:19 GMT,
  15. >>>>> elton@cbnewsb.cb.att.com (elton.huang) said:
  16.  
  17.  
  18. > Dear Folks,
  19.  
  20. > I would like to have something like that in emacs, my cursor is somewhere
  21. > in a C file I am editing but since the nae of the function that the 
  22. > cursor is in can not be shown unless I scroll up though sometime it's
  23. > long, I hope I can press a key and the name of the function can be shown
  24. > in the mini-buffer.
  25.  
  26. > I have to know how to do searches and regular expression in elisp. The
  27. > algorithm I have in mind is 
  28.  
  29. > search backward for "^{" and on success,
  30. > search backward for "(" and on success,
  31. > print out the word immediate before "(" found.
  32.  
  33. > Would some kind soul knowing how to do this give me a solution or a hint ?
  34. > Thanks in advance,
  35.  
  36. > Elton
  37.  
  38. (defun c-display-function-name ()
  39.   "your own documentation goes here"
  40.   (interactive)
  41.   (save-excursion
  42.     (if (re-search-backward "^{" (point-min) t)
  43.     (if (re-search-backward "(" (point-min) t)
  44.         (progn
  45.           (backward-word 1)
  46.           (mark-word 1)
  47.           (message (buffer-substring (region-beginning) (region-end)))
  48.           (sit-for 2) ))))
  49.   ) ; defun
  50.  
  51. You need to bind this to a key, of course.
  52.  
  53. Minimal testing has been done on this. It works as it should. However, I'm not
  54. so sure that this is what you really want, because it depends on the fact that
  55. the beginning opening brace of a C function is always on the beginning of a
  56. line, and that no other opening brace is on the beginning of any line. Maybe
  57. we should use something like backward-sexp? I'll leave that to you to think
  58. about.
  59.  
  60. Good luck,
  61.  
  62.         Kai
  63.  
  64.  
  65. --
  66.   Kai Grossjohann            Phone (voice): 49 231 75 30 15
  67.   Baroper Str. 331 App. 510  E-Mail: 
  68.   W-4600 Dortmund 50         grossjoh@ls6.informatik.uni-dortmund.de
  69.   Germany                   
  70.