3

Generate a file with this:

(echo '#!/bin/bash'
echo 'myfunc() {'
echo "cat <<'z'"
seq 135
echo zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
echo z
echo '}') >out

Open it in Emacs. When pressing C-M-f I get the error:

Scan error: "Containing expression ends prematurely", 515, 515

Then I press M-> to get to end of file, C-x C-x to move back to where I came from, and now I can press C-M-f and move to the next sexp.

It is as if emacs does not really index the full file before I have been to the end of the file.

How can I fix this?

Drew
  • 75,699
  • 9
  • 109
  • 225
Ole Tange
  • 143
  • 4
  • Do you see the same thing when you start Emacs using `emacs -Q` (no init file? If not, bisect your init file to find the culprit. If yes, consider filing a bug report: `M-x report-emacs-bug`. – Drew Mar 05 '18 at 21:54

1 Answers1

4

Made a bug report for this: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30726

Bug-source is in but-last line of the def in lisp.el, where

(goto-char (or (scan-sexps (point) arg) (buffer-end arg)))

scan-sexps sends the error.

Wrapping it into (ignore-errors:

(or (ignore-errors (scan-sexps (point) arg))...

makes it gone.

Error showed up when forward-sexp was called from closing parenthesis at last line of example code. Seen from emitting scan-sexps that error might be justified, however forward-sexp should deal with it. There may be more occasions to fail. IMHO forward-sexp navigates strangely from inside a string - try it at a functions docstring.

To avoid these wrote ar-forward-sexp

which see here: https://github.com/andreas-roehler/thingatpt-utils-core/blob/master/ar-subr.el

Andreas Röhler
  • 1,894
  • 10
  • 10