Subject: bug#55002: 27.1; Abnormal behaviour in C mode

From: Bill Purvis <[email-masked]>
Date: Mon, 18 Apr 2022 12:59:24 +0100

I was creating a C program, and part way through I skipped back to
define an additional variable. I started to type: 'static int...'
but instead of displaying the characters it inserted newlines until it
encountered a punctuation character, whereupon the characters I had
typed appeared and the inserted newlines disappeared. I found this very
disconcerting. Saving the file, restarting emacs and the problem
remains.

I have eventually tracked down what brings it up, spending the whole of
a morning trying variants of code, and finally tracked it down to an
incomplete character string lower down in the program. However, I still
rate this behaviour as a bug and did a google search on Stack Exchange
and was advised by 'drew' to look at me .emacs file. I have been using
for many years (30+?) and my .emacs file has accumulated over the years.
Most of the entries I can't what they do or why I added them, so I spent
quite a while commenting them out, to see if that modifies the effect.

I have finally concluded that the line:
(global-font-lock-mode 0)
appears to be the culprit.

Here is a copy of my current .emacs file:
---------------------------o><o---------------------------------
(display-time) ; Enable time (& date ?) display.

(setq default-frame-alist
'(
;;; Define here the default geometry or via ~/.Xdefaults.
(width . 84) (height . 58)
(cursor-color . "red")
(cursor-type . box)
(foreground-color . "black")
(background-color . "white")))

(defun force-revert-buffer ()
"reload from disk without prompt"
(interactive )
(revert-buffer t t))

(setq inhibit-startup-message t)

(global-set-key [f1] 'what-line)
(global-set-key [f2] 'goto-line)
(global-set-key [f3] 'scroll-right)
(global-set-key [f4] 'scroll-left)

(global-set-key [f5] 'compile)
(global-set-key [f6] 'indent-region)
(global-set-key [f7] 'force-revert-buffer)
(global-set-key [f8] 'nexttab)

(global-set-key [f10] 'word-search-forward)
(global-set-key [f11] 'word-search-backward)
(global-set-key [f12] 'call-last-kbd-macro)

;;(global-font-lock-mode 0)
------------------------------o><o-------------------------------
The final statement, is uncommented provokes the problem with the
following C file
------------------------------o><o-------------------------------
// encode.c
//

static FILE *out, *in;
static char filename[300];
static int linect;
static int ch;
static int key=-1;
static int size;
static int mode='n'; // type static int on next line....

static void parseSetting(void);

static int next(void) {
if (ch == EOF)
abort("unexpected end of file
ch = fgetc(in);
if (ch == '
')
linect++;
while (ch == '=')
parseSetting();
return ch;
--------------------------------o><o-----------------------------
As you can see it is incomplete, and there is an incomplete character
string. I have added a comment at the place where I encounter the problem.

I hope the above demonstrates the problem to you. I am happy to engage
in testing any proposed fixes.

Bill
--------------
In GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, 
cairo version 1.16.0)
of 2021-01-18, modified by Debian built on lgw01-amd64-045
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Ubuntu 21.10

Recent messages:
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el 
(source)...done
Loading debian-ispell...done
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el 
(source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Saving file /home/bill/Church/SongSheets/XML/bug1.c...
Wrote /home/bill/Church/SongSheets/XML/bug1.c
No other windows to delete

Configured using:
'configure --build x86_64-linux-gnu --prefix=/usr
--sharedstatedir=/var/lib --libexecdir=/usr/lib
--localstatedir=/var/lib --infodir=/usr/share/info
--mandir=/usr/share/man --enable-libsystemd --with-pop=yes
--enable-locallisppath=/etc/emacs:/usr/local/share/emacs/27.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/27.1/site-lisp:/usr/share/emacs/site-lisp 

--with-sound=alsa --without-gconf --with-mailutils --build
x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
--libexecdir=/usr/lib --localstatedir=/var/lib
--infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd
--with-pop=yes
--enable-locallisppath=/etc/emacs:/usr/local/share/emacs/27.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/27.1/site-lisp:/usr/share/emacs/site-lisp 

--with-sound=alsa --without-gconf --with-mailutils --with-cairo
--with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
'CFLAGS=-g -O2
-ffile-prefix-map=/build/emacs-P5Mppj/emacs-27.1+1=. 
-fstack-protector-strong
-Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
-D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro''

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF
ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD
JSON PDUMPER LCMS2 GMP

Important settings:
value of $LC_COLLATE: C
value of $LC_CTYPE: en_GB.UTF-8
value of $LC_MESSAGES: en_GB.UTF-8
value of $LANG: C
value of $XMODIFIERS: @im=ibus
locale-coding-system: utf-8-unix

Major mode: C/*l

Minor modes in effect:
display-time-mode: t
tooltip-mode: t
global-eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
abbrev-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml mml-sec password-cache epa derived epg epg-config
gnus-util rmail rmail-loaddefs text-property-search time-date subr-x seq
byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils cc-mode cc-fonts
easymenu cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars
cc-defs cl-loaddefs cl-lib time tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote threads dbusbind inotify lcms2 dynamic-setting
system-font-setting font-render-setting cairo move-toolbar gtk x-toolkit
x multi-tty make-network-process emacs)

Memory information:
((conses 16 68177 7974)
(symbols 48 8621 1)
(strings 32 22059 2059)
(string-bytes 1 820630)
(vectors 16 12846)
(vector-slots 8 162294 9650)
(floats 8 22 41)
(intervals 56 369 8)
(buffers 1000 13))

-- 
+----------------------------------------+
| Bill Purvis                            |
| email: [email-masked]                  |
+----------------------------------------+