C function exploration



  • Hello guys, one quick question (once I didn’t find it using the search functionality):
    I have a C code with lots of functions with big bodies among them. I make usage of the function list to switch from one to the other, but once the body of each of them is big (as i foresaid) I was wondering if any plugin exists which does the following: from wherever point I am within the body of the fuction to be able to go to the start/definition of the fuction. Or at least to understand in which Function I currently am, witout being necessary to go to the definition/start of function.
    Thanks guys.



  • @Telis-Tnilit

    So it would be nice if the Function List would dynamically highlight the function the caret is in as the caret is moved. Sadly, it does not do this…

    I don’t see any reason that this behavior couldn’t be scripted using one of the plugins (Pythonscript / Luascript) but you’d probably want to define it more.

    • How would you want to be shown what function you are currently in? Examples include: dynamically on status bar, on-demand MessageBox, etc.

    • Is it sufficient that the name of the C function appears one line above an opening brace { and that brace always appears in column 1 (and the closing brace } also always appears in column 1)?



  • @Telis-Tnilit

    Try out the TagsView plug-in. It highlights the current function and allows you to easily navigate to function definitions and more.



  • @Telis-Tnilit

    So…not sure if the TagsView plug-in met your need, but I modified something I already had scripted (in Pythonscript) to do what you want , albeit in a basic way: The script needs to see the enclosing C function braces ( { and } ) in column 1, and when it does it takes the single line above the { as the function signature.

    So for a C function like this:

    void test2(void)
    {
        x = 1;
    
        if (1)
        {
            x = 2;
        }
    }
    

    when the caret is inside the function body, the status bar will show this:

    Imgur

    I call the script CFunctionShowInStatusBar.py :

    def CFSISB__callback_sci_UPDATEUI(args):
        def sb_print(x):
            if len(x) == 0: x = ' '  # writing '' to status bar does nothing, so change it!
            notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, x)
        if notepad.getCurrentFilename().lower().endswith('.c'):
            f = editor.findText(FINDOPTION.REGEXP, editor.getCurrentPos(), 0, '^[{}]')
            if f != None:
                (found_start_pos, found_end_pos) = f
                if '{' == editor.getTextRange(found_start_pos, found_end_pos):
                    line_nbr = editor.lineFromPosition(found_start_pos)
                    if line_nbr == 0:
                        sb_print('not in function?')
                    else:
                        sb_print('in function: ' + editor.getLine(line_nbr - 1).rstrip())
                else:
                    sb_print('not in function')
            else:
                sb_print('not in function!')
        else:
            sb_print('')
    
    editor.callback(CFSISB__callback_sci_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])```

Log in to reply