NOTE: I was careless in evaluating this problem, and the data I posted here is not correct and does not reflect the actual issue that I am facing.
Since there are already answers to this question, I cannot delete it.
Please see the following question for the updated and corrected version of my query:
query-replace{-regexp} fails in linux in a non-X terminal when I am in anything other than text mode
Please ignore the rest of this. Thank you.
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, buffer-substring
is failing when I run it 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 buffer-substring
still works 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 (buffer-substring 0 1)
works. However, if I run (elisp-mode)
and then do a (buffer-substring 0 1)
, I get this error: args-out-of-range #<buffer test.txt> 0 1
This occurs no matter what arguments I pass to buffer-substring
. However, if I leave off -nw
and do all the same things in an X-Window instance of emacs, buffer-substring
always works.
In other words, with emacs test.txt
(i.e., no -nw
flag), I never get this problem with buffer-substring
, no matter what mode I am running in.
This is not only specific to elisp-mode
. The error with buffer-substring
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:
I set debug-on-error
and re-ran (buffer substring 0 1)
in one of the cases that fails. Here is what I got:
Debugger entered--Lisp error: (args-out-of-range #<buffer test.txt> 0 1)
buffer-substring(0 1)
eval((buffer-substring 0 1) nil)
eval-expression((buffer-substring 0 1) nil nil 127)
funcall-interactively(eval-expression (buffer-substring 0 1) nil nil 127)
call-interactively(eval-expression nil nil)
command-execute(eval-expression)
FURTHER UPDATE:
This error does not occur when I am running from my system console (with 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.
debug-on-error
and then cause the error to happen again. That will give you a backtrace that you should add to your question. You can enabledebug-on-error
withM-x toggle-debug-on-error RET
(assuming that it was disabled before - if not, just toggle it again. The echo area should sayDebug on Error enabled globally
.)~ $ emacs -Q --batch --eval '(buffer-substring 0 1)'
=>Args out of range: #<buffer *scratch*>, 0, 1
*scratch*
is an empty buffer in your example. However, when running in a non-empty buffer as I have outlined above,(buffer-substring 0 1)
works, except in the error cases I mentioned.elisp-mode
?