From: Richard Stallman <rms@gnu.org>
To: Kevin Ryde <user42@zip.com.au>
Cc: emacs-devel@gnu.org
Subject: Re: html-mode demanding <html> a bit too tight
Date: Wed, 25 Apr 2007 10:51:48 -0400 [thread overview]
Message-ID: <E1HgiqS-0003M4-5O@fencepost.gnu.org> (raw)
In-Reply-To: <87mz0y8vyk.fsf@zip.com.au> (message from Kevin Ryde on Tue, 24 Apr 2007 10:20:03 +1000)
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
next parent reply other threads:[~2007-04-25 14:51 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87647ooxwm.fsf@zip.com.au>
[not found] ` <jwvps5vry60.fsf-monnier+emacs@gnu.org>
[not found] ` <462CC030.8030203@gmail.com>
[not found] ` <87mz0y8vyk.fsf@zip.com.au>
2007-04-25 14:51 ` Richard Stallman [this message]
2007-04-25 17:36 ` html-mode demanding <html> a bit too tight Stefan Monnier
2007-04-25 18:18 ` Lennart Borgman (gmail)
2007-04-27 5:59 ` Richard Stallman
2007-04-26 4:11 ` Glenn Morris
2007-04-27 5:59 ` Richard Stallman
2007-04-27 6:22 ` David Kastrup
2007-04-27 13:08 ` Eli Zaretskii
2007-04-27 10:27 ` Kim F. Storm
2007-04-27 11:14 ` Lennart Borgman (gmail)
2007-04-27 11:41 ` David Kastrup
2007-04-27 11:49 ` Lennart Borgman (gmail)
2007-04-27 11:56 ` David Kastrup
2007-04-27 12:03 ` Lennart Borgman (gmail)
2007-04-27 12:22 ` David Kastrup
2007-04-27 21:41 ` Lennart Borgman (gmail)
2007-04-27 12:48 ` Eli Zaretskii
2007-04-27 14:11 ` David Reitter
2007-04-27 20:17 ` Lennart Borgman (gmail)
2007-04-27 20:53 ` Chong Yidong
2007-04-27 21:02 ` Lennart Borgman (gmail)
2007-04-27 18:58 ` Edward O'Connor
2007-04-27 12:53 ` Eli Zaretskii
2007-04-27 20:53 ` Kim F. Storm
2007-04-28 4:06 ` Richard Stallman
2007-04-28 13:59 ` David Kastrup
2007-04-28 14:20 ` Juanma Barranquero
2007-04-29 21:17 ` Kim F. Storm
2007-04-30 22:09 ` Richard Stallman
2007-05-04 9:13 ` unicode-2 and multitty (was: html-mode demanding <html> a bit too tight) David Kastrup
2007-05-04 9:41 ` unicode-2 and multitty Jason Rumney
2007-05-04 10:14 ` David Kastrup
2007-05-04 20:46 ` Kim F. Storm
2007-05-05 0:26 ` David Kastrup
2007-05-05 21:54 ` Stefan Monnier
2007-05-07 9:55 ` Kim F. Storm
2007-05-07 10:09 ` David Kastrup
2007-05-04 9:42 ` Ulrich Mueller
2007-05-04 10:39 ` unicode-2 and multitty (was: html-mode demanding <html> a bit too tight) Eli Zaretskii
2007-05-04 11:12 ` unicode-2 and multitty David Kastrup
2007-05-04 21:18 ` unicode-2 and multitty (was: html-mode demanding <html> a bit too tight) Richard Stallman
2007-05-05 0:17 ` unicode-2 and multitty David Kastrup
2007-04-27 11:17 ` html-mode demanding <html> a bit too tight Leo
2007-04-27 19:51 ` Glenn Morris
2007-04-28 4:07 ` Richard Stallman
2007-04-28 8:04 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1HgiqS-0003M4-5O@fencepost.gnu.org \
--to=rms@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=user42@zip.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).