home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / emacs / help / 3431 < prev    next >
Encoding:
Text File  |  1992-07-21  |  1.4 KB  |  51 lines

  1. Path: sparky!uunet!olivea!decwrl!elroy.jpl.nasa.gov!ucla-cs!twinsun!usenet
  2. From: sdk@shadow.twinsun.com (Scott D Kalter)
  3. Newsgroups: gnu.emacs.help
  4. Subject: Re: question on universal-argument or C-u
  5. Message-ID: <biNj#doJ@twinsun.com>
  6. Date: 21 Jul 92 16:14:34 GMT
  7. References: <1992Jul16.193150.5172@Warren.MENTORG.COM>
  8. Sender: usenet@twinsun.com
  9. Organization: Twin Sun, Inc.
  10. Lines: 37
  11. In-Reply-To: sharma@euler.Warren.MENTORG.COM's message of Thu, 16 Jul 1992 19:31:50 GMT
  12. Nntp-Posting-Host: shadow
  13.  
  14. In article <1992Jul16.193150.5172@Warren.MENTORG.COM> sharma@euler.Warren.MENTORG.COM (Sharma Kunapalli) writes:
  15.  
  16. -> I have defined rathed defun'ed :-) a function in
  17. -> emacs lisp. Call that function f. Now I want to
  18. -> write another function which will call this function
  19. -> a certain number of times equal to the number of lines 
  20. -> in the buffer. 
  21. -> 
  22. -> (defun f ()
  23. ->   (re-search-forward "^#" nil)
  24. ->   (beginning-of-line)
  25. ->   (kill-line)
  26. ->   (kill-line))
  27. -> 
  28. -> (defun my-rep ()
  29. ->    (interactive)
  30. ->    (universal-argument 4 (next-line)))
  31. -> 
  32.  
  33. First, a reasonable way of finding the number of lines in a buffer is:
  34.  
  35. (count-lines (point-min) (point-max))
  36.  
  37. Second, a reasonable way of attacking the original problem (assuming
  38. the intent is to remove all lines starting with '#' from a buffer) is
  39. to use the regular expression facilities in emacs:
  40.  
  41. (defun f ()
  42.   (save-excursion
  43.     (goto-char (point-min))
  44.     (replace-regexp "^#.*\n" "")))    
  45.  
  46.  
  47.  
  48. Hope this helps,
  49.  
  50. -sdk
  51.