From: Steve Youngs Date: Fri, 10 Jul 2015 06:21:34 +0000 (+1000) Subject: Support both "-*-coding:" and "-*- coding:" in magic cookies X-Git-Tag: v22.1.16~21 X-Git-Url: http://cgit.sxemacs.org/?p=sxemacs;a=commitdiff_plain;h=7ce6c3cc03be110d63340d790a9c336125299e9b Support both "-*-coding:" and "-*- coding:" in magic cookies The code responsible for checking coding sytem magic cookies in files was only searching for "-*-coding:...", however most (most == all in SXEmacs, but in XEmacs and GNU/Emacs most == majority) files that have these cookies seem to use "-*- coding:...". This changeset means SXEmacs will now honour the coding cookie regardless of it being "-*-coding" or "-*- coding". * src/mule/file-coding.c (autodetect_real_coding_system): Look for " coding:" as well as "coding:" Signed-off-by: Steve Youngs --- diff --git a/src/mule/file-coding.c b/src/mule/file-coding.c index a64a0a9..90b7dc7 100644 --- a/src/mule/file-coding.c +++ b/src/mule/file-coding.c @@ -1853,7 +1853,7 @@ void autodetect_real_coding_system(lstream_t stream, Lisp_Object * codesys_in_out, eol_type_t * eol_type_in_out) { - static const char mime_name_valid_chars[] = + static const char mime_name_valid_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789" @@ -1932,7 +1932,7 @@ autodetect_real_coding_system(lstream_t stream, Lisp_Object * codesys_in_out, while (*p == ' ' || *p == '\t') { p++; } - + /* Get coding system name */ save = *suffix; *suffix = '\0'; @@ -1950,6 +1950,42 @@ autodetect_real_coding_system(lstream_t stream, Lisp_Object * codesys_in_out, } break; } + /* Try " coding:" */ + if (NILP(coding_system)) { + for (p = local_vars_beg, scan_end = suffix - LENGTH(" coding:?"); + p <= scan_end; p++) { + Extbyte save; + int n; + + if (memcmp(" coding:", p, LENGTH(" coding:")) != 0) { + continue; + } + if (p != local_vars_beg && strchr(" \t;", *p) == NULL ) { + continue; + } + p += LENGTH(" coding:"); + while (*p == ' ' || *p == '\t') { + p++; + } + + /* Get coding system name */ + save = *suffix; + *suffix = '\0'; + /* Characters valid in a MIME charset + name (rfc 1521), and in a Lisp + symbol name. */ + n = strspn((char *)p, mime_name_valid_chars); + *suffix = save; + if (n > 0) { + save = p[n]; + p[n] = '\0'; + coding_system = Ffind_coding_system( + intern((char *)p)); + p[n] = save; + } + break; + } + } break; } break;