From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: html-mode demanding a bit too tight Date: Wed, 25 Apr 2007 10:51:48 -0400 Message-ID: References: <87647ooxwm.fsf@zip.com.au> <462CC030.8030203@gmail.com> <87mz0y8vyk.fsf@zip.com.au> Reply-To: rms@gnu.org NNTP-Posting-Host: lo.gmane.org Content-Type: text/plain; charset=ISO-8859-15 X-Trace: sea.gmane.org 1177512954 2782 80.91.229.12 (25 Apr 2007 14:55:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 25 Apr 2007 14:55:54 +0000 (UTC) Cc: emacs-devel@gnu.org To: Kevin Ryde Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 25 16:55:53 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HgiuL-0003nM-DO for ged-emacs-devel@m.gmane.org; Wed, 25 Apr 2007 16:55:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hgizx-0003dH-Ay for ged-emacs-devel@m.gmane.org; Wed, 25 Apr 2007 11:01:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Hgiyk-00036e-Nz for emacs-devel@gnu.org; Wed, 25 Apr 2007 11:00:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Hgiyi-00035w-My for emacs-devel@gnu.org; Wed, 25 Apr 2007 11:00:21 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hgiyi-00035m-AG for emacs-devel@gnu.org; Wed, 25 Apr 2007 11:00:20 -0400 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Hgit4-0001k8-Mb for emacs-devel@gnu.org; Wed, 25 Apr 2007 10:54:30 -0400 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.60) (envelope-from ) id 1HgiqS-0003M4-5O; Wed, 25 Apr 2007 10:51:48 -0400 In-reply-to: <87mz0y8vyk.fsf@zip.com.au> (message from Kevin Ryde on Tue, 24 Apr 2007 10:20:03 +1000) X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:70104 Archived-At: What do people think of this method of fixing the problem? It will allow moving certain patterns from `magic-mode-alist' to `file-start-mode-alist', but only those we need to move. *** files.el 23 Apr 2007 17:14:10 -0400 1.896 --- files.el 24 Apr 2007 23:47:25 -0400 *************** *** 2151,2158 **** \"allow `auto-mode-alist' to decide for these files.\")") (put 'magic-mode-alist 'risky-local-variable t) (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. --- 2151,2171 ---- \"allow `auto-mode-alist' to decide for these files.\")") (put 'magic-mode-alist 'risky-local-variable t) + (defvar file-start-mode-alist + nil + "Like `magic-mode-alist' but has lower priority than `auto-mode-alist'. + Each element looks like (REGEXP . FUNCTION) or (MATCH-FUNCTION . FUNCTION). + After visiting a file, if REGEXP matches the text at the beginning of the + buffer, or calling MATCH-FUNCTION returns non-nil, `normal-mode' will + call FUNCTION, provided that `magic-mode-alist' and `auto-mode-alist' + have not specified a mode for this file. + + If FUNCTION is nil, then it is not called.") + (put 'file-start-mode-alist 'risky-local-variable t) + (defvar magic-mode-regexp-match-limit 4000 ! "Upper limit on `magic-mode-alist' regexp matches. ! Also applies to `file-start-mode-alist'.") (defun set-auto-mode (&optional keep-mode-if-same) "Select major mode appropriate for current buffer. *************** *** 2207,2216 **** (or (set-auto-mode-0 mode keep-mode-if-same) ;; continuing would call minor modes again, toggling them off (throw 'nop nil)))))) (unless done - ;; If we didn't, look for an interpreter specified in the first line. - ;; As a special case, allow for things like "#!/bin/env perl", which - ;; finds the interpreter anywhere in $PATH. (setq mode (save-excursion (goto-char (point-min)) (if (looking-at auto-mode-interpreter-regexp) --- 2220,2229 ---- (or (set-auto-mode-0 mode keep-mode-if-same) ;; continuing would call minor modes again, toggling them off (throw 'nop nil)))))) + ;; If we didn't, look for an interpreter specified in the first line. + ;; As a special case, allow for things like "#!/bin/env perl", which + ;; finds the interpreter anywhere in $PATH. (unless done (setq mode (save-excursion (goto-char (point-min)) (if (looking-at auto-mode-interpreter-regexp) *************** *** 2223,2229 **** ;; If we found an interpreter mode to use, invoke it now. (if done (set-auto-mode-0 (cdr done) keep-mode-if-same))) ! ;; If we didn't, match the buffer beginning against magic-mode-alist. (unless done (if (setq done (save-excursion (goto-char (point-min)) --- 2236,2242 ---- ;; If we found an interpreter mode to use, invoke it now. (if done (set-auto-mode-0 (cdr done) keep-mode-if-same))) ! ;; Next try matching the buffer beginning against magic-mode-alist. (unless done (if (setq done (save-excursion (goto-char (point-min)) *************** *** 2236,2274 **** (if (functionp re) (funcall re) (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 ! (let ((name buffer-file-name)) ! ;; Remove backup-suffixes from file name. ! (setq name (file-name-sans-versions name)) ! (while name ! ;; Find first matching alist entry. ! (setq mode ! (if (memq system-type '(vax-vms windows-nt cygwin)) ! ;; System is case-insensitive. ! (let ((case-fold-search t)) ! (assoc-default name auto-mode-alist ! 'string-match)) ! ;; System is case-sensitive. ! (or ! ;; First match case-sensitively. ! (let ((case-fold-search nil)) ! (assoc-default name auto-mode-alist ! 'string-match)) ! ;; Fallback to case-insensitive match. ! (and auto-mode-case-fold ! (let ((case-fold-search t)) ! (assoc-default name auto-mode-alist ! 'string-match)))))) ! (if (and mode ! (consp mode) ! (cadr mode)) ! (setq mode (car mode) ! name (substring name 0 (match-beginning 0))) ! (setq name)) ! (when mode ! (set-auto-mode-0 mode keep-mode-if-same))))))))) ;; When `keep-mode-if-same' is set, we are working on behalf of ;; set-visited-file-name. In that case, if the major mode specified is the --- 2249,2303 ---- (if (functionp re) (funcall re) (looking-at re))))))) ! (set-auto-mode-0 done keep-mode-if-same))) ! ;; Next compare the filename against the entries in auto-mode-alist. ! (unless done ! (if buffer-file-name ! (let ((name buffer-file-name)) ! ;; Remove backup-suffixes from file name. ! (setq name (file-name-sans-versions name)) ! (while name ! ;; Find first matching alist entry. ! (setq mode ! (if (memq system-type '(vax-vms windows-nt cygwin)) ! ;; System is case-insensitive. ! (let ((case-fold-search t)) ! (assoc-default name auto-mode-alist ! 'string-match)) ! ;; System is case-sensitive. ! (or ! ;; First match case-sensitively. ! (let ((case-fold-search nil)) ! (assoc-default name auto-mode-alist ! 'string-match)) ! ;; Fallback to case-insensitive match. ! (and auto-mode-case-fold ! (let ((case-fold-search t)) ! (assoc-default name auto-mode-alist ! 'string-match)))))) ! (if (and mode ! (consp mode) ! (cadr mode)) ! (setq mode (car mode) ! name (substring name 0 (match-beginning 0))) ! (setq name)) ! (when mode ! (set-auto-mode-0 mode keep-mode-if-same) ! (setq done t)))))) ! ;; Next try matching the buffer beginning against file-start-mode-alist. ! (unless done ! (if (setq done (save-excursion ! (goto-char (point-min)) ! (save-restriction ! (narrow-to-region (point-min) ! (min (point-max) ! (+ (point-min) magic-mode-regexp-match-limit))) ! (assoc-default nil file-start-mode-alist ! (lambda (re dummy) ! (if (functionp re) ! (funcall re) ! (looking-at re))))))) ! (set-auto-mode-0 done keep-mode-if-same))))) ;; When `keep-mode-if-same' is set, we are working on behalf of ;; set-visited-file-name. In that case, if the major mode specified is the