Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Charles Dagny <1800@DEV.NULL> Newsgroups: gnu.emacs.help Subject: Re: copying enriched text with soft breaks as space Date: Fri, 21 Mar 2025 16:59:58 -0300 Organization: A noiseless patient Spider Lines: 53 Message-ID: <87sen6gnnl.fsf@DEV.NULL> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sun, 23 Mar 2025 21:18:19 +0100 (CET) Injection-Info: dont-email.me; posting-host="8e02a978fc21f6b0cf1564dba1755287"; logging-data="3318420"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RdDfSaiXKswqG0Yd4H76+LajgM8hJ1GI=" Cancel-Lock: sha1:6wQJv0QcAfXQ/3f3wQSFdDAaDJU= sha1:SCVSUW08/vDYxN2igcVERPXIthA= Xref: csiph.com gnu.emacs.help:61013 Mike Small writes: > Hello, > > Is there any built in way in GNU emacs or an existing extension to allow > one to copy lines of text from a buffer that is in enriched text mode so > that the soft newlines get copied to the X primary selection or > clipboard as spaces? > > When editing text locally, before pasting it into a web form, I find it > convenient to use autofill in emacs. But when it comes time to paste > what I've written to the web form I usually want to remove the newlines > within paragraphs to allow the page's scripting to take over the > filling. I'd hoped that using enriched text mode and only using its soft > newline feature would provide a more automatic way to achieve what I > want than manually joining lines before copying. Maybe it would be > simple to program it, but I wanted to check if something already exists > first. To remove the line breaks, one simple solution is to fill-paragraph having reset fill-column before. The procedure below applies this hack: (defun remove-hard-wrap-region (start end) "Replace line endings and spaces into a single space." (interactive "r") (let ((fill-column 1000000)) ;; That's a hack, you see? (fill-region start end))) You can then map this procedure to a certain key combination: (global-set-key (kbd "M-3") 'remove-hard-wrap-region) Apparently, I've written another solution to the same problem, but I'm believe I've been using the above more often. (defun unwrap-line () "Remove all newlines until we get to two consecutive ones. Or until we reach the end of the buffer. Great for unwrapping quotes before sending them on IRC." (interactive) (let ((start (point)) (end (copy-marker (or (search-forward "\n\n" nil t) (point-max)))) (fill-column (point-max))) (fill-region start end) (goto-char end) (newline) (goto-char start))) I'm also noticing here that I should've used save-excursion instead of using variables such as /start/ and /end/, but now it's too late. It's quite possible that I didn't write this myself because I don't think I ever used the copy-marker procedure before.