¿Cómo limpio el código (sangría automática) en Komodo Edit 5?


2

Tengo un html.erbarchivo Rails en Komodo Edit 5 y la sangría se ha vuelto un poco salvaje.

¿Hay algún complemento o función que sangra automáticamente mi código para que sea más fácil de leer?


El soporte de formato de código, en realidad, es un IDE de Komodo incorporado . También uso Komodo Edit simple y obtengo soporte de kludge de la macro. Actualicé la macro con Ruby Support, considere aceptar mi respuesta.
JM Becker

Respuestas:


2

Yo uso esta versión ligeramente editada de otro código publicado. Las variaciones han estado flotando alrededor de los foros de Komodo durante algún tiempo. He actualizado la macro para Komodo Edit 7.0 y 6.X, por lo general funciona lo suficientemente bien. Cambié algunas de las opciones ordenadas y csstidy, agregué el soporte XML y modifiqué la alerta de sintaxis indefinida. También tuve que crear un kludge muy feo para que astyle funcionara, ya que astyle no acepta stdin. En este punto, la macro completa necesita ser completamente renovada, ya que sus limitaciones se han vuelto obvias.

En cuanto al soporte de Ruby, consulte rbeautify , finalmente he integrado el soporte para Ruby, debe tener instalado rbeautify en su PATH. Debo advertirte, no tengo instalado Ruby, así que no puedo probar completamente. También debería mencionar que mi JS es terrible, pero verifiqué lo que pude y la macro funcionó. Esto finalmente debería responder a esta pregunta, podría ser hora de aceptar mi respuesta.

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;
}

1

No directamente. Sin embargo, el sistema " Ejecutar comandos " (y posiblemente el uso de macros) se puede usar para ayudar a ejecutar un script externo que masajeará el contenido del búfer actual. Entonces, si tiene un script que puede hacer un buen formato .html.erb, entonces debería poder integrarlo.

Aparte: Komodo IDE (el pariente comercial de Komodo Edit) tiene un marco para formateadores de código de integración en Komodo. Se entrega con un formateador "HTML Tidy" que podría funcionar bien con el formato .html.erb.


1

Para reformatear el código a su gusto, intente con un estilo

Es posible que pueda encontrar esto como un paquete, por ejemplo, ap


0

Me encontré con este script formato (macro) y lo adaptó para mi uso personal con la última Komodo Edit (v6.1.0). Funciona bien (suponiendo que tenga HTML Tidy disponible en su sistema) e incluí el código de formato de JavaScript proporcionado por un comentarista, pero creo que solo puede funcionar con Komodo IDE. No es importante para mis propósitos. Quizás alguien por ahí pueda encontrar una mejora universal (usando algo como html ordenado).

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();
}
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.