When using ansi-term on Emacs a get the following error whenever I press enter in char-mode:

wrong type argument: characterp, return

I used toggle-debug-on-error and get the following:

Debugger entered--Lisp error: (wrong-type-argument characterp return)
  (let ((cua-delete-selection (not autopair-autowrap)) (blink-matching-paren (not autopair-action))) (call-interactively beyond-autopair))
  (let* ((autopair-emulation-alist nil) (beyond-cua (let ((cua--keymap-alist nil)) (autopair-original-binding fallback-keys))) (beyond-autopair (autopair-original-binding fallback-keys))) (if autopair-autowrap (progn (setq autopair-wrap-action (autopair-calculate-wrap-action)))) (setq this-autopair-command this-command) (setq this-original-command beyond-cua) (if (and (featurep (quote paredit)) (symbolp beyond-cua) (string-match "paredit" (symbol-name beyond-cua))) (progn (setq autopair-action nil))) (let ((cua-delete-selection (not autopair-autowrap)) (blink-matching-paren (not autopair-action))) (call-interactively beyond-autopair)))
  (let ((pair (autopair-find-pair (char-before)))) (if (and pair (eq (char-syntax pair) 41) (eq (char-after) pair)) (progn (setq autopair-action (list (quote newline) pair (point))))) (autopair-fallback (kbd "RET")))
  call-interactively(autopair-newline nil nil)

And after that the Enter key starts to work normally, but I do have to go through the toggle-debug-on-error every time I open Emacs.

I looked around but didn't find anything that could help me on that.

In my .emacs I've got the following reference to ansi-term:

(defvar my-term-shell "/bin/zsh")
(defadvice ansi-term (before force-bash)
  (interactive (list my-term-shell)))
(ad-activate 'ansi-term)

(defun my-term-use-utf8 ()
  (set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))
(add-hook 'term-exec-hook 'my-term-use-utf8)
  • 1
    It seems that you're using autopair and cua-mode. Have you tried disabling them. They (or your configuration of them) might be the cause of your problem. – user12563 Apr 2 '19 at 16:57

Found the answer, it was a conflict with autopair, solved by adding the following to .emacs

(add-hook 'term-mode-hook (lambda()
                            (autopair-mode -1)
  • Consider submitting an autopair-mode bug report for this, if the standard config results in this problem. – phils May 2 '19 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.