Skip to content

Commit f242ac4

Browse files
committed
support more elisp types
- ring - vector - hash-table
1 parent d155175 commit f242ac4

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

haskell-emacs.el

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,15 @@ Read C-h f haskell-emacs-init for more instructions")
258258
"Take XS and remove recursively all text properties."
259259
(if (stringp xs)
260260
(substring-no-properties xs)
261-
(if (listp xs)
262-
(mapcar 'haskell-emacs--no-properties xs)
263-
xs)))
261+
(if (ring-p xs)
262+
(haskell-emacs--no-properties (ring-elements xs))
263+
(if (or (listp xs) (vectorp xs) (bool-vector-p xs))
264+
(mapcar 'haskell-emacs--no-properties xs)
265+
(if (hash-table-p xs)
266+
(let ((pairs))
267+
(maphash (lambda (k v) (push (list k v) pairs)) xs)
268+
(haskell-emacs--no-properties pairs))
269+
xs)))))
264270

265271
(defun haskell-emacs--fun-wrapper (fun args docs)
266272
"Take FUN with ARGS and return wrappers in elisp with the DOCS."

test/HaskellEmacsTest.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module HaskellEmacsTest where
44

55
import Control.Monad
6+
import Data.Char
67
import qualified Data.Text as T
78
import External.NBody
89
import Foreign.Emacs
@@ -56,6 +57,17 @@ allTrue = and
5657
anyTrue :: [Bool] -> Bool
5758
anyTrue = or
5859

60+
-- Char
61+
62+
nextChar :: Char -> Char
63+
nextChar = chr . succ . ord
64+
65+
-- Lisp
66+
67+
symbolReverse :: Lisp -> Lisp
68+
symbolReverse (Symbol s) = Symbol $ T.reverse s
69+
symbolReverse x = x
70+
5971
-- Num
6072

6173
nextNum :: Int -> Int

test/haskell-emacs-test.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@
7575
((HaskellEmacsTest.concatFst '(("a" 1) ("b" 2) ("c" 3))) "abc")
7676
((HaskellEmacsTest.longAnswer 2) "aaaa")
7777
((HaskellEmacsTest.nthFib 10) 55)
78+
;;;; Supported types, look at #38
79+
((HaskellEmacsTest.nextNum 7) 8)
80+
((HaskellEmacsTest.multiply 4.5 2.0) 9.0)
81+
((HaskellEmacsTest.nextChar "a") "b")
82+
((HaskellEmacsTest.symbolReverse 'abcd) dcba)
83+
((HaskellEmacsTest.summation [1 2 3]) 6)
84+
((HaskellEmacsTest.allTrue (make-bool-vector 3 t)) t)
85+
((HaskellEmacsTest.summation (let ((r (make-ring 5)))
86+
(ring-insert r 1)
87+
(ring-insert r 2)
88+
r)) 3)
89+
((HaskellEmacsTest.concatFst (let ((h (make-hash-table)))
90+
(puthash "c" 12 h)
91+
(puthash "b" 17 h)
92+
(puthash "a" 22 h)
93+
h)) "abc")
94+
;;;;
7895
((mapcar 'eval (list (HaskellEmacsTest.multiply-async 2 4)
7996
(HaskellEmacsTest.multiply-async 1 9)
8097
(HaskellEmacsTest.multiply-async 10 15)))

0 commit comments

Comments
 (0)