【问题标题】:Textmate: Auto indenting long line of PHP codeTextmate:自动缩进长行 PHP 代码
【发布时间】:2016-04-03 23:52:06
【问题描述】:

在 Textmate 中,我可能有一行非常长的 PHP 代码,由于我的窗口宽度,我可能会换成 2 行以上:

echo 'This may be a long line of code, which will wrap to multiple lines depending on the width of the browser window...';

我注意到在行尾添加// 会使其自动缩进第一行下方的任何多行,这样看起来会更好。

echo 'This may be a long line of code, which will wrap to multiple
    lines depending on the width of the browser window...'; //

如何使这种行为自动化(不必将// 放在我编写的几乎每一行代码的末尾),以及如何将相同的格式添加到其他代码库,例如 HTML、CSS 和SQL?

【问题讨论】:

    标签: php textmate


    【解决方案1】:

    你可以试试 View->Soft Wrap 或 View->Wrap Columns 吗?

    您应该尽量不要在代码中使用超长的字符串,因为这会使其他人难以阅读(尤其是那些将显示器置于 90 度角的人)。很多时候,如果我必须在 PHP 中有这样的超长字符串,我会这样做:

    echo 'This may be a long line of code, which will wrap to multiple '
         . 'lines depending on the width of the browser window...';
    

    如果我出于某种原因需要将一堆文本放入变量中,例如原始 SQL 查询:

    $query = 'SELECT id, name, other_column, this_property, something_else '
           . 'FROM really_long_table_name_for_no_reason '
           . 'WHERE other_column IN ['item1', 'item2', 'item3', 'item4'] '
           . 'AND this_property = 7 '
           . 'AND something_else = 'nine_why_not' '
           . 'ORDER BY id DESC LIMIT 30,90';
    

    【讨论】:

      猜你喜欢
      • 2010-12-28
      • 2012-09-25
      • 1970-01-01
      • 2018-07-11
      • 1970-01-01
      • 2011-04-26
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      相关资源
      最近更新 更多