X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/f36d46caffc209065f29e7e7fa8daa01994d2e88..1bf6d4b5c112dbf6233ff2cfc3b85adfa6cbd291:/lisp/files.el diff --git a/lisp/files.el b/lisp/files.el index 112056e4f9..fee3a5ea65 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1,7 +1,8 @@ ;;; files.el --- file input and output commands for Emacs -;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, -;; 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994, 1995, 1996, +;; 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +;; 2006 Free Software Foundation, Inc. ;; Maintainer: FSF @@ -2047,6 +2048,9 @@ to decide the buffer's major mode. If FUNCTION is nil, then it is not called. (That is a way of saying \"allow `auto-mode-alist' to decide for these files.\")") +(defvar magic-mode-regexp-match-limit 4000 + "Upper limit on `magic-mode-alist' regexp matches.") + (defun set-auto-mode (&optional keep-mode-if-same) "Select major mode appropriate for current buffer. @@ -2120,9 +2124,13 @@ only set the major mode, if that would change it." (unless done (if (setq done (save-excursion (goto-char (point-min)) - (assoc-default nil magic-mode-alist - (lambda (re dummy) - (looking-at re))))) + (save-restriction + (narrow-to-region (point-min) + (min (point-max) + (+ (point-min) magic-mode-regexp-match-limit))) + (assoc-default nil magic-mode-alist + (lambda (re dummy) + (looking-at re)))))) (set-auto-mode-0 done keep-mode-if-same) ;; Compare the filename against the entries in auto-mode-alist. (if buffer-file-name