Last active
April 9, 2021 10:59
-
-
Save takaxp/519139e54ce5ab8034887443a16e63c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 my-replace-punctuation-to-scientific () | |
(interactive) | |
(my-replace-punctuation 'scientific)) | |
(defun my-replace-punctuation-to-normal () | |
(interactive) | |
(my-replace-punctuation 'normal)) | |
(defun my-replace-punctuation (to) | |
(let ((pos (point)) | |
(source (cond ((eq to 'normal) "\\(,\\)\\|\\(.\\)") | |
((eq to 'scientific) "\\(、\\)\\|\\(。\\)")))) | |
(if (not source) | |
(error "Target punctuation is wrong") | |
(goto-char (point-min)) | |
(while (re-search-forward source nil :noerror) | |
(let ((w (match-string-no-properties 0))) | |
(cond ((equal w ",") (replace-match "、")) | |
((equal w ".") (replace-match "。")) | |
((equal w "、") (replace-match ",")) | |
((equal w "。") (replace-match "."))))) | |
(goto-char pos)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment