LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Emacs - convert whitespace to single space? (https://www.linuxquestions.org/questions/linux-software-2/emacs-convert-whitespace-to-single-space-622574/)

jantman 02-20-2008 02:05 PM

Emacs - convert whitespace to single space?
 
Hi,

I'm looking for a little elisp (EMACS) function that will convert whitespace (preferably also line breaks) from the point until the next text character into one space.

I'm dealing with a query log file that looks like:
Code:

SELECT
                        usr_lang
                    FROM
                        eventum.eventum_user
                    WHERE
                        usr_id = 2

Since this is all one query, I'd like it all on one line. I'm also editing out the stuff I don't need on-the-fly, and adding punctuation and notes, so it doesn't seem like the best job for a script (since there aren't any semicolons, I need to find the end of the query manually).

Ideally, I'd like to just map the function to an F key, to get something like:

Code:

SELECT{}
                        usr_lang

With the point being at "{}", Press F-whatever and get:
Code:

SELECT usr_lang
Any ideas?

Thanks,
Jason

BrianK 02-20-2008 08:03 PM

you may try something like regex replace, i.e.

M-cntl-% (that's alt-cntl-shift-5)
the for the query, use:
[ cntl-q-j]* (that's bracket, space, cntl-q-j,bracket,star)
and for the reaplce, use a single space.

.. works moderatly well.


All times are GMT -5. The time now is 09:55 PM.