PHP #region for code folding?

前端 未结 15 1581
星月不相逢
星月不相逢 2021-01-31 14:06

Is there an equivilent of c#\'s #region in PHP?

15条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 15:01

    In Sublime Text there's a package called SyntaxFold.

    Installation

    1. Ctrl+Shift+P type install and select Package Control: Install Package;
    2. In the new menu type SyntaxFold, begin the download and installation by selecting it;
    3. Check on the status bar below if it was installed correctly.

    Configuration

    1. Press Shift+F5 to pop-up the fold panel and select Add Another to accesss the config file;
    2. Ensure that it has a default with the strings you want (for some odd reason mine had a quote before the hash: '#Start). I ended up changing it to:

      {
          //you can change in here other config options
          "default":
          {
              "endMarker": "#EOB",
              "name": "Default",
              "startMarker": "#BOB"
          }
      }
      
    3. You can also alter the key bindings (the ones below in the Usage section) on Windows by changing them in the file:

      C:\Users\YOUR_USER\AppData\Roaming\Sublime Text 3\Packages\SyntaxFold\Default (Windows).sublime-keymap

    Usage

    1. Add the enclosing tags you defined in the config file (you can add a description after each tag), in my case:

      #BOB pandora box
      public function alpha()
      {
          # code...
      }
      public function omega()
      {
          # code...
      }
      #EOB pandora box
      
    2. To hide the code between the tags, place the cursor between them and press Alt+1 twice.
    3. To show it again, place the cursor on the first tag and press Alt+Shift+1 twice.

    Alternative for Comment blocks

    If you are just interested in folding comment blocks then with Fold Comments package you can press Ctrl+Shift+C to hide and show all comments (it may hide tags of SyntaxFold though).

提交回复
热议问题