Subject: bug#20891: emacs: Back off if .doc is not an Office document

From: Robert Pluim <[email-masked]>
Date: Fri, 15 Nov 2019 10:14:19 +0100

>>>>> On Thu, 14 Nov 2019 18:42:40 +0200, Eli Zaretskii <[email-masked]> said:

    Eli> So we want to remove docx? from auto-mode-alist and instead to add the
    Eli> magic signature to magic-mode-alist?  But then AFAIK MS Word documents
    Eli> had different signatures for different versions, so we should have
    Eli> several.  And a literal docx should be left in auto-mode-alist, right?

Yes. The following detects a word 97 file for me, and a text .doc file
opens in fundamental-mode.

diff --git i/lisp/files.el w/lisp/files.el
index 053583b4cb..ea3d3deb34 100644
--- i/lisp/files.el
+++ w/lisp/files.el
@@ -2798,7 +2798,7 @@ auto-mode-alist
      ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
      ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MS-DOS
      ("\\.[eE]?[pP][sS]\\'" . ps-mode)
-     ("\\.\\(?:PDF\\|DVI\\|OD[FGPST]\\|DOCX?\\|XLSX?\\|PPTX?\\|pdf\\|djvu\\|dvi\\|od[fgpst]\\|docx?\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
+     ("\\.\\(?:PDF\\|DVI\\|OD[FGPST]\\|DOCX\\|XLSX?\\|PPTX?\\|pdf\\|djvu\\|dvi\\|od[fgpst]\\|docx\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
      ("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
      ("\\.s\\(v\\|iv\\|ieve\\)\\'" . sieve-mode)
      ("BROWSE\\'" . ebrowse-tree-mode)
@@ -3062,6 +3062,7 @@ magic-fallback-mode-alist
             (comment-re (concat "\\(?:!--" incomment-re "*-->[ \t\r\n]*<\\)")))
        (concat "[ \t\r\n]*<" comment-re "*!DOCTYPE "))
      . sgml-mode)
+    ("\320\317\021\340\241\261\032\341" . doc-view-mode-maybe)
     ("%!PS" . ps-mode)
     ("# xmcd " . conf-unix-mode)))
   "Like `magic-mode-alist' but has lower priority than `auto-mode-alist'.