LaTeX コードをクリーンアップするための優れた elisp マクロを知っている人はいますか?
私は他の人々のソースの多くの LaTeX 編集を行っており、クリーンアップ ツールのセットを拡張したいと考えています。
特に興味深いのは、関数 X をバッファで実行し、すべての LaTeX 環境 (\begin{...} と \end{...} のペア) を独自の行に配置することです。これにより、コード。
私はこれを自分で試すことができますが、そのような関数をプログラミングするためのベスト プラクティスについての提案を聞きたいです。
提案?
編集: アーカイブについては、与えられた回答に基づいた現在のバージョンを次に示します (auctex の使用を想定しています)。現時点では、多かれ少なかれ私のニーズに合っています。思いもよらなかったコーナーケースを検出できるようにするために、y-or-n テストを追加しました。
(defun enviro-split ()
  "Find begin and end macros, and put them on their own line."
  (interactive)
  (save-excursion
(beginning-of-buffer)
;; loop over document looking for begin and end macros
(while (re-search-forward "\\\\\\(begin\\|end\\)" nil t)
  (catch 'continue 
    ; if the line is a pure comment, then goto next
    (if (TeX-in-commented-line)
    (throw 'continue nil)
      )
    ;; when you find one, back up to the beginning of the macro
    (search-backward "\\")
    ;; If it's not at the beginning of the line, add a newline
    (when (not (looking-back "^[ \t]*"))
      (if (y-or-n-p "newline?")
      (insert "\n")
    )
      )
    ;; move over the arguments, one or two pairs of matching braces
    (search-forward "{")        ; start of the argument
    (forward-char -1)
    (forward-sexp)          ; move over the argument
    (if (looking-at "[ \t]*{")  ; is there a second argument?
    (forward-sexp)
      )             ; move over it if so
    (if (looking-at "[ \t]*\\[")    ; is there a second argument?
    (forward-sexp)
      )             ; move over it if so
    (when (looking-at (concat "[ \t]*" (regexp-quote TeX-esc) "label"))
      (goto-char (match-end 0))
      (forward-sexp)
      )
    (if (looking-at (concat "[ \t]*%" ))
    (throw 'continue nil)
      ) 
    ;; If there is anything other than whitespace following the macro,
    ;; insert a newline
    (if (not (looking-at "\\s *$"))
    ;;(insert "\n")
    (if (y-or-n-p "newline (a)?")
        (insert "\n")
      )
      )
    ) ; end catch 'continue
  )
(LaTeX-fill-buffer 'left)
)
  )