0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

秀丸エディタのマクロ内にJavaScriptを書く

Last updated at Posted at 2025-09-30

秀丸エディタのマクロの中にJavaScriptが書けるようになっていたので試してみた。連番を出力するマクロを書いた。

js{} のブロック内にJavaScriptを記述する。hidemaruというオブジェクトが秀丸マクロのオブジェクトで getVar() で秀丸マクロの変数を値を取得している。

// 連番+改行 の出力
// JavaScriptを使用

$end = input("最後の数を入力してください。");
#numEnd = val($end);

$dig = input("前ゼロ付ける場合の桁数を入力してください。");
#maxDig = val($dig);

disabledraw;

// スクリプトエンジンの指定
jsmode "WebView2";

// ブロック内はJavaScriptnoコード
js {

    let numEnd = hidemaru.getVar("#numEnd");
    let maxDig = hidemaru.getVar("#maxDig");

    for (let i = 1; i <= numEnd; i++) {

        // 前ゼロを作る。
        let charsZero = "";
        for (let dig = 1, digLimit = 1; dig < maxDig; dig++) {
            digLimit *= 10;
            if (i < digLimit) {
                charsZero += "0";
            }
        }

        insert(charsZero + i + "\n");
    }

}

enabledraw;

endmacro;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?