home *** CD-ROM | disk | FTP | other *** search
/ MacPeople 2003 February 1 / MACPEOPLE-2003-02-01.ISO.7z / MACPEOPLE-2003-02-01.ISO / ぶらりオンラインウェアの旅 / 定番ソフト / Jedit(OS9) / MacroCollectionJ.sea / MacroCollection-J / 章節図番号再割付 / スクリプトの解説 < prev    next >
Text File  |  2001-01-01  |  4KB  |  106 lines

  1. 章節図 番号再割付スクリプト
  2.  
  3. Programmed by Satoshi Matsumoto
  4. 章、節、図の番号をふり直す。
  5. 選択範囲の章・節・図の見出しの位置を正規表現で検出して、番号をふり直す。
  6.  
  7. --------
  8.  
  9. ダイアログの設定をする
  10. property theDialog : {size:[360, 150], contents:[ツ
  11.     {class:push button, bounds:[270, 120, 330, 140], name:"OK", enabled:3}, ツ
  12.     {class:push button, bounds:[190, 120, 250, 140], name:"Cancel"}, ツ
  13.     {class:text field, bounds:[65, 30, 270, 30 + 16], name bounds:ツ
  14.         章見出しのデフォルトパターンを指定する
  15.         [10, 30, 60, 30 + 16], name:"章見出し", value:"^{第}{[¥¥s0-9]+}{章}"}, ツ
  16.     {class:text field, bounds:[285, 30, 330, 30 + 16], value:"1"}, ツ
  17.     {class:text field, bounds:[65, 55, 270, 55 + 16], name bounds:ツ
  18.         節見出しのデフォルトパターンを指定する
  19.         [10, 55, 60, 55 + 16], name:"節見出し", value:"^{第}{[¥¥s¥¥.0-9]+}{節}"}, ツ
  20.     {class:text field, bounds:[285, 55, 330, 55 + 16], value:"1"}, ツ
  21.     {class:text field, bounds:[65, 80, 270, 80 + 16], name bounds:ツ
  22.         図見出しのデフォルトパターンを指定する
  23.         [10, 80, 60, 80 + 16], name:"図見出し", value:"^{第}{[¥¥s¥¥.0-9]+}{図}"}, ツ
  24.     {class:text field, bounds:[285, 80, 330, 80 + 16], value:"1"}, ツ
  25.     {class:static text, bounds:[120, 10, 180, 10 + 16], contents:"正規表現"}, ツ
  26.     {class:static text, bounds:[290, 10, 340, 10 + 16], contents:"初期値"} ツ
  27.         ], timeout after:60}
  28.  
  29. tell application "Jedit4"
  30.     Jeditのバージョンが4.0.4以上かどうかをチェック。そうでない時は中止。
  31.     if version < 404 then
  32.         preDialog
  33.         display dialog "Jedit4.0 Rev4.0.4 以降を使用してください" buttons {" 了解"}
  34.         postDialog
  35.         error number -128
  36.     end if
  37.     preDialog
  38.     ダイアログを表示する
  39.     set dialogResult to (dd auto dialog theDialog with grayscale)
  40.     postDialog
  41.     if item 1 of dialogResult is false then
  42.         ダイアログでキャンセルボタンを押したときは中止する
  43.         error number -128
  44.     end if
  45.     ダイアログの結果を各変数に格納
  46.     set chapPattern to item 3 of dialogResult
  47.     set chapNum to ((item 4 of dialogResult) as integer) - 1
  48.     set secPattern to item 5 of dialogResult
  49.     set secNum to ((item 6 of dialogResult) as integer) - 1
  50.     set figPattern to item 7 of dialogResult
  51.     set figNum to ((item 8 of dialogResult) as integer) - 1
  52.     ウィンドウを前面へ
  53.     activate
  54.     if (count document) < 1 then
  55.         preDialog
  56.         ウィンドウが開いていないときは警告をだして終了
  57.         display dialog "行番号を付加する書類を先に開いてください。" buttons {" 了解"}
  58.         postDialog
  59.         error number -128
  60.     end if
  61.     tell document 1
  62.         if length of selection < 1 then
  63.             なにも選択されていないときは書類全体を対象に
  64.             set startPara to 1
  65.             set endPara to paragraph number of last character
  66.         else
  67.             選択領域の開始/終了パラグラフ番号を変数にセット
  68.             set startPara to paragraph number of selection
  69.             set endPara to paragraph number of last character of selection
  70.         end if
  71.         改めて対象領域をパラグラフ単位で設定しなおす
  72.         select (paragraphs startPara thru endPara)
  73.         選択範囲の章見出し、節見出し、図見出しのどれかに一致する文字列をとりあえず見つける
  74.         repeat while (find (chapPattern & "|" & secPattern & "|" & figPattern) in selection with grep without entire word)
  75.             見つかった文字列の先頭と最後のオフセットを変数へ保存
  76.             set startOff to byteoffset of selection
  77.             set endOff to startOff + (length of selection)
  78.             章、節、図のそれぞれに応じて処理する
  79.             if find chapPattern in bytes startOff thru endOff then
  80.                 章番号をインクレメント
  81.                 set chapNum to chapNum + 1
  82.                 節番号、図番号をリセット
  83.                 set secNum to 0
  84.                 set figNum to 0
  85.                 章見出しの番号部分を再割付
  86.                 replace chapPattern to "¥¥1 " & chapNum & " ¥¥3" in selection with grep
  87.             else if find secPattern in bytes startOff thru endOff then
  88.                 節番号をインクレメント
  89.                 set secNum to secNum + 1
  90.                 節見出しの番号部分を再割付
  91.                 replace secPattern to "¥¥1 " & chapNum & "." & secNum & " ¥¥3" in selection with grep
  92.             else if find figPattern in bytes startOff thru endOff then
  93.                 図番号をインクレメント
  94.                 set figNum to figNum + 1
  95.                 図見出しの番号部分を再割付
  96.                 replace figPattern to "¥¥1 " & chapNum & "." & figNum & " ¥¥3" in selection with grep
  97.             end if
  98.             残りの部分を再選択し直す
  99.             set startOff to byteoffset of selection
  100.             set startOff to startOff + (length of selection)
  101.             set endOff to byteoffset of last byte of paragraph endPara
  102.             select (bytes startOff thru endOff)
  103.         end repeat
  104.     end tell
  105. end tell
  106.