Skip to content

Instantly share code, notes, and snippets.

@kikujin
Last active February 4, 2024 18:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikujin/1df7ec2e1e1197df48fd7a8837417fa6 to your computer and use it in GitHub Desktop.
Save kikujin/1df7ec2e1e1197df48fd7a8837417fa6 to your computer and use it in GitHub Desktop.
秀丸エディタ : 青空文庫マクロ
// 青空文庫テキスト用強調表示ファイル
// ルビ《ふりがな》 → 強調表示1
// 注記[#3字下げ] → 強調表示2
17,(?:|(.+))??《.+?》
81,[#.*?]
/*
拡張子を .vtxt に変更した青空文庫のテキストファイルに適用する。
例えば 短編.vtxt というファイルでこのマクロを実行すると、
同じフォルダにある 短編[-].vtxt を開きスクロール同期させる。
短編[-].vtxt は 短編.vtxt からルビ《》と注記[#]を除いたもので、
同じフォルダに無ければ 短編.vtxt から生成する。
短編[-].vtxt でこのマクロを実行した場合は、同じフォルダにある
短編.vtxt を開きスクロール同期させる。
同じフォルダに 短編.vtxt が無ければエラーメッセージを
表示してマクロを終了する。
*/
$EXT = ".vtxt";
$REGEX = "[#.*?]|(?:|(.+))??《.+?》";
$REPLACEMENT = "\\1";
$SUFFIX = "[-]";
if (filetype != $EXT) {
message("このファイルは縦書きテキスト(" + $EXT +
")ではありません。\nマクロを終了します。");
endmacro;
}
#initial_lineno = lineno;
#was_opened_dest = false;
$name = leftstr(basename, strlen(basename) - strlen($EXT));
#name_len = strlen($name);
#suffix_len = strlen($SUFFIX);
if (#name_len > #suffix_len) {
if ($SUFFIX == rightstr($name, #suffix_len)) {
#was_opened_dest = true; //dest -> [-].vtxt
$dest_file = basename;
#dest_handle = hidemaruhandle(0);
$src_file = leftstr($name, #name_len - #suffix_len) + $EXT;
if (!existfile($src_file)) {
message($src_file + "が見つかりません。\n" +
"マクロを終了します。");
endmacro;
}
#src_num = findhidemaru($src_file);
if (#src_num == -1) {
readonlyopenfile $src_file;
} else {
setactivehidemaru #src_num;
}
}
}
// current active hidemaru -> srcfile
disabledraw;
if (!readonly) {
readonlyloadfile basename;
}
gofiletop;
#src_handle = hidemaruhandle(0);
if (!#was_opened_dest) {
$dest_file = $name + $SUFFIX + $EXT;
#dest_num = findhidemaru($dest_file);
if (#dest_num == -1) {
if (!existfile($dest_file)) {
#is_new_dest = true;
selectall;
copy;
}
openfile $dest_file;
} else {
setactivehidemaru #dest_num;
}
#dest_handle = hidemaruhandle(0);
disabledraw;
}
if (#is_new_dest) {
paste;
replaceallfast $REGEX, $REPLACEMENT, regular;
gofiletop;
beginclipboardread;
call getcliipboard2;
$line = $$return;
while ($line != "") {
#EOF = false;
#line_length = strlen($line) - 1;
if (rightstr($line, 1) != "\x0a") {
#line_length = #line_length + 1;
#EOF = true;
}
golineend2;
#diff = #line_length - column;
while (#diff > 0) {
insert " ";
#diff = #diff - 1;
}
if (!#EOF) {
moveto2 0, lineno + 1;
}
call getcliipboard2;
$line = $$return;
}
save;
}
setactivehidemaru #dest_handle;
readonlyloadfile $dest_file;
gofiletop;
scrolllink #src_handle;
#dest_handle = hidemaruhandle(0);
setactivehidemaru #src_handle;
scrolllink #dest_handle;
movetolineno 0, #initial_lineno;
setactivehidemaru #dest_handle;
movetolineno 0, #initial_lineno;
endmacro;
//getclipboardの4KB制限を無くすサブルーチン (秀丸マクロヘルプより)
getcliipboard2:
$$line = "";
while (true) {
$$add = getclipboard;
if ($$add == "") {
break;
}
$$line = $$line + $$add;
if (strstr($$add, "\x0a") >= 0) {
break;
}
}
return $$line;
Copyright (c) 2019 kikujin
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*マクロファイルと強調表示定義ファイルの置き場所
*強調表示定義ファイルの設定
*マクロファイルの設定と実行《じっこう》
[#3字下げ][#中見出し]強調表示定義ファイルの置き場所[#中見出し終わり]
メニュー→その他→動作環境→左ツリーで環境をクリック
設定ファイル用のフォルダはキー割り当てや強調表示、色の設定などでデフォルトの保存・読み込み先となるフォルダです。
表示されるダイアログには設定ファイル用フォルダ内の強調表示|定義《ていぎ》ファイルがリスト表示されているので目的《もくてき》のもの[#「もの」に傍点]を選択してOKをクリックします。
aozora.macは拡張子を vtxt に変更した青空文庫のテキストファイルからルビ《》と注記[#]を取り除いたものを生成し、元のファイルとスクロール同期させます。
生成されたファイルは拡張子を除いた元のファイル名の末尾に[-]を加えた名前となります。
ルビ《》と注記[#]を取り除く際にはその行末に取り除いた分の半角スペースが挿入されるので等幅フォントをご使用ください。
一度、[-]ファイルを生成すると、元のファイルとどちらかでこのマクロを実行する事で、もう一方とスクロール同期させます。
改行文字を表示する設定にすると行末に空白がある事でルビ又は注釈が削除されているのが分かるので、もし確認したい場合には元の方で確認するという形になります。
aozora.hilightを適用すると確認の際にルビと注釈がそれぞれ強調表示1、強調表示2に設定した色で表示されます。
test.vtxtはテスト及び設定用のファイルです。
イメージを含めた、詳しい設定は以下にありますのでご参照ください。
青空文庫を秀丸エディタで読む際の設定とマクロ
https://fujinand.hatenablog.com/entry/hidemaru-aozora
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment