|
* 選択行コメントアウト [#m8e63c54] -ページ: [[Macro/投稿]] -作者: [[maru]] -カテゴリー: js -投稿日: 2005-07-21 (木) 00:03:54 ** メッセージ [#o096a14e] よくある選択範囲コメントマクロです。 -コメントアウト化 #code(javascript){{ //Comment.js //拡張子別に行コメント文字を定義 var aExt = new Array(); aExt["c"] = "//"; aExt["cpp"] = "//"; aExt["h"] = "//"; aExt["js"] = "//"; aExt["vbs"] = "'"; aExt["bas"] = "'"; aExt["frm"] = "'"; aExt["cls"] = "'"; aExt["mac"] = "//"; aExt["pl"] = "#"; aExt["pm"] = "#"; aExt["cgi"] = "#"; aExt["tex"] = "%"; aExt["php"] = "//"; aExt["asm"] = ";"; aExt["uws"] = "//"; aExt["conf"] = ";"; aExt["cnf"] = ";"; aExt["ini"] = ";"; aExt["inf"] = ";"; aExt["ppa"] = "//"; aExt["cmd"] = "rem"; aExt["bat"] = "rem"; //行選択されていなくても GoLineTop(13); sSelect = GetSelectedString(0); if (sSelect.length == 0) GoLineEnd_Sel(); //拡張子を切り出し sExt = ExpandParameter("$f"); sExt = sExt.substring( sExt.lastIndexOf(".") + 1); sExt = sExt.toLowerCase() //選択範囲を置換 if (aExt[sExt] == "rem"){ //コメントアウト用 ReplaceAll ("^.", "rem\t$&", 148); //コメント解除用 //ReplaceAll ("^([\t\s]*)rem[\t\s]", "$1", 148); } else { //コメントアウト用 ReplaceAll ("^.", aExt[sExt] + "$&", 148); //コメント解除用 //ReplaceAll ("^([\t\s]*)" + aExt[sExt], "$1", 148); } CancelMode(); SearchClearMark(); ReDraw(0); }} -コメントアウト解除 #code(javascript){{ //CommentUndo.js //拡張子別に行コメント文字を定義 var aExt = new Array(); aExt["c"] = "//"; aExt["cpp"] = "//"; aExt["h"] = "//"; aExt["js"] = "//"; aExt["vbs"] = "'"; aExt["bas"] = "'"; aExt["frm"] = "'"; aExt["cls"] = "'"; aExt["mac"] = "//"; aExt["pl"] = "#"; aExt["pm"] = "#"; aExt["cgi"] = "#"; aExt["tex"] = "%"; aExt["php"] = "//"; aExt["asm"] = ";"; aExt["uws"] = "//"; aExt["conf"] = ";"; aExt["cnf"] = ";"; aExt["ini"] = ";"; aExt["inf"] = ";"; aExt["ppa"] = "//"; aExt["cmd"] = "rem"; aExt["bat"] = "rem"; //行選択されていなくても GoLineTop(13); sSelect = GetSelectedString(0); if (sSelect.length == 0) GoLineEnd_Sel(); //拡張子を切り出し sExt = ExpandParameter("$f"); sExt = sExt.substring( sExt.lastIndexOf(".") + 1); sExt = sExt.toLowerCase() //選択範囲を置換 if (aExt[sExt] == "rem"){ //ReplaceAll ("^.", "rem\t$&", 148); //コメントアウト ReplaceAll ("^([\t\s]*)rem[\t\s]", "$1", 148); //コメント解除 } else { //ReplaceAll ("^.", aExt[sExt] + "$&", 148); //コメントアウト ReplaceAll ("^([\t\s]*)" + aExt[sExt], "$1", 148); //コメント解除 } CancelMode(); SearchClearMark(); ReDraw(0); }} ---- - 新規編集の時undefinedを避ける定義 その1aExt["(無題)"] = "> "; その2aExt["nonext"] = "> "; として切り出しのところを置き換える if ( sExt.lastIndexOf(".") == -1) {sExt = "nonext";} else {sExt = sExt.substring( sExt.lastIndexOf(".") + 1); sExt = sExt.toLowerCase();} jscript未学習です。学習する気はありません。お粗末ですが、工夫しまてみました。 -- [[お粗末ですが]] &new{2011-01-21 (金) 17:59:17}; #comment |