Skip to content

Instantly share code, notes, and snippets.

@takaxp
Last active April 9, 2021 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaxp/519139e54ce5ab8034887443a16e63c0 to your computer and use it in GitHub Desktop.
Save takaxp/519139e54ce5ab8034887443a16e63c0 to your computer and use it in GitHub Desktop.
(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