昨日のサクラエディタのマクロをちょっと改良。ファイルの拡張子で起動するインタプリタを切り替えられるようにしてみた。

//ファイル名から拡張子を取り出す関数
function getExt(filename) {
	ext = ExpandParameter(currfile)
	ext = ext.substring( ext.lastIndexOf(".") + 1);
	ext = ext.toLowerCase()
	return ext
}

FileSave();

var wsh = new ActiveXObject("WScript.Shell");
var currfile = GetFilename();

var command = ""
switch (getExt(currfile)) {
case "rb":
	command = "cmd.exe /C ruby -w " + "\"" + currfile + "\"";
	wsh.Run(command, 1);
	break;
case "pl":
	command = "cmd.exe /C perl " + "\"" + currfile + "\"";
	wsh.Run(command, 1);
	break;
case "lisp":
	command = "cmd.exe /C clisp " + currfile;
	wsh.Run(command, 1);
	break;
}

なんとかしたい点

  • case文ごとに wsh.Run(command, 1); があるのが気に入らない。

こんな↓感じにしたいのだが、JScriptにはexitが無いらしい。

switch (getExt(currfile)) {
case "rb":
	command = "cmd.exe /C ruby -w " + "\"" + currfile + "\"";
	break;
case "pl":
	command = "cmd.exe /C perl " + "\"" + currfile + "\"";
	break;
case "lisp":
	command = "cmd.exe /C clisp " + currfile;
	break;
default:
        exit;
}
wsh.Run(command, 1);
  • clispにスペースを含むパスを渡せない。

パスを短いファイル名に変換できれば解決か?