Last active
February 6, 2019 05:14
-
-
Save FromAtom/4518441 to your computer and use it in GitHub Desktop.
YaTeXでTeXを書いている状態で保存時に動作する。
"、"と"。"を","と"." に変換し、全角英数字を半角英数字に変換する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;バッファ全体の句読点と読点をコンマとピリオドに変換 | |
(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