;;; input-method-generator.el --- Input Method Generator ;; Copyright (C) 2021 by Jean Louis ;; Author: Jean Louis ;; Version: 0.1 ;; Package-Requires: () ;; Keywords: convenience ;; URL: https://hyperscope.link/3/7/7/4/1/Emacs-Input-Method-Generator-37741.html ;; This file is not part of GNU Emacs. ;; This program is free software: you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;;; ;;; Run M-x rcd-input-method-generator RET to generate ๐“ฏ๐“ช๐“ท๐“ฌ๐”‚ input ;;; methods. ;;; ;;; CIRCLED LATIN: โ“โ“‘โ“’โ““โ“”โ“•โ“—โ“˜โ“™โ“šโ“›โ“œโ“โ“žโ“Ÿโ“ โ“กโ“ขโ“ฃโ“ฆโ“งโ“จโ“ฉ ;;; FULLWIDTH LATIN: ๏ผฆ๏ผต๏ผฌ๏ผฌ๏ผท๏ผฉ๏ผค๏ผด๏ผจ ๏ผฌ๏ผก๏ผด๏ผฉ๏ผฎ ;;; สŸแด€แด›ษชษด สŸแด‡แด›แด›แด‡ส€ ๊œฑแดแด€สŸสŸ แด แด‡ส€ส ษดษชแด„แด‡ ๊œฐแดส€ ๊œฑแดแด„ษชแด€สŸ แดแด‡แด…ษชแด€ ;;; ๐•ธ๐–†๐–™๐–๐–Š๐–’๐–†๐–™๐–Ž๐–ˆ๐–†๐–‘ ๐•ญ๐–”๐–‘๐–‰ ๐•ฑ๐–—๐–†๐–๐–™๐–š๐–— ;;; ๐‘ด๐’‚๐’•๐’‰๐’†๐’Ž๐’‚๐’•๐’Š๐’„๐’‚๐’ ๐‘ฉ๐’๐’๐’… ๐‘ฐ๐’•๐’‚๐’๐’Š๐’„ ;;; ๐Œ๐š๐ญ๐ก๐ž๐ฆ๐š๐ญ๐ข๐œ๐š๐ฅ ๐๐จ๐ฅ๐ ;;; ๐”ป๐•†๐•Œ๐”น๐•ƒ๐”ผ ๐•Š๐•‹R๐•ŒC๐•‚ ;;; ๐‘€๐ด๐‘‡๐ป๐ธ๐‘€๐ด๐‘‡๐ผ๐ถ๐ด๐ฟ ๐ผ๐‘‡๐ด๐ฟ๐ผ๐ถ ;;; ๐“‚๐’ถ๐“‰๐’ฝe๐“‚๐’ถ๐“‰๐’พ๐’ธ๐’ถ๐“ ๐“ˆ๐’ธ๐“‡๐’พ๐“…๐“‰ ;;; ๐“ช๐“ท๐“ญ ๐“ผ๐“ฎ๐“ฟ๐“ฎ๐“ป๐“ช๐“ต ๐“ธ๐“ฝ๐“ฑ๐“ฎ๐“ป๐“ผ ;;; ;;; customize place to save the in variable `rcd-input-method-directory' ;;; ;;; Change Log: ;;; Code: (defcustom rcd-input-method-directory "~/" "Define the directory to generated input method files." :group 'rcd :type 'string) (defun string-to-file-force (string file) "Print STRING into file, matters not if file exists. Return FILE as file name." (with-temp-file file (insert string)) file) (defvar rcd-input-methods '( "CIRCLED LATIN@" "FULLWIDTH LATIN@" "LATIN LETTER SMALL" "MATHEMATICAL BOLD FRAKTUR" "MATHEMATICAL BOLD ITALIC" "MATHEMATICAL BOLD SCRIPT" "MATHEMATICAL BOLD" "MATHEMATICAL DOUBLE-STRUCK" "MATHEMATICAL ITALIC" "MATHEMATICAL MONOSPACE" "MATHEMATICAL SANS-SERIF BOLD ITALIC" "MATHEMATICAL SANS-SERIF BOLD" "MATHEMATICAL SANS-SERIF ITALIC" "MATHEMATICAL SANS-SERIF" "MATHEMATICAL SCRIPT" ) "The input methods that this package can generate and load.") (defun rcd-input-method-generator () "Generate ๐“ฏ๐“ช๐“ท๐“ฌ๐”‚ input method. Activate it with \\[toggle-input-method] or set it with \\[set-input-method]" (interactive) (let* ((completion-ignore-case t) (input-method (completing-read"Input method: " rcd-input-methods)) (unicode-part (upcase (string-trim input-method))) (name (string-replace "@" "" (downcase input-method))) (name (string-replace " " "-" name)) (title (capitalize input-method)) (description (concat title " Input Method")) (file (concat "input-method-" name ".el"))) (string-to-file-force (rcd-input-method-generate input-method unicode-part name title description) file) (load-file file))) (defun rcd-input-method-generate (input-method unicode-part name title description) "Generate INPUT-METHOD. Uses UNICODE-PART, NAME, TITLE and DESCRIPTION." (let* ((mode-1 (when (string-match "@" unicode-part) t)) (unicode-part (replace-regexp-in-string "@" "" unicode-part)) (unicode-part-capital (if mode-1 (concat unicode-part " CAPITAL LETTER ") (concat unicode-part " CAPITAL "))) (unicode-part-small (if mode-1 (concat unicode-part " SMALL LETTER ") (concat unicode-part " SMALL ")))) (with-temp-buffer (insert (format ";;;; Input method: %s\n\n" title)) (insert "(quail-define-package\n") (insert (format " \"%s\" \"Unicode\" \"%s\" t\n" name title)) (insert (format " \"%s\"\n" description)) (insert (format " nil t nil nil nil nil nil nil nil nil t)\n\n")) (insert "(quail-define-rules") (let ((num 65)) (while (< num 91) (let* ((name (concat unicode-part-capital (char-to-string num))) (char-from-name (condition-case nil (char-from-name name) (error "")))) (when char-from-name (insert (format "\n (\"%s\" %d)" (char-to-string num) char-from-name)))) (setq num (1+ num)))) (let ((num 97)) (while (< num (+ 97 26)) (let* ((name (concat unicode-part-small (upcase (char-to-string num)))) (char-from-name (condition-case nil (char-from-name name) (error "")))) (when char-from-name (insert (format "\n (\"%s\" %d)" (char-to-string num) char-from-name)))) (setq num (1+ num)))) (insert ")\n\n") (buffer-string)))) ;;; input-method-generator.el ends here