omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Comment/Uncomment block of lines

    Pythonista
    4
    6
    5449
    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.
    • regrunger
      regrunger last edited by

      I am a new user and I can not find a way to comment/uncomment the selected block of code.
      I use Pythonista v.3.2 on iPad

      Could anybody help me to find this option in UI or suggest a solution to fix this moment because each line commenting is very uncomfortable for me?

      1 Reply Last reply Reply Quote 0
      • pulbrich
        pulbrich last edited by

        Put the following code to your sites packages folder and create a shortcut under the wrench tool.

        
        #Comment/Uncomment selected lines
        
        import editor
        
        text = editor.get_text()
        selection = editor.get_line_selection()
        selected_text = text[selection[0]:selection[1]]
        is_comment = selected_text.strip().startswith('#')
        replacement = ''
        for line in selected_text.splitlines():
            if is_comment:
                if line.strip().startswith('#'):
                    replacement += line[line.find('#') + 1:] + '\n'
                else:
                    replacement += line + '\n'
            else:
                replacement += '#' + line + '\n'
        
        editor.replace_text(selection[0], selection[1], replacement)
        editor.set_selection(selection[0], selection[0] + len(replacement) - 1)
        
        
        1 Reply Last reply Reply Quote 4
        • cvp
          cvp last edited by

          You can also put a line with 3 quotes above and under these lines

          '''
          these 
          lines 
          are 
          commented
          ''' 
          
          1 Reply Last reply Reply Quote 3
          • regrunger
            regrunger last edited by

            Thank you for the help!

            1 Reply Last reply Reply Quote 0
            • Ivan_OE
              Ivan_OE last edited by

              A big THANK to you pulbrich :)

              1 Reply Last reply Reply Quote 0
              • pulbrich
                pulbrich last edited by

                @Ivan_OE I didn’t write this code, only use it. But I am happy if it helped.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors