Tapatalk

How to customize auto-indent in PHP files?

How to customize auto-indent in PHP files?

5

    Feb 27, 2013#1

    Hi!

    I'm editing a PHP file and have several blocks I want indented.

    At the beginning, I enter the <p> tag and when I go to the end of the line I enter closing </p> tag, but when I hit the / key, the whole line unindents by one tab stop. What gives?

    6,685587
    Grand MasterGrand Master
    6,685587

      Feb 27, 2013#2

      Files with the file extension PHP are by default highlighted by UltraEdit as multi-language HTML file. HTML sections are highlighted with the wordfile html.uew stored in directory you can see at Advanced - Configuration - Editor Display - Syntax Highlighting. In this dialog you can also select the syntax highlighting language and open the wordfile of this language with button Open. A CSS section is highlighted with css.uew, a Javascript section with javascript.uew and a PHP section with php.uew. The status bar at bottom of the UltraEdit main window displays in a box which syntax highlighting language is active at position of the caret. For more details see Multi-language syntax highlighting for HTML files.

      If you open html.uew, you most likely see in html.uew following 2 lines:

      /Indent Strings = "<"
      /Unindent Strings = "</"


      So with the auto-indent feature enabled the current line is unindented when </ is entered and if < is entered in a line and key RETURN is hit, the next line is indented by 1 indent value (1 tab if not configured different).

      In a PHP section php.uew is active which contains:

      /Open Fold Strings = "{"
      /Close Fold Strings = "}"


      You can define multiple indent/unindent strings in double quotes. So you can fine tune on which strings an automatic indent on next line should occur and on which strings an automatic unindent of the current line. Of course you can also turn off auto-indent feature for all languages. A per language auto-indent configuration setting is not available.

      As I vary the indentation in HTML files depending on content and the kind of tags, I have configured in my html.uew:

      /Indent Strings = "no_unindent"
      /Unindent Strings = "no_unindent"


      With this definition there is no automatic indent and unindent (as long as I do not enter in a line the string no_unindent). I need to indent a line manually and also need to unindent a line manually. But that is no problem for me as I use as indent value for HTML files simply a single space character. The advantage in comparison to a turned off auto-indent setting is that a new line starts with this setting always at same indentation level as the line above. So I need to hit SPACE or BACKSPACE key only once when I want to indent/unindent the current line and all other lines are automatically indented at same level as the line above.

      Most often I need to hit only key SPACE as the closing tag is automatically added by UltraEdit beginning at same indentation level as the starting tag. So if I enter for example <ul>, UE automatically adds </ul> and sets the caret between these 2 tags. Next I hit key RETURN and SPACE and can continue with <li></li> now indented by 1 space and entering the content of the list element.

      5

        Feb 27, 2013#3

        Great information. Thank you!