home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 November / VPR9711A.ISO / VPR_DATA / Special / movemn8s / movemn8s.lzh / CENTER.MAC next >
Text File  |  1997-03-06  |  3KB  |  159 lines

  1. //  センタリングマクロ ver.8.00
  2. //  by JRくん(GFB03426)  97.3.7
  3.  
  4.     if (readonly) {
  5.         message "センタリング:「上書き禁止」なので実行を中止します。";
  6.         endmacro;
  7.     }
  8.     if (browsemode) {
  9.         message "センタリング:「閲覧モード」なので実行を中止します。";
  10.         endmacro;
  11.     }
  12.  
  13.     $b=searchbuffer;
  14.     #s=searchoption;
  15.  
  16.     $space80 = "                                                                               ";
  17.  
  18. //  ワードラップ使用時には警告
  19.     if ( kinsokustate ) {
  20.         if ( getininum("hidemaru.ini","Env","Wordwrap") == 1 ) {
  21.         question "センタリング:\n"
  22.                + "現在この秀丸はワードラップ機能を使用していますが、\n"
  23.                + "このまま処理を続けると、レイアウトが崩れたり、\n"
  24.                + "行の最後が2文字程度欠落したりする場合があります。\n"
  25.                + "\nこのまま処理を続けますか?";
  26.         if ( result == no ) endmacro;
  27.         }
  28.     }
  29.  
  30.     disableinvert;
  31.  
  32. //  処理範囲を取得
  33.  
  34.     if ((selecting) || (rectselecting)) {
  35.         #y1 = seltopy;
  36.         #y2 = selendy;
  37.         if (selendx == 0) #y2 = #y2 - 1;
  38.         escape;
  39.     } else {
  40.         #y1 = y;
  41.         #y2 = y;
  42.     }
  43.  
  44. //  1行分の文字列を処理するルーチン
  45. OneLineLoop:
  46.     moveto 0, #y1;
  47.  
  48. //  (EOF対策)
  49.     #IsEof = ( #y1 == linecount - 1 );
  50.  
  51. //  その行の開始x座標を取得
  52.  
  53.     #xstart = 0;
  54.     #Code = code;
  55.     if (#Code == 0x0d) {
  56.         //  改行だけだった場合
  57.         goto OneLineEnd;
  58.     } else if ((#Code == 0x20) || (#Code == 0x8140)
  59.         || (#Code == 0)    || (#Code == 0x09))  {
  60.         //  半角/全角スペース・ヌル文字・タブ
  61.         searchdown "[^  \t]",regular;
  62.         if ((y > #y1) || (code == 0x0d) || (code == eof)) {
  63.             //  その行すべてがスペース等だった場合
  64.             goto AllChrDel;
  65.         } else {
  66.             #xstart = x;
  67.         }
  68.     }
  69.  
  70. //  終了x座標を取得
  71.  
  72.     golineend;
  73.     #Code = code;
  74.     if ((#Code == 0x20) || (#Code == 0x8140) || (#Code == 0)
  75.      || (#Code == 0x09) || (#Code == 0x0d)   || (#Code == eof))  {
  76.         //  半角/全角スペース・ヌル文字・タブ・改行・EOFの場合
  77.         searchup "[^  \t]",regular;
  78.     }
  79.     right;
  80.     #xend = x;
  81.     #yend = y;
  82.  
  83.  
  84. //  タブ処理
  85.     moveto 0, #y1;
  86.     beginsel;
  87.     golineend;
  88.     tospace;
  89.     escape;
  90.  
  91. //  カット後の文字列を取得
  92.     $tcutted = gettext(#xstart, #y1, #xend, #yend);
  93.  
  94.  
  95. //  左側のスペースを計算
  96.     #len = strlen($tcutted);
  97.     #space = (width - #len) / 2;    //  センタリング
  98.  
  99.  
  100.     $space = "";
  101.     if (#space > 0) {
  102.  
  103.         #sp1 = #space / 80;
  104.         #sp2 = #space % 80;
  105.  
  106.         while (#sp1 > 0) {
  107.             $space = $space + $space80;
  108.             #sp1 = #sp1 - 1;
  109.         }
  110.         $space = $space + leftstr($space80, #sp2);
  111.     }
  112.  
  113.     moveto 0, #y1;
  114.  
  115. //  前行末に半角分の空きがある場合には改行を追加挿入するための下準備
  116.     $preface = "";
  117.     if (column != 0) {
  118.         up;
  119.         if (linelen < width) $preface = "\n";
  120.         down;
  121.     }
  122.  
  123. //  文字列挿入処理
  124.     beginsel;
  125.     if (#IsEof) {
  126.         golineend;
  127.         insert $preface + $space + $tcutted;
  128.     } else if (#len >= width) {
  129.         down;
  130.         insert $preface + $space + $tcutted;
  131.     } else {
  132.         down;
  133.         insert $preface + $space + $tcutted + "\n";
  134.     }
  135.  
  136.     goto OneLineEnd;
  137.  
  138. //  その行すべてがスペース等の場合は、改行と置き換える、または削除
  139.     AllChrDel:
  140.     moveto 0, #y1;
  141.     beginsel;
  142.     if (#IsEof) {
  143.         golineend;
  144.         delete;
  145.     } else {
  146.         down;
  147.         insert "\n";
  148.     }
  149.  
  150. //  ループ
  151.     OneLineEnd:
  152.     #y1 = #y1 + 1;
  153.     if (#y1 <= #y2) goto OneLineLoop;
  154.  
  155. //  終了処理
  156.     setsearch $b,#s;
  157.     enableinvert;
  158.     endmacro;
  159.