14.6 Yanking into Other Buffers

The plain y (calc-copy-to-buffer) command inserts the number at the top of the stack into the most recently used normal editing buffer. (More specifically, this is the most recently used buffer which is displayed in a window and whose name does not begin with ‘*’. If there is no such buffer, this is the most recently used buffer except for Calculator and Calc Trail buffers.) The number is inserted exactly as it appears and without a newline. (If line-numbering is enabled, the line number is normally not included.) The number is not removed from the stack.

With a prefix argument, y inserts several numbers, one per line. A positive argument inserts the specified number of values from the top of the stack. A negative argument inserts the ‘n’th value from the top of the stack. An argument of zero inserts the entire stack. Note that y with an argument of 1 is slightly different from y with no argument; the former always copies full lines, whereas the latter strips off the trailing newline.

With a lone C-u as a prefix argument, y replaces the region in the other buffer with the yanked text, then quits the Calculator, leaving you in that buffer. A typical use would be to use C-x * g to read a region of data into the Calculator, operate on the data to produce a new matrix, then type C-u y to replace the original data with the new data. One might wish to alter the matrix display style (see Vector and Matrix Display Formats) or change the current display language (see Language Modes) before doing this. Also, note that this command replaces a linear region of text (as grabbed by C-x * g), not a rectangle (as grabbed by C-x * r).

If the editing buffer is in overwrite (as opposed to insert) mode, and the C-u prefix was not used, then the yanked number will overwrite the characters following point rather than being inserted before those characters. The usual conventions of overwrite mode are observed; for example, characters will be inserted at the end of a line rather than overflowing onto the next line. Yanking a multi-line object such as a matrix in overwrite mode overwrites the next n lines in the buffer, lengthening or shortening each line as necessary. Finally, if the thing being yanked is a simple integer or floating-point number (like ‘-1.2345e-3’) and the characters following point also make up such a number, then Calc will replace that number with the new number, lengthening or shortening as necessary. The concept of “overwrite mode” has thus been generalized from overwriting characters to overwriting one complete number with another.

The C-x * y key sequence is equivalent to y except that it can be typed anywhere, not just in Calc. This provides an easy way to guarantee that Calc knows which editing buffer you want to use!