|
![]() |
![]() |
|
カレンダー
英文の語数を集計する(1)-a
英文の語数を集計する(1)-b
英文の語数を集計する(2)
任意のワード数だけ選択
Grepで辞書を引く
任意のタグで選択文字列を挟むver0.1
任意のタグで選択文字列を挟むver0.2
選択したURLをFirefoxで開く(PPA不要) ←新しい
以下の各マクロ(“//”以下)を、サクラエディタの新規ウインドウにコピー&ペーストして好きな名前で保存する(保存先は「共通設定」-「マクロ」-「マクロ一覧」のディレクトリにする)。拡張子は ppa にする(「カレンダ.ppa」等)。それをサクラエディタから読み込んで(「ツール」-「キーマクロの読み込み」)、実行する。よく使うマクロは「共通設定」の「マクロ」タブで登録しておくと便利。「共通設定」-「キー割り当て」タブでマクロごとに専用のショートカットキーを設定することもできる。
※ カレンダーマクロはアプリケーションソフト固有の変数・関数を使用していないので、サクラエディタにかぎらず、PPA採用アプリで等しく利用できるはずです。
ここに掲載されたソースコードは自由に再利用、改変できるものとします。ご自由に改良してくだされば幸いです。
//ある月のカレンダーを表示するマクロ(calendar.ppa)
//作成者: 堀内悟 作成時期: 2004/02 (2/26 v0.9発表)
//任意の日の曜日判定に下の書籍紹介のアルゴリズムを利用
//参照文献:気賀康夫著「電卓に強くなる」(講談社ブルーバックス)
//有効範囲:1900/03--2100/02
var
YM: String; //任意の年月
Y,M,D: Integer; //西暦年・月・日
MDays: Integer; //月間日数
Mk: Integer; //月係数
preN,N: Real; //修正(前,後)の数字
id: Integer; //曜日判定の元になる数字
idw:Integer; //曜日指数(日=0, 月=1,...)
WD: String; //曜日('日', '月'...)
Date: Integer; //カレンダーの日付
kari: String; //汎用変数
CRLF: String; // 文字列変数 CRLF を用意
i, j: Integer; //ループカウンタ
SPC,SPCx1,SPCx3:String; //スペース
Head: String; //カレンダーのヘッダ: 年─月
Head2: String; //カレンダーのヘッダ: 曜日
Line_1: String; //カレンダーの行: 日付第1行
Line_2: String; //カレンダーの行: 日付第2行以降
MSG: String; //ダイアログメッセージ
// <処理の流れ>
// 1. 月初日の曜日を求める
// 2. 年月と曜日を表示するヘッダ2行分を設定
// 3. 1.の結果に基づいて日付部分の1行目を生成
// 4. 繰り返し命令で2行目以降を生成
// 5. すべての行を結合させてダイアログに表示
begin
CRLF := '
';
SPCx1 := ' ';
SPCx3 := ' ';
//任意の年-月の入力
YM := InputBox('年月の入力', '例: 200402 有効範囲: 190003-210002', '');
Y := StrToInt( Copy(YM, 1, 4) );
M := StrToInt( Copy(YM, 5, 2) );
D := 1; //月初日
//月間日数を求める
if M= 1 then MDays := 31;
if M= 3 then MDays := 31;
if M= 5 then MDays := 31;
if M= 7 then MDays := 31;
if M= 8 then MDays := 31;
if M=10 then MDays := 31;
if M=12 then MDays := 31;
if M= 4 then MDays := 30;
if M= 6 then MDays := 30;
if M= 9 then MDays := 30;
if M=11 then MDays := 30;
//うるう年かどうか判定
// 100の倍数は通常年だが、400の倍数ならうるう年
if M=2 then
begin
if Y mod 4 <> 0 then MDays := 28 else //else前=まったき通常年
begin
if Y mod 100 = 0 then
begin
if Y mod 400 = 0 then MDays := 29 else
MDays := 28;
end
else
MDays := 29;
end
end;
//月係数の代入
if M= 1 then Mk := 5;
if M= 2 then Mk := 8;
if M= 3 then Mk := 8;
if M= 4 then Mk := 4;
if M= 5 then Mk := 6;
if M= 6 then Mk := 9;
if M= 7 then Mk := 4;
if M= 8 then Mk := 7;
if M= 9 then Mk := 3;
if M=10 then Mk := 5;
if M=11 then Mk := 1;
if M=12 then Mk := 3;
preN := Y/0.8 + Mk + D; //(Y/0.8)だと"右括弧がありません"エラー!
preN := Trunc(preN); //小数部を切り捨ててInt64型の値にする
if M<3 then N := preN-1;
if M>2 then N := preN;
N := Frac(N/7);
kari := FloatToStr(N);
kari := Copy(kari, 3, 1);
id := StrToInt(kari);
if id= 1 then WD := '月';
if id= 2 then WD := '火';
if id= 4 then WD := '水';
if id= 5 then WD := '木';
if id= 7 then WD := '金';
if id= 8 then WD := '土';
if id= 0 then WD := '日';
//ヘッダ設定および日付部分を表わす変数の初期化
Head := ' ' + IntToStr(Y) + '-' + IntToStr(M) + ' ';
Head2 := '日 月 火 水 木 金 土';
Line_1 := '';
Line_2 := '';
MSG := '';
//曜日を表わす指数を設定する
//日 月 火 水 木 金 土
// 0 1 2 3 4 5 6 = idw
if WD = '日' then idw := 0;
if WD = '月' then idw := 1;
if WD = '火' then idw := 2;
if WD = '水' then idw := 3;
if WD = '木' then idw := 4;
if WD = '金' then idw := 5;
if WD = '土' then idw := 6;
//月初日の曜日を基に日付部分第1行の左インデント幅を設定
if WD = '日' then Line_1 := '';
if WD = '月' then Line_1 := SPCx3;
if WD = '火' then Line_1 := SPCx3+SPCx3;
if WD = '水' then Line_1 := SPCx3+SPCx3+SPCx3;
if WD = '木' then Line_1 := SPCx3+SPCx3+SPCx3+SPCx3;
if WD = '金' then Line_1 := SPCx3+SPCx3+SPCx3+SPCx3+SPCx3;
if WD = '土' then Line_1 := SPCx3+SPCx3+SPCx3+SPCx3+SPCx3+SPCx3;
//日付1行目 (Line_1) に表示される日付は 1 から (7-idw) まで
i := 0;
while i < (7-idw) do
begin
i := i + 1;
Line_1 := Line_1 + ' ' + IntToStr(i)+ ' ';
end;
//このルーチン開始時点で i = 1行目最後の日付
Date := i;
while (Date < MDays) do
begin
for j := 1 to 7 do //1週間分の日付を並べる
begin
if Date = Mdays then Continue;
Date := Date + 1;
if Date < 10 then SPC := SPCx1 else SPC := '';
Line_2 := Line_2 + SPC + IntToStr(Date) + SPCx1;
end;
Line_2 := Line_2 + CRLF;
end;
//ダイアログメッセージ生成
MSG := Head + CRLF + Head2 + CRLF + Line_1 + CRLF + Line_2;
MessageBox(MSG, 'カレンダー', 0);
end
[コントロールパネル]-[画面]-[デザイン]-[メッセージボックスの文字]に等幅フォントを使用しない場合レイアウトがくずれます(Win98で確認)。
2004/02/29 PPAを採用している TrueStoriesEditor 2.7 でも利用できることを確認(その他のPPA採用アプリでも動くはずです)。
//選択領域のワード数を数えるためのPPAマクロ
//Written by Horiuchi Satoru in Dec, 2003
var
WordC: Integer; //ワード数
i : Integer; //検査対象文字の選択文字列内位置
StrLen : Integer; //選択文字列長
Str : String; //選択文字列
Char : String; //検査対象文字
SPC : String; //シングルスペース
begin
Str := Trim(S_GetSelectedString(0));
StrLen := Length(Str);
WordC := 0;
i := 1;
SPC := ' ';
if StrLen = 0 then
begin
MessageBox('文字が選択されていません。', 'エラー',0);
Exit;
end;
while (i <= StrLen) do
begin
Char := Copy(Str, i, 1);
if Char <> SPC then
begin
i := i + 1;
Continue;
end;
if Char = SPC then
begin
if Copy(Str, i+1, 1) = SPC then i := i + 2; //二連続空白の場合
if Copy(Str, i+1, 1)<> SPC then i := i + 1;
WordC := WordC + 1;
end;
end;
WordC := WordC + 1;
MessageBox(IntToStr(WordC) + '語です。', '計算結果',0);
end
語間の空白を数えているだけなので、選択領域内にダッシュ(--)、タブが含まれている場合は実際よりも少ない結果になる。全文に渡って1文字ずつ調べるので処理が遅く、「K6-2 333MHz+Win98上のサクラエディタ1.4.3.3, ウインドウ幅で折り返し」で毎秒20語前後。
//ワード数計算マクロ-Pos関数で効率向上Ver
// 2004.1.6 堀内悟作成
var
WordC: Integer; //ワード数
p : Integer; //空白の文字列内位置
StrLen : Integer; //選択文字列長
Str,tmpStr : String; //選択文字列, 調査中現行文字列
SPC : String; //シングルスペース
//処理の流れ
//文字列内の空白の位置を調べる
//空白があればワード数を1増
//先頭からその位置までを削除→tmpStrに格納
//tmpStrをTrim+Deleteで加工、ループ先頭に戻る
//空白なし→ループ終了
begin
Str := Trim(S_GetSelectedString(0));
StrLen := Length(Str);
WordC := 0;
SPC := ' ';
tmpStr := Str;
if StrLen = 0 then
begin
MessageBox('文字が選択されていません。', 'エラー',0);
Exit;
end;
p := Pos(SPC, tmpStr);
while (p <> 0) do
begin
p := Pos(SPC, tmpStr); //空白の位置を調べる
if p = 0 then Break;
WordC := WordC + 1;
tmpStr := Trim(Delete(tmpStr, 1, p)); //先頭から空白まで削除
end;
WordC := WordC + 1;
MessageBox(IntToStr(WordC) + '語です。', '計算結果',0);
end
処理速度:上述の使用環境で毎秒150語前後。
//ワード数計算マクロ(EWCount.ppa)--スペース+ダッシュVer
// 2004.1.7 堀内悟作成
var
WordC,DC: Integer; //ワード数, ダッシュ数
p,d : Integer; //(空白, ダッシュ)の文字列内位置
StrLen : Integer; //選択文字列長
Str,tmpStr : String; //選択文字列, 調査中現行文字列
SPC,DSH : String; //シングルスペース, ダッシュ
//処理の流れ
//文字列内の空白の位置を調べる、空白があればワード数を1増
//文字列先頭からその位置までを削除→tmpStrに格納
//tmpStrをTrim+Deleteで加工、先頭に戻る
//空白なし→ループ終了
//ダッシュ'--'についても同様のループ
//最後にダッシュの分を語数に足す
begin
Str := Trim(S_GetSelectedString(0));
StrLen := Length(Str);
WordC := 0;
SPC := ' ';
DSH := '--'; //em dash
tmpStr := Str;
if StrLen = 0 then
begin
MessageBox('文字が選択されていません。', 'エラー',0);
Exit;
end;
p := Pos(SPC, tmpStr);
while (p <> 0) do
begin
p := Pos(SPC, tmpStr); //空白の位置を調べる
if p = 0 then Break;
WordC := WordC + 1;
tmpStr := Trim(Delete(tmpStr, 1, p)); //先頭から空白まで削除
end;
//ダッシュ数計算
tmpStr := Str; //検査対象文字列を復元
d := Pos(DSH, tmpStr);
while (d <> 0) do
begin
d := Pos(DSH, tmpStr); //ダッシュの位置を調べる
if d = 0 then Break;
DC := DC + 1;
tmpStr := Trim(Delete(tmpStr, 1, d+1)); //先頭からダッシュまで削除
end;
//語数集計
WordC := WordC + 1 + DC;
MessageBox(IntToStr(WordC) + '語です。', '計算結果',0);
end
//注 後続語がないダッシュ(例: 会話文末の「--”」)も1語とみなす
処理速度:上述の使用環境で毎秒 85 語前後
//任意のワード数(正または負)だけ選択
//2004.8.31公開
var
strW: String; //任意の語数
intW: Integer; //任意の語数
intWN: Integer; //ワード数カウンタ
begin
intWN := 0;
strW := InputBox('語数入力', '', '');
intW := StrToInt(strW);
//入力された数値によって選択方向を分ける
//数値=正: S_WordRight_Sel カーソルの右方向
//数値=負: S_WordLeft_Sel カーソルの左方向
if intW >0 then
begin
while (intWN < intW) do
begin
S_WordRight_Sel();
intWN := intWN + 1;
end;
end
else
begin
while (intWN > intW) do
begin
S_WordLeft_Sel();
intWN := intWN - 1;
end;
end;
end
このマクロの「ワード数」は「英文の語数を集計する」マクロで計算されるものとは違い、「編集」-「選択」-「単語の(左|右)端に移動」コマンドと同様のものです。
//選択した文字列をGrepに渡して辞書を引く
var
moji : String;
begin
moji:=S_ExpandParameter('$C');
S_Grep(moji, '辞書ファイル名', '辞書へのパス', 25400); // Grep
end
s_expandparameter('$c')を使用しているので、場合によっては文字列を選択せずに単語内に挿入ポインタを移動させるだけですぐにgrepコマンドを実行できます。
//選択文字列を任意のタグで挟むPPAマクロver0.1
//2004.9.5 公開
var
strSourceStr: String; //タグで挟む文字列
strTag: String; //任意のタグ(大文字小文字の区別あり)
strStr: String; //タグが付いた後の文字列
strTagOption: String; //ex.<a href="">の「 href=""」
begin
strTagOption := '';
strSourceStr := S_GetSelectedString(0);
strTag := InputBox('タグの入力', '', '');
//オプションがあるタグについては下のif文を参考にして
//適宜追加・設定してください
if UpperCase(strTag) = 'A' then strTagOption := ' href=""';
// br,img等の空要素タグも挿入できるように改良することはすごく簡単だが需要があるだろうか
// if UpperCase(strTag) = 'IMG' then strTagOption := ' src="" align="" alt=""';
strStr := '<' + strTag + strTagOption + '>' + strSourceStr + '</' + strTag + '>';
S_InsText(strStr);
end
挟みたい文字列を選択した後、マクロを実行してください。ダイアログが開きますので、任意の要素名(p, b, div等の開始タグと終了タグ両方を必要とするもの)をタイプしてください。
//選択文字列を任意のタグで挟むPPAマクロ ver0.2
//
//終了タグ不要の空要素も打てるようになりました
//HTML4.01の空要素(非推奨要素を除く)を登録済み
//作成日:2009.1.27
var
strSourceStr : String; //タグで挟む文字列
strLt: String; //最初の左カッコ
strGt: String; //最初の右カッコ
str2ndLt: String; //2番目の左カッコ
str2ndGt: String; //2番目の右カッコ
strStartEle: String; //開始タグの要素名(大文字小文字の区別あり)
strEndEle: String; //終了タグの要素名(大文字小文字の区別あり)
strAttribute: String; //要素の属性
strSlash: String; //終了タグのスラッシュ
strStr : String; //タグが付いた後の文字列
strEle : String; //入力された要素の容器
NULL: String; //無の容器
begin
//変数の初期化
NULL := '';
strLt:= '<';
strGt:= '>';
str2ndLt:= '<';
str2ndGt:= '>';
strSlash:= '/';
strAttribute :='';
//選択文字列の取得
strSourceStr := S_GetSelectedString(0);
//要素の入力
strEle := InputBox('タグの要素名の入力', '', '');
strStartEle := strEle;
//空要素ではない要素名を開始タグと終了タグとで揃える
strEndEle := strStartEle;
//以下お好みに合わせて要素と属性を追加・編集してください
if UpperCase(strEle) = 'A' then strAttribute := ' href=""';
//空要素の場合開始タグの後をナルにする
if UpperCase(strEle) = 'META' then
begin
strAttribute := ' content=""';
strSourceStr := NULL;
str2ndLt := NULL;
strSlash := NULL;
strEndEle := NULL;
str2ndGt := NULL;
end;
if UpperCase(strEle) = 'BR' then
begin
strAttribute := '';
strSourceStr := NULL;
str2ndLt := NULL;
strSlash := NULL;
strEndEle := NULL;
str2ndGt := NULL;
end;
if UpperCase(strEle) = 'IMG' then
begin
strAttribute := ' src="" alt=""';
strSourceStr := NULL;
str2ndLt := NULL;
strSlash := NULL;
strEndEle := NULL;
str2ndGt := NULL;
end;
if UpperCase(strEle) = 'PARAM' then
begin
strAttribute := ' name=""';
strSourceStr := NULL;
str2ndLt := NULL;
strSlash := NULL;
strEndEle := NULL;
str2ndGt := NULL;
end;
if UpperCase(strEle) = 'BASE' then
begin
strAttribute := '';
strSourceStr := NULL;
str2ndLt := NULL;
strSlash := NULL;
strEndEle := NULL;
str2ndGt := NULL;
end;
if UpperCase(strEle) = 'LINK' then
begin
strAttribute := '';
strSourceStr := NULL;
str2ndLt := NULL;
strSlash := NULL;
strEndEle := NULL;
str2ndGt := NULL;
end;
if UpperCase(strEle) = 'COL' then
begin
strAttribute := '';
strSourceStr := NULL;
str2ndLt := NULL;
strSlash := NULL;
strEndEle := NULL;
str2ndGt := NULL;
end;
if UpperCase(strEle) = 'INPUT' then
begin
strAttribute := '';
strSourceStr := NULL;
str2ndLt := NULL;
strSlash := NULL;
strEndEle := NULL;
str2ndGt := NULL;
end;
//挿入する文字列を生成
strStr := strLt + strStartEle + strAttribute + strGt + strSourceStr + str2ndLt + strSlash + strEndEle + str2ndGt;
S_InsText(strStr);
end
//FirefoxGo.mac
//動作確認環境:Windows XP SP2, Firefox 3.5.9, サクラエディタ1.6.3.0
//下の行内のFirefoxのファイルパスは環境により異なる場合があるので、
//適宜変更してください
ExecCommand( 'C:\Program Files\Mozilla Firefox\firefox.exe $C', 0 );
![]() |
![]() |