Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Emacs(Elisp): 全角英数字を半角英数字に、半角カナを全角に、UTF-8の濁点分離を直す。
;;; ------------------------------------------------------------
;;; 全角英数字を半角英数字に、半角カナを全角に、UTF-8の濁点分離を直す
;; gist-description: Emacs(Elisp): 全角英数字を半角英数字に、半角カナを全角に、UTF-8の濁点分離を直す。
;; gist-id: 08a752b04107dbc50ef5
;; gist-name: normalize-chars.el
;; gist-private: nil
(require 'ucs-normalize)
(prefer-coding-system 'utf-8)
(setq file-name-coding-system 'utf-8-hfs)
(setq locale-coding-system 'utf-8-hfs)
(defun normalize-chars ()
"Normarize chars."
;; 選択範囲があればそこを対象にする
(let (type
(if (region-active-p)
(setq beg (region-beginning))
(setq end (region-end)))
(setq type (read-string "normalize whole buffer?(y, n): " nil))
(if (string= type "y")
(setq beg (point-min))
(setq end (point-max)))
(error "Error: no target region"))))
(japanese-zenkaku-region beg end t)
(japanese-hankaku-region beg end t)
(ucs-normalize-NFC-region beg end)))
;; 音引、句読点等を除外
;; thx
(put-char-code-property ?ー 'ascii nil)
(put-char-code-property ?~ 'ascii nil)
(put-char-code-property ?、 'ascii nil)
(put-char-code-property ?。 'ascii nil)
;; 確実に変換
(put-char-code-property ?, 'jisx0208 ?,)
(put-char-code-property ?. 'jisx0208 ?.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment