Elisp destructuring-bind for cons cell?

I cannot think on anything as elegant as destructuring-bind, but this would work:

(let* ((b (bounds-of-thing-at-point 'symbol))
       (start (car b))
       (end   (cdr b)))
  ...)

I'd use

(pcase-let ((`(,start . ,end) (bounds-of-thing-at-point 'symbol)))
  ...)

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.

Tags:

Emacs

Elisp