I'm a novice in Lisp, so I feel like I'm missing something very basic here. My intention was to create a function/shortcut to remove all whitespace and newline chars from the selected text and copy the resulting string to the X primary clipboard/selection. For example, when selecting the text:
line 1
line 2
The function should copy line1line2
to the clipboard. To be precise, it should be copied to the primary selection. I've written the following code for this presumably easy task:
(defun copy-no-white-space ()
(interactive)
(gui-set-selection
'PRIMARY
(replace-regexp-in-string "[\s\n]" "" (buffer-substring (region-beginning) (region-end))))
Unfortunately, this does not work this way. When I try to paste the modified pattern, it only yields the original region with no modifications and I just can not wrap my head around why: It works when PRIMARY
is replaced with CLIPBOARD
(only that I really want to use PRIMARY
). What confuses me even more is the fact that it works with (edit: only when nothing is marked) Why? ;)PRIMARY
when I remove the regular expression in favor of a fixed string and that it also works when I put it outside of the function.