I am running emacs 26.1 under linux. It has been working fine for over a year. Recently, I upgraded a lot of packages on my machine, but I did not upgrade nor alter emacs in any way. Now, query-replace
and query-replace-regexp
are failing when I run either of them in a non-X terminal with the -nw
emacs command-line flag when not in text-mode
. This failure never used to occur before my system upgrades. And it turns out that query-replace{-regexp}
still work fine in all cases when I start emacs in an X window.
For example, suppose I have the following data in a file called test.txt
...
AAAA
BBBB
CCCC
DDDD
If I run emacs -nw test.txt
, then position to the top of the file and run (query-replace "AAAA" "XXXX")
, it works. However, if I run (emacs-lisp-mode)
and then run (query-replace "AAAA" "XXXX")
in the same way, I get this result (with debug-on-error
set) ...
Debugger entered--Lisp error: (args-out-of-range #<buffer test.txt> 0 1)
buffer-substring-no-properties(0 1)
perform-replace("AAAA" "XXXX" t nil nil nil nil nil nil nil nil)
query-replace("AAAA" "XXXX")
eval((query-replace "AAAA" "XXXX") nil)
eval-expression((query-replace "AAAA" "XXXX") nil nil 127)
funcall-interactively(eval-expression (query-replace "AAAA" "XXXX") nil nil 127)
call-interactively(eval-expression nil nil)
command-execute(eval-expression)
However, if I leave off -nw
and do all the same things in an X-Window instance of emacs, (query-replace ...)
always works.
In other words, with emacs test.txt
(i.e., no -nw
flag), I never get this problem with query-replace
, no matter what mode I am running in.
This is not only specific to emacs-lisp-mode
. The error with query-replace
in a non-X terminal buffer also occurs for sh-mode
and some other modes.
Does anyone know what could be causing this error and what I have to do to fix it?
Thank you in advance.
UPDATE:
This error does not occur when I am running from my system console (i.e., no X services running at all). The errors I saw did occur in xterm
and urxvt
windows under my X desktop manager, even when I have explicitly unset DISPLAY
.
It seems like there is something about running within an X desktop manager which is confusing emacs with regard to buffer attributes when running with -nw
, even with DISPLAY
unset.
And again, this problem only started happening a short time ago after updating a number of software components, but with no changes to emacs, at all. I have rebooted a few times since then, to no avail.
FURTHER UPDATE:
This error does not occur when I run (replace-string "AAAA" "XXXX")
.
major-mode
gets set toemacs-lisp-mode
, and I then get this error behavior. Also, I know this is nearly impossible to reproduce. I am running emacs-26.1 on two other machines, and this behavior doesn't occur.font-lock
command when running it in anemacs -nw
session. If I comment out all(font-lock ...)
code in all my startup files, then this error behavior goes away.