It looks like ipython is printing invalid (or at least unknown to Emacs) 

I got it to ignore them by setting

(setq ansi-color-drop-regexp
      " 
\\[\\([ABCDsuK]\\|[12][JK]\\|=[0-9]+[hI]\\|[0-9;]*[HfDnC]\\|\\?[0-9]+[hl]\\|J\\)")

There is also a bug in my version of Emacs which causes these eliminated escape 
sequences to mess with the use of the start variable in 
'ansi-color-filter-apply'.  To make a long story short I changed the 
implementation to 

(defun ansi-color-filter-apply (string)
  "Filter out all ANSI control sequences from STRING.

Every call to this function will set and use the buffer-local variable
`ansi-color-context' to save partial escape sequences.  This information
will be used for the next call to `ansi-color-apply'.  Set
`ansi-color-context' to nil if you don't want this.

This function can be added to `comint-preoutput-filter-functions'."
  (let ((start 0) end result)
    ;; if context was saved and is a string, prepend it
    (if (cadr ansi-color-context)
        (setq string (concat (cadr ansi-color-context) string)
              ansi-color-context nil))
    ;; eliminate unrecognized escape sequences
    (while (string-match ansi-color-drop-regexp string)
      (setq string
            (replace-match "" nil nil string)))
    ;; find the next escape sequence
    (while (setq end (string-match ansi-color-regexp string start))
      (setq result (concat result (substring string start end))
            start (match-end 0)))
    ;; save context, add the remainder of the string to the result
    (let (fragment)
      (if (string-match "\033" string start)
          (let ((pos (match-beginning 0)))
            (setq fragment (substring string pos)
                  result (concat result (substring string start pos))))
        (setq result (concat result (substring string start))))
      (setq ansi-color-context (if fragment (list nil fragment))))
    result))

and it fixed it for me (I swapped the order of the "eliminate unrecognized 
escape sequences" and "find the next escape sequence".  I have filed a bug on 
it.  

Let me know if that solves the issue.  If so, then maybe we can add a 
workaround to sage-mode or figure out how to get ipython to stop sending the 
control sequences.  If not it would be helpful to know what version of Emacs 
you’re running.

-Ivan

> On Aug 11, 2016, at 3:49 PM, 'Martin R' via sage-devel 
> <sage-devel@googlegroups.com> wrote:
> 
> This is now https://trac.sagemath.org/ticket/21227
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-devel+unsubscr...@googlegroups.com 
> <mailto:sage-devel+unsubscr...@googlegroups.com>.
> To post to this group, send email to sage-devel@googlegroups.com 
> <mailto:sage-devel@googlegroups.com>.
> Visit this group at https://groups.google.com/group/sage-devel 
> <https://groups.google.com/group/sage-devel>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to