Skip to content

Commit

Permalink
Add haskell-unicode-input-method.el to distribution (re #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
hvr committed Jun 2, 2013
1 parent cf92f10 commit b336d76
Show file tree
Hide file tree
Showing 3 changed files with 341 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -29,6 +29,7 @@ ELFILES = \
haskell-session.el \
haskell-string.el \
haskell-show.el \
haskell-unicode-input-method.el \
ghc-core.el \
inf-haskell.el

Expand Down
38 changes: 38 additions & 0 deletions README.md
Expand Up @@ -189,6 +189,44 @@ inferior-haskell-mode, and therefore keybindings which work for
inferior-haskell-mode will not magically work for the above new
modules.

Haskell Unicode input method
----------------------------

This package provides `haskell-unicode-input-method`, an input
method which allows you to easily type a number of Unicode symbols
that are useful when writing Haskell code.

To automically load in haskell-mode put the following code in your
`.emacs` file:

```el
(require 'haskell-unicode-input-method)
(add-hook 'haskell-mode-hook
(lambda () (set-input-method "haskell-unicode")))
```

Make sure the directory containing the .el file is in your load-path,
for example:

```el
(add-to-list 'load-path "~/.elisp/emacs-haskell-unicode-input-method")
```

To manually enable use `M-x set-input-method` or `C-x RET C-\\` with
`haskell-unicode`. Note that the elisp file must be evaluated for this
to work.

Now you can simply type `->` and it is immediately replaced with
``. Use `C-\\` to toggle the input method. To see a table of all key
sequences use `M-x describe-input-method haskell-unicode`. A sequence
like `<=` is ambiguous and can mean either `` or ``. Typing it
presents you with a choice. Type `1` or `2` to select an option or
keep typing to use the default option.

If you don't like the highlighting of partially matching tokens you
can turn it off:

(setq input-method-highlight-flag nil)

Customization
-------------
Expand Down
302 changes: 302 additions & 0 deletions haskell-unicode-input-method.el
@@ -0,0 +1,302 @@
;; Haskell Unicode helper functions
;;
;; Copyright 2010—2011 Roel van Dijk
;;
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; * Redistributions of source code must retain the above
;; copyright notice, this list of conditions and the following
;; disclaimer.
;;
;; * Redistributions in binary form must reproduce the above
;; copyright notice, this list of conditions and the following
;; disclaimer in the documentation and/or other materials
;; provided with the distribution.
;;
;; * The name of Roel van Dijk and the names of contributors may
;; NOT be used to endorse or promote products derived from this
;; software without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
;; COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
;; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
;; OF THE POSSIBILITY OF SUCH DAMAGE.

(provide 'haskell-unicode-input-method)
(require 'quail)

(quail-define-package
"haskell-unicode" ;; name
"UTF-8" ;; language
"\\" ;; title
t ;; guidance
"Haskell Unicode input method.
Designed to be used with the Haskell UnicodeSyntax language
extension in combination with the x-unicode-symbols set of
packages (base-unicode-symbols and containers-unicode-symbols).
" ;; 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
;; 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|" [""])

;; Types
("::" [""])

;; Quantifiers
("forall" [""])
("exists" [""])

;; Arrows
("->" [""])
;; ("-->" ["⟶"])
("<-" [""])
;; ("<--" ["⟵"])
;; ("<->" ["↔"])
;; ("<-->" ["⟷"])

("=>" [""])
;; ("==>" ["⟹"])
;; ("<=" ["⇐"])
;; ("<==" ["⟸"])
;; ("<=>" ["⇔"])
;; ("<==>" ["⟺"])

;; ("|->" ["↦"])
;; ("|-->" ["⟼"])
;; ("<-|" ["↤"])
;; ("<--|" ["⟻"])

;; ("|=>" ["⤇"])
;; ("|==>" ["⟾"])
;; ("<=|" ["⤆"])
;; ("<==|" ["⟽"])

("~>" [""])
;; ("~~>" ["⟿"])
("<~" [""])
;; ("<~~" ["⬳"])

;; (">->" ["↣"])
;; ("<-<" ["↢"])
;; ("->>" ["↠"])
;; ("<<-" ["↞"])

;; (">->>" ["⤖"])
;; ("<<-<" ["⬻"])

;; ("<|-" ["⇽"])
;; ("-|>" ["⇾"])
;; ("<|-|>" ["⇿"])

;; ("<-/-" ["↚"])
;; ("-/->" ["↛"])

;; ("<-|-" ["⇷"])
;; ("-|->" ["⇸"])
;; ("<-|->" ["⇹"])

;; ("<-||-" ["⇺"])
;; ("-||->" ["⇻"])
;; ("<-||->" ["⇼"])

;; ("-o->" ["⇴"])
;; ("<-o-" ["⬰"])

;; Boolean operators
;; ("not" ["¬"])
("&&" [""])
("||" [""])

;; Relational operators
("==" [""])
("/=" ["" ""])
("<=" [""])
(">=" [""])
("/<" [""])
("/>" [""])

;; Arithmetic
;; (" / " [" ÷ "])
(" * " [""])

;; Containers / Collections
;; ("++" ["⧺"])
;; ("+++" ["⧻"])
;; ("|||" ["⫴"])
;; ("empty" ["∅"])
("elem" [""])
("notElem" [""])
("member" [""])
("notMember" [""])
("union" [""])
("intersection" [""])
("isSubsetOf" [""])
("isProperSubsetOf" [""])

;; Other
;; ("<<" ["≪"])
;; (">>" ["≫"])
("<<<" [""])
(">>>" [""])
("<|" [""])
("|>" [""])
("><" [""])
;; ("mempty" ["∅"])
("mappend" [""])
;; ("<*>" ["⊛"])
(" . " [""])
("undefined" [""])
(":=" [""])
("=:" [""])
("=def" [""])
("=?" [""])
("..." [""])

;; Braces
;; ("[|" ["〚"])
;; ("|]" ["〛"])

;; Numeric subscripts
("_0 " [""])
("_1 " [""])
("_2 " [""])
("_3 " [""])
("_4 " [""])
("_5 " [""])
("_6 " [""])
("_7 " [""])
("_8 " [""])
("_9 " [""])

;; Numeric superscripts
("^0 " [""])
("^1 " ["¹"])
("^2 " ["²"])
("^3 " ["³"])
("^4 " [""])
("^5 " [""])
("^6 " [""])
("^7 " [""])
("^8 " [""])
("^9 " [""])
)

0 comments on commit b336d76

Please sign in to comment.