コード圧縮
Posted feedbacks - Emacs Lisp
昔ゴルフ用に書いたものを書き直しました。Emacs のバッファを書き換えます。対象言語は Common Lisp で、バッファのモードは lisp-mode と仮定しています。
- 出力例:
- (defun mylib-compress-need-space-p()(cond((or(bobp)(eobp))nil)((string-match"["'(),`]"(string(following-char)))nil)((looking-back"#[0-9]+#")nil)((looking-back"#\\.")t)((string-match"["()]"(string(preceding-char)))nil)(t)))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | (defun mylib-compress-region (&optional start end)
(interactive "r")
(save-restriction
(when (and start end)
(narrow-to-region start end)
(goto-char (point-min)))
(loop
do (delete-region (point)
(progn (while (forward-comment 1)) (point)))
until (or (eobp) (= (following-char) ?\)))
if (mylib-compress-need-space-p)
do (insert " ")
if (looking-at "\\(#'?\\|['`]\\|,@?\\)?(")
do
(down-list 1)
(mylib-compress-region)
(up-list 1)
else do (forward-sexp 1))))
(defun mylib-compress-need-space-p ()
(cond ((or (bobp) (eobp))
nil)
((string-match "[\"'(),`]" (string (following-char)))
nil)
((looking-back "#[0-9]+#")
nil)
((looking-back "#\\\\.")
t)
((string-match "[\"()]" (string (preceding-char)))
nil)
(t)))
|


sweetie089 #6664() Rating-6/10=-0.60
[ reply ]