NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

-----------------------------------
CommentAdd.js
-----------------------------------
/*
* @file CommentAdd.js
* @brief 選択範囲、もしくはカーソル行をコメントアウトするサクラエディタマクロ
* @author phodra
*
* maru氏作成の同様のマクロを改変したもの。
* http://sakura.qp.land.to/?Macro%2F%C5%EA%B9%C6%2F64
*
* ・各折り返しモード対応。
* ・検索マークがちらつかない。
* ・終了時に選択範囲を復元する。
*
*** 2015/01/03 0.2 Editor.ReplaceAll() を使用しない
*** 2015/01/01 0.1 Editor.ReplaceAll() を使用するバージョン
*
*/

(function(){

// エディタがビューモード(読み取り専用)なら終了。
if( Editor.ExpandParameter("${R?r$:$:$}") == "r" ) return;
// 拡張子別にコメントステートメントを定義
var comment = new Array();
comment["cpp"] = "//"; comment["c"] = "//"; comment["h"] = "//";
comment["js"] = "//"; comment["java"] = "//";
comment["php"] = "//"; comment["uws"] = "//";
comment["mac"] = "//"; comment["ppa"] = "//";
comment["vbs"] = "'"; comment["bas"] = "'"; comment["frm"] = "'";
comment["cls"] = "'"; comment["vb"] = "'";
comment["cgi"] = "#"; comment["pl"] = "#"; comment["pm"] = "#";
comment["asm"] = ";"; comment["ini"] = ";"; comment["inf"] = ";";
comment["cnf"] = ";"; comment["conf"] = ";";
comment["tex"] = "%";
comment["cmd"] = "REM ";
comment["bat"] = "REM ";
comment["txt"] = " "; comment["noext"] = " ";

// 拡張子を切り出し
var fname = Editor.ExpandParameter("$f");
var ext = fname.substring( fname.lastIndexOf(".") + 1);
ext = ext==fname? "noext": ext.toLowerCase();
// 登録されていない拡張子であれば終了。
if( comment[ext] == null ) return;

// ちらつき防止
Editor.SetDrawSwitch(0);

// 選択モード(この変数は復元する際にも使用する)
var selmode = Editor.IsTextSelected();
if( selmode ){ // 選択状態
// レイアウト座標を取得
var lay_fl = Editor.GetSelectLineFrom();
var lay_tl = Editor.GetSelectLineTo();
// レイアウト座標をロジック座標に変換
// 選択位置のロジック座標を取得する関数はない?
var fl = Editor.LayoutToLogicLineNum( lay_fl );
var tl = Editor.LayoutToLogicLineNum( lay_tl );
var fc = Editor.LineColumnToIndex( lay_fl, Editor.GetSelectColmFrom() );
var tc = Editor.LineColumnToIndex( lay_tl, Editor.GetSelectColmTo() );
// 行選択でマクロに入った場合、一つ上の行までにする
var endl = tc==1? tl-1: tl;

// 範囲内の行を配列としてとる
var lines = new Array();
var str = "";
for( var i=fl; i<=endl; i++ ){
str = Editor.GetLineStr(i)
lines.push( comment[ext] + str );
}

// 必要な範囲を行選択
Editor.MoveCursor( fl, 1, 0);
Editor.MoveCursor( endl, str.length+1, 1);

// 選択範囲を上書き
Editor.InsText( lines.join("") );

// 選択範囲を復元
Editor.MoveCursor( fl, fc+comment[ext].length, 0);
Editor.MoveCursor( tl, tc==1? tc: tc+comment[ext].length, selmode);
}else{ // 選択していない
// ロジック座標を取得
// 選択範囲がないのでレイアウトから変換する必要はない
var l = parseInt(Editor.ExpandParameter("$y"));
var c = parseInt(Editor.ExpandParameter("$x"));

// 行頭に移動
Editor.MoveCursor( l, 1, 0);
// コメントステートメントを挿入
Editor.InsText(comment[ext]);

// 位置を復元
Editor.MoveCursor( l, c+comment[ext], selmode);
}

// 描画フラグを戻してから再描画
Editor.SetDrawSwitch(1);
Editor.ReDraw(0);

})();

-----------------------------------
CommentRemove.js
-----------------------------------
/*
* @file CommentRemove.js
* @brief 選択範囲、もしくはカーソル行のコメントを外すサクラエディタマクロ
* @author phodra
*
* maru氏作成の同様のマクロを改変したもの。
* http://sakura.qp.land.to/?Macro%2F%C5%EA%B9%C6%2F64
*
* ・各折り返しモード対応。
* ・検索マークがちらつかない。
* ・終了時に選択範囲を復元する。
*
*** 2015/01/03 0.2 Editor.ReplaceAll() を使用しない
*** 2015/01/01 0.1 Editor.ReplaceAll() を使用するバージョン
*
*/
(function(){

// エディタがビューモード(読み取り専用)なら終了。
if ( Editor.ExpandParameter("${R?r$:$:$}") == "r") return;
// 拡張子別にコメントステートメントを定義
var comment = new Array();
comment["cpp"] = "//"; comment["c"] = "//"; comment["h"] = "//";
comment["js"] = "//"; comment["java"] = "//";
comment["php"] = "//"; comment["uws"] = "//";
comment["mac"] = "//"; comment["ppa"] = "//";
comment["vbs"] = "'"; comment["bas"] = "'"; comment["frm"] = "'";
comment["cls"] = "'"; comment["vb"] = "'";
comment["cgi"] = "#"; comment["pl"] = "#"; comment["pm"] = "#";
comment["asm"] = ";"; comment["ini"] = ";"; comment["inf"] = ";";
comment["cnf"] = ";"; comment["conf"] = ";";
comment["tex"] = "%";
comment["cmd"] = "REM ";
comment["bat"] = "REM ";
comment["txt"] = " "; comment["noext"] = " ";

// ちらつき防止
Editor.SetDrawSwitch(0);

//拡張子を切り出し
var fname = Editor.ExpandParameter("$f");
var ext = fname.substring( fname.lastIndexOf(".") + 1);
ext = ext==fname? "noext": ext.toLowerCase();
// 登録されていない拡張子であれば終了。
if( comment[ext] == null ) return;

// 置換対象にする部分の正規表現
// なぜかエスケープしないといけない
var uncmt = new RegExp("(^\s*?)" + comment[ext]);
// 選択モード(この変数は復元する際にも使用する)
var selmode = Editor.IsTextSelected();

if( selmode ){ // 選択状態
// レイアウト座標を取得
var lay_fl = Editor.GetSelectLineFrom();
var lay_tl = Editor.GetSelectLineTo();
// レイアウト座標をロジック座標に変換
// 選択位置のロジック座標を取得する関数はない?
var fl = Editor.LayoutToLogicLineNum( lay_fl );
var tl = Editor.LayoutToLogicLineNum( lay_tl );
var fc = Editor.LineColumnToIndex( lay_fl, Editor.GetSelectColmFrom() );
var tc = Editor.LineColumnToIndex( lay_tl, Editor.GetSelectColmTo() );
// 行選択でマクロに入った場合、一つ上の行までにする
var endl = tc==1? tl-1: tl;

// 範囲内の行を配列としてとる
var lines = new Array();
var reped = new Array();
var str = "";
var cnt = 0;
for( var i=fl; i<=endl; i++ ){
str = Editor.GetLineStr(i);
var rep = str.replace( uncmt, "$1" );
lines.push( str );
reped.push( rep );
if( str == rep ) cnt++;
}

// 処理していない行が全体の行数に等しいときは何もしない
if( cnt < reped.length ){
// 必要な範囲を行選択
Editor.MoveCursor( fl, 1, 0);
Editor.MoveCursor( endl, str.length+1, 1);

// 選択範囲を上書き
Editor.InsText( reped.join("") );

// 範囲復元時のX位置
// コメントステートメントより後ならコメントステートメントの字数分ずらす
// コメントステートメントの中ならコメントステートメントが現れた位置
// コメントステートメントより前ならそのままの位置
var idx = lines[0].indexOf( comment[ext] );
var gap_f =
fc>idx+comment[ext].length? fc-comment[ext].length:
fc>idx+1? idx+1:
fc;
idx = lines[lines.length-1].indexOf( comment[ext] );
var gap_t =
tc>idx+comment[ext].length? tc-comment[ext].length:
tc>idx+1? idx+1:
tc;
// 選択範囲を復元
Editor.MoveCursor( fl, gap_f, 0);
Editor.MoveCursor( tl, gap_t, selmode);
}
}else{ // 選択していない
// ロジック座標を取得
// 選択範囲がないのでレイアウトから変換する必要はない
var l = parseInt(Editor.ExpandParameter("$y"));
var c = parseInt(Editor.ExpandParameter("$x"));
// 対象行の文字列を取得
var str = Editor.GetLineStr(l);
// コメントステートメントを除去した文字列
var rep = str.replace( uncmt, "$1" );

if( str != rep ){
// 行選択
Editor.MoveCursor( l, 1, 0);
Editor.MoveCursor( l, str.length+1, 1);

// 置換した文字列で上書き
Editor.InsText( rep );

// 復元時のカーソルX位置
// コメントステートメントより後ならコメントステートメントの字数分ずらす
// コメントステートメントの中ならコメントステートメントが現れた位置
// コメントステートメントより前ならそのままの位置
var idx = str.indexOf( comment[ext] );
var gap =
c>idx+comment[ext].length? c-comment[ext].length:
c>idx+1? idx+1:
c;
// カーソル位置を復元
Editor.MoveCursor( l, gap, selmode);
}
}

// 描画フラグを戻してから再描画
Editor.SetDrawSwitch(1);
Editor.ReDraw(0);

})();
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.