Skip to content

Commit

Permalink
Add racket-unicode-input-method
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Hendershott committed Apr 23, 2015
1 parent 429ca4a commit 08dbcdc
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 6 deletions.
30 changes: 24 additions & 6 deletions README.md
Expand Up @@ -84,18 +84,19 @@ $ raco pkg install drracket
To start, there are only two [variables](Reference.md#variables) you
_might_ need to set:

- **racket-racket-program**, the name or pathname of the Racket
- `racket-racket-program` is the name or pathname of the Racket
executable. This defaults to `Racket.exe` on Windows else `racket`.

- Set **racket-raco-program**, the name or pathname of the Raco
- `racket-raco-program` is the name or pathname of the Raco
executable. This defaults to `Raco.exe` on Windows else `raco`.

On Windows or Linux, these defaults will probably work for you.

On OS X, downloading Racket doesn't add its `bin` directory to your
`PATH`. Even after you add it, GUI Emacs doesn't automatically use
your path (unless you use the handy [exec-path-from-shell] package).
Therefore you may want to set both of these to be full pathames.
Therefore you may want to set both of these to be full pathames like
`/usr/racket/bin/racket` and `/usr/racket/bin/raco`.

[exec-path-from-shell]: http://melpa.org/#/exec-path-from-shell

Expand All @@ -106,16 +107,33 @@ prefer.
### Key bindings

To customize things like key bindings, you can use `racket-mode-hook`
in your Emacs init file. For example, although <kbd>F5</kbd> is bound
to the **racket-run** command, let's say you wanted <kbd>C-c r</kbd>
to be an additional binding:
in your Emacs init file. For example, although <kbd>F5</kbd> and
<kbd>C-c C-k</kbd> are bound to the `racket-run` command, let's say
you wanted <kbd>C-c r</kbd> to be an additional binding:

```cl
(add-hook 'racket-mode-hook
(lambda ()
(define-key racket-mode-map (kbd "C-c r") 'racket-run)))
```

### Unicode input method

An optional Emacs input method, `racket-unicode`, 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:

```cl
(add-hook 'racket-mode-hook #'racket-unicode-input-method-enable)
(add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable)
```

For more information, see the documentation: <kbd>C-h f
racket-unicode-input-method-enable</kbd>.

### Completion

To have <kbd>TAB</kbd> do completion as well as indent, add the
Expand Down
42 changes: 42 additions & 0 deletions Reference.md
Expand Up @@ -485,6 +485,48 @@ r racket-check-syntax-mode-rename
```


### racket-unicode-input-method-enable
<kbd>M-x racket-unicode-input-method-enable</kbd>

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` buffers use `M-x customize-variable <RET>
racket-mode-hook` or put the following code in your Emacs init
file:

(add-hook 'racket-mode-hook #'racket-unicode-input-method-enable)

Likewise for `racket-repl-mode` buffers:

(add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable)

To temporarily enable this input method for a single buffer you
can use `M-x racket-unicode-input-method-enable`.

Use `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)

To see a table of all key sequences use `M-x
describe-input-method <RET> racket-unicode`.

If you don’t like the highlighting of partially matching tokens you
can turn it off by setting `input-method-highlight-flag` to nil via
`M-x customize-variable`.

## Macro expand

### racket-expand-region
Expand Down
1 change: 1 addition & 0 deletions makefile
Expand Up @@ -29,6 +29,7 @@ compile: clean \
racket-profile.elc \
racket-repl.elc \
racket-tests.elc \
racket-unicode-input-method.elc \
racket-util.elc

# Install packages we depend on. Intended for one-time use by
Expand Down
2 changes: 2 additions & 0 deletions racket-make-doc.el
Expand Up @@ -17,6 +17,7 @@
(require 'racket-mode)
(require 'racket-profile)
(require 'racket-edit)
(require 'racket-unicode-input-method)
(require 'dash)
(require 's)

Expand Down Expand Up @@ -80,6 +81,7 @@
racket-cycle-paren-shapes
racket-backward-up-list
racket-check-syntax-mode
racket-unicode-input-method-enable
"Macro expand"
racket-expand-region
racket-expand-definition
Expand Down
230 changes: 230 additions & 0 deletions racket-unicode-input-method.el
@@ -0,0 +1,230 @@
;;; racket-unicode-input-method.el --- Racket Unicode helper functions

;; Copyright (c) 2015 by Greg Hendershott
;; Portions Copyright (c) 2010-2011 by Roel van Dijk

;; Author: Greg Hendershott
;; URL: https://github.com/greghendershott/racket-mode

;; License:
;; This 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 2, or (at your option)
;; any later version. This 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. See
;; http://www.gnu.org/licenses/ for details.

;; 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` buffers use `M-x customize-variable <RET>
racket-mode-hook` or put the following code in your Emacs init
file:
(add-hook 'racket-mode-hook #'racket-unicode-input-method-enable)
Likewise for `racket-repl-mode` buffers:
(add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable)
To temporarily enable this input method for a single buffer you
can use `M-x racket-unicode-input-method-enable`.
Use `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)
To see a table of all key sequences use `M-x
describe-input-method <RET> racket-unicode`.
If you don’t like the highlighting of partially matching tokens you
can turn it off by setting `input-method-highlight-flag' to nil via
`M-x customize-variable`."
(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" [""])
;; These would be nice except no such aliases provided by racket/contract.
;; ("->" ["→"])
;; ("case->" ["case→"])

;; Redex
("test-->>E" ["test-->>∃"])

;; 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)

;; Local Variables:
;; coding: utf-8
;; comment-column: 40
;; indent-tabs-mode: nil
;; require-final-newline: t
;; show-trailing-whitespace: t
;; End:

;;; racket-unicode-input-method.el ends here

0 comments on commit 08dbcdc

Please sign in to comment.