Elisp destruct-bind for cons cell?

abo*_*abo 12 emacs elisp

我想做

(destructuring-bind (start end) (bounds-of-thing-at-point 'symbol))
Run Code Online (Sandbox Code Playgroud)

但是bounds-of-thing-at-point返回一个cons单元而不是列表,所以 destructuring-bind不起作用.什么可以适用于这种情况?

小智 20

由于destructuring-bindcl包中的宏,因此有必要查看Common Lisp文档以获取更多示例.

此页面显示宏的语法.请注意(wholevar reqvars optvars . var).虽然我不确定cl版本destructuring-bind实际上支持所有不太常见的情况(许多关键字只有在与Common Lisp宏/函数一起使用时才有意义,但在Emacs Lisp中没有那个含义).

从而:

(destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol) ;...)
Run Code Online (Sandbox Code Playgroud)

应该管用.


Ste*_*fan 6

我用了

(pcase-let ((`(,start . ,end) (bounds-of-thing-at-point 'symbol)))
  ...)
Run Code Online (Sandbox Code Playgroud)