黄身 (トーク | 投稿記録)
編集の要約なし
黄身 (トーク | 投稿記録)
編集の要約なし
 
(2人の利用者による、間の65版が非表示)
1行目: 1行目:
Ginnieから移行中。何か変な所があったらその癖が抜けてないせいです……
さよならWindows。
=覚え書き=
 
;Document.GetLine
=KL=
:デフォルトでは表示行を取得。meGetLineLogicalが未定義なので0を指定する。
 
;最初の数
==ダウンロード==
:行:1 (Document.GetLine)
 
:文頭からの位置:0 (Selection.GetActivePos)
[https://bitbucket.org/kimigatame/mery_kl BitBucket]
:桁:1 (Selection.GetActivePointX)
 
:Editor,Document:0 (Editors.Item.Documents.Item)
==概要==
;Window.Document
 
:Document.NewFile後も更新されない。
{| class="wikitable"
<source lang="javascript" style="word-wrap:break-word;">
!マクロ
Editor.ActiveDocument.NewFile();
!中身とか注意事項とか
Alert(Document.Text);
|-
</source>
|KL.js
;Editor.FindInFiles
|Mery組み込みオブジェクトの拡張。
:ディレクトリ名は最後を"\\"か"\\*"にする。
|-
:アクティブな文書が結果表示で乗っ取られる。
|global.js
;PopupMenu.Track
|グローバルなメソッドや変数。
:引数無しだとエラー。0でキャレット位置に表示。mePosMouseは1。
|-
:返り値を変数に入れるなりOutputするなりしないとメニューは表示されない。
|polyfill.js
|Chakraで実装されていないメソッドなどの拡張。
|-
|ArrExt.js<br />StrExt.js<br />MathExt.js
|それぞれのオブジェクトへのメソッドの追加。
|-
|WidePop.js
|リッチなポップアップ。
|-
|ComText.js
|マッチ結果とテンプレートから文字列を作成する。
|-
|InsertOption.js
|ComText.jsによって作成した文字列を挿入する。
|-
|InsetSearch.js
|ComText.jsによって作成した文字列で検索する。
|-
|MouseEmurator.js
|マウスの操作。
|-
|Commentize.js
|コメント化もしくはコメント解除する。
|-
|MoveSelection.js
|選択文字列を移動する。
|-
|Exes
|マクロの実行用ファイル。
|}
 
==KL.js==
 
KLを名前空間として独自のオブジェクトとMery組み込みオブジェクトの拡張を含む。
 
===オブジェクト===
 
;KL.Range
:範囲を表す。
;KL.Coord
:座標系を表す。
;KL.Dir
:選択方向を表す。
;KL.Point
:座標を表す。
 
===メソッド===
 
;KL.GetScroll/KL.SetScroll
:スクロール位置の取得/設定。
 
===組み込みオブジェクトの拡張===
 
Selection/Document/Editorのラッパ。Mery組み込みのメソッドやプロパティと追加したものを同じ方法で呼び出せる。また一部は組み込みのものを拡張している。
 
e.g.  
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
let $s=KL.Selection();
$s.Reverse();
$s.Text=$s.GetLeft();
</syntaxhighlight>
組み込みのSelectionを直接呼び出すには<code>KL.Selection#Original</code>か、global.jsの<code>GSO()</code>を使う。
 
====KL.Editor====
 
{| class="wikitable"
|Original
|組み込みのEditor。
|-
|Documents
|KL.Documents。組み込みのDocumentsではない。
|-
|ActiveDocument
|アクティブな文書のKL.Document。組み込みのActiveDocumentではない。
|-
|NewFile
|文書を新規作成する。
|-
|GetDocument
|Documentオブジェクトを取得する。
|-
|}
 
====KL.Documents====
 
他に合わせて用意しているだけで追加したメソッドは存在しない。
 
====KL.Document====
 
{| class="wikitable"
|Original
|組み込みのDocument。
|-
|Close
|文書を閉じる。組み込みのを追加拡張している。
|-
|Selection
|KL.Selectionを取得。組み込みのSelectionではない。
|-
|LineEndingChar
|改行文字を取得する。
|-
|ToSerial
|座標を文頭からの位置に変換する。
|-
|ToLogical
|座標を論理行座標に変換する。
|-
|ToView
|座標を表示行座標に変換する。
|-
|LogicalToView
|論理行座標を表示行座標に変換する。
|-
|LogicalToSerial
|論理行座標を文頭からの位置に変換する。
|-
|SerialToLogical
|文頭からの位置を論理行座標に変換する。
|-
|SerialToView
|文頭からの位置を表示行座標に変換する。
|-
|ViewToLogical
|表示行座標を論理行座標に変換する。
|-
|ViewToSerial
|表示行座標を文書先頭からの位置に変換する。
|-
|Clone
|文書のクローンを作成する。
|-
|Lines
|行を取得する。
|-
|}
 
====KL.Selection====
 
{| class="wikitable"
|Original
|組み込みのDocument。
|-
|OriginalParent
|親となる組み込みのDocument。
|-
|Parent
|親となるKL.Documentオブジェクト。
|-
|SelectLines
|複数の行を選択する。
|-
|SelectLineRange
|複数の行を選択する。
|-
|SelectIfEmpty
|選択されていなければ選択する。
|-
|IsLogicalStart
|論理行頭かどうか判定する。
|-
|IsLogicalEnd
|論理行末かどうか判定する。
|-
|IsViewStart
|表示行頭かどうか判定する。
|-
|IsViewEnd
|表示行末かどうか判定する。
|-
|IsEOF
|文末かどうか判定する。
|-
|Inline
|行内選択かどうか判定する。
|-
|Multiline
|複数行に渡る選択かどうか判定する。
|-
|WholeLines
|行の全体を選択しているかどうか判定する。
|-
|GetRange
|選択範囲を取得する。
|-
|SetRange
|範囲選択する。
|-
|GetDirection
|テキスト選択方向を取得する。
|-
|SetDirection
|テキスト選択方向を設定する。
|-
|Reverse
|選択範囲を反転する。
|-
|GetBottomPos
|選択範囲の文末側の位置を取得する。
|-
|GetTopPos
|選択範囲の文頭側の位置を取得する。
|-
|GetAnchorPoint
|カーソル位置を取得する。
|-
|GetActivePoint
|選択範囲の開始位置を取得する。
|-
|GetBottomPoint
|選択範囲の文末側の位置を取得する。
|-
|GetTopPoint
|選択範囲の文頭側の位置を取得する。
|-
|GetLeft
|選択範囲より左の文字列を取得する。
|-
|GetRight
|選択範囲より右の文字列を取得する。
|-
|Exclude
|選択部分から文末側の改行を除外する。
|-
|Duplicate
|テキスト二重化。
|-
|Sort
|選択範囲の行または文字列をソートする。
|-
|DeleteLines
|行を削除する。
|-
|}
 
==global.js==
 
グローバルに確保したメソッドや変数。KL名前空間下には含まれない。
 
{| class="wikitable"
|meGetLineLogical
|論理座標で指定するフラグ。
|-
|mePosCaret
|キャレット位置で指定するフラグ。
|-
|GEO
|組み込みのEditorオブジェクトを取得する。
|-
|GDO
|組み込みのDocumentオブジェクトを取得する。
|-
|GSO
|組み込みのSelectionを取得する。
|-
|O
|OutputBar.Writeへのショートカット。
|-
|RelativePath
|実行中のスクリプトから相対的にファイルパスを取得する
|-
|}
 
==polyfill.js==
 
ECMAScriptにありChakraでは使用できないものの補完。
 
* Array.from()
* Array.of()
* Array.prototype.copyWithin()
* Array.prototype.fill()
* Array.prototype.find()
* Array.prototype.findIndex()
* Array.prototype.flat()
* Array.prototype.flatMap()
* Array.prototype.includes()
* Math.trunc()
* Number.isFinite()
* Number.isInteger()
* Number.isNaN()
* Number.parseFloat()
* Number.parseInt()
* Object.is()
* String.fromCodePoint()
* String.prototype.codePointAt()
* String.prototype.endsWith()
* String.prototype.includes()
* String.prototype.padEnd()
* String.prototype.padStart()
* String.prototype.repeat()
* String.prototype.startsWith()
* String.prototype.trimEnd()
 
==Chakraへの追加==


=KILI.js=
===ArrExt.js===
グローバルに用意しているのはこの「KILI」オブジェクトと次の項に挙げたいくつかのみ。<br />
(これ以外のファイルでも)引数のコメントで「*」が付いてるものは既定値。
;よく出てくる変数名
:$d:対象となる文書のDocument。
:$s:対象となる文書のSelection。
:SB:StateBackup。
;対象とするDocument/Selection
:$d/$s→defaultDocument/Selection→アクティブの順で使用。
;clearDefault
:既定をクリア
<source lang="javascript" style="word-wrap:break-word;">
function clearDefault()
</source>
;getDocument
:既定のDocumentを取得
<source lang="javascript" style="word-wrap:break-word;">
function getDocument($d)
</source>
*return:<Document>
;getSelection
:既定のSelectionを取得
<source lang="javascript" style="word-wrap:break-word;">
function getSelection()
</source>
*return:<Selection>
;setDefault
:既定のDocument/Selectionを指定
<source lang="javascript" style="word-wrap:break-word;">
function setDefault($d)
</source>


==KILIオブジェクトに含まれないもの==
{| class="wikitable"
あまりにもよく使ってるので特別にグローバルに用意。よほどの事がない限りこれ以上増やさない。
|unique
;GEO
|配列から重複を削除する。
:Editorを取得
|-
<source lang="javascript" style="word-wrap:break-word;">
|last
function GEO(eIndex)
|配列の最後の要素。
</source>
|-
*eIndex:<number> エディタのインデックス。不正な値の場合はアクティブ。
|}
*return:<Document>
;GDO
:Documentを取得
<source lang="javascript" style="word-wrap:break-word;">
function GDO(dIndex,eIndex)
</source>
*dIndex:<number> 文書のインデックス。不正な値の場合はアクティブ。
*eIndex:<number> エディタのインデックス。不正な値の場合はアクティブ。
*return:<Document>
;GSO
:Selectionを取得
<source lang="javascript" style="word-wrap:break-word;">
function GSO($d,eIndex)
</source>
*$d:<Document|number>
**Document 対象のDocument。
**number 文書のインデックス。*undefined:アクティブ。
*eIndex:<number> @$dで#numberを指定した場合、エディタのインデックス。
*return:<Selection>
;O
:OutputBar.Writeln()へのショートカット<br />
null、undefinedは念のため文字列として出力。
<source lang="javascript" style="word-wrap:break-word;">
function O(data,nobreak,clear,focus)
</source>
*data:<Object> 出力データ。
*nobreak:<boolean> 改行しない。
*clear:<boolean> 出力前にウィンドウをクリアする。
*focus:<boolean> 出力ウィンドウにフォーカスを移す。
;Seiko.run
:関数を指定回数実行して時間計測
<source lang="javascript" style="word-wrap:break-word;">
function Seiko.run(func,count)
</source>
*func:<Function> 計測する関数。
*count:<number> 実行回数。
*return:<number> 経過時間。


==KILI.selex==
===StrExt.js===
Selection拡張。KILI.editと違い、文書は編集されない。
;getBottomPos
:選択範囲の文末側の位置を取得
<source lang="javascript" style="word-wrap:break-word;">
function getBottomPos($d)
</source>
;getDirection
:テキスト選択方向を取得
<source lang="javascript" style="word-wrap:break-word;">
function getDirection($d)
</source>
*return:<number> 0:無選択、1:順方向、-1:逆方向。
;getLineEndPos
:全ての論理行末の位置を取得
<source lang="javascript" style="word-wrap:break-word;">
function getLineEndPos($d)
</source>
*return:<Array>
;getLineHeadPos
:全ての論理行頭の位置を取得
<source lang="javascript" style="word-wrap:break-word;">
function getLineHeadPos($d)
</source>
*return:<Array>
;getRange
:選択範囲を取得する
<source lang="javascript" style="word-wrap:break-word;">
function getRange(posType,topToBottom,$d)
</source>
*posType:<number> 形式。*0:文頭からの位置、1:論理行、2:物理行。
*topToBottom:<number> true:常に文頭側を開始位置とする、*false:選択方向に従う。
*return:<Object{start,end}>
**start,end:<number|Object{x,y}> 開始位置、終了位置。
;getTopPos
:選択範囲の文頭側の位置を取得
<source lang="javascript" style="word-wrap:break-word;">
function getTolPos($d)
</source>
;getViewEndPos
:全ての表示行末の位置を取得
<source lang="javascript" style="word-wrap:break-word;">
function getViewEndPos($d)
</source>
;getViewHeadPos
:全ての表示行頭の位置を取得
<source lang="javascript" style="word-wrap:break-word;">
function getViewHeadPos($d)
</source>
;getWrapPos
:全ての折り返し位置を取得
<source lang="javascript" style="word-wrap:break-word;">
function getWrapPos(asLogical,$d)
</source>
*asLogical:<boolean> 論理行・桁で返す。
*return:<Array> @asLogicalがtrueならば各要素は{x,y}。
;isLogicalEnd
:論理行末かどうか
<source lang="javascript" style="word-wrap:break-word;">
function isLogicalEnd(x,y,$d)
</source>
*x:<number> 表示行桁もしくは文頭からの位置。*:現在位置。
*y:<number> 表示行。*:@xを文頭からの位置とみなす。
*return:<boolean>
;isLogicalHead
:論理行頭かどうか
<source lang="javascript" style="word-wrap:break-word;">
function isLogicalHead(x,y,$d)
</source>
*x:<number> 表示行桁もしくは文頭からの位置。*:現在位置。
*y:<number> 表示行。*:@xを文頭からの位置とみなす。
*return:<boolean>
;logicalToPos
:論理行・桁を文頭からの位置に変換
<source lang="javascript" style="word-wrap:break-word;">
function logicalToPos(x,y,$d)
</source>
*x:<number> 論理行桁。
*y:<number> 論理行。
*return:<number>
;logicalToView
:論理行・桁を表示行・桁に変換
<source lang="javascript" style="word-wrap:break-word;">
function logicalToView(x,y,$d)
</source>
*x:<number> 論理行桁。
*y:<number> 論理行。
*return:<Object{x,y}>
;posToLogical
:文頭からの位置を論理行・桁に変換
<source lang="javascript" style="word-wrap:break-word;">
function posToLogical(pos,$d)
</source>
*pos:<number> 文頭からの位置。
*return:<Object{x,y}>
;posToView
:文頭からの位置を表示行・桁に変換
<source lang="javascript" style="word-wrap:break-word;">
function posToView(pos,$d)
</source>
*pos:<number> 文頭からの位置。
*return:<Object{x,y}>
;reverse
:選択範囲を反転する
<source lang="javascript" style="word-wrap:break-word;">
function reverse($d)
</source>
;searchTextLines
:文字列を含む論理行を取得
<source lang="javascript" style="word-wrap:break-word;">
function searchTextLines(seg,noText,$d)
</source>
*seg:<String||RegExp> 指定しない場合は選択部分。
*noText:<boolean> 文字列を含まない行を取得。
*return:<Array>
;searchTextPos
:文字列を文書全体から探して位置を取得
<source lang="javascript" style="word-wrap:break-word;">
function searchTextPos(seg,$d)
</source>
*seg:<String||RegExp> 指定しない場合は選択部分。
*return:<Array>
;selectIfEmpty
:選択されていなければ選択する
<source lang="javascript" style="word-wrap:break-word;">
function selectIfEmpty(range,$d)
</source>
*range:<number> 選択範囲。*0:全体、1:論理行、2:表示行。
;selectLines
:複数の行を選択。
<source lang="javascript" style="word-wrap:break-word;">
function selectLines(from,count,selectBreak,asView,$d)
</source>
*from:<number> 開始行。
*num:<number> 選択行数。0:選択しない、負:文頭方向へ選択。
*selectBreak:<boolean> true:選択終了位置の改行も選択する、*false:改行前まで。
*asView:<boolean> 物理行で処理する。
;setRange
:範囲選択する
<source lang="javascript" style="word-wrap:break-word;">
function setRange(start,end,asView,$d)
</source>
*start,end:<number|Object{x,y}> 開始位置、終了位置。
**number 文頭からの位置
**Object *論理行での位置。@asViewがtrueなら表示行。
*asView:<boolean> @start,@endを表示行で指定する。
;viewToLogical
:表示行・桁を論理行・桁に変換
<source lang="javascript" style="word-wrap:break-word;">
function viewToLogical(x,y,$d)
</source>
*x:<number> 表示行桁。
*y:<number> 表示行。
*return:<Object{x,y}>
;viewToPos
:表示行・桁を文書先頭からの位置に変換
<source lang="javascript" style="word-wrap:break-word;">
function viewToPos(x,y,$d)
</source>
*x:<number> 表示行桁。
*y:<number> 表示行。
*return:<number>


==KILI.edit==
{| class="wikitable"
Selection拡張。KILI.selexと違い、文書は編集される。
|bracket
;breakAll
|文字列の前後に文字列を挿入する。
:文字列を全て改行にする
|-
<source lang="javascript" style="word-wrap:break-word;">
|quote
function breakAll(seg,$d)
|「'...'」で囲む。
</source>
|-
*seg:<String> 指定しない場合は選択部分。
|parens
;deleteAll
|「(...)」で囲む。
:文字列を全て削除
|-
<source lang="javascript" style="word-wrap:break-word;">
|braces
function deleteAll(seg,$d)
|「[...]」で囲む。
</source>
|-
*seg:<String> 指定しない場合は選択部分。
|curls
;deleteAllNoTextLines
|「{...}」で囲む。
:文字列を含まない行を全て削除
|-
<source lang="javascript" style="word-wrap:break-word;">
|crlf
function deleteAllNoTextLines(seg,$d)
|改行コードを変換する。
</source>
|-
*seg:<String> 指定しない場合は選択部分。
|insert
;deleteAllTextLines
|文字列を挿入する。
:文字列を含む行を全て削除
|-
<source lang="javascript" style="word-wrap:break-word;">
|escapeRe
function deleteAllTextLines(seg,$d)
|正規表現で使用される文字をエスケープする。
</source>
|-
*seg:<String> 指定しない場合は選択部分。
|unescapeRe
;deleteLine
|エスケープされた正規表現で使用される文字を戻す。
:行削除
|-
<source lang="javascript" style="word-wrap:break-word;">
|cpcount
function deleteLine(line,asView,$d)
|サロゲートペアを考慮して文字列の長さを取得する。
</source>
|-
*line:<number> 削除行。
|cpsplit
*asView:<boolean> true:表示行、*false:論理行。
|サロゲートペアを考慮して文字列を分割する。
;deleteLines
|-
:行を全て削除
|}
<source lang="javascript" style="word-wrap:break-word;">
function deleteLines(lines,asView,$d)
</source>
*lines:<Array> 行番号。
*asView:<boolean> true:表示行、*false:論理行。
;duplicate
:論理行二重化
無選択時は現在の論理行、複数行選択時は範囲内の論理行、行内選択時は選択部分を二重化。
<source lang="javascript" style="word-wrap:break-word;">
function duplicate($d)
</source>
;sort
:テキストソート
選択範囲の論理行が対象。無選択の場合は全体。行内選択の場合長さ順は無効。
<source lang="javascript" style="word-wrap:break-word;">
function sort(sortType,$d)
</source>
*sortType:<number> ソートの種類。*0:逆順、1:昇順、2:降順、3:長さ昇順、4:長さ降順。


==KILI.docex==
===MathExt.js===
Document拡張。Editorの領分と思われるものも含む。<br />
あまり仕様が固まってないので激変の可能性あり。
;clone
:文書のクローンを作成
<source lang="javascript" style="word-wrap:break-word;">
function clone(destination,$d)
</source>
*destination:<Editor> 文書作成先のEditor。*:アクティブ。
*return:<Document> 作成した文書。
;listupAll
:全てのDocumentを取得
<source lang="javascript" style="word-wrap:break-word;">
function listupAll(asObject)
</source>
*asObject:<boolean> 結果を{editorIndex:{documentIndex:Document}}の形式で返す。
*return:<Array||Object>
;newFile
:テキストとスタイルを指定して新規作成
<source lang="javascript" style="word-wrap:break-word;">
function newFile(text,encoding,mode,readOnly,overwrite,destination)
</source>
*text:<String>
*encoding:<Document.Encoding> *:自動選択。
*mode:<Document.Mode> *:Text
*readOnly:<Document.ReadOnly> *:false
*overwrite:<Selection.OverwriteMode> *:false
*destination:<Editor> 文書作成先のEditor。*:アクティブ。
*return:<Document> 作成した文書。


=KILI.code.js=
{| class="wikitable"
文字・コードポイントの相互変換とその表現を扱う。Unicodeのみが対象。
|within
;decode
|n以上m以下であるか判定する。
:コードポイントの配列を文字列に変換
|-
<source lang="javascript" style="word-wrap:break-word;">
|clamp
function decode(code)
|数値を範囲内に収める。
</source>
|-
*code:<Array> 文字コードの配列。
|}
*return:<String>
;decodeAll
:文字列中のコード表現を文字列にする<br />
対応する形式
*U+hhhh
*\uhhhh
*\x{hhhh}
*&#dddd
*&#xhhhh
<source lang="javascript" style="word-wrap:break-word;">
function decodeAll(seg)
</source>
*seg:<String>
*return:<String>
;decodeSurrogate
:サロゲートペアをコードポイントに変換
<source lang="javascript" style="word-wrap:break-word;">
function decodeSurrogate(higher,lower)
</source>
*higher,lower:<number> 上位・下位サロゲート。
*return:<number>
;encode
:文字列をコードポイントの配列に変換
<source lang="javascript" style="word-wrap:break-word;">
function encode(seg,surrogate,alignmentString)
</source>
*seg:<String>
*surrogate:<boolean> サロゲートペアで出力する。
*alignmentString:<number> 指定した桁数の文字列で出力する。
*return:<Array>
;encodeSurrogate
:コードポイントをサロゲートペアで表現<br />
コードポイントが0x10000未満の場合そのまま返す。
<source lang="javascript" style="word-wrap:break-word;">
function encodeSurrogate(code)
</source>
*code:<number>
*return:<Array[high,low]|number>
;fromCharCode
:0x10000以上にも対応したfromCharCode<br />
引数・戻り値はfromCharCodeと同じ。
<source lang="javascript" style="word-wrap:break-word;">
function fromCharCode(arg,...)
</source>
*args:<number>
*return:<string>
;fromEntity
:文字列中の数値実体参照(&#dddd,&#xhhhh)を文字に変換
<source lang="javascript" style="word-wrap:break-word;">
function fromEntity(seg,radix)
</source>
*seg:<String>
*radix:<boolean> true:十進数のみ、false:十六進数のみ、*:両方。
*return:<String>
;fromOnig
:文字列中の鬼車のコード表現(\x{hhhh})を文字に変換
<source lang="javascript" style="word-wrap:break-word;">
function fromOnig(seg)
</source>
*seg:<String>
*return:<String>
;fromRegex
:文字列中の正規表現のコード表現(\uhhhh)を文字に変換
<source lang="javascript" style="word-wrap:break-word;">
function fromRegex(seg)
</source>
*seg:<String>
*return:<String>
;fromUnicode
:文字列中のUnicodeのコード表現(U+hhhh)を文字に変換
<source lang="javascript" style="word-wrap:break-word;">
function fromUnicode(seg)
</source>
*seg:<String>
*return:<String>
;toEntity
:文字列を数値実体参照(&#dddd,&#xhhhh)に変換
<source lang="javascript" style="word-wrap:break-word;">
function toEntity(seg,surrogate,alignmentString,radix)
</source>
*seg:<String>
*surrogate:<boolean> サロゲートペアで出力する。
*alignmentString:<number> 指定した桁数の文字列で出力する。
*radix:<boolean> true:十進数表記、*false:十六進数表記。
*return:<String>
;toOnig
:文字列を鬼車のコード表現(\x{hhhh})に変換
<source lang="javascript" style="word-wrap:break-word;">
function toOnig(seg,surrogate,alignmentString)
</source>
*seg:<String>
*surrogate:<boolean> サロゲートペアで出力する。
*alignmentString:<number> 指定した桁数の文字列で出力する。
*return:<String>
;toRegex
:文字列を正規表現のコード表現(\uhhhh)に変換
<source lang="javascript" style="word-wrap:break-word;">
function toRegex(seg,surrogate,alignmentString)
</source>
*seg:<String>
*surrogate:<boolean> サロゲートペアで出力する。
*alignmentString:<number> 指定した桁数の文字列で出力する。
*return:<String>
;toUnicode
:文字列をUnicodeのコード表現(U+hhhh)に変換
<source lang="javascript" style="word-wrap:break-word;">
function toUnicode(seg,surrogate,alignmentString)
</source>
*seg:<String>
*surrogate:<boolelan> サロゲートペアで出力する。
*alignmentString:<number> 指定した桁数の文字列で出力する。
*return:<String>


=組み込みオブジェクト拡張=
==WidePop.js==
名前の衝突に注意。特にStringExはincludeライブラリのStringExと衝突しています。
==ArrayEx.js==
組み込みArray拡張。
;clone
:配列を値渡し
<source lang="javascript" style="word-wrap:break-word;">
function clone()
</source>
*return:<Array>
;compact
:空文字列、null、undefinedを削除する
<source lang="javascript" style="word-wrap:break-word;">
function compact()
</source>
*return:<Array>
;del
:一致した要素を削除
<source lang="javascript" style="word-wrap:break-word;">
function del(arg,...)
</source>
*args:<*> 削除する要素。
*return:<Array>
;indexOf
:配列から文字列を検索
<source lang="javascript" style="word-wrap:break-word;">
function indexOf(str,from)
</source>
*str:<string> 検索文字列。
*from:<number> 検索開始インデックス。
*return:<number> 配列インデックス。見つからなければ-1。
;insert
:要素を挿入する
<source lang="javascript" style="word-wrap:break-word;">
function insert(pos,itte)
</source>
*pos:<number> 挿入位置。
*item:<Object> 挿入要素。
*return:<Array>
;last
:配列の最後の要素を返す
<source lang="javascript" style="word-wrap:break-word;">
function last()
</source>
*return:<*>
;mine
:指定条件にマッチする要素を集める
<source lang="javascript" style="word-wrap:break-word;">
function mine(func,returnElement)
</source>
*func:<Function(element)> 条件を判定する関数。
**element:<*> 配列の各要素。
**return:<boolean>
*returnElement:<boolean> true:要素自体を返す。false:インデックスを返す。
*return:<Array>
;e.g.
:<source lang="javascript" style="word-wrap:break-word;">
[1,2,3,4,5].mine(function(e){return e%2;}); //[0,2,4]
[1,2,3,4,5].mine(function(e){return e%2;},true); //[1,3,5]
</source>
;pickup
:指定したインデックスの要素を取り出した配列を返す
<source lang="javascript" style="word-wrap:break-word;">
function pickup(arg,...)
</source>
*args:<number> 取り出す要素のインデックス。
*return:<Array>
;e.g.
<source lang="javascript" style="word-wrap:break-word;">
[1,2,3,4,5,6].pickup(2,5,1); //[3,6,2]
</source>
;siblings
:オブジェクトの配列の各要素から同名のプロパティを取得
<source lang="javascript" style="word-wrap:break-word;">
function siblings(name)
</source>
*name:<string> プロパティ名。
*return:<Array>
;e.g.
<source lang="javascript" style="word-wrap:break-word;">
[{a:1,b:2},{a:3,c:4},{a:5,d:6}].siblings("a"); //[1,3,5];
</source>
;undup
:配列から重複を削除
<source lang="javascript" style="word-wrap:break-word;">
function undup()
</source>
*return:<Array>


==NumberEx.js==
リッチなPopupMenu。機能は以下の通り。
Numberオブジェクト拡張
;constrain
:数値を範囲内に収める
<source lang="javascript" style="word-wrap:break-word;">
function constrain(min,max)
</source>
*min,max:<number> 最小値、最大値。
*return:<number>
;inRange
:n以上m以下
<source lang="javascript" style="word-wrap:break-word;">
function inRange(r1,r2)
</source>
*r1,r2:<number> 範囲。大小の順は不問。
*return:<boolean>
;padding
:桁揃え<br />
文字列としての長さが@digitより長い場合、切り捨ては行わない。
<source lang="javascript" style="word-wrap:break-word;">
function padding(digit,pad)
</source>
*digit:<number> 全体の桁数。*4。
*pad:<string> 埋め文字。*0。
*return:<string>
;toHexString
:十六進数表記で返す
<source lang="javascript" style="word-wrap:break-word;">
function toHexString()
</source>
*return:<string>


==StringEx.js==
* 配列のみでのメニュー定義
Stringオブジェクト拡張
* チェックボックス
;crlf
* ラジオボタン
:改行をCRLFにする
* チェック、有効・無効の切り換え
<source lang="javascript" style="word-wrap:break-word;">
* サブメニュー
function crlf()
* 選択時にコマンド実行
</source>
* MouseEmurator.jsを利用してメニューの位置を一定にする
*return:<string>
;cut
:指定の長さで分割
<source lang="javascript" style="word-wrap:break-word;">
function cut(arg,...)
</source>
*args[0]:<number> 最初の分割長。argsが1つだけの場合、負:分割しない、0:(0,false)と同じ、正:その長さで全体を分割する。
*args[1-]:<number|boolean>
**number 2番目以降の分割長。0:空要素となる。負:その分遡る。
**boolean ここで処理を中断する。true:残りを出力しない、*false:残りを1つの要素として出力する。
*return:<Array>
;e.g.
<source lang="javascript" style="word-wrap:break-word;">
"abcdefgh".cut(2); //[ab,cd,ef,gh]
"abcdefgh".cut(1,2,3,true); //[a,bc,def]
"abcdefgh".cut(1,-2,3,-1); //[a,abc,cdefgh]
</source>
;dQuot
「"」で囲む
<source lang="javascript" style="word-wrap:break-word;">
function dQuot()
</source>
*return:<string>
;enclose
:指定の文字列で囲む
<source lang="javascript" style="word-wrap:break-word;">
function enclose(pre,post)
</source>
*pre:<string> 囲み開き文字。
*post:<string> 囲み閉じ文字。*:@preと同じ。
*return:<string>
;enclosed
:文字列で囲まれている
<source lang="javascript" style="word-wrap:break-word;">
function enclosed(pre,post,ignoreCase)
</source>
*pre:<string> 囲み開き文字。
*post:<string> 囲み閉じ文字。*:@preと同じ。
*ignoreCase:<boolean> 大文字小文字を無視する。
*return:<boolean>
;endsWith
:末尾にマッチする
<source lang="javascript" style="word-wrap:break-word;">
function endsWith(seg,ignoreCase)
</source>
*seg:<string> マッチ文字列。
*ignoreCase:<boolean> 大文字小文字を無視する。
*return:<boolean>
;insert
:文字列を挿入する
<source lang="javascript" style="word-wrap:break-word;">
function insert(seg,pos)
</source>
*seg:<string> 挿入する文字列。
*pos:<number> 挿入位置。
*return:<string>
;repeat
:文字列を繰り返す
<source lang="javascript" style="word-wrap:break-word;">
function repeat(count)
</source>
*count:<number> 繰り返し回数。
*return:<string>
;sQuot
:「'」で囲む
<source lang="javascript" style="word-wrap:break-word;">
function sQuot()
</source>
*return:<string>
;startsWith
:先頭にマッチする
<source lang="javascript" style="word-wrap:break-word;">
function startsWith(seg,ignoreCase)
</source>
*seg:<string> マッチ文字列。
*ignoreCase:<boolean> 大文字小文字を無視する。
*return:<boolean>


=SimplePM.js=
e.g.
テキストと実行コマンドのみからなる単純なPopupMenu。
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
;メニューの定義
<source lang="javascript" style="word-wrap:break-word;">
var menu=[[text,command],...];
</source>
*text:<string> メニューのテキスト。
*command:<Function||Array>
**Function:メニュー選択時に実行する関数。
**Array:サブメニュー。
空の配列の場合、区切りとなる。
;track
:メニューを表示、コマンドを実行
コマンドが関数・配列でない場合はその値を返す。関数・配列を返したい場合は関数内でreturnする。
<source lang="javascript" style="word-wrap:break-word;">
function track(pos,returnId)
</source>
*pos:<number> *0:カーソル位置に表示、1:キャレット位置に表示。
*returnId:<boolean> コマンド未定義の場合の返り値。true:ID、*false:メニューのテキスト。
*return:<*> 関数の返り値、コマンドの内容、もしくは@returnIdに従う。キャンセルした場合は-1。
;create
:メニューを作成
<source lang="javascript" style="word-wrap:break-word;">
function create(menu,returnPopupMenu)
</source>
*menu:<Array> メニュー定義の配列。
*returnPopupMenu:<boolean> true:PopupMenuを返す、*false:自身を返す。
*return:<PopupMenu||PPM>
;getText
:IDの項目のテキストを返す
<source lang="javascript" style="word-wrap:break-word;">
function getText(menu,returnPopupMenu)
</source>
*id:<number> ID。
;getCommand
:IDの項目のコマンドを返す
<source lang="javascript" style="word-wrap:break-word;">
function getCommand(menu,returnPopupMenu)
</source>
*id:<number> ID。
*return:<*> 未定義の場合はテキストを返す。
;e.g.
<source lang="javascript" style="word-wrap:break-word;">
var menu=[
var menu=[
   ["a",function(){Alert("a");}],
   ["a",1,function(pop,me){Alert(me.tags[0]);},null,["A","a"]],
   [],
   [], //区切り線
   ["b",[
   ["b",20], //チェック済み&ラジオボタンのグループ開始
     ["b-a",function(){return ["b","a"];}], //配列を返す
  ["c",4],  //"b"がチェック済みなのでチェックされない
     ["b-c","b-c"]
  ["d",4],  //ラジオボタンのグループ終了
   ]]
  ["e",1,function(pop,me){return this.caption},[
]
     ["-a",2,"e-a"], //チェックボックス
var p=new SimplePM();
    ["-b",1,function(pop,me){return pop.getItemById(me.parent).command()+me.caption}],
p.create(menu);
    ["-c",1,"unalbled"]
p.track();
  ]],
</source>
  ["f",0] //無効
];
var p=new WidePop(menu);
p.getItemFromPosition(5,2).enabled=false;
p.check(1,function(pos,me){return me.caption=="-a"});
p.create().track(0,true);
Alert(p.getResult().value)
</syntaxhighlight>
 
メニューの実体は<code>WidePop#Item</code>。メニュー定義は引数を同じ順序で格納した配列か、仮引数をキーとした辞書を使う。メニューのタイプは引数<code>flag</code>で設定する。連続したラジオボタンは自動的に1つのグループになる。
 
メニュー定義は<code>WidePop</code>オブジェクトに保存され、後から項目の有効無効などを切り換えたり、複数回実行する事ができる。
 
==ComText.js==
 
キャレット行をマッチした情報から条件を満たすテンプレートを取得し、文字列を作成する。
 
===テンプレート===
 
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
{
  "entries": [
     {
      "name":"for",
      "template":"for(var {0:8-1,0:8}=0;{0:8-1,0:8}<{s}.length;{0:8-1,0:8}++){\n\t\n}",
      "indent":true,
      "modes":["JavaScript","C#","C++","Java"],
      "conditions":[
        {
          "type":14,
          "text":"for[ijk]$"
        }
      ],
      "range":"0"
    }
  ],
  "sub":{
    "name":"sub",
    "comment":"一致するものが無ければ単純に改行する",
    "template":"\n"
  }
}
</syntaxhighlight>
 
;entries
:entry(検索条件とテンプレートのセット)の配列。
;name
:entryの名前。
;template
:テンプレート。「{...}」で囲まれた部分にマッチ結果から文字列を埋め込む事ができる。
;indent
:文字列の挿入時にインデントするかどうか。
;modes
:entryを使用する編集モード
;conditions
:検索条件の配列。
;type
:検索方法(<code>ComText.SearchTypes</code>のいずれか)。
;text
:検索文字列。
;range
:文字列の挿入位置。
;sub
:代替entry。
 
====文字列の埋め込み====
 
テンプレートの「{<開始位置>,<終了位置>}」は元のテキストの範囲を表し、マッチ結果を利用してその範囲の文字列を埋め込む。
<開始位置>と<終了位置>は共に「<インデックス>:<位置><差分>」「<インデックス>:<位置>」「<位置><差分>」「<位置>」の形式を取る。
<インデックス>はマッチした''entry''の''conditions''のインデックスを表す。省略した場合は0。
<位置>はマッチした文字列中での位置を表す。<code>ComText.RangeTypes</code>のいずれかを指定する。
<差分>は<インデックス>と<位置>で特定された位置からの差分を「+<数値>」「-<数値>」の形式で表す。省略した場合は0。
 
「{<インデックス>}」の形式も使用できる。この場合はマッチ位置の全体を表す。
 
e.g.
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
{0:8-1,0:8}
</syntaxhighlight>
 
この場合、開始位置は0番目の''condition''(0)のマッチ終了位置(8)から1文字戻った(-1)位置を表す。
終了位置は0番目の''condition''(0)のマッチ終了位置(8)を表す。
 
''range''の範囲指定も同じ記法を用いる(「{...}」で囲む必要はない)。
 
===使用例===
 
ここでは上記のJSONを使うものとする。
 
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
let os=new ComText(path,option).match();
</syntaxhighlight>
 
# ComTextのコンストラクタはpathに指定したJSONファイルのentriesをリスト化し、現在の編集モードが''modes''にあればそのエントリーを検索に使用する。
# <code>ComText#match</code>で検索を実行する。検索範囲は現在の行に限る。引数に<code>true</code>を指定すると1つのエントリーがマッチした時点で強制終了する。
# ''conditions''の全ての条件にマッチした時のみ、そのエントリーがマッチしたとみなす。''type''が14なので「選択位置より前の文字列を正規表現検索」する。''text''は検索パターンになる。
# マッチが成功すれば、マッチ結果などがコンストラクタの引数<code>option</code>のインスタンスとして<code>ComText#options</code>に追加される。<code>option</code>には<code>ComText.Option</code>かそれを継承したオブジェクトを指定する。
# <code>option</code>のインスタンスは必要になった時にマッチ結果と''template''から文字列を作成する。「{0:8-1,0:8}」の部分には元のテキストの「0番目のconditionsのマッチ終了位置より1文字遡った位置から、conditionsの0番目のマッチ終了位置」までの文字列が埋め込まれる。
# どのエントリーもマッチしなかった場合は代わりに''sub''から<code>option</code>のインスタンスを作成する。''sub''が存在しなければ<code>ComText#options</code>は空になる。
 
デフォルトの<code>ComText.Option</code>は文字列の作成までしか行わないので、利用するには別の関数に渡したり、<code>ComText</code>や<code>ComText.Option</code>を継承したオブジェクトを作る必要がある。
 
==InsertOption.js==
 
<code>ComText.Option</code>の拡張。作成した文字列を挿入するメソッドを持つ。
 
e.g
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
let os=new ComText(path,InsertOption).match().options;
if(os.length){
   os[0].insert();
}
</syntaxhighlight>
 
# <code>ComText.Option</code>はマッチしたエントリーの情報も保持しているので、挿入位置は''range''を使用する。上記のJSONでは「0」だけを指定しているので、「0番目のconditionsのマッチ位置全体」に挿入(上書き)する。
# 文字列が複数行の場合に''indent''を指定していると、2行目以降に1行目に合わせてインデントを追加する。
# テンプレート中の「{s}」「{e}」は挿入後の選択範囲を表す。
 
==InsetSearch.js==
 
ComText.jsを利用して選択文字列から作成した文字列で検索する。<code>ComText</code>の引数<code>option</code>はデフォルトのままで、<code>ComText</code>を継承する事で処理を追加している。
 
e.g
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
let os=new InsetSearch(path,option).execute();
</syntaxhighlight>
 
==MouseEmulator.js==
Mouse.dll(http://ja.syoubook.info/wsh/wsftemplate/<nowiki />)を利用してマウスの操作や座標の取得をする。
 
=kili=
 
旧版。非推奨。
 
==ダウンロード==
 
[https://bitbucket.org/kimigatame/merymacro BitBucket]
 
=Events=
 
イベントマクロを使いやすく(?)したもの。
大体のメリットとしては、
 
* ポップアップ地獄を回避。
* イベント編集に必要なファイルは1つだけ。
* 同じ様な処理にファイルを分けなくていい。
 
;Event.js
:イベントを実行するクラス。イベント名に応じてEventMain.jsの関数を呼び出す。また例外メッセージをアウトプットに投げている。
;EventMain.js
:イベントで実行される関数のファイル。イベントの編集はこのファイルをいじるだけでいい。
;EventTemplate.js
:1つのファイルで通常とイベントと両方のマクロに利用できるようするテンプレート。
;「On~」で始まるファイル
:Meryでイベントとして登録するファイル。Event.executeを呼び出すだけ。
;EventMethod.js
:イベント用に作った関数。
 
==ダウンロード==
[https://bitbucket.org/kimigatame/merymarco_event BitBucket]
 
=覚え書き=
;OnDocumentCloseで閉じたタブをもう一度開こうとすると
以下のNewFileで開いたタブを閉じるとき、定期的?にonDocumentCloseが呼ばれない。またOpenFileは何回かに一回しか成功しない。
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
var file="";
Editor.NewFile();
Editor.OpenFile(file,meEncodingUTF16LE,false);
</syntaxhighlight>
OnModifiedなどでは問題ない。
;コマンドラインオプションからマクロ実行
Window.PromptとWindow.Confirmは実行できない。
;Document.GetLine
デフォルトでは表示行を取得。meGetLineLogicalが未定義なので0を指定する。
;最初の数
*行:1 (Document.GetLine)
*文頭からの位置:0 (Selection.GetActivePos)
*桁:1 (Selection.GetActivePointX)
*Editor,Document:0 (Editors.Item.Documents.Item)
;Window.Document
Document.NewFile後も更新されない。
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
Editor.ActiveDocument.NewFile();
Alert(Document.Text);
</syntaxhighlight>
;Editor.FindInFiles
*ディレクトリ名は最後を"\\"か"\\*"にする。
*アクティブな文書が結果表示で乗っ取られる。
;PopupMenu.Track
*引数無しだとエラー。0でキャレット位置に表示。mePosMouseは1。
*キャンセルした場合の返り値は0。
*返り値を変数に入れるなりOutputするなりしないとメニューは表示されない。
*領域外をクリックしてキャンセルした場合、続けてTrackしていても実行されない。Escでだとされる。
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
var p=CreatePopupMenu();
p.Add("1");
var x=p.Track(0); //ここでキャンセル
if(x==0){
  x=p.Track(0);
}
</syntaxhighlight>
;Selection.Replace
検索オプションを何も付けたくない場合はflagに0を指定する。
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
//正規表現を使わず、大文字と小文字を区別せず、カーソル位置の次の一つだけ、単語の途中でもマッチする
Selection.Replace("x","y",0);
</syntaxhighlight>
 
検索文字列が0x000aから始まるとき、meFindReplaceRegExpを指定しないと、meReplaceAllがおかしい。
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
Selection.Replace("\n","",meReplaceAll); //文書全体の最初の1つだけ処理される
Selection.Replace(";\n","",meReplaceAll); //全て処理される
Selection.Replace("\n;","",meReplaceAll); //文書全体の最初の1つだけ処理される
</syntaxhighlight>
;Document.Text
代入する場合、設定上の改行コードに関わらず、改行記号は文字列中の改行によって変わる。これがSelection.Textだと変わらない。
<syntaxhighlight lang="javascript" style="word-wrap:break-word;">
Document.Text=Document.Text; //改行記号はLFになる
Selection.SelectAll();
Selection.Text=Selection.Text; //元のまま
</syntaxhighlight>
;Selection.CharLeft,CharRight,LineUp,LineDown
Countが0の時は1と同じ。負の場合、逆方向に移動。
;Selection.Find
正規表現の時meFindReplaceOnlyWordは無効。
スポンサーリンク