Community
    • Login

    C function exploration

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 2.2k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Telis TnilitT Offline
      Telis Tnilit
      last edited by

      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.

      Scott SumnerS 2 Replies Last reply Reply Quote 1
      • Scott SumnerS Offline
        Scott Sumner @Telis Tnilit
        last edited by

        @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)?

        1 Reply Last reply Reply Quote 0
        • Jim DaileyJ Offline
          Jim Dailey
          last edited by

          @Telis-Tnilit

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

          1 Reply Last reply Reply Quote 2
          • Scott SumnerS Offline
            Scott Sumner @Telis Tnilit
            last edited by

            @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])```
            1 Reply Last reply Reply Quote 1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors