Source of Nothingness - format

* Menu

About | Profile | まとめ | オリジナル | xyzzy | あんてな | | buzz

* RandomNoteWiki記法 - TextFormat

(ReadMore...)

* xyzzy lisp : format ~W

(format nil "~W" 'hoge)
"hoge"

* xyzzy lisp : format ~F

(format nil "~F" 123.45)
"123.45"
(format nil "~@F" 123.45)
"+123.45"
(format nil "~10F" 123.45)
"    123.45"
(format nil "~10,5F" 123.45)
" 123.45000"
(format nil "~10,5,2F" 123.45)
"12345.00000"
(format nil "~10,5,2,'#F" 123.45)
"##########"
(format nil "~10,,,,'$F" 123.45)
"$$$$123.45"

* xyzzy lisp : format ~G

* xyzzy lisp : format ~E

(format nil "~E" 123.45)
"1.2345e+2"
(format nil "~@E" 123.45)
"+1.2345e+2"
(format nil "~10E" 123.45)
" 1.2345e+2"
(format nil "~10,5E" 123.45)
"1.23450e+2"
(format nil "~10,5,2E" 123.45)
"1.23450e+02"
(format nil "~10,5,2,3E" 123.45)
"123.450e+00"
(format nil "~10,5,2,3,'%E" 123.45)
"%%%%%%%%%%"
(format nil "~15,,,,,'=@E" 123.45)
"=====+1.2345e+2"
(format nil "~15,,,,,,'D@E" 123.45)
"     +1.2345D+2"

* xyzzy lisp : format ~S

(format nil "~S" nil)
"nil"
(format nil "~:S" nil)
"()"
(format nil "~10S" 'hoge)
"hoge      "
(format nil "~10@S" 'hoge)
"      hoge"
(format nil "~10,5@S" 'hogehogehoge)
"   hogehogehoge"
(format nil "~,,5,'$S" 'hoge)
"hoge$$$$$"

* xyzzy lisp : format ~A

(format nil "~A" nil)
"nil"
(format nil "~:A" nil)
"()"
(format nil "~10A" 'hoge)
"hoge      "
(format nil "~10@A" 'hoge)
"      hoge"
(format nil "~10,5@A" 'hogehogehoge)
"   hogehogehoge"
(format nil "~,,5,'#A" 'hoge)
"hoge#####"

* xyzzy lisp : format ~[

(format nil "~[zero~;one~;two~:;many~]" 1)
"one"
(format nil "~[zero~;one~;two~:;many~]" 10)
"many"
(format nil "~1[zero~;one~;two~:;many~]" 10)
"one"
(format nil "~:[false~;true~]" nil)
"false"
(format nil "~:[false~;true~]" 'true)
"true"
(format nil "~@[~A~]" nil)
""
(format nil "~@[~A~]" 'true)
"true"
; こういうこともできるらしい
(format nil "~#[zero~;one~;two~:;many~]" 10 10)
"two"

* xyzzy lisp : format ~$


(format nil "~10,4,30$" +123.45)
"               0123.4500000000"
(format nil "~10,4,30@$" +123.45)
"              +0123.4500000000"
(format nil "~10,4,30:$" +123.45)
"               0123.4500000000"
(format nil "~10,4,30:@$" +123.45)
"+              0123.4500000000"
(format nil "~10,4,30,'*$" +123.45)
"***************0123.4500000000"

* 適当すぎる

(ReadMore...)

* xyzzy lisp : insert-include

てきとー
(defun insert-include (file &optional cwd)
  (interactive "lHeader: " :default0 (merge-pathnames "*.h"))
  (unless cwd
    (if (get-buffer-file-name)
        (setq cwd (directory-namestring (get-buffer-file-name)))
      (return-from insert-include nil)))
  (if (consp file)
      (dolist (f file)
        (insert-include f cwd))
    (insert (format nil "~%#include \"~A\"" (substitute-string file (regexp-quote cwd) "" :case-fold t)))))

* xyzzy : モバイルxyzzyの件

ヒストリ変数でパスを指定する場合でのみ問題ということであれば.xyzzy.historyの出力をどうにかすればいいのでは?と思い、書いてみる。
未テストなので注意。
帰ってからテストします。
(ReadMore...)

* 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で閉じたときの動作だけは感知する手段が無くて無理でした。


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

* xyzzy lisp : format ~R

(format nil "~10,10,'*,'-,2:R" 12345)
"***1-23-45"
(format nil "~R" 12345)
"twelve thousand, three hundred and forty-five"
(format nil "~:R" 12345)
"twelve thousand, three hundred and forty-fifth"
(format nil "~@R" 1234)
"MCCXXXIV"
(format nil "~:@R" 1234)
"MCCXXXIIII"

* xyzzy lisp : format ~^

(format nil "~D~^~D~^~D~^~D" 1)
"1"
(format nil "~D~^~D~^~D~^~D" 1 2 3)
"123"
(format nil "~{~A~^ + ~}" '(1 2 3 4))
"1 + 2 + 3 + 4"
(format nil "~:{~A~^X^~D+~}" '((a 3) (b 2) (c 1) (d 0)))
"aX^3+bX^2+cX^1+dX^0+"
(format nil "~:{~A~:^X^~D+~}" '((a 3) (b 2) (c 1) (d 0)))
"aX^3+bX^2+cX^1+d"
(format nil "~A~V^~A~V^~A~V^~A" 'a 2 'b 1 'c 0 'd)
"abc"
(format nil "~A~V,V^~A~V,V^~A~V,V^~A" 'a 1 2 'b 2 2 'c 2 3 'd)
"ab"
(format nil "~A~V,V,V^~A~V,V,V^~A~V,V,V^~A" 'a 1 1 2 'b 2 1 2 'c 2 3 4 'd)
"a"