Skip to content

Commit

Permalink
Convert list from python to elisp
Browse files Browse the repository at this point in the history
  • Loading branch information
813gan committed Aug 16, 2024
1 parent d1360f6 commit b880dce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions emacspy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ cdef emacs_value unwrap(obj) except *:
obj = make_int(obj)
elif obj is None:
obj = nil
elif isinstance(obj, list):
obj = make_list(obj)
elif isinstance(obj, tuple):
obj = make_list(list(obj))

if isinstance(obj, EmacsValue):
return (<EmacsValue>obj).v
Expand Down Expand Up @@ -216,6 +220,9 @@ cpdef make_bool(bool b):
return EmacsValue.wrap(env.intern(env, "t".encode('utf8')))
return nil

cpdef make_list(list l):
return funcall(sym("list"), l)

cdef emacs_value string_ptr(str s):
cdef emacs_env* env = get_env()
s_utf8 = s.encode('utf8')
Expand Down
10 changes: 10 additions & 0 deletions tests/test.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(require 'cl)

(ert-deftest ert-test-emacspy-py-import ()
(should-error (py-import "test" "NON_EXISTING_MOD")
:type 'python-exception) )
Expand Down Expand Up @@ -75,3 +77,11 @@
"test" (py-set-global "test" -1 "test_int"))))
(should (eq 0 (py-get-global-variable
"test" (py-set-global "test" 0 "test_int")))) )

(ert-deftest ert-test-emacspy-data-list ()
(should (cl-every 'eq '(t 2 3)
(py-run-string "test" "[True, 2, 3]") ))
(should (cl-every 'eq '(1 nil 3)
(py-run-string "test" "(1, False, 3)") ))
(should (cl-every 'string= '("test")
(py-run-string "test" "['test']") )) )

0 comments on commit b880dce

Please sign in to comment.