tags:

views:

235

answers:

2

I have configured my emacs to run zsh shell within ansi-term. However, copy/paste no longer works i.e. nothing is getting pasted from kill-ring to the terminal. Changing the TERM to vt100, or eterm doesn't solve the problem.

Would appreciate any ideas or solution.

To provide context I have configured ansi-term as follows:

(global-set-key "\C-x\C-a" '(lambda ()(interactive)(ansi-term "/bin/zsh")))
(global-set-key "\C-x\ a" '(lambda ()(interactive)(ansi-term "/bin/zsh")))

Thanks
Sandeep

A: 

ansi-term, in char-mode, takes the ordinary bindings for the terminal emulation. You need a new binding, plus a way to output to ansi-term correctly. I use this:

(defun ash-term-hooks ()
  ;; dabbrev-expand in term
  (define-key term-raw-escape-map "/"
    (lambda ()
      (interactive)
      (let ((beg (point)))
        (dabbrev-expand nil)
        (kill-region beg (point)))
      (term-send-raw-string (substring-no-properties (current-kill 0)))))
  ;; yank in term (bound to C-c C-y)
  (define-key term-raw-escape-map "\C-y"
    (lambda ()
       (interactive)
       (term-send-raw-string (current-kill 0))))
  (add-hook 'term-mode-hook 'ash-term-hooks)

When you do this, C-c C-y will yank. It only does one yank, though, and you can't cycle through your kill-buffer. It's possible to do this, but I haven't implemented it yet.

Appreciate your response. A ")" was missing in the end. Unfortunately this doesn't seem to work for me. I am getting error C-c C-y is undefined.
Sandeep
Hm, I tried running "emacs -q" with emacs 23.2, and (after fixing the missing paren you pointed out), I evaluated, copied some random text, then started ansi-term. Pressing C-c C-y did in fact paste it.Since this is using a hook, make sure you have restarted ansi-term after you evaluate it. if that doesn't work, try it on an emacs started with -q.You can also try pressing C-c C-h, which list bindings starting with C-c. C-c C-y should be listed with ?? (?? because we're using an unnamed lambda).
Hello. I tried restarting emacs both with and without -q. But it is still not working. I am using emacs 23.1 on ubuntu. R C-c C-h does not show any bindings when I start emacs normally. With -q I have several bindings but none about C-c C-y. Is there a log or debug output that I can look into to see whats missing. Thanks. -Sandeep
Sandeep
+2  A: 

You may want to simply switch between character mode and line mode while using the terminal. C-x C-j will activate term-line-mode, which treats the terminal buffer more like a normal text-buffer in which you can move the cursor and yank text. You can switch back to character mode with C-c C-k.

0x4b
Great tip, thanks! +1
danlei