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

  1. //  右寄せマクロ ver.8.00
  2. //  (折り返し文字数-1+改行)
  3. //  by JRくん(GFB03426)  97.3.7
  4.  
  5.     if (readonly) {
  6.         message "右寄せ:「上書き禁止」なので実行を中止します。";
  7.         endmacro;
  8.     }
  9.     if (browsemode) {
  10.         message "右寄せ:「閲覧モード」なので実行を中止します。";
  11.         endmacro;
  12.     }
  13.  
  14.     $b=searchbuffer;
  15.     #s=searchoption;
  16.  
  17.     $space80 = "                                                                               ";
  18.  
  19. //  ワードラップ使用時には警告
  20.     if ( kinsokustate ) {
  21.         if ( getininum("hidemaru.ini","Env","Wordwrap") == 1 ) {
  22.         question "右寄せ:\n"
  23.                + "現在この秀丸はワードラップ機能を使用していますが、\n"
  24.                + "このまま処理を続けると、レイアウトが崩れたり、\n"
  25.                + "行の最後が2文字程度欠落したりする場合があります。\n"
  26.                + "\nこのまま処理を続けますか?";
  27.         if ( result == no ) endmacro;
  28.         }
  29.     }
  30.  
  31.     disableinvert;
  32.  
  33. //  処理範囲を取得
  34.  
  35.     if ((selecting) || (rectselecting)) {
  36.         #y1 = seltopy;
  37.         #y2 = selendy;
  38.         if (selendx == 0) #y2 = #y2 - 1;
  39.         escape;
  40.     } else {
  41.         #y1 = y;
  42.         #y2 = y;
  43.     }
  44.  
  45. //  1行分の文字列を処理するルーチン
  46. OneLineLoop:
  47.     moveto 0, #y1;
  48.  
  49. //  (EOF対策)
  50. #IsEof = ( #y1 == linecount - 1 );
  51.  
  52. //  その行の開始x座標を取得
  53.  
  54.     #xstart = 0;
  55.     #Code = code;
  56.     if (#Code == 0x0d) {
  57.         //  改行だけだった場合
  58.         goto OneLineEnd;
  59.     } else if ((#Code == 0x20) || (#Code == 0x8140)
  60.         || (#Code == 0)    || (#Code == 0x09))  {
  61.         //  半角/全角スペース・ヌル文字・タブ
  62.         searchdown "[^  \t]",regular;
  63.         if ((y > #y1) || (code == 0x0d) || (code == eof)) {
  64.             //  その行すべてがスペース等だった場合
  65.             goto AllChrDel;
  66.         } else {
  67.             #xstart = x;
  68.         }
  69.     }
  70.  
  71. //  終了x座標を取得
  72.  
  73.     golineend;
  74.     #Code = code;
  75.     if ((#Code == 0x20) || (#Code == 0x8140) || (#Code == 0)
  76.      || (#Code == 0x09) || (#Code == 0x0d)   || (#Code == eof))  {
  77.         //  半角/全角スペース・ヌル文字・タブ・改行・EOFの場合
  78.         searchup "[^  \t]",regular;
  79.     }
  80.     right;
  81.     #xend = x;
  82.     #yend = y;
  83.  
  84.  
  85. //  タブ処理
  86.     moveto 0, #y1;
  87.     beginsel;
  88.     golineend;
  89.     tospace;
  90.     escape;
  91.  
  92. //  カット後の文字列を取得
  93.     $tcutted = gettext(#xstart, #y1, #xend, #yend);
  94.  
  95.  
  96. //  左側のスペースを計算
  97.     #len = strlen($tcutted);
  98.     #space = width - #len - 1;    //  右寄せ
  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.