LoginSignup
2
6

More than 5 years have passed since last update.

【サクラエディタマクロ】自分用に残しておくマクロ集

Last updated at Posted at 2017-04-23

はじめに

パソコンがお無くなりになったときとかに
マクロが無くなってしまって作り直すことも増えて来たので以前作ったものをここに置いていく。
いずれは全部置けると良いんだけど、ソースを忘れてしまったものも数知れず。。。

マクロ一覧

重複カウント用マクロ

・行単位に同じ文字が現れた際にカウントするマクロ。
 出力先はサクラエディタのアウトプットに出てくる。
 「NNN<タブ区切り>文字列」の形式で出力される。NNNは重複数。

count.js
var Count = function(){
    var m_strResult;
    var m_aryLineList;
    this.Init();
    this.Main();
    this.Dest();
}

Count.prototype.Init = function(){
    this.m_strResult = "";
    this.m_aryLineList = new Array();
}
Count.prototype.Main = function(){
    var nMaxLineCount = Editor.GetLineCount(0) + 1;
    for(var i=1;i < nMaxLineCount;i++){
        var line =  Editor.GetLineStr(i);
        if(this.m_aryLineList[line] == undefined){
            this.m_aryLineList[line] = 1;
        }else{
            this.m_aryLineList[line]++;
        }
    }
}
Count.prototype.Dest = function(){

    for(var line in this.m_aryLineList){
        this.m_strResult += this.LPadding(this.m_aryLineList[line],3,"0") + "\t" + line;
    }
    Editor.TraceOut(this.m_strResult,0);
}
Count.prototype.LPadding = function(num,len,strParam){
    var Padding = function(nLength){
        var str = "";
        for(var i=0;i < nLength;i++){
            str += strParam;
        }
        return str;
    }
    return (Padding(len) + num).slice(-len);
}

new Count();

文書インデント整形マクロ

特定の記号単位に、階層を作るマクロ。要するに記号単位にタブでインデント階層を作れる。
打ち合わせのメモを取るときとかに一括でタブインデントを揃えたいときに利用する。
順序が考慮されていて、【、■、□、・の4つだけ使用しているが変更可能。(上部のPREFIX_LISTを変更すれば良い。)
F11キー押下時のテキストトピックツリーと相性が良い。

docmentFormat.js
var  PREFIX_LIST = (function() { return ["","","",""] }());
var DocmentFormat = function(aryStart){
    this.Init(aryStart);
}
DocmentFormat.prototype.Init = function(aryStart){
    this.aryStart = {}
    for(var i=0;i < aryStart.length;i++){
        this.aryStart[aryStart[i]] = i;
    }
    this.count = 0;
    this.strResult = "";
}
DocmentFormat.prototype.GetBlank = function(cnt){
    var str = "";
    for(var i=0;i < cnt;i++){
        str += "\t";
    }
    return str;
}

DocmentFormat.prototype.Count = function(strLine){
    var strBlank = this.GetBlank(this.count);
    var strPrefix = strLine.substring(0,1);
    if(this.aryStart[strPrefix] != undefined){
        this.count = this.aryStart[strPrefix];
        strBlank = this.GetBlank(this.count);
    }else{
        strBlank = this.GetBlank(this.count + 1);
    }
    this.strResult += strBlank + strLine;
}
DocmentFormat.prototype.GetResult = function(){
    return this.strResult;
}

var Format = function(){
    this.Init();
    this.Main();
    this.Dest();
}

Format.prototype.Init = function(){
    this.m_x = Editor.ExpandParameter("$x")
    this.m_y = Editor.ExpandParameter("$y")
}
Format.prototype.Main = function(){
    var nMaxLineFormat = Editor.GetLineCount(0) + 1;
    var objCnt = new DocmentFormat(PREFIX_LIST);
    for(var i=1;i < nMaxLineFormat;i++){
        var line =  Editor.GetLineStr(i);
        objCnt.Count(line.replace(/^[ \t]+/g,''));
    }
    Editor.SelectAll();
    Editor.InsText(objCnt.GetResult());
    Editor.MoveCursor(this.m_y,this.m_x,0);
}
Format.prototype.Dest = function(){
}

new Format();

最後に

随時、思いついたら更新する予定。

2
6
2

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
2
6