combobulate icon indicating copy to clipboard operation
combobulate copied to clipboard

How to select anonymous Javascript function with its variable

Open stevemolitor opened this issue 1 year ago • 2 comments

How can I select this entire declaration?

const add = (a, b) => {
  return a + b;
}

combolute-mark-defn will select the anonymous function declaration but won't include const add = . That is 100% correct as it is not part of the function. However conceptually in JS we often think of the above as being equivalent to this:

function add(a, b) {
  return a + b;
}

So it'd be nice if, optionally, combobulate could select both uniformly.

stevemolitor avatar May 31 '23 14:05 stevemolitor

Unfortunately combobulate's navigation commands mark by node type, and there is no distinct node types for arrow functions bound to a variable declarator with an optional scoping declaration.

The only way to resolve this is to check the parents of the nodes, which would require changing the list structure combobulate currently uses to one that can scan the parents also. That might happen in the future, but it's sadly not on the roadmap right now.

Workaround is to tap M-h after C-M-h to use expand region.

mickeynp avatar Jun 01 '23 06:06 mickeynp

Workaround is to tap M-h after C-M-h to use expand region.

Discovered that it that works - thanks!

stevemolitor avatar Jun 01 '23 13:06 stevemolitor