On 15/03/10 10:39, mobi phil wrote:
I think what Antony wanted to say is: What do you understand by 'a
function'? How can it be identified in text?

IMHO a function is such a highly language-dependent construct that a
definition for a corresponding text object can not be easily described
by a single flag or even some parameters and that it is best put inside
a filetype plugin where you can make use of Vim's scripting language,
e.g., by defining expressions for start and end of a function or for the
whole body.

Regards,
Jürgen

Sorry... Indeed Antony wrote "define". It seems that I wanted so much
not to read that "write a function" :)

Vim is and was primarily c and c++ programmers editor, and lots of
features are tuned for c.

* Without going deep into c's (or C++'s) grammar I think by starting
backwards to search for an opening "{" that has no ";" before it.
* The statement before it can be only a function definition or
while/for/if/switch statement. If we found a statement keep going
backwards.
* If we found a function header we do our best to find the full header
(ret type, name , formal params)
* After the opening "{" was found, use existing algo to find its pair.

Such an algo should work with C, C++, java, php, javascript, etc. etc.


So.. nobody moves functions around? Just reordering time to time,
based on logical groups etc... would make sense... and with such a
selection tool, job would be easier :)

rgrds,
mobi phil

being mobile, but including technology
http://mobiphil.com


Well, OK, so let's take a look at a typical function. It starts like this:

---8<---

/*
 * Version of strchr() and strrchr() that handle unsigned char strings
 * with characters from 128 to 255 correctly.  It also doesn't return a
 * pointer to the NUL at the end of the string.
 */
    char_u  *
vim_strchr(string, c)
    char_u      *string;
    int         c;
{
    char_u      *p;
    int         b;

    p = string;
#ifdef FEAT_MBYTE
    if (enc_utf8 && c >= 0x80)
    {
--->8---
etc.

Of course you would want to include the type declaration "char_u *" which is on a different line, and the comment before that. (Vim source, src/misc2.c lines 1795 sqq.). Notice that the starting brace of the function body _is_ preceded by a semicolon, while the true-block of the if inside the #ifdef isn't. (See also at the end of ":help style-examples".)

I think this should be handled by ad-hoc vimscript, probably as an operator-pending mapping with an <expr> argument calling a function.


Best regards,
Tony.
--
"Apathy is not the problem, it's the solution"

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui