Some general debugging tips
Try to get the debugger invoked when something tries to insert this text. This will give you a backtrace which should at least let you know what is doing the inserting, and hopefully that will in turn lead you towards how to work around the bug. Locate a read-only file
read-only-file.txt (for example an OS file) and run
emacs --eval '(setq debug-on-error t debug-ignored-errors nil)' -nw read-only-file.txt
You should also determine whether the issue is with Emacs startup or with file opening. If you run plain
emacs -nw, is the text inserted somewhere? If you open another file, is the text inserted into it as well? In the latter case, you can set
debug-ignored-errors after starting Emacs and open any file read-only with
If you have trouble locating which package or which part of the init file is responsible for something, the tips in How do I troubleshoot Emacs problems? and How to debug startup problem, if `--debug-init' has no effect should help.
What is causing this
Given the text that's inserted, there's a good chance that the above generic tips will be unhelpful because they'll point at
self-insert-command. The text looks like a response from a terminal when an application sends the escape sequence to query the terminal's color configuration. Normally, Emacs should send
\e is the escape character, octal code 033, and
\a is the bell character, octal code 007, which can be replaced by character 034), and the terminal replies
\e]12;rgb:0000/0000/0000\a to say that the cursor color is black. It seems that something here is going wrong: Emacs is sending the color query command but not reading the response back. Your terminal configuration may be incorrect, or it may be a bug in the terminal code.
Check that the value of
TERM is correct. If you have any code or package that tries to talk to the terminal directly, review it. Check in particular the package whose name is the same as the value of
TERM — see the manual section about terminal-specific initialization.
Unfortunately, I can't think of a simple way to set a breakpoint where something writes to the terminal. If you can't find the source of the problem on your own, there are some complicated ways, such as running Emacs under GDB, or running Emacs under an Expect script that sends SIGUSR2 when it sees the escape sequence in question.
To facilitate debugging, note that given the probable cause, it's likely that this text will be inserted every time you open a new terminal, so if you run the Emacs server you can set things up in an Emacs session and attach to a new terminal every time you want to test. This may help to debug: set a breakpoint at the beginning of the terminal setup function, and step through it until you find where it causes the problem (but note that the debugger's input/output may change the behavior of that part of the code).