web-dev-qa-db-ja.com

Komodo Edit 5でコードをクリーンアップ(自動インデント)するにはどうすればよいですか?

私はRails html.erb Komodo Edit 5のファイルで、インデントが少し乱暴になっています。

コードを自動的にインデントして読みやすくするプラグインまたは関数はありますか?

2
conspirisi

私は他の投稿されたコードのこのわずかに編集されたバージョンを使用します。しばらくの間、バリエーションがコモドフォーラムの周りに浮かんでいます。 Komodo Edit 7.0と6.Xの両方のマクロを更新しましたが、通常は十分に機能します。 tidyオプションとcsstidyオプションの一部を変更し、XMLサポートを追加し、未定義の構文アラートを変更しました。また、astyleはstdinを受け入れないため、astyleを機能させるには、非常に醜い応急修理を作成する必要がありました。この時点で、マクロの制限が明らかになったため、マクロ全体を完全にやり直す必要があります。

Rubyサポート、チェックアウト rbeautify 、ついにRubyのサポートを統合しました。PATHにrbeautifyをインストールする必要があります。警告する必要があります。 Rubyがインストールされているため、完全にテストできません。JSが恐ろしいことにも言及する必要がありますが、できることとマクロが機能することを確認しました。これで、最終的にこの質問に答えられるはずです。私の答えを受け入れる時かもしれません。

Format_Syntax.js

komodo.assertMacroVersion(3);
if (komodo.view.scintilla) {
    komodo.view.scintilla.focus();
} // bug 67103
var koDoc = (komodo.koDoc === undefined ? komodo.document : komodo.koDoc);
var formatter;
var language = koDoc.language;
var cannot_tidy_selection = false;

switch (language) {
case 'C#':
    cannot_tidy_selection = true;
    formatter = 'astyle --style=ansi --mode=cs --convert-tabs --indent=spaces=4 %F > /dev/null 2>&1; cat %F';
    break;
case 'C++':
    cannot_tidy_selection = true;
    formatter = 'astyle --style=linux --mode=c --convert-tabs --indent=spaces=4 %F > /dev/null 2>&1; cat %F';
    break;
case 'CSS':
    formatter = 'csstidy - --preserve_css=true --lowercase_s=true --case_properties=true --sort_properties=true --remove_bslash=false --silent=true --template=medium';
    break;
case 'HTML':
    cannot_tidy_selection = true;
    formatter = 'tidy -q -asxhtml -i -b -c -w 120 --show-warnings no --show-errors 0 --tidy-mark no --css-prefix block --drop-proprietary-attributes yes --anchor-as-name no --enclose-text yes';
    break;
case 'Java':
    cannot_tidy_selection = true;
    formatter = 'astyle --style=Java --mode=Java --convert-tabs --indent=spaces=4 %F > /dev/null 2>&1; cat %F';
    break;
case 'Perl':
    formatter = 'perltidy';
    break;
case 'PHP':
    formatter = 'php_beautifier -s4 -l"Pear()"';
    break;
case 'Ruby':
    formatter = 'rbeautify.rb -';
    break;
case 'XSLT':
    cannot_tidy_selection = true;
    formatter = 'tidy -q -xml -i -w 120 --show-warnings no --show-errors 0 --tidy-mark no';
    break;
case 'XML':
    cannot_tidy_selection = true;
    formatter = 'xmllint --format --recover -';
    break;
default:
    alert("Syntax Undefined, Add Case to Macro " + language);
    return null;
}

// Save Curser Position
var currentPos = komodo.editor.currentPos;
try {
    // Save the file, Check Changes with "File -> Show Unsaved Changes"
    //komodo.doCommand('cmd_save');
    // Group operations in a single undo
    komodo.editor.beginUndoAction();
    // Select Buffer, pipe it into formatter.
    var text_not_selected = cannot_tidy_selection || komodo.editor.selText == "";
    if (text_not_selected) {
        komodo.doCommand('cmd_selectAll');
    }
    Run_RunEncodedCommand(window, formatter + " {'insertOutput': True, 'operateOnSelection': True}");
    if (text_not_selected) {
        komodo.editor.gotoPos(currentPos);
    }
    // Restore Cursor Position
    komodo.editor.gotoPos(currentPos);
    // Clean Potential EOL Mismatches
    komodo.doCommand('cmd_cleanLineEndings');
}
catch (e) {
    alert(e);
}
finally {
    // End Undo Action to Avoid Edit Buffer Corruption
    // komodo.editor.endUndoAction();
    return true;
}
2
J. M. Becker

直接ではありません。ただし、「 コマンドの実行 」システム(および場合によってはマクロの使用)を使用して、現在のバッファーの内容をマッサージする外部スクリプトの実行を支援できます。したがって、適切な.html.erbフォーマットを実行できるスクリプトがある場合は、それを統合できるはずです。

余談ですが、Komodo IDE(Komodo Editの商用親戚)には、Komodoにコ​​ードフォーマッターを統合するためのフレームワークがあります。htmlの問題なく機能する可能性のある「HTMLTidy」フォーマッターが付属しています。 erbフォーマット。

1
Trent Mick

コードを好みに合わせて再フォーマットするには、 astyle を試してください。

これをパッケージとして見つけることができる場合があります。 ap

1
etep

このフォーマットスクリプト(マクロ)を見つけました そしてそれを最新のKomodo Edit(v6.1.0)で個人的に使用するために適合させました。これはうまく機能し(システムでHTML Tidyを利用できると仮定)、コメンテーターから提供されたJavaScriptフォーマットコードを含めましたが、KomodoIDEでのみ機能する可能性があると思います。それは私の目的にとって重要ではありません。おそらく、そこにいる誰かが普遍的な改善を見つけることができます(htmltidyのようなものを使用して)。

komodo.assertMacroVersion(3);
if (komodo.view) { komodo.view.setFocus(); }

var formatter;
var language = komodo.document.language;
switch (language) {
    case 'Perl':
        formatter = 'perltidy -i=2 -pt=2 -l=0';
        break;
    case 'XML':
    case 'XUL':
    case 'XLST':
        formatter = 'tidy -q -xml -i -w 80';
        break;
    case 'HTML':
        formatter = 'tidy -q -asxhtml -i -w 120';
        break;
  //case 'JavaScript':
  //    ko.views.manager.currentView.scimoz.selectAll();
  //    ko.views.manager.currentView.scimoz.replaceSel(js_beautify(ko.views.manager.currentView.scimoz.text, {indent_size: 2}));
  //    return null;
  default:
        alert("I don't know how to tidy " + language);
        return null;
}

//save current cursor position
var currentPos = komodo.editor.currentPos;

try {
    // Save the file.  After the operation you can check what changes where made by
    // File -> Show Unsaved Changes
    komodo.doCommand('cmd_save');

    // Group operations into a single undo
    komodo.editor.beginUndoAction();

    // Select entire buffer & pipe it into formatter.
    komodo.doCommand('cmd_selectAll');
    Run_RunEncodedCommand(window, formatter + " {'insertOutput': True, 'operateOnSelection': True}");

     // Restore cursor.  It will be close to the where it started depending on how the text was modified.
     komodo.editor.gotoPos(currentPos);

    // On windows, when the output of a command is inserted into an edit buffer it has unix line ends.
    komodo.doCommand('cmd_cleanLineEndings');
}
catch (e) {
    alert(e);
}
finally {
    // Must end undo action or may corrupt edit buffer
    komodo.editor.endUndoAction();
}
0
TAOCode