Skip to content

Instantly share code, notes, and snippets.

@ifree
Created June 24, 2015 01:17
Show Gist options
  • Save ifree/0146135a0de3b07d4e1d to your computer and use it in GitHub Desktop.
Save ifree/0146135a0de3b07d4e1d to your computer and use it in GitHub Desktop.
add space between Chinese and Englisth letters
(defun ifree--format-article (begin end)
"Add space between Chinese and English letters between BEGIN and END."
(interactive "r")
(let (region-begin
region-end
(matcher-begin "\\(?1:[\u4e00-\u9fa5]+\\)\\(?2:[a-zA-Z]+\\)") ;cjk,
;symbols?
(matcher-end "\\(?1:[a-zA-Z]+\\)\\(?2:[\u4e00-\u9fa5]+\\)"))
(if (region-active-p)
(setq region-begin begin region-end end)
(setq region-begin (point-min) region-end (point-max)))
(save-excursion
(goto-char region-begin)
(while (re-search-forward matcher-begin region-end t)
(replace-match "\\1 \\2")
(setq region-end (+ 1 region-end)))
(goto-char region-end)
(while (re-search-backward matcher-end region-begin t)
(replace-match "\\1 \\2")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment