diff --git a/doc/generate.el b/doc/generate.el index 5a5c23db..34f2808c 100644 --- a/doc/generate.el +++ b/doc/generate.el @@ -16,7 +16,7 @@ (require 'racket-xp) (require 'racket-util) (require 'racket-show) -(require 'racket-unicode-input-method) +(require 'racket-input) (require 'racket-smart-open) (require 'racket-repl-buffer-name) (require 'racket-hash-lang) @@ -38,6 +38,7 @@ `("Edit" racket-mode racket-insert-lambda + racket-insert-symbol racket-fold-all-tests racket-unfold-all-tests racket-tidy-requires @@ -49,7 +50,7 @@ racket-insert-closing racket-cycle-paren-shapes racket-backward-up-list - racket-unicode-input-method-enable + racket-input-mode racket-align racket-unalign racket-complete-at-point @@ -228,7 +229,10 @@ "Showing information" racket-show-functions "Running racket and raco commands in a shell or terminal" - racket-shell-or-terminal-function) + racket-shell-or-terminal-function + "Racket input method" + racket-input-prefix + racket-input-translations) "Variables to include in the Reference.") (defun racket-generate--variables () diff --git a/doc/racket-mode.org b/doc/racket-mode.org index 01b323c5..d60476fe 100644 --- a/doc/racket-mode.org +++ b/doc/racket-mode.org @@ -382,20 +382,13 @@ Note: Racket Mode does not support the "old" eldoc API that uses ~eldoc-document You can use {{{ref(racket-mode-start-faster)}}} to make the Racket REPL start faster. -** Unicode input method +** Inserting Unicode math symbols -An optional Emacs input method, ~racket-unicode~, lets you easily type various Unicode symbols that might be useful when writing Racket code. +To insert various Unicode math symbols, you can: -To automatically enable the ~racket-unicode~ input method in ~racket-mode~ and ~racket-repl-mode~ buffers, put the following code in your Emacs init file: +- Use a command: {{{see(racket-insert-symbol)}}}. -#+BEGIN_SRC lisp -(add-hook 'racket-mode-hook #'racket-unicode-input-method-enable) -(add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable) -#+END_SRC - -{{{see(racket-unicode-input-method-enable)}}}. - -{{{see(racket-insert-lambda)}}}. +- Use an Emacs input method, which you can enable in a buffer using a minor mode: {{{see(racket-input-mode)}}}. ** Ligatures diff --git a/doc/racket-mode.texi b/doc/racket-mode.texi index edd87c62..e36b1b08 100644 --- a/doc/racket-mode.texi +++ b/doc/racket-mode.texi @@ -77,7 +77,7 @@ Configure * Edit buffers and REPL buffers:: * eldoc:: * Start faster:: -* Unicode input method:: +* Inserting Unicode math symbols:: * Ligatures:: Commands @@ -97,6 +97,7 @@ Edit * racket-mode:: * racket-insert-lambda:: +* racket-insert-symbol:: * racket-fold-all-tests:: * racket-unfold-all-tests:: * racket-tidy-requires:: @@ -108,7 +109,7 @@ Edit * racket-insert-closing:: * racket-cycle-paren-shapes:: * racket-backward-up-list:: -* racket-unicode-input-method-enable:: +* racket-input-mode:: * racket-align:: * racket-unalign:: * racket-complete-at-point:: @@ -203,6 +204,7 @@ Variables * Experimental debugger variables:: * Showing information:: * Running racket and raco commands in a shell or terminal:: +* Racket input method:: General variables @@ -262,6 +264,11 @@ Running racket and raco commands in a shell or terminal * racket-shell-or-terminal-function:: +Racket input method + +* racket-input-prefix:: +* racket-input-translations:: + Configuration functions * Showing information: Showing information (1). @@ -557,7 +564,7 @@ You can @code{setq} this directly in your Emacs init file (@samp{~/.emacs} or @s * Edit buffers and REPL buffers:: * eldoc:: * Start faster:: -* Unicode input method:: +* Inserting Unicode math symbols:: * Ligatures:: @end menu @@ -844,21 +851,18 @@ Note: Racket Mode does not support the ``old'' eldoc API that uses @code{eldoc-d You can use @ref{racket-mode-start-faster} to make the Racket REPL start faster. -@node Unicode input method -@section Unicode input method - -An optional Emacs input method, @code{racket-unicode}, lets you easily type various Unicode symbols that might be useful when writing Racket code. +@node Inserting Unicode math symbols +@section Inserting Unicode math symbols -To automatically enable the @code{racket-unicode} input method in @code{racket-mode} and @code{racket-repl-mode} buffers, put the following code in your Emacs init file: - -@lisp -(add-hook 'racket-mode-hook #'racket-unicode-input-method-enable) -(add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable) -@end lisp +To insert various Unicode math symbols, you can: -@xref{racket-unicode-input-method-enable}. +@itemize +@item +Use a command: @xref{racket-insert-symbol}. -@xref{racket-insert-lambda}. +@item +Use an Emacs input method, which you can enable in a buffer using a minor mode: @xref{racket-input-mode}. +@end itemize @node Ligatures @section Ligatures @@ -940,6 +944,7 @@ You can also view these by using the normal Emacs help mechanism: @menu * racket-mode:: * racket-insert-lambda:: +* racket-insert-symbol:: * racket-fold-all-tests:: * racket-unfold-all-tests:: * racket-tidy-requires:: @@ -951,7 +956,7 @@ You can also view these by using the normal Emacs help mechanism: * racket-insert-closing:: * racket-cycle-paren-shapes:: * racket-backward-up-list:: -* racket-unicode-input-method-enable:: +* racket-input-mode:: * racket-align:: * racket-unalign:: * racket-complete-at-point:: @@ -1034,7 +1039,21 @@ penultimate step during initialization. Insert λ. -To insert Unicode symbols generally, see @ref{racket-unicode-input-method-enable}. +To insert Unicode symbols generally, see @ref{racket-input-mode}. + +@node racket-insert-symbol +@subsection racket-insert-symbol + +@kbd{M-x} @code{racket-insert-symbol} + +Insert a symbol from @ref{racket-input-translations}. + +A command alternative to the ``Racket'' input method activated by +@ref{racket-input-mode}. + +Presents a @code{completing-read} UI, in which the symbols that would +be inserted are shown as annotations -- a preview unlike what is +currently provided by the Emacs UI for input method. @node racket-fold-all-tests @subsection racket-fold-all-tests @@ -1390,70 +1409,54 @@ especially not repeatedly. Instead, initially use string or comment, if any, then use normal @code{backward-up-list} repeatedly. -@node racket-unicode-input-method-enable -@subsection racket-unicode-input-method-enable +@node racket-input-mode +@subsection racket-input-mode + +@kbd{M-x} @code{racket-input-mode} -@kbd{M-x} @code{racket-unicode-input-method-enable} +A minor mode to enable the ``Racket'' input method. -Set input method to racket-unicode. +The Racket input method lets you type @ref{racket-input-prefix}, +followed by a key sequence from @ref{racket-input-translations}, +directly in a buffer, to insert a symbol. -The racket-unicode input method lets you easily type various -Unicode symbols that might be useful when writing Racket code. +For example when @ref{racket-input-prefix} is the default ``\'', you +can type ``\All'' and it is immediately replaced with ``∀''. -To automatically enable the racket-unicode input method in -racket-mode and racket-repl-mode buffers, put the following code -in your Emacs init file: +To enable @ref{racket-input-mode} (and the Racket input method) for +all new buffers, put the following in your Emacs init file: @lisp - (add-hook 'racket-mode-hook #'racket-unicode-input-method-enable) - (add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable) + (dolist (hook '(racket-mode-hook + racket-hash-lang-mode-hook + racket-repl-mode-hook)) + (add-hook hook #'racket-input-mode)) @end lisp -To temporarily enable this input method for a single buffer you -can use ``M-x racket-unicode-input-method-enable''. - -Use the standard Emacs key C-\ to toggle the input method. - -When the racket-unicode input method is active, you can for -example type ``All'' and it is immediately replaced with ``∀''. A -few other examples: - -@multitable {aaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaa} -@item omega -@tab ω -@item x@math{_1} -@tab x₁ -@item x@math{^1} -@tab x¹ -@item A -@tab 𝔸 -@item test-->>E -@tab test-->>∃ (racket/redex) -@item vdash -@tab ⊢ -@end multitable +Tip: You may use the standard Emacs key C-\ to toggle the +current input method. -To see a table of all key sequences use ``M-x -describe-input-method racket-unicode''. +Tip: If you don’t like the highlighting of partially matching +tokens you can disable that using @code{input-method-highlight-flag}. -If you want to add your own mappings to the ``racket-unicode'' -input method, you may add code like the following example in your -Emacs init file: +See the Emacs manual for other information about input methods. -@lisp - ;; Either (require 'racket-mode) here, or, if you use - ;; use-package, put the code below in the :config section. - (with-temp-buffer - (racket-unicode-input-method-enable) - (set-input-method "racket-unicode") - (let ((quail-current-package (assoc "racket-unicode" - quail-package-alist))) - (quail-define-rules ((append . t)) - ("^o" ["ᵒ"])))) -@end lisp +Tip: Another way to use @ref{racket-input-translations} is by using a +command: @ref{racket-insert-symbol}. + +This is a minor mode. If called interactively, toggle the +@code{Racket-Input mode} mode. If the prefix argument is positive, +enable the mode, and if it is zero or negative, disable the mode. -If you don’t like the highlighting of partially matching tokens you -can turn it off by setting @code{input-method-highlight-flag} to nil. +If called from Lisp, toggle the mode if ARG is @code{toggle}. Enable +the mode if ARG is nil, omitted, or is a positive number. +Disable the mode if ARG is a negative number. + +To check whether the minor mode is enabled in the current buffer, +evaluate @ref{racket-input-mode}. + +The mode's hook is called both when the mode is enabled and when +it is disabled. @node racket-align @subsection racket-align @@ -3093,6 +3096,7 @@ Delete the ``compiled'' directories made by @ref{racket-mode-start-faster}. * Experimental debugger variables:: * Showing information:: * Running racket and raco commands in a shell or terminal:: +* Racket input method:: @end menu @node General variables @@ -3770,6 +3774,46 @@ send a newline or enter. Predefined choices include @ref{racket-shell}, @ref{racket-term}, @ref{racket-ansi-term}, and @ref{racket-vterm}. +@node Racket input method +@section Racket input method + +@menu +* racket-input-prefix:: +* racket-input-translations:: +@end menu + +@node racket-input-prefix +@subsection racket-input-prefix + +A prefix used by the ``Racket'' input method. + +This string is prepended to the key sequence strings in +@ref{racket-input-translations}, when setting up the input method. + +Using some non-nil, non-blank prefix avoids conflicts between key +sequences and portions of normal words. For example ``oint'' +would insert ``∮'' while you're typing ``point'' -- but not +``\oint''. + +If you change this setting manually with @code{setq} (instead of using +the customization buffer or @code{setopt}) you need to call +@code{racket-input-setup} in order for the change to take effect. + +@node racket-input-translations +@subsection racket-input-translations + +A list of translations. + +Each element is (KEY-SEQUENCE-STRING TRANSLATION-STRING). + +Used by the ``Racket'' input method activated by +@ref{racket-input-mode}, as well as by the @ref{racket-insert-symbol} +command. + +If you change this setting manually with @code{setq} (instead of using +the customization buffer or @code{setopt}) you need to call +@code{racket-input-setup} in order for the change to take effect. + @node Configuration functions @chapter Configuration functions diff --git a/racket-common.el b/racket-common.el index 59b61ac3..82caf664 100644 --- a/racket-common.el +++ b/racket-common.el @@ -207,7 +207,7 @@ property whose value is STRING. The close | syntax is set by (defun racket-insert-lambda () "Insert λ. -To insert Unicode symbols generally, see `racket-unicode-input-method-enable'." +To insert Unicode symbols generally, see `racket-input-mode'." (interactive) (insert-char racket-lambda-char 1)) (put 'racket-insert-lambda 'delete-selection t) diff --git a/racket-hash-lang.el b/racket-hash-lang.el index 29c7efa0..1efcc18f 100644 --- a/racket-hash-lang.el +++ b/racket-hash-lang.el @@ -76,6 +76,7 @@ "---" ["Comment" comment-dwim] ["Insert λ" racket-insert-lambda] + ["Insert Symbol" racket-insert-symbol] ["Indent Region" indent-region] ["Cycle Paren Shapes" racket-cycle-paren-shapes :active (racket--sexp-edit-mode-p)] ["Align" racket-align :active (racket--sexp-edit-mode-p)] diff --git a/racket-input.el b/racket-input.el new file mode 100644 index 00000000..1e86f8a3 --- /dev/null +++ b/racket-input.el @@ -0,0 +1,349 @@ +;;; racket-input.el -*- lexical-binding: t; -*- + +;; Copyright (c) 2024 by Greg Hendershott + +;; Author: Greg Hendershott +;; URL: https://github.com/greghendershott/racket-mode + +;; SPDX-License-Identifier: GPL-3.0-or-later + +(require 'quail) +(require 'racket-complete) +(require 'racket-util) + +(defgroup racket-input nil + "The Racket input method." + :group 'racket) + +(defcustom racket-input-prefix "\\" + "A prefix used by the \"Racket\" input method. + +This string is prepended to the key sequence strings in +`racket-input-translations', when setting up the input method. + +Using some non-nil, non-blank prefix avoids conflicts between key +sequences and portions of normal words. For example \"oint\" +would insert \"∮\" while you're typing \"point\" -- but not +\"\\oint\". + +If you change this setting manually with `setq' (instead of using +the customization buffer or `setopt') you need to call +`racket-input-setup' in order for the change to take effect." + :type '(choice (string :tag "Prefix") + (const :tag "None" nil))) + +(defcustom racket-input-translations + '(;; Typed Racket + ("All" "∀") + ("Union" "U") + ("Intersection" "∩") + ;; Redex + ("test-->>E" "test-->>∃") + ;; Turnstile + ("vdash" "⊢") + ("gg" "≫") + ("succ" "≻") + ;; Other type rule symbols + ("times" "×") + ("Uparrow" "⇑") + ("Downarrow" "⇓") + ("Leftarrow" "⇐") + ("Rightarrow" "⇒") + ("leftarrow" "←") + ("rightarrow" "→") + ("nwarrow" "↖") + ("nearrow" "↗") + ("uparrow" "↑") + ("downarrow" "↓") + ("searrow" "↘") + ("swarrow" "↙") + ("leftrightarrow" "↔") + ("updownarrow" "⇕") + ("aleph" "א") + ("emptyset" "∅") + ("nabla" "∇") + ("surd" "√") + ("negation" "¬") + ("infinity" "∞") + ("prod" "∏") + ("coprod" "∐") + ("integrate" "∫") + ("oint" "∮") + ("vee" "∨") + ("wedge" "∧") + ("follows" "∘") + ("setin" "∈") + ("ni" "∋") + ("notin" "∉") + ("sqsubset" "⊏") + ("sqsupset" "⊐") + ("sqsubseteq" "⊑") + ("sqsupseteq" "⊒") + ("subset" "⊂") + ("superset" "⊃") + ("subseteq" "⊆") + ("supseteq" "⊇") + ("approx" "≈") + ("cong" "≌") + ("neq" "≠") + ("sqcap" "⊓") + ("sqcup" "⊔") + ("models" "⊧") + ;; Greek letters + ("alpha" "α") + ("Alpha" "Α") + ("beta" "β") + ("Beta" "Β") + ("gamma" "γ") + ("Gamma" "Γ") + ("delta" "δ") + ("Delta" "Δ") + ("epsilon" "ε") + ("Epsilon" "Ε") + ("zeta" "ζ") + ("Zeta" "Ζ") + ("eta" "η") + ("Eta" "Η") + ("theta" "θ") + ("Theta" "Θ") + ("iota" "ι") + ("Iota" "Ι") + ("kappa" "κ") + ("Kappa" "Κ") + ("lambda" "λ") + ("Lambda" "Λ") + ("lamda" "λ") + ("Lamda" "Λ") + ("mu" "μ") + ("Mu" "Μ") + ("nu" "ν") + ("Nu" "Ν") + ("xi" "ξ") + ("Xi" "Ξ") + ("omicron" "ο") + ("Omicron" "Ο") + ("pi" "π") + ("Pi" "Π") + ("rho" "ρ") + ("Rho" "Ρ") + ("sigma" "σ") + ("Sigma" "Σ") + ("tau" "τ") + ("Tau" "Τ") + ("upsilon" "υ") + ("Upsilon" "Υ") + ("phi" "φ") + ("Phi" "Φ") + ("chi" "χ") + ("Chi" "Χ") + ("psi" "ψ") + ("Psi" "Ψ") + ("omega" "ω") + ("Omega" "Ω") + ("digamma" "ϝ") + ("Digamma" "Ϝ") + ("san" "ϻ") + ("San" "Ϻ") + ("qoppa" "ϙ") + ("Qoppa" "Ϙ") + ("sampi" "ϡ") + ("Sampi" "Ϡ") + ("stigma" "ϛ") + ("Stigma" "Ϛ") + ("heta" "ͱ") + ("Heta" "Ͱ") + ("sho" "ϸ") + ("Sho" "Ϸ") + ;; Double-struck letters + ("|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|" "ℤ") + ("|gamma|" "ℽ") + ("|Gamma|" "ℾ") + ("|pi|" "ℼ") + ("|Pi|" "ℿ") + ;; Quantifiers + ("forall" "∀") + ("exists" "∃") + ;; Numeric subscripts + ("_0" "₀") + ("_1" "₁") + ("_2" "₂") + ("_3" "₃") + ("_4" "₄") + ("_5" "₅") + ("_6" "₆") + ("_7" "₇") + ("_8" "₈") + ("_9" "₉") + ;; Numeric superscripts + ("^0" "⁰") + ("^1" "¹") + ("^2" "²") + ("^3" "³") + ("^4" "⁴") + ("^5" "⁵") + ("^6" "⁶") + ("^7" "⁷") + ("^8" "⁸") + ("^9" "⁹")) + "A list of translations. + +Each element is (KEY-SEQUENCE-STRING TRANSLATION-STRING). + +Used by the \"Racket\" input method activated by +`racket-input-mode', as well as by the `racket-insert-symbol' +command. + +If you change this setting manually with `setq' (instead of using +the customization buffer or `setopt') you need to call +`racket-input-setup' in order for the change to take effect." + :set 'racket-custom-set + :initialize 'custom-initialize-default + :type '(repeat (list (string :tag "Key sequence") + (string :tag "Translation")))) + +(defun racket-input-setup () + "Set up the Racket input method based on the customization +variables." + (with-temp-buffer + (quail-define-package + "Racket" ;name + "UTF-8" ;language + "∏" ;title (in mode line) + t ;guidance + "Racket input method." ;docstring + nil ;translation-keys + nil ;forget-last-selection + nil ;deterministic + nil ;kbd-translate + nil ;show-layout + nil ;create-decode-map + nil ;maximum-shortest + nil ;overlay-plist + nil ;update-translation-function + nil ;conversion-keys + t)) ;simple + (dolist (tr racket-input-translations) + (pcase-let* ((`(,key ,translation) tr) + (key (concat racket-input-prefix key))) + (quail-defrule key translation "Racket" t)))) + +(defun racket-custom-set (sym val) + (set-default sym val) + (racket-input-setup)) + +;; Set up the input method. +(racket-input-setup) + +;;; Minor mode + +;; This is a convenience for user configuration, as well as a good +;; documentation location. + +(define-minor-mode racket-input-mode + "A minor mode to enable the \"Racket\" input method. + +The Racket input method lets you type `racket-input-prefix', +followed by a key sequence from `racket-input-translations', +directly in a buffer, to insert a symbol. + +For example when `racket-input-prefix' is the default \"\\\", you +can type \"\\All\" and it is immediately replaced with \"∀\". + +To enable `racket-input-mode' (and the Racket input method) for +all new buffers, put the following in your Emacs init file: + +#+BEGIN_SRC elisp + (dolist (hook \\='(racket-mode-hook + racket-hash-lang-mode-hook + racket-repl-mode-hook)) + (add-hook hook #\\='racket-input-mode)) +#+END_SRC + +Tip: You may use the standard Emacs key C-\\ to toggle the +current input method. + +Tip: If you don’t like the highlighting of partially matching +tokens you can disable that using `input-method-highlight-flag'. + +See the Emacs manual for other information about input methods. + +Tip: Another way to use `racket-input-translations' is by using a +command: `racket-insert-symbol'." + :lighter "" + (if racket-input-mode + (set-input-method "Racket") + (when (equal current-input-method "Racket") + (deactivate-input-method)))) + +(define-obsolete-function-alias + 'racket-unicode-input-method-enable + #'racket-input-mode + "2024-10-15") + +;;; Command flavor, using completing-read with annotations + +(defun racket-insert-symbol () + "Insert a symbol from `racket-input-translations'. + +A command alternative to the \"Racket\" input method activated by +`racket-input-mode'. + +Presents a `completing-read' UI, in which the symbols that would +be inserted are shown as annotations -- a preview unlike what is +currently provided by the Emacs UI for input method." + (interactive) + (let* ((translations racket-input-translations) + (affixator + (lambda (strs) + (let ((max-len 16)) + (dolist (str strs) + (setq max-len (max max-len (1+ (length str))))) + (seq-map (lambda (str) + (let ((v (cadr (assoc str translations)))) + (list str + "" + (concat + (make-string (- max-len (length str)) 32) + (propertize v 'face 'bold))))) + strs)))) + (collection + (racket--completion-table + translations + `((category . racket-symbol-name) + (affixation-function . ,affixator)))) + (predicate nil) + (require-match t)) + (when-let (str (completing-read "Symbol: " + collection + predicate + require-match)) + (insert (cadr (assoc str racket-input-translations)))))) + +(provide 'racket-input) + +;;; racket-input.el ends here diff --git a/racket-mode.el b/racket-mode.el index f898a4f9..cc71870f 100644 --- a/racket-mode.el +++ b/racket-mode.el @@ -40,6 +40,7 @@ (require 'racket-lisp-mode) (require 'racket-bug-report) (require 'racket-util) +(require 'racket-input) (require 'easymenu) (defvar racket-mode-map @@ -102,6 +103,7 @@ "---" ["Comment" comment-dwim] ["Insert λ" racket-insert-lambda] + ["Insert Symbol" racket-insert-symbol] ["Indent Region" indent-region] ["Cycle Paren Shapes" racket-cycle-paren-shapes] ["Align" racket-align] diff --git a/racket-repl.el b/racket-repl.el index 826a95dc..4cd419b5 100644 --- a/racket-repl.el +++ b/racket-repl.el @@ -1422,6 +1422,7 @@ The command varies based on how many \\[universal-argument] command prefixes you ["Exit" racket-repl-exit] "---" ["Insert Lambda" racket-insert-lambda] ;λ in string breaks menu + ["Insert Symbol" racket-insert-symbol] ["Indent Region" indent-region] ["Cycle Paren Shapes" racket-cycle-paren-shapes] ("Macro Expand" diff --git a/racket-unicode-input-method.el b/racket-unicode-input-method.el deleted file mode 100644 index 0bb1dd90..00000000 --- a/racket-unicode-input-method.el +++ /dev/null @@ -1,283 +0,0 @@ -;;; racket-unicode-input-method.el -*- lexical-binding: t; -*- - -;; Copyright (c) 2015-2020 by Greg Hendershott -;; Portions Copyright (c) 2010-2011 by Roel van Dijk - -;; Author: Greg Hendershott -;; URL: https://github.com/greghendershott/racket-mode - -;; SPDX-License-Identifier: GPL-3.0-or-later - -;; Following the example of haskell-unicode-input-method.el - -(require 'quail) - -;;;###autoload -(defun racket-unicode-input-method-enable () - "Set input method to racket-unicode. - -The racket-unicode input method lets you easily type various -Unicode symbols that might be useful when writing Racket code. - -To automatically enable the racket-unicode input method in -racket-mode and racket-repl-mode buffers, put the following code -in your Emacs init file: - -#+BEGIN_SRC elisp - (add-hook \\='racket-mode-hook #\\='racket-unicode-input-method-enable) - (add-hook \\='racket-repl-mode-hook #\\='racket-unicode-input-method-enable) -#+END_SRC - -To temporarily enable this input method for a single buffer you -can use \"M-x racket-unicode-input-method-enable\". - -Use the standard Emacs key C-\\ to toggle the input method. - -When the racket-unicode input method is active, you can for -example type \"All\" and it is immediately replaced with \"∀\". A -few other examples: - -| omega | ω | -| x_1 | x₁ | -| x^1 | x¹ | -| A | 𝔸 | -| test-->>E | test-->>∃ (racket/redex) | -| vdash | ⊢ | - -To see a table of all key sequences use \"M-x -describe-input-method racket-unicode\". - -If you want to add your own mappings to the \"racket-unicode\" -input method, you may add code like the following example in your -Emacs init file: - -#+BEGIN_SRC elisp - ;; Either (require \\='racket-mode) here, or, if you use - ;; use-package, put the code below in the :config section. - (with-temp-buffer - (racket-unicode-input-method-enable) - (set-input-method \"racket-unicode\") - (let ((quail-current-package (assoc \"racket-unicode\" - quail-package-alist))) - (quail-define-rules ((append . t)) - (\"^o\" [\"ᵒ\"])))) -#+END_SRC - -If you don’t like the highlighting of partially matching tokens you -can turn it off by setting `input-method-highlight-flag' to nil." - (interactive) - (set-input-method "racket-unicode")) - -(quail-define-package - "racket-unicode" ;name - "UTF-8" ;language - "λ" ;title (in mode line) - t ;guidance - "Racket Unicode input method." ;docstring - nil ;translation-keys - nil ;forget-last-selection - nil ;deterministic - nil ;kbd-translate - nil ;show-layout - nil ;create-decode-map - nil ;maximum-shortest - nil ;overlay-plist - nil ;update-translation-function - nil ;conversion-keys - t) ;simple - -(quail-define-rules - ;; Typed Racket - ("All " ["∀"]) - ("Union " ["U"]) - ("Intersection " ["∩"]) - - ;; Redex - ("test-->>E " ["test-->>∃"]) - - ;; Turnstile - ("vdash " ["⊢"]) - ("gg " ["≫"]) - ("rightarrow " ["→"]) - ("Rightarrow " ["⇒"]) - ("Leftarrow " ["⇐"]) - ("succ " ["≻"]) - - ;; Other type rule symbols - ;; (added: common math chars currently unsupported) - ("times " ["×"]) - ("Uparrow " ["⇑"]) - ("Downarrow " ["⇓"]) - ("Leftrightarrow " ["⇔"]) - ("rightarrow " ["→"]) - ("leftarrow " ["←"]) - ("Rightarrow " ["⇒"]) - ("Leftarrow " ["⇐"]) - ("nwarrow " ["↖"]) - ("nearrow " ["↗"]) - ("uparrow " ["↑"]) - ("downarrow " ["↓"]) - ("searrow " ["↘"]) - ("swarrow " ["↙"]) - ("leftrightarrow " ["↔"]) - ("updownarrow " ["⇕"]) - ("aleph " ["א"]) - ("emptyset " ["∅"]) - ("nabla " ["∇"]) - ("surd " ["√"]) - ("negation " ["¬"]) - ("infinity " ["∞"]) - ("prod " ["∏"]) - ("coprod" ["∐"]) - ("integrate " ["∫"]) - ("Oint " ["∮"]) - ("vee " ["∨"]) - ("wedge " ["∧"]) - ("follows " ["∘"]) - ("setin " ["∈"]) - ("ni " ["∋"]) - ("notin " ["∉"]) - ("sqsubset " ["⊏"]) - ("sqsupset " ["⊐"]) - ("sqsubseteq " ["⊑"]) - ("sqsupseteq " ["⊒"]) - ("subset " ["⊂"]) - ("superset " ["⊃"]) - ("subseteq " ["⊆"]) - ("supseteq " ["⊇"]) - ("approx " ["≈"]) - ("cong " ["≌"]) - ("neq " ["≠"]) - ("sqcap " ["⊓"]) - ("sqcup " ["⊔"]) - ("models " ["⊧"]) - - ;; Greek letters - ("alpha " ["α"]) - ("Alpha " ["Α"]) - ("beta " ["β"]) - ("Beta " ["Β"]) - ("gamma " ["γ"]) - ("Gamma " ["Γ"]) - ("delta " ["δ"]) - ("Delta " ["Δ"]) - ("epsilon " ["ε"]) - ("Epsilon " ["Ε"]) - ("zeta " ["ζ"]) - ("Zeta " ["Ζ"]) - ("eta " ["η"]) - ("Eta " ["Η"]) - ("theta " ["θ"]) - ("Theta " ["Θ"]) - ("iota " ["ι"]) - ("Iota " ["Ι"]) - ("kappa " ["κ"]) - ("Kappa " ["Κ"]) - ("lambda " ["λ"]) - ("Lambda " ["Λ"]) - ("lamda " ["λ"]) - ("Lamda " ["Λ"]) - ("mu " ["μ"]) - ("Mu " ["Μ"]) - ("nu " ["ν"]) - ("Nu " ["Ν"]) - ("xi " ["ξ"]) - ("Xi " ["Ξ"]) - ("omicron " ["ο"]) - ("Omicron " ["Ο"]) - ("pi " ["π"]) - ("Pi " ["Π"]) - ("rho " ["ρ"]) - ("Rho " ["Ρ"]) - ("sigma " ["σ"]) - ("Sigma " ["Σ"]) - ("tau " ["τ"]) - ("Tau " ["Τ"]) - ("upsilon " ["υ"]) - ("Upsilon " ["Υ"]) - ("phi " ["φ"]) - ("Phi " ["Φ"]) - ("chi " ["χ"]) - ("Chi " ["Χ"]) - ("psi " ["ψ"]) - ("Psi " ["Ψ"]) - ("omega " ["ω"]) - ("Omega " ["Ω"]) - ("digamma " ["ϝ"]) - ("Digamma " ["Ϝ"]) - ("san " ["ϻ"]) - ("San " ["Ϻ"]) - ("qoppa " ["ϙ"]) - ("Qoppa " ["Ϙ"]) - ("sampi " ["ϡ"]) - ("Sampi " ["Ϡ"]) - ("stigma " ["ϛ"]) - ("Stigma " ["Ϛ"]) - ("heta " ["ͱ"]) - ("Heta " ["Ͱ"]) - ("sho " ["ϸ"]) - ("Sho " ["Ϸ"]) - - ;; Double-struck letters - ("|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|" ["ℤ"]) - ("|gamma|" ["ℽ"]) - ("|Gamma|" ["ℾ"]) - ("|pi|" ["ℼ"]) - ("|Pi|" ["ℿ"]) - - ;; Quantifiers - ("forall " ["∀"]) - ("exists " ["∃"]) - - ;; Numeric subscripts - ("_0 " ["₀"]) - ("_1 " ["₁"]) - ("_2 " ["₂"]) - ("_3 " ["₃"]) - ("_4 " ["₄"]) - ("_5 " ["₅"]) - ("_6 " ["₆"]) - ("_7 " ["₇"]) - ("_8 " ["₈"]) - ("_9 " ["₉"]) - - ;; Numeric superscripts - ("^0 " ["⁰"]) - ("^1 " ["¹"]) - ("^2 " ["²"]) - ("^3 " ["³"]) - ("^4 " ["⁴"]) - ("^5 " ["⁵"]) - ("^6 " ["⁶"]) - ("^7 " ["⁷"]) - ("^8 " ["⁸"]) - ("^9 " ["⁹"])) - -(provide 'racket-unicode-input-method) - -;;; racket-unicode-input-method.el ends here diff --git a/racket-util.el b/racket-util.el index 4684225b..2db00aa4 100644 --- a/racket-util.el +++ b/racket-util.el @@ -171,6 +171,13 @@ s-expressions." (thing-at-point thing no-properties)) (thing-at-point thing no-properties))) +(defun racket--bounds-of-thing-at-point (thing) + (if-let (pos (racket--menu-position)) + (save-excursion + (goto-char pos) + (bounds-of-thing-at-point thing)) + (bounds-of-thing-at-point thing))) + (defun racket--symbol-at-point-or-prompt (force-prompt-p prompt &optional