Skip to content

Commit cae6554

Browse files
committed
Adjust lispy--function-parse to a new object representation.
* lispy.el (lispy--function-parse): Update function to a newer object representation. Fix `lispy-flatten'. In Emacs 30, it began to use dedicated type to represent interpreted-function values, `read' function now returns Closure Function Type instead of simple lists for most types that `lispy--function-parse' tries to handle (except macros, at least). See: - https://git.sv.gnu.org/cgit/emacs.git/commit/?id=f2bccae22bd47a2e7e0937b78ea06131711b935a - (elisp) Closure Type - (elisp) Closure Objects Compare (defmacro test-macro (&rest body) ,@Body) (symbol-function 'test-macro) ;; (macro . #[(&rest body) ((\,@ body)) (t)]) with (defun test-defun (x) (+ x 1)) (symbol-function 'test-defun) ;; #[(x) ((+ x 1)) (t)] There's alternative way to mitigate it, by changing end of `lispy--function-str' to: (error (let ((str (cl-prin1-to-string (symbol-function fun)))) (if (string-prefix-p "#f" str) (substring str 2) str))) But it hides the underlying change that needs to be addresed in the future. Partially fixes `lispy-let-flatten' as well, but keywords (&optional, &rest) in function's signature are not recognized correctly.
1 parent c2acc4b commit cae6554

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

lispy.el

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7640,42 +7640,48 @@ Defaults to `error'."
76407640
(defun lispy--function-parse (str)
76417641
"Extract the function body and args from it's expression STR."
76427642
(let ((body (lispy--read str))
7643-
args)
7644-
(cond ((eq (car body) 'lambda)
7645-
(setq body (cons 'defun body)))
7646-
((eq (car body) 'closure)
7647-
(setq body `(defun noname ,@(cddr body))))
7648-
((eq (car body) 'defsubst)
7649-
(setq body (cons 'defun (cdr body)))))
7650-
(cond ((memq (car body) '(defun defmacro))
7651-
(setq body (lispy--whitespace-trim (cdr body))))
7652-
((eq (car body) 'defalias)
7653-
(let ((name (cadr (cadr (read str)))))
7654-
(setq body
7655-
(cons name (cdr (symbol-function name))))))
7656-
(t
7657-
(error "Expected defun, defmacro, or defalias got %s" (car body))))
7658-
(if (symbolp (car body))
7659-
(setq body (lispy--whitespace-trim (cdr body)))
7660-
(error "Expected function name, got %s" (car body)))
7661-
(if (listp (car body))
7662-
(progn
7663-
(setq args (car body))
7643+
args)
7644+
(if (not (consp body))
7645+
(progn (setq args (aref body 0))
7646+
(setq body (aref body 1)))
7647+
;; In Emacs 30, `read' returns a dedicated type, instead of
7648+
;; simple list, for lambdas, defuns, closures, etc. And code
7649+
;; below is only valid for `defmacro'. Keep it for Emacs < 30.
7650+
(cond ((eq (car body) 'lambda)
7651+
(setq body (cons 'defun body)))
7652+
((eq (car body) 'closure)
7653+
(setq body `(defun noname ,@(cddr body))))
7654+
((eq (car body) 'defsubst)
7655+
(setq body (cons 'defun (cdr body)))))
7656+
(cond ((memq (car body) '(defun defmacro))
7657+
(setq body (lispy--whitespace-trim (cdr body))))
7658+
((eq (car body) 'defalias)
7659+
(let ((name (cadr (cadr (read str)))))
7660+
(setq body
7661+
(cons name (cdr (symbol-function name))))))
7662+
(t
7663+
(error "Expected defun, defmacro, or defalias got %s" (car body))))
7664+
(if (symbolp (car body))
7665+
(setq body (lispy--whitespace-trim (cdr body)))
7666+
(error "Expected function name, got %s" (car body)))
7667+
(if (listp (car body))
7668+
(progn
7669+
(setq args (car body))
7670+
(setq body (lispy--whitespace-trim (cdr body))))
7671+
(error "Expected function arguments, got %s" (car body)))
7672+
;; skip docstring
7673+
(if (and (listp (car body))
7674+
(eq (caar body) 'ly-raw)
7675+
(eq (cadar body) 'string))
7676+
(setq body (lispy--whitespace-trim (cdr body))))
7677+
;; skip declare
7678+
(if (and (listp (car body))
7679+
(eq (caar body) 'declare))
76647680
(setq body (lispy--whitespace-trim (cdr body))))
7665-
(error "Expected function arguments, got %s" (car body)))
7666-
;; skip docstring
7667-
(if (and (listp (car body))
7668-
(eq (caar body) 'ly-raw)
7669-
(eq (cadar body) 'string))
7670-
(setq body (lispy--whitespace-trim (cdr body))))
7671-
;; skip declare
7672-
(if (and (listp (car body))
7673-
(eq (caar body) 'declare))
7674-
(setq body (lispy--whitespace-trim (cdr body))))
7675-
;; skip interactive
7676-
(if (and (listp (car body))
7677-
(eq (caar body) 'interactive))
7678-
(setq body (lispy--whitespace-trim (cdr body))))
7681+
;; skip interactive
7682+
(if (and (listp (car body))
7683+
(eq (caar body) 'interactive))
7684+
(setq body (lispy--whitespace-trim (cdr body)))))
76797685
(list args body)))
76807686

76817687
(defun lispy--flatten-function (fstr e-args)

0 commit comments

Comments
 (0)