Search code examples
emacselisp

Elisp destructuring-bind for cons cell?


I'd like to do

(destructuring-bind (start end) (bounds-of-thing-at-point 'symbol))

But bounds-of-thing-at-point returns a cons cell and not a list, so destructuring-bind doesn't work. What could work for this case?


Solution

  • Since destructuring-bind is a macro from cl package, it may be worthwhile to look into Common Lisp documentation for more examples.

    This page shows the syntax of the macro. Note the (wholevar reqvars optvars . var). Though I'm not sure cl version of destructuring-bind actually supports all of the less common cases (many keywords only make sense when used with Common Lisp macros / functions, but don't have that meaning in Emacs Lisp).

    Thus:

    (destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol) ;...)
    

    should work.