Emacs Part 46
■ このスレッドは過去ログ倉庫に格納されています
0001名無しさん@お腹いっぱい。
2014/06/23(月) 02:42:14.91GNU Emacs - GNU Project - Free Software Foundation (FSF)
https://www.gnu.org/software/emacs/
EmacsWiki: サイトマップ
http://www.emacswiki.org/emacs/
前スレ
Emacs Part 45
http://peace.2ch.net/test/read.cgi/unix/1391839128/
0248名無しさん@お腹いっぱい。
2014/09/05(金) 17:19:18.19(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 (my-inside-string-or-comment-p)
(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)
;; 直前の行末尾がコメント内であれば何もしない
(save-excursion
(forward-line -1)
(end-of-line)
(my-inside-string-or-comment-p)))
(replace-match (match-string 1))))
;; ついでにインデント
(indent-region (point-min) (point-max))))))
0249名無しさん@お腹いっぱい。
2014/09/05(金) 18:07:42.79>>248
末尾が "(" なコメントが含まれているとその次の行をコメント行に連結してしまう不具合を修正
(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)
(let ((regexps '("\\([^?\\](\\)[ \t\n]+" "[ \t\n]+\\()\\)"))
re)
(while (setq re (pop regexps))
(goto-char (point-min))
(while (re-search-forward re nil t)
(unless (my-inside-string-or-comment-p (match-beginning 1))
(replace-match (match-string 1))))))
(indent-region (point-min) (point-max))))))
■ このスレッドは過去ログ倉庫に格納されています