forked from GitHub/comp-syntax-gu-mlt
syllables->jamo on save
This commit is contained in:
4
.dir-locals.el
Normal file
4
.dir-locals.el
Normal file
@@ -0,0 +1,4 @@
|
||||
((nil
|
||||
. ((eval . (progn (add-to-list 'load-path (project-root (project-current)))
|
||||
(require 'helpers)
|
||||
(add-hook 'before-save-hook #'hangul-convert-buffer-to-jamo))))))
|
||||
55
helpers.el
Normal file
55
helpers.el
Normal file
@@ -0,0 +1,55 @@
|
||||
(defun hangul-syllables-to-jamo (str)
|
||||
"Convert HANGUL SYLLABLES characters in STR to their HANGUL JAMO
|
||||
equivalents."
|
||||
(let ((result "")
|
||||
(i 0))
|
||||
(while (< i (length str))
|
||||
(let ((char (aref str i)))
|
||||
(if (and (>= char #xAC00) (<= char #xD7A3))
|
||||
;; Hangul syllable
|
||||
(let* ((code (- char #xAC00))
|
||||
(lead (/ code (* 21 28)))
|
||||
(medial (/ (% code (* 21 28)) 28))
|
||||
(final (% code 28))
|
||||
(lead-jamo (+ #x1100 lead))
|
||||
(medial-jamo (+ #x1161 medial))
|
||||
(final-jamo (if (> final 0) (+ #x11A7 final) nil)))
|
||||
(setq result
|
||||
(concat result (char-to-string lead-jamo)
|
||||
(char-to-string medial-jamo)
|
||||
(if final-jamo (char-to-string final-jamo) ""))))
|
||||
;; Not a Hangul syllable
|
||||
(setq result (concat result (char-to-string char)))))
|
||||
(setq i (1+ i)))
|
||||
result))
|
||||
|
||||
(defun hangul-convert-region-to-jamo (beg end)
|
||||
(interactive "r")
|
||||
(replace-region-contents
|
||||
beg end (lambda ()
|
||||
(hangul-syllables-to-jamo (buffer-substring (point-min)
|
||||
(point-max))))))
|
||||
|
||||
(defun hangul-convert-buffer-to-jamo ()
|
||||
(interactive)
|
||||
(hangul-convert-region-to-jamo (point-min) (point-max)))
|
||||
|
||||
(require 'dash)
|
||||
|
||||
(defconst gf-hangul/choseong
|
||||
(cl-loop for i from #x1100 to #x1112 collect i))
|
||||
|
||||
(defconst gf-hangul/jungseong
|
||||
(cl-loop for i from #x1161 to #x1175 collect i))
|
||||
|
||||
(defconst gf-hangul/batchim
|
||||
(cl-loop for i from #x11a8 to #x11c2 collect i))
|
||||
|
||||
(defun gf-hangul/make-pattern (name seq)
|
||||
(format "'%s' : pattern Str = #(%s) ;"
|
||||
name (->> seq
|
||||
(--map (concat "\"" it "\""))
|
||||
(-interpose " | ")
|
||||
(apply #'concat))))
|
||||
|
||||
(provide 'helpers)
|
||||
Reference in New Issue
Block a user