Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- HTML Tidy Macro for Komodo Edit
- Pipes tidy output through sed to convert space indentation to tabs (tidy doesn't support tab indentation).
- Requires that tidy and sed be installed.
- BSD License
- */
- 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 --indent-spaces 4 -w 80';
- break;
- case 'HTML':
- formatter = 'tidy -q -asxhtml -i --indent-spaces 4 -w 120';
- break;
- default:
- alert("I don't know how to tidy " + language);
- return null;
- }
- formatter += ' | sed \'s/ /\t/g\'';
- //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();
- }
Add Comment
Please, Sign In to add comment