1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

丸括弧付き文字への変換 [例 (16) → ⒃ ]

Last updated at Posted at 2023-03-17

概要

コマンド M-x parenthesized-region で、範囲指定したテキストの中に

ASCIIコードの丸括弧 '()' で括った文字
(1) (2) (3) (4) (5) (6) (7) (8) (9) (10)
(11) (12) (13) (14) (15) (16) (17) (18) (19) (20)
(A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M)
(N) (O) (P) (Q) (R) (S) (T) (U) (V) (W) (X) (Y) (Z)
(a) (b) (c) (d) (e) (f) (g) (h) (i) (j) (k) (l) (m)
(n) (o) (p) (q) (r) (s) (t) (u) (v) (w) (x) (y) (z)

(一) (二) (三) (四) (五) (六) (七) (八) (九) (十)
(月) (火) (水) (木) (金) (土) (日)
(株) (有) (社) (名) (特) (財) (祝)
(労) (代) (呼) (学) (監) (企) (資)
(協) (祭) (休) (自) (至)

(ᄀ) (ᄂ) (ᄃ) (ᄅ) (ᄆ)
(ᄇ) (ᄉ) (ᄋ) (ᄌ) (ᄎ) (ᄏ) (ᄐ) (ᄑ)
(ᄒ) (가) (나) (다) (라) (마) (바) (사)
(아) (자) (차) (카) (타) (파) (하) (주)
(오전) (오후)

があった場合は

丸括弧付き文字
⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽
⑾ ⑿ ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇
🄐 🄑 🄒 🄓 🄔 🄕 🄖 🄗 🄘 🄙 🄚 🄛 🄜
🄝 🄞 🄟 🄠 🄡 🄢 🄣 🄤 🄥 🄦 🄧 🄨 🄩
⒜ ⒝ ⒞ ⒟ ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨
⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯ ⒰ ⒱ ⒲ ⒳ ⒴ ⒵

㈠ ㈡ ㈢ ㈣ ㈤ ㈥ ㈦ ㈧ ㈨ ㈩
㈪ ㈫ ㈬ ㈭ ㈮ ㈯ ㈰
㈱ ㈲ ㈳ ㈴ ㈵ ㈶ ㈷
㈸ ㈹ ㈺ ㈻ ㈼ ㈽ ㈾
㈿ ㉀ ㉁ ㉂ ㉃

㈀ ㈁ ㈂ ㈃ ㈄
㈅ ㈆ ㈇ ㈈ ㈉ ㈊ ㈋ ㈌
㈍ ㈎ ㈏ ㈐ ㈑ ㈒ ㈓ ㈔
㈕ ㈖ ㈗ ㈘ ㈙ ㈚ ㈛ ㈜
㈝ ㈞

に変換します。

逆変換は M-x ucs-normalize-NFKC-region を使ってください。

ソースコード

parenthesized.el
(defconst parenthesized-symbols-alist
  '(("(1)" . "⑴") ("(2)" . "⑵") ("(3)" . "⑶") ("(4)" . "⑷")
    ("(5)" . "⑸") ("(6)" . "⑹") ("(7)" . "⑺") ("(8)" . "⑻")
    ("(9)" . "⑼") ("(10)" . "⑽") ("(11)" . "⑾") ("(12)" . "⑿")
    ("(13)" . "⒀") ("(14)" . "⒁") ("(15)" . "⒂") ("(16)" . "⒃")
    ("(17)" . "⒄") ("(18)" . "⒅") ("(19)" . "⒆") ("(20)" . "⒇")
    ("(A)" . "🄐") ("(B)" . "🄑") ("(C)" . "🄒") ("(D)" . "🄓") ("(E)" . "🄔")
    ("(F)" . "🄕") ("(G)" . "🄖") ("(H)" . "🄗") ("(I)" . "🄘") ("(J)" . "🄙")
    ("(K)" . "🄚") ("(L)" . "🄛") ("(M)" . "🄜") ("(N)" . "🄝") ("(O)" . "🄞")
    ("(P)" . "🄟") ("(Q)" . "🄠") ("(R)" . "🄡") ("(S)" . "🄢") ("(T)" . "🄣")
    ("(U)" . "🄤") ("(V)" . "🄥") ("(W)" . "🄦") ("(X)" . "🄧") ("(Y)" . "🄨")
    ("(Z)" . "🄩")
    ("(a)" . "⒜") ("(b)" . "⒝") ("(c)" . "⒞") ("(d)" . "⒟") ("(e)" . "⒠")
    ("(f)" . "⒡") ("(g)" . "⒢") ("(h)" . "⒣") ("(i)" . "⒤") ("(j)" . "⒥")
    ("(k)" . "⒦") ("(l)" . "⒧") ("(m)" . "⒨") ("(n)" . "⒩") ("(o)" . "⒪")
    ("(p)" . "⒫") ("(q)" . "⒬") ("(r)" . "⒭") ("(s)" . "⒮") ("(t)" . "⒯")
    ("(u)" . "⒰") ("(v)" . "⒱") ("(w)" . "⒲") ("(x)" . "⒳") ("(y)" . "⒴")
    ("(z)" . "⒵")

    ("(一)" . "㈠") ("(二)" . "㈡") ("(三)" . "㈢") ("(四)" . "㈣") ("(五)" . "㈤")
    ("(六)" . "㈥") ("(七)" . "㈦") ("(八)" . "㈧") ("(九)" . "㈨") ("(十)" . "㈩")
    ("(月)" . "㈪") ("(火)" . "㈫") ("(水)" . "㈬") ("(木)" . "㈭") ("(金)" . "㈮")
    ("(土)" . "㈯") ("(日)" . "㈰")
    ("(株)" . "㈱") ("(有)" . "㈲") ("(社)" . "㈳") ("(名)" . "㈴") ("(特)" . "㈵")
    ("(財)" . "㈶") ("(祝)" . "㈷") ("(労)" . "㈸") ("(代)" . "㈹") ("(呼)" . "㈺")
    ("(学)" . "㈻") ("(監)" . "㈼") ("(企)" . "㈽") ("(資)" . "㈾") ("(協)" . "㈿")
    ("(祭)" . "㉀") ("(休)" . "㉁") ("(自)" . "㉂") ("(至)" . "㉃")

    ("(ᄀ)" . "㈀") ("(ᄂ)" . "㈁") ("(ᄃ)" . "㈂") ("(ᄅ)" . "㈃") ("(ᄆ)" . "㈄")
    ("(ᄇ)" . "㈅") ("(ᄉ)" . "㈆") ("(ᄋ)" . "㈇") ("(ᄌ)" . "㈈") ("(ᄎ)" . "㈉")
    ("(ᄏ)" . "㈊") ("(ᄐ)" . "㈋") ("(ᄑ)" . "㈌") ("(ᄒ)" . "㈍")
    ("(가)" . "㈎") ("(나)" . "㈏") ("(다)" . "㈐") ("(라)" . "㈑") ("(마)" . "㈒")
    ("(바)" . "㈓") ("(사)" . "㈔") ("(아)" . "㈕") ("(자)" . "㈖") ("(차)" . "㈗")
    ("(카)" . "㈘") ("(타)" . "㈙") ("(파)" . "㈚") ("(하)" . "㈛") ("(주)" . "㈜")
    ("(오전)" . "㈝") ("(오후)" . "㈞")
    ))

(defun parenthesized-region (beg end)
  (interactive (list (mark) (point)))
  (let (pos kv val klen
            (swp (< end beg)))
    (when swp
      (setq pos end)
      (setq end beg)
      (setq beg pos))
    (goto-char beg)
    (while (and (setq pos (re-search-forward "([^()]+)" nil t))
                (<= pos end))
      (when (setq kv (assoc (match-string 0) parenthesized-symbols-alist))
        (setq klen (length (car kv)))
        (setq val (cdr kv))
        (setq end (+ end (length val) (- klen)))
        (delete-char (- klen))
        (insert val)))
    (goto-char (if swp beg end))))

久しぶりに Emacs-Lisp を使ったので、もっと良い書き方があるかと思います。

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?