# kill-ring-save rectangle and paste transposed?

Suppose I have some code written like:

``````a_to_b = self.tversky(a, b)
b_to_c = self.tversky(b, c)
d_to_e = self.tversky(d, e)
e_to_f = self.tversky(e, f)
g_to_h = self.tversky(g, h)
``````

I would like to select as a rectangle the variable names `x_to_y` and then paste it into array as so:

``````return [a_to_b, b_to_c, d_to_e, e_to_f, g_to_h]
``````

I don't necessarily need the commas in one command, but basically selecting a few columns and then applying `M-S ^` to each line. So I can get them all next to each other.

• What is `M-S ^`, and what did you intend by applying it to each line?
– Drew
Mar 16, 2020 at 3:50

1. Select the rectangle (e.g. use `C-x SPC`).

2. Use this command (`M-x foo`) to copy the variables to the `kill-ring`, as the string `"a_to_b, b_to_c, d_to_e, e_to_f, g_to_h"`:

``````(defun foo (beg end)
(interactive "r")
(let ((vars  (mapconcat #'identity
(extract-rectangle (region-beginning) (region-end))
", ")))
(kill-new vars)))
``````
1. Move to where you want the result.

2. Use this command (`M-x bar`) to insert the result at point.

``````(defun bar ()
(interactive)
(insert "return [")
(yank)
(insert "]\n"))
``````
• Thanks, `M-S ^` is `delete-indentation`. When I posted the question, I had an OS shortcut overiding that command and couldn't `C-h k` for it. Mar 16, 2020 at 17:07
• Hi @dylanjm, that would normally be written `M-^` (or `S-M-6`, but that ties you to a US or UK keyboard). Mar 18, 2020 at 11:20
{"ft_lang_label":"__label__en","ft_lang_prob":0.91146195,"math_prob":0.7672487,"size":556,"snap":"2022-27-2022-33","text_gpt3_token_len":170,"char_repetition_ratio":0.1539855,"word_repetition_ratio":0.0,"special_character_ratio":0.29316548,"punctuation_ratio":0.168,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98927474,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-15T12:27:26Z\",\"WARC-Record-ID\":\"<urn:uuid:ff2a06eb-f9cf-4012-82d5-aed7d47f875b>\",\"Content-Length\":\"222549\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:babb070a-2be1-4ce5-8d3f-b54272c5010c>\",\"WARC-Concurrent-To\":\"<urn:uuid:11f65750-7469-48bf-bb63-a5aca8c21457>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://emacs.stackexchange.com/questions/56168/kill-ring-save-rectangle-and-paste-transposed\",\"WARC-Payload-Digest\":\"sha1:TUH74TSKAEO4AAITAXW7YFDFK6GFN2VY\",\"WARC-Block-Digest\":\"sha1:OC37QIGDWXEZ5KKYMJYC4BLMHNCQIDXQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882572174.8_warc_CC-MAIN-20220815115129-20220815145129-00790.warc.gz\"}"}