Skip to content

Instantly share code, notes, and snippets.

@FromAtom
Last active February 6, 2019 05:14
Show Gist options
  • Save FromAtom/4518441 to your computer and use it in GitHub Desktop.
Save FromAtom/4518441 to your computer and use it in GitHub Desktop.
YaTeXでTeXを書いている状態で保存時に動作する。 "、"と"。"を","と"." に変換し、全角英数字を半角英数字に変換する。
;;バッファ全体の句読点と読点をコンマとピリオドに変換
(defun replace-commaperiod-buffer ()
(interactive "r")
(save-excursion
(replace-string "、" "," nil (point-min) (point-max))
(replace-string "。" "." nil (point-min) (point-max))))
;;選択範囲内の全角英数字を半角英数字に変換
(defun hankaku-eisuu-region (start end)
(interactive "r")
(while (string-match
"[0-9A-Za-z]+"
(buffer-substring start end))
(save-excursion
(japanese-hankaku-region
(+ start (match-beginning 0))
(+ start (match-end 0))
))))
;;バッファ全体の全角英数字を半角英数字に変換
(defun hankaku-eisuu-buffer ()
(interactive)
(hankaku-eisuu-region (point-min) (point-max)))
;;YaTeXモードの時にのみ動作させる用に条件分岐
(defun replace-commaperiod-before-save-if-needed ()
(when (memq major-mode
'(yatex-mode))
(replace-commaperiod-buffer)(hankaku-eisuu-buffer)))
;;保存前フックに追加
(add-hook 'before-save-hook 'replace-commaperiod-before-save-if-needed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment