- Subject: Re: How do I get text from the buffer? SLang?
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Mon, 27 Sep 2004 21:40:07 -0400
jeremy@xxxxxxxxxx <jeremy@xxxxxxxxxx> wrote:
>define change_name()
>{
> variable fname, lname, bvcd_line;
>
> !if (bsearch("BEGIN:VCARD")) { beep; return; }
> bvcd_line = what_line ();
>
> % ===
> % Find the N:John;Doe; line
> !if (fsearch("N:")) { add_name(); return; }
The above search did not find "N:John;Doe;". It found "N:VCARD". You
will need add "eol();" to skip to the end of the "BEGIN:VCARD" line.
> % Get the First Name
> right(2); push_mark();
The "right" function returns a value that you are leaving on the
stack. Use
go_right(2);
if you want a version that does not return a value.
> !if (fsearch(";")) { add_name(); return; }
> fname = bufsubstr (); pop_mark ();
>
> right(1); push_mark();
>
> % Get the Last Name
> !if (fsearch(";")) { return; }
If the ';' must be on the current line and not on some other line,
then you should use the ffind function, which does not cross lines:
!if (ffind (";")) return;
> lname = bufsubstr (); pop_mark ();
The bufsubstr function implicitly calls "pop_mark". You do not
want to use it here.
> % ===
> % Read the new first/last name
> fname = read_mini("First Name:", fname, "");
> lname = read_mini("Last Name:", lname, "");
>
> % ===
> % Delete old, insert new
>
> % Handle FN: line
> goto_line (bvcd_line);
> () = fsearch("FN:");
Since you want "FN:" to occur at the beginning of a line, I would
use the bol_fsearch function.
> bol (); push_mark ();
> eol (); del_region (); pop_mark ();
You do not want to use pop_mark here since del_region performs this
function. In fact, all functions that operate on regions pop the
mark. In fact, the above can be replaced by
bol ();
del_eol ();
> insert("FN:"+fname+" "+lname);
You might want to consider:
vinsert ("FN:%s %s", fname, lname);
> % Handle N: line
> goto_line (bvcd_line);
> () = fsearch("N:");
Use: ()=bol_fsearch ("N:");
> bol (); push_mark ();
> eol (); del_region (); pop_mark ();
> insert("N:"+fname+";"+lname);
Same comments apply here.
I hope this helps.
--John
--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.
[2004 date index]
[2004 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]