• Login
Community
  • Login

C function exploration

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 1.9k Views
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.
  • T
    Telis Tnilit
    last edited by Dec 26, 2017, 12:08 PM

    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.

    S 2 Replies Last reply Dec 26, 2017, 1:14 PM Reply Quote 1
    • S
      Scott Sumner @Telis Tnilit
      last edited by Dec 26, 2017, 1:14 PM

      @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
      • J
        Jim Dailey
        last edited by Dec 26, 2017, 5:20 PM

        @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
        • S
          Scott Sumner @Telis Tnilit
          last edited by Dec 30, 2017, 2:49 AM

          @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
          1 out of 4
          • First post
            1/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors