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

  1. Path: sparky!uunet!ogicse!uwm.edu!caen!uflorida!travis!shirono
  2. From: shirono@ssd.csd.harris.com (Roberto Shironoshita)
  3. Newsgroups: gnu.emacs.help
  4. Subject: Re: adding new functions
  5. Message-ID: <SHIRONO.92Jul23180947@gcx1.ssd.csd.harris.com>
  6. Date: 23 Jul 92 23:09:47 GMT
  7. Article-I.D.: gcx1.SHIRONO.92Jul23180947
  8. References: <Jul23.203033.61716@yuma.ACNS.ColoState.EDU>
  9. Sender: news@travis.csd.harris.com
  10. Reply-To: shirono@ssd.csd.harris.com
  11. Distribution: gnu
  12. Organization: Harris Computer Systems
  13. Lines: 62
  14. In-reply-to: ryanr@lamar.ColoState.EDU's message of 23 Jul 92 20:30:33 GMT
  15.  
  16. In article <Jul23.203033.61716@yuma.ACNS.ColoState.EDU> ryanr@lamar.ColoState.EDU (Richard Ryan) writes:
  17.  
  18. > I'm trying to figure out add a new  function.
  19. > I tried putting the following in a file I've loaded
  20. > with load-file and I've also tried putting it in
  21. > the .emacs file.
  22. > (defun gt-indent-region ()
  23. >   (shell-command-on-region 4 "sed -e '/^\(.\)/s//> \1/'"))
  24. >
  25. > Although I'm not very certain this would work, I can't even
  26. > try it out if I can't load it.  When I try executing it after
  27. > loading the file it's in I get a "No match" message.  I've
  28. > looked in the FAQ's, but I couldn't find this question there.
  29. > Funny, it seemed like an FAQ kind of thing to me.
  30.  
  31. It sounds as if you are trying to make an interactive function.  To do so,
  32. the body of the function must call the "interactive" function:
  33.  
  34.     (defun gt-indent-region ()
  35.       (interactive)
  36.  
  37. Furthermore, on-line help for shell-command-on-region says:
  38.  
  39.     Noninteractive args are START, END, COMMAND, FLAG.
  40.     Noninteractively FLAG means insert output in place of text from START
  41.     to END, and put point at the end, but don't alter the mark.
  42.  
  43. So, your call is missing a couple of arguments.
  44.  
  45. Another problem exists with your command string.  Backslash (\) inside
  46. strings mean something to GNU Emacs lisp, so you can't just do what you
  47. did.  What you need is something like:
  48.  
  49.     "sed -e '/^\\(.\\)/s//> \\1/'"
  50.  
  51. > Also, what I'm trying to do with this command is put a "> "
  52. > in the left margin.  If you've got a better function, please
  53. > send me a copy.
  54.  
  55. There is no need to call on sed to do this.  The following function does
  56. the change you want in place.
  57.  
  58.     (defun gt-indent-region (start end)
  59.       (interactive "r")
  60.       (save-excursion
  61.         (push-mark end t)
  62.         (let ((em (mark-marker)))
  63.           (goto-char start)
  64.           (if (looking-at "^.")
  65.           (insert "> "))
  66.           (while (and (= 0 (forward-line 1))
  67.               (<= (point) (marker-position em)))
  68.         (if (looking-at "^.")
  69.             (insert "> "))))))
  70. --
  71.  
  72.      Roberto Shironoshita      ||   Internet: shirono@ssd.csd.harris.com
  73.       Harris Corporation       ||
  74.    Computer Systems Division   ||   UUCP: ...!uunet!ssd.csd.harris.com!shirono
  75.                                ||
  76. DISCLAIMER: The opinions expressed here are my own; they in no way reflect the
  77.             opinion or policies of Harris Corporation.
  78.