2013年1月11日金曜日

OEditでhowm

OEditでhowmファイルを作成する方法です。

準備


OEditのscmlibフォルダにoedit.scmを作ります。xyzzyにおける.xyzzyみたいなものらしい。
次に、OEditの(ぷち)資料室 - Schemeサンプルソースからxlib-base.scmとxlib-event.scmをダウンロードし、scmlibフォルダに保存します。


oedit.scm


先ほど作成したoedit.scmに以下をコピペ

(use xlib-base)  ;◆汎用基礎関数ライブラリ
(use xlib-event) ;◆拡張ハンドラ操作ライブラリ


;▼コマンドライン引数(文字列)をバラして、文字列リストにして返す関数▼
(define (apx-get-command-line-args) (get-args (app-get-command-line-option)))
(define (get-args s)
  (define (skip-space) ;◆半角空白をスキップ。(その次位置へ)
    (define c (peek-char ip))
    (if (eqv? c #\space) (begin (read-char ip) (skip-space)))
  )
  (define (get-inner-quote os) ;◆"~"内の文字列を取得。(その次位置へ)
    (define c (read-char ip))
    (if (or (eof-object? c) (eqv? c #\"))
      os
      (get-inner-quote (string-append os (string c)))
    )
  )
  (define (get-word os) ;◆単語を取得。(その次位置へ)
    (define c (peek-char ip))
    (cond
      ((or (eof-object? c) (eqv? c #\space)) os)
      ((eqv? c #\") (begin (read-char ip) (string-append os (get-inner-quote ""))))
      (else (get-word (string-append os (string (read-char ip)))))
    )
  )
  (define ip (open-input-string s))
  (let loop ( (ol '()) )
    (define c (read-char ip))
    (cond
      ((eof-object? c)  (close-input-port ip) (reverse ol))
      ((eqv? c #\space) (skip-space) (loop ol))
      ((eqv? c #\") (loop (cons (get-inner-quote "")  ol)))
      (else         (loop (cons (get-word (string c)) ol)))
    )
  )
)

;▼自作起動オプション処理用ハンドラ▼
(define handle-my-option (lambda ()
  (define (option-launcher ops)
    (cond
      ((equal? ops "/howm") (define s (sys-strftime "\= \n\n\n[%Y-%m-%d %H:%M]" (sys-localtime (sys-time))))(editor-paste-string s)(editor-set-row-col 0 2))
      ((rxmatch #/^\/xa(\d+)-(\d+)-(\d+)-(\d+)$/ ops) => (lambda (m)
        (editor-set-select-area
          (- (string->number (rxmatch-substring m 1)) 1)
          (- (string->number (rxmatch-substring m 2)) 1)
          (- (string->number (rxmatch-substring m 3)) 1)
          (- (string->number (rxmatch-substring m 4)) 1)
        )))
      ((rxmatch #/^\/xc(\d+)-(\d+)$/ ops) => (lambda (m)
        (editor-set-row-col
          (- (string->number (rxmatch-substring m 1)) 1)
          (- (string->number (rxmatch-substring m 2)) 1)
        )))
    )
  )
  (for-each option-launcher (apx-get-command-line-args))
))

;▼on-open-fileイベントハンドラとしてセット▼
(app-add-event-handler "on-open-file-first" handle-my-option)


;▼ howm追加▼
(app-set-key "Ctrl+3" (lambda() (howm-add)))
(define (howm-add)
  (begin
  (define howm-editor-path (string-append (app-get-tool-dir) "oedit.exe"))
  (define fn (editor-get-filename)) ;◆現在編集中のテキストのファイルパス
  (if (and fn (string>? fn "")) ;◆カレントファイルのあるディレクトリにファイルを作成。無題ならば起動ディレクトリに作成する
   (define howm-path 
    (string-append (regexp-replace #/^(.*\\).*$/ fn "$1") (sys-strftime "%Y-%m-%d-%H%M%S" (sys-localtime (sys-time))) ".howm /howm"))
   (define howm-path (string-append (sys-strftime "%Y-%m-%d-%H%M%S" (sys-localtime (sys-time))) ".howm /howm")))
  (win-exec howm-editor-path howm-path )))


howm追加より上が、howmの起動オプションを追加するためのもの。起動オプションに/howmがあれば、howmの書式をコピペするようにしてます。ほぼOEditの(ぷち)資料室 - メモ|OEdit関連の自作起動オプションのコピペです。
howm追加のところは僕が書いたもの。Ctrl+3を押せば、新規にhowmファイルを作成します。(app-set-key "Ctrl+3" (lambda() (howm-add)))の"Ctrl+3"の箇所を書き換えることで、別のキーに割り当てることができます。

PPxの設定


次に、PPxから新規作成でhowmファイルを作れるようにします。
まず、TORO's Libraryに行ってPaper Plane xUI Text Moduleをダウンロード。その中にあるPPXTEXT.DLLをPPxフォルダに置きます。
あとは、以下のようなコマンドをキーかメニューかに登録すればおk。

%Ob D:\bin\oedit\oedit.exe %*nowdatetime(Y-N-D-HMS).howm /howm

参考にしたサイト


あとはDocフォルダ内のmacro_ref.txtを読みましょう

0 件のコメント:

コメントを投稿