Pregunta

I'm using emacs terminal emulator. GNU Emacs 23.2.1 with GNU bash, version 3.00.0(1)-release. When some command, say grep 1 file.txt prints very long lines, emacs trunkate them to fit the window width. But it do that right with that lines, so when I copy such line, i get not single long line, but several eaqually-width lines.

For example:

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

After echoing it, say with cat lorem.ipsum I get (if i have a 38-character wide terminal):

Lorem ipsum dolor sit amet, consectet
ur adipisicing elit, sed do eiusmod t
empor incididunt ut labore et dolore 
magna aliqua. 

And now, if I copy it from the terminal, I will have 4 lines separated with \n characters. It is very annoying, how to dispose of it?

¿Fue útil?

Solución

Actually I didn't found the answer, but I've wirtten a quick hack for easy pasting such cuts into the term:

;; Linearize the last kill-ring entry
(defun make-single-line-in-clipboard ()
  (interactive)
  (with-temp-buffer
    (yank)
    (pop kill-ring)
    (goto-char 0)
    (while (search-forward "\n" nil t)
      (replace-match "" nil t))
    (kill-region (point-min) (point-max))))

;; Paste into terminal the linearized last killed text
(defun paste-into-term-singlelined ()
  (interactive)
  (term-line-mode)
  (make-single-line-in-clipboard)
  (end-of-buffer)
  (clipboard-yank)
  (term-char-mode))

And then, the binging for C-y (I use the multi-term extension).

 (cons "C-y" 'paste-into-term-singlelined)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top