From 998ed49ccad7ecab877e37beda650fbc159ac83b Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Fri, 18 Sep 2020 13:14:24 +0200 Subject: Tweak input method management - Stop requiring quail, since all functions I need are autoloaded. - Reformat quail-define-package clause ala TeX. Using the "UTF-8" language environment means the input method now shows up on C-h L UTF-8. - Since I might define more input methods, use a more "specific" name. - Move comment about user bindings where it belongs. - Make a proper defun, so that which-key can tell me which binding activates which method. - Note that docstrings could cross-reference input methods, if not for help-xref-mule-regexp. --- .emacs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/.emacs b/.emacs index bc4075a..5190636 100644 --- a/.emacs +++ b/.emacs @@ -47,12 +47,12 @@ ;; Hopefully these will be easier to remember than TeX commands: -(require 'quail) -(quail-define-package "my/input-method" "symbols" "𝒰" t - "Input arbitrary symbols with other arbitrary symbols.") +(quail-define-package + "my/symbols" "UTF-8" "𝒰" t + "Input arbitrary Unicode symbols with other arbitrary symbols.") (mapc (lambda (item) - (quail-defrule (car item) (cdr item) "my/input-method")) + (quail-defrule (car item) (cdr item) "my/symbols")) (list ;; Punctuation '("..." ?…) @@ -67,17 +67,21 @@ ;; Pictograms '("/!\\" ?⚠))) -;; C-c [[:alpha:]] is reserved for users - let's make good use of it. - -(defun my/make-toggle-input-method (input-method) - (lambda () - (:documentation (format "Toggle `%s' input method." input-method)) - (interactive) - ;; `current-input-method' is a string; if INPUT-METHOD is a - ;; symbol, neither eq, eql nor equal would return t. - (if (string= current-input-method input-method) - (deactivate-input-method) - (set-input-method input-method t)))) +(defmacro my/make-input-toggle (input-method) + (let ((fsym (intern (format "my/toggle-input-%s" input-method))) + ;; Unfortunately, by default `help-make-xrefs' does not try to + ;; cross-reference input methods, as `help-xref-mule-regexp' + ;; is nil. This can be worked around by setting this variable + ;; to `help-xref-mule-regexp-template'. + (doc (format "Toggle `%s' input method." input-method))) + `(defun ,fsym () + ,doc + (interactive) + ;; `current-input-method' is a string; if INPUT-METHOD is a + ;; symbol, neither eq, eql nor equal would return t. + (if (string= current-input-method ',input-method) + (deactivate-input-method) + (set-input-method ',input-method t))))) (defun my/set-tab-width (&optional arg) (interactive "P") @@ -123,12 +127,14 @@ (require 'project) (magit-status (project-prompt-project-dir))) +;; C-c [[:alpha:]] is reserved for users - let's make good use of it. + (global-set-key (kbd "C-c c") 'compile) (global-set-key (kbd "C-c d t") 'toggle-truncate-lines) (global-set-key (kbd "C-c d v") 'visual-line-mode) (global-set-key (kbd "C-c e f") 'auto-fill-mode) -(global-set-key (kbd "C-c i t") (my/make-toggle-input-method 'TeX)) -(global-set-key (kbd "C-c i u") (my/make-toggle-input-method 'my/input-method)) +(global-set-key (kbd "C-c i t") (my/make-input-toggle TeX)) +(global-set-key (kbd "C-c i u") (my/make-input-toggle my/symbols)) (global-set-key (kbd "C-c k f") 'my/kill-ring-filename) (global-set-key (kbd "C-c k |") 'my/kill-ring-pipe-region) (global-set-key (kbd "C-c k !") 'my/kill-ring-shell) -- cgit v1.2.3