Skip to content

Instantly share code, notes, and snippets.

@so-c
Created January 31, 2016 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save so-c/c56b62223bb22efeca71 to your computer and use it in GitHub Desktop.
Save so-c/c56b62223bb22efeca71 to your computer and use it in GitHub Desktop.
// 選択行に連番を降るサクラエディタマクロ
autoFill = (function(){
var i = 0,
lines = '',
firstLine = 0,
length = 0,
digit = 0;
lines = Editor.GetSelectedString(/* API仕様の固定値 */0);
if (lines === '') {
return false;
}
firstLine = Editor.GetSelectLineFrom();
length = Editor.GetSelectLineTo() - firstLine + 1;
Editor.Jump(firstLine, 0x00);
Editor.GoLineTop(0x01);
digit = Math.floor(Math.log(length)/Math.log(10)) + 2;
for (i = 0; i < length; i++) {
// 各行の先頭に移動し、連番を振る
Editor.InsText(pad(i + 1, digit) + ' ');
Editor.Down();
Editor.GoLineTop(0x01);
}
}())
function pad(/* 埋める対象 */ n,
/* 埋める桁数 */ p,
/* 埋めるのに使う文字 */ c) {
var padChar = typeof c !== 'undefined' ? c : '0';
var pad = new Array(1 + p).join(padChar);
return (pad + n).slice(-pad.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment