Loading ...
Sorry, an error occurred while loading the content.

RE: Function question

Expand Messages
  • Sean C. Hubbell
    Great! Thank you very much. Sean
    Message 1 of 4 , Dec 1, 2004
    • 0 Attachment
      Great! Thank you very much.

      Sean

      > -----Original Message-----
      > From: Jürgen Krämer [mailto:jkr@...]
      > Sent: Wednesday, December 01, 2004 10:19 AM
      > To: vim mailing list
      > Subject: Re: Function question
      >
      >
      >
      > Hi,
      >
      > Sean C. Hubbell schrieb:
      > >
      > > I was wondering if I could get some advice. I created a function and I
      > > have two issues. The first issue is when I print to the screen my
      > > LineComment variable, I always get a new line after echoing the
      > LineComment
      > > using the following function:
      > >
      > > function TFunc(num1, num2, ...)
      > > let Tab = " "
      > >
      > > " let LineComment =
      > >
      > "/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
      > \*\*\*\*\*
      > >
      > \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
      > \*\*\*\*\*
      > > \*\*\*/"
      > > let LineComment =
      > >
      > "\/***************************************************************
      > **********
      > > *****/"
      >
      > that's because LineComment contains exactly 80 character and 80 is
      > probably the width of your VIM window. After echoing <width of window>
      > characters VIM enters the next line so that an additional 81st character
      > would have been put at the beginning of the nex line. (If you append
      > "123" to LineComment you will see that "123" will start a new line and
      > that there is no additional empty line.) The value of the wrap option
      > is of no relevance here.
      >
      > > "let LineComment = "/\*\*/"
      > > echo LineComment
      > > echo a:num1 a:num2
      > > echo LineComment
      > > echo Tab "{"
      > > echo Tab "/* ."
      > > echo
      > > echo Tab Tab "History:"
      > > echo Tab Tab Tab expand (strftime("%d %b %y")) "- Created. SCHubbell"
      > > echo Tab "*/"
      > > echo Tab "} /* " a:num2 " */"
      > > endfunction
      > >
      > >
      > > If I assign LineComment to the following:
      > >
      > > let LineComment = "/\*\*/"
      > >
      > > I do not get a new line at the end. I checked to see if I had
      > wrap set but I
      > > do not. Does anyone have an idea?
      > >
      > > Next, I get all of this printed to the screen, but what I
      > really want is
      > > the best way to insert the text generated by my function into
      > the current
      > > line that the cursor is on? Do I need to set the function to write to a
      > > buffer and then paste the buffer?
      >
      > You can return the text as the result of your function
      >
      > function TFunc(num1, num2, ...)
      > let Tab = " "
      > let LineComment =
      > "/****************************************************************
      > **************/"
      >
      > let res = ''
      >
      > let res = res . LineComment
      > let res = res . a:num1 a:num2
      > let res = res . LineComment
      > let res = res . Tab "{"
      > let res = res . Tab "/* ."
      > let res = res .
      > let res = res . Tab Tab "History:"
      > let res = res . Tab Tab Tab expand (strftime("%d %b %y")) "-
      > Created. SCHubbell"
      > let res = res . Tab "*/"
      > let res = res . Tab "} /* " a:num2 " */"
      >
      > return res
      > endfunction
      >
      > and insert it into your buffer by calling the function through :put
      >
      > :put =TFunc('void', 'print()')
      >
      > Note the equal sign which denotes the expression register. Everything
      > on the right side of the equal sign is considered as an expression and
      > its value is returned and then inserted by :put.
      >
      > Regards,
      > Jürgen
      >
      > --
      > Jürgen Krämer Softwareentwicklung
      > Habel GmbH mailto:jkr@...
      > Hinteres Öschle 2 Tel: (0 74 61) 93 53 - 15
      > 78604 Rietheim-Weilheim Fax: (0 74 61) 93 53 - 99
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.