¿Cómo eliminar todas las líneas nuevas de la región seleccionada en Emacs?


¿Cómo eliminar todas las líneas nuevas de la región seleccionada en Emacs?

Author: RzR, 2011-03-04

4 answers

M-x replace-string C-q C-j RET RET

El truco es citar el C-j, pero de lo contrario reemplazar nuevas líneas es como reemplazar cualquier otra cosa.

 69
Author: Bruce Stephens,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-03-04 13:42:36

Con mis combinaciones de teclas, que creo que son estándar, en Windows:

Seleccione la región

Shift-alt - %

Ctrl-Q ctrl-J

Return

Return

!

O para decirlo de otra manera, consulta reemplazar región, ctrl-q para obtener caracteres extendidos, ctrl-j para poner una nueva línea, reemplazar con nada, todos ellos.

 13
Author: Pete,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-03-04 13:41:22

Si desea crear una función para hacer esto (y vincularla a F8) puede intentar:

(defun remove-newlines-in-region ()
  "Removes all newlines in the region."
  (interactive)
  (save-restriction
    (narrow-to-region (point) (mark))
    (goto-char (point-min))
    (while (search-forward "\n" nil t) (replace-match "" nil t))))

(global-set-key [f8] 'remove-newlines-in-region)

Que se basa en un ejemplo I que I encontrado aquí.

 9
Author: Mark Longair,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-12 00:32:13

También podría considerar el antiguo standby delete-blank-lines, normalmente vinculado a C-x C-o.

 -2
Author: Joseph Gay,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-09 22:17:47