Get calling cell name in called function

Is there a way to get a “callings cell”'s name?
I am looking for a keyword or variable that will resolve to the name of the cell that a function is being called from:

Age = slider({ value: 10, min: 0, max: 120 }) // Slider can now show `"Age"` as title

slider = ({
  title = CELL_NAME, // or `import.meta.cell_name` or something
}) => {
  // Render slider with `title`

It seems like this is not yet possible. I do get why, as it is quite tricky (if not impossible) to make it work reliable. I think it would make experimenting with different inputs a lot easier, however. I now use a custom stylesheet to show a cells name to the left, because I just want to do Age = slider({ value: 10, min: 0, max: 120 }) and not have to worry about showing the title.

Also it is useful for the sub-notebooks I’m using now, as repeating the cell name with room for error feels wasteful (Example: Sub-notebook example: Debate Round Scheduler / Matcher / Michiel Dral / Observable)

I made some examples for how to carry the name through functions calls using the Error stack, though this requires wrapping it explicitly, which is obviously even worse when not integrated into Observable:

Is there a way I am missing that is currently available, or something more fundamental that makes it incompatible? Would love to see what comes up :slight_smile:

1 Like

No, that’s not possible. However, if you’re only interested in speeding up your prototyping workflow, you can create a user style to display each cell’s name:

In its early days Observable would display each cell name in the editor UI (similar to what the above user CSS does). Many older notebooks include only unlabeled inputs because they relied on that feature.

1 Like

Yeah, I have that now. Though it just doesn’t compare to having cell_name = in the result view :frowning: