Subject: bug#78635: 30.1.90; wishlist: labels/comments/annotations for individual stack entries

From: Christopher Howard <[email-masked]>
Date: Tue, 29 Jul 2025 12:53:19 -0800

After exploring the calc codebase for a while, it seems like this is the simplest approach to implementing this feature: store the stack entry "comment", as a string, in the currently unused fourth slot of the entry's stack entry list (see calc-stack variable). Also, modify math-format-stack-value so that it can extract the fourth entry (if non-nil) and modify the output string accordingly:

```
    (setq s (if (stringp c)
		(if calc-display-raw
		    (prin1-to-string c)
		  c)
	      (math-composition-to-string c w)))
    (if comment (setq s (concat s " ;; " comment)))
    (when calc-language-output-filter
      (setq s (funcall calc-language-output-filter s)))
```

...the "comment" variable being the cadddr of the entry parameter of math-format-stack-value.

So far, this seems to work fine. Other calc functions don't seem to care whether or not there is a fourth element in the entry list, either ignoring it or dropping it. I could modify the other functions to be aware of the entry comment, as appropriate.

An area I could use help with: to test this, I am currently editing the stack by hand (using setq), not being familiar with the API for modifying the calc stack. Could somebody throw together for me a basic example function that accesses the proper stack entry (topmost entry...? entry selected...?) and shows me how I would save the entry back to stack after I modified it? I have been trying to look at conceptually simple functions like calc-enter for guidance, but am still getting lost in the weeds.

-- 
Christopher Howard