Emacs Part 46
■ このスレッドは過去ログ倉庫に格納されています
0251名無しさん@お腹いっぱい。
2014/09/06(土) 12:26:32.31あー、修正ついでにwhile式を一つだけにしようとしていたら都合よく錯覚したみたい
あと最初の二文字が "(<改行>" の文字列を壊してしまう不具合があったのでそれも直しました
(defun my-inside-string-or-comment-p (&optional point)
(let ((point (or point (point))))
(save-excursion
(let ((state (parse-partial-sexp (point-min) point)))
(or (nth 3 state) (nth 4 state))))))
(defun my-pretty-lisp-code-region (start end)
(interactive "r")
(save-excursion
(save-restriction
(save-match-data
(narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward "\\((\\)[ \t\n]+" nil t)
(unless (or (my-inside-string-or-comment-p (match-beginning 1))
;; "?(" 及び "\(" を除外
(member (char-after (1- (match-beginning 1))) '(?? ?\\)))
(replace-match (match-string 1))))
(goto-char (point-min))
(while (re-search-forward "[ \t\n]+\\()\\)" nil t)
(unless (or (my-inside-string-or-comment-p (match-beginning 1))
;; 直前の要素(空白類以外)が改行終端型コメントの場合を除外
(my-inside-string-or-comment-p (match-beginning 0)))
(replace-match (match-string 1))))
(indent-region (point-min) (point-max))))))
■ このスレッドは過去ログ倉庫に格納されています