home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!uwm.edu!caen!uflorida!travis!shirono
- From: shirono@ssd.csd.harris.com (Roberto Shironoshita)
- Newsgroups: gnu.emacs.help
- Subject: Re: adding new functions
- Message-ID: <SHIRONO.92Jul23180947@gcx1.ssd.csd.harris.com>
- Date: 23 Jul 92 23:09:47 GMT
- Article-I.D.: gcx1.SHIRONO.92Jul23180947
- References: <Jul23.203033.61716@yuma.ACNS.ColoState.EDU>
- Sender: news@travis.csd.harris.com
- Reply-To: shirono@ssd.csd.harris.com
- Distribution: gnu
- Organization: Harris Computer Systems
- Lines: 62
- In-reply-to: ryanr@lamar.ColoState.EDU's message of 23 Jul 92 20:30:33 GMT
-
- In article <Jul23.203033.61716@yuma.ACNS.ColoState.EDU> ryanr@lamar.ColoState.EDU (Richard Ryan) writes:
-
- > I'm trying to figure out add a new function.
- > I tried putting the following in a file I've loaded
- > with load-file and I've also tried putting it in
- > the .emacs file.
- > (defun gt-indent-region ()
- > (shell-command-on-region 4 "sed -e '/^\(.\)/s//> \1/'"))
- >
- > Although I'm not very certain this would work, I can't even
- > try it out if I can't load it. When I try executing it after
- > loading the file it's in I get a "No match" message. I've
- > looked in the FAQ's, but I couldn't find this question there.
- > Funny, it seemed like an FAQ kind of thing to me.
-
- It sounds as if you are trying to make an interactive function. To do so,
- the body of the function must call the "interactive" function:
-
- (defun gt-indent-region ()
- (interactive)
-
- Furthermore, on-line help for shell-command-on-region says:
-
- Noninteractive args are START, END, COMMAND, FLAG.
- Noninteractively FLAG means insert output in place of text from START
- to END, and put point at the end, but don't alter the mark.
-
- So, your call is missing a couple of arguments.
-
- Another problem exists with your command string. Backslash (\) inside
- strings mean something to GNU Emacs lisp, so you can't just do what you
- did. What you need is something like:
-
- "sed -e '/^\\(.\\)/s//> \\1/'"
-
- > Also, what I'm trying to do with this command is put a "> "
- > in the left margin. If you've got a better function, please
- > send me a copy.
-
- There is no need to call on sed to do this. The following function does
- the change you want in place.
-
- (defun gt-indent-region (start end)
- (interactive "r")
- (save-excursion
- (push-mark end t)
- (let ((em (mark-marker)))
- (goto-char start)
- (if (looking-at "^.")
- (insert "> "))
- (while (and (= 0 (forward-line 1))
- (<= (point) (marker-position em)))
- (if (looking-at "^.")
- (insert "> "))))))
- --
-
- Roberto Shironoshita || Internet: shirono@ssd.csd.harris.com
- Harris Corporation ||
- Computer Systems Division || UUCP: ...!uunet!ssd.csd.harris.com!shirono
- ||
- DISCLAIMER: The opinions expressed here are my own; they in no way reflect the
- opinion or policies of Harris Corporation.
-