Source of Nothingness - 正規表現

* Menu

[[About:self:AboutPage.txt]] | [[Profile:http://iddy.jp/profile/southly/]] | [[まとめ:self:1163859357.txt]] | [[オリジナル:http://ninjinix.x0.com/rn/]] | [[xyzzy:http://raido.sakura.ne.jp/southly/xyzzy/site-lisp/]] | [[あんてな:http://i-know.jp/southly/listall]] | [[■:http://raido.sakura.ne.jp/southly/lisp/ni/view.lisp]] | [[buzz:http://www.google.com/profiles/southly#buzz]]

* xyzzy lisp : ミニバッファの入力にエスケープシーケンス

interactive指定子を作っちゃえば楽に置き換えられるんじゃね?
ってことで、こんな。
(in-package "editor")
(defun interactive-read-string-with-escape-sequence (prompt default history title)
  (list (decode-escape-sequence (read-string prompt :default default :history history) nil)))
(pushnew '(#\w . interactive-read-string-with-escape-sequence)
	 *interactive-specifier-alist* :test #'equal)
(defun interactive-read-regexp-with-escape-sequence (prompt default history title)
  (list (decode-escape-sequence (read-string prompt :default default :history history) t)))
(pushnew '(#\W . interactive-read-regexp-with-escape-sequence)
	 *interactive-specifier-alist* :test #'equal)

;; こんな感じで使う
;; 文字列
(defun search-forward-wes (pattern &optional noerror)
  (interactive "wSearch forward: "
    :default0 *last-search-string* :history0 'search)
  (search-command pattern nil nil (interactive-p) noerror))
;; 正規表現
(defun re-search-forward-wes (regexp &optional noerror)
  (interactive "WRe-search forward: "
    :default0 *last-search-regexp* :history0 'search)
  (search-command regexp nil t (interactive-p) noerror))
(export '(search-forward-wes re-search-forward-wes))
(in-package "user")

* Scrapbook : 正規表現プログラミングFAQ

 http://capslockabcjp.kitunebi.com/faq.html

* xyzzy : bregex.dll

戯れに作ってみた。
Boost C++ Libraries の Regex を使うライブラリです。
Perl風の正規表現が使いたい人、動作テストよろしくです。

使い方はstring-matchとかに揃えているので大丈夫かなと思っていたり。

とりあえずc系統とw系統の違いだけ触れておきます。
文字列のデータが「char」なので日本語を扱えません。

文字列のデータが「wchar_t」なので日本語を扱えます。
ただし、Shift_JISの範囲のみです。(たぶん)

なぜ二系統作っているかというとBoost.Regexがどのくらい日本語を扱えるのか
NANRIが知らないからです。しかもVC8との組み合わせで。
wstring-match系で問題なければそれで一本化する予定。

つーことで、動作報告お待ちしています。(あとでXyzzy Wikiにページ作っておきます→作りました [[拡張lisp/Boost.Regex:http://xyzzy.s53.xrea.com/wiki/index.php?%B3%C8%C4%A5lisp%2FBoost.Regex]])
動いた or 動かない、うまくいくパターン or うまくいかないパターンなどなど。

作った時点で興味を失ってるし、今後使う予定も無いのでスタティックリンク版
を作ったらそのまま放置する可能性大です。


あと、リンク禁止なんてことはもちろんありません。どうぞご自由に。
[[(ReadMore...) index.rb?1171550503.txt]]

* xyzzy lisp : 候補の絞込みをするpopup-list

http://xyzzy.s53.xrea.com/wiki/index.php?%BC%C1%CC%E4%C8%A2%2F173
上のページにいくつかありますが元のpopup-listと引数が異なっていて置き換えにくいので書き直し。正規表現を使っていなかった佐野さんのがベース。

(defun popup-list-loop (list callback &optional point with-insert)
  (let ((str "") (matched list) matched1 selected input)
    (loop
      (if with-insert (insert str))
      (popup-list matched (lambda (x) (setq selected x)) point) ; #\ESC
      (refresh-screen)
      (while (not (or selected (setq input (read-char-no-hang *keyboard*))))
        (do-events))
      (if with-insert (delete-region (- (point) (length str)) (point)))
      (cond (selected
             (funcall callback selected)
             (if (eql input #\SPC) (unread-char input))
             (return t))
;           ((eql input #\ESC) (return nil))
            ((eql input #\C-h) (unless (zerop (length str)) (setq str (substring str 0 -1))))
            ((graphic-char-p input) (setq str (format nil "~A~C" str input)))
            (t (unread-char input) (return nil)))
      (setq matched1 (remove-if (lambda (x)
                                  (or (< (length x) (length str))
                                      (string/= x str :end1 (length str))))
                                list))
      (if (endp matched1) (if with-insert
                              (progn (funcall callback str) (return t))
                            (setq str (substring str 0 -1)))
        (setq matched matched1)))))
できるだけ元のpopup-listと同じ操作感になるようにしたつもりですが、ウィンドウをESCで閉じたときの動作だけは感知する手段が無くて無理でした。


ちなみに実際に使うときは[[これ:self:1155828305.txt]]みたいに引数にbase(すでに一致している部分)をとらないといけないような気がしてる。

* xyzzy topic : migemoと大括弧