1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

サクラエディタでハイフン含む連続文字を一括で選択できるマクロ

Last updated at Posted at 2021-11-30

COBOLデータ定義に「WK-XXXXX」のような”-”ハイフンを含む変数がよくあります。残念ながら、サクラエディタで「WK-XXXXX」をダブルクリックして「WK-XXXXX」を1つ単語として認識されなくて、変数全体が選択されません。COBOLコーディング時、簡単にコピーやハイライト表示できず非常に不便と感じます。他の対応方法がわからなくて、初めて以下のサクラエディタマクロ(JavaScript)を作成しました。
サクラエディタ「共通設定」「マクロ」導入設定し、また「キー割り当て」「外部マクロ」のショートカットキーを設定したら非常に便利になると思います。ご意見とご参考をいただければと思います。是非試してみてください。

サクラエディタのJavaScriptマクロは、JavaScript関数とサクラエディタ関数でマクロを作成します。以下サイトのサクラエディタ関数はすべてマクロに使用できると思い参考してください。
コマンド一覧 (機能別)
マクロ専用関数/変数
サクラエディタ関数(コマンド)全一覧(このサイトに他のマクロ例もある)

renzokumoji.js
//\s 正規表現空白文字半角SPACE Tab 改行
//\S すべての非空白文字
//連続文字を区っきりする符号を変数pattに追加
//var patt = /\S/;
var patt = /[^\f\n\r\t\v\(\)."'  ()「」]/;
var cx=0, cy=0, cx1=0, cy1=0, cx2=0, cy2=0;
var star=0, end=0
var text=""

Editor.CancelMode(0);
cx = Editor.ExpandParameter( '$y' ); //現在位置行の取得
cy = Editor.ExpandParameter( '$x' ); //現在位置列の取得

// 現在位置から左へ空白までカーソル移動
//patt.test(text)JavaScript 正規表現でtext内容に非空白文字をチェック
Left_Sel();
text = GetSelectedString();
while (patt.test(text)) {
  Left();
  Left_Sel();
  text = GetSelectedString();
}
Right();
cx1 = Editor.ExpandParameter( '$y' ); // 左側位置行の取得
cy1 = Editor.ExpandParameter( '$x' ); // 左側位置列の取得

MoveCursor(cx,cy,0)
// 現在位置から右へ空白までカーソル移動
Right_Sel();
text = GetSelectedString();
while (patt.test(text)) {
  Right();
  Right_Sel();
  text = GetSelectedString();
}

cx2 = Editor.ExpandParameter( '$y' ); //右側位置行の取得
cy2 = Editor.ExpandParameter( '$x' ); //右側位置列の取得

//連続文字列を**選択**
MoveCursor(cx1,cy1,1);

//検索文字列**コピー**
Copy();
//検索文字列**ハイライト**表示されます検索マーク
SearchClearMark();
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?