diff options
| author | Richard M. Stallman | 1995-11-10 19:08:56 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-11-10 19:08:56 +0000 |
| commit | d0fc03efcfff391cc252a872f3b4576be9a4a481 (patch) | |
| tree | fcf215e127b49798b876a23f82a1317a20456645 | |
| parent | 5a79ed267fcac373f138aaefd3f6fef6231a7424 (diff) | |
| download | emacs-d0fc03efcfff391cc252a872f3b4576be9a4a481.tar.gz emacs-d0fc03efcfff391cc252a872f3b4576be9a4a481.zip | |
(set-auto-mode): If mode cmds move point, obey them.
| -rw-r--r-- | lisp/files.el | 98 |
1 files changed, 52 insertions, 46 deletions
diff --git a/lisp/files.el b/lisp/files.el index 1b2afa8aa7f..46668238611 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1013,7 +1013,7 @@ Local Variables section of the file; for that, use `hack-local-variables'. | |||
| 1013 | If `enable-local-variables' is nil, this function does not check for a | 1013 | If `enable-local-variables' is nil, this function does not check for a |
| 1014 | -*- mode tag." | 1014 | -*- mode tag." |
| 1015 | ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- | 1015 | ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- |
| 1016 | (let (beg end done) | 1016 | (let (beg end done modes) |
| 1017 | (save-excursion | 1017 | (save-excursion |
| 1018 | (goto-char (point-min)) | 1018 | (goto-char (point-min)) |
| 1019 | (skip-chars-forward " \t\n") | 1019 | (skip-chars-forward " \t\n") |
| @@ -1067,52 +1067,58 @@ If `enable-local-variables' is nil, this function does not check for a | |||
| 1067 | (forward-char -1) | 1067 | (forward-char -1) |
| 1068 | (goto-char end)) | 1068 | (goto-char end)) |
| 1069 | (skip-chars-backward " \t") | 1069 | (skip-chars-backward " \t") |
| 1070 | (funcall (intern (concat (downcase (buffer-substring beg (point))) "-mode"))) | 1070 | (setq modes (cons (intern (concat (downcase (buffer-substring beg (point))) "-mode")) |
| 1071 | (setq done t)) | 1071 | modes))) |
| 1072 | ;; Simple -*-MODE-*- case. | 1072 | ;; Simple -*-MODE-*- case. |
| 1073 | (funcall (intern (concat (downcase (buffer-substring beg end)) "-mode"))) | 1073 | (setq modes (cons (intern (concat (downcase (buffer-substring beg end)) |
| 1074 | (setq done t)))) | 1074 | "-mode")) |
| 1075 | ;; If we didn't find a mode from a -*- line, try using the file name. | 1075 | modes)))))) |
| 1076 | (if (and (not done) buffer-file-name) | 1076 | ;; If we found modes to use, invoke them now, |
| 1077 | (let ((name buffer-file-name) | 1077 | ;; outside the save-excursion. |
| 1078 | (keep-going t)) | 1078 | (if modes |
| 1079 | ;; Remove backup-suffixes from file name. | 1079 | (progn (mapcar 'funcall modes) |
| 1080 | (setq name (file-name-sans-versions name)) | 1080 | (setq done t))) |
| 1081 | (while keep-going | 1081 | ;; If we didn't find a mode from a -*- line, try using the file name. |
| 1082 | (setq keep-going nil) | 1082 | (if (and (not done) buffer-file-name) |
| 1083 | (let ((alist auto-mode-alist) | 1083 | (let ((name buffer-file-name) |
| 1084 | (mode nil)) | 1084 | (keep-going t)) |
| 1085 | ;; Find first matching alist entry. | 1085 | ;; Remove backup-suffixes from file name. |
| 1086 | (let ((case-fold-search | 1086 | (setq name (file-name-sans-versions name)) |
| 1087 | (memq system-type '(vax-vms windows-nt)))) | 1087 | (while keep-going |
| 1088 | (while (and (not mode) alist) | 1088 | (setq keep-going nil) |
| 1089 | (if (string-match (car (car alist)) name) | 1089 | (let ((alist auto-mode-alist) |
| 1090 | (if (and (consp (cdr (car alist))) | 1090 | (mode nil)) |
| 1091 | (nth 2 (car alist))) | 1091 | ;; Find first matching alist entry. |
| 1092 | (progn | 1092 | (let ((case-fold-search |
| 1093 | (setq mode (car (cdr (car alist))) | 1093 | (memq system-type '(vax-vms windows-nt)))) |
| 1094 | name (substring name 0 (match-beginning 0)) | 1094 | (while (and (not mode) alist) |
| 1095 | keep-going t)) | 1095 | (if (string-match (car (car alist)) name) |
| 1096 | (setq mode (cdr (car alist)) | 1096 | (if (and (consp (cdr (car alist))) |
| 1097 | keep-going nil))) | 1097 | (nth 2 (car alist))) |
| 1098 | (setq alist (cdr alist)))) | 1098 | (progn |
| 1099 | (if mode | 1099 | (setq mode (car (cdr (car alist))) |
| 1100 | (funcall mode) | 1100 | name (substring name 0 (match-beginning 0)) |
| 1101 | ;; If we can't deduce a mode from the file name, | 1101 | keep-going t)) |
| 1102 | ;; look for an interpreter specified in the first line. | 1102 | (setq mode (cdr (car alist)) |
| 1103 | (let ((interpreter | 1103 | keep-going nil))) |
| 1104 | (save-excursion | 1104 | (setq alist (cdr alist)))) |
| 1105 | (goto-char (point-min)) | 1105 | (if mode |
| 1106 | (if (looking-at "#! *\\([^ \t\n]+\\)") | 1106 | (funcall mode) |
| 1107 | (buffer-substring (match-beginning 1) | 1107 | ;; If we can't deduce a mode from the file name, |
| 1108 | (match-end 1)) | 1108 | ;; look for an interpreter specified in the first line. |
| 1109 | ""))) | 1109 | (let ((interpreter |
| 1110 | elt) | 1110 | (save-excursion |
| 1111 | ;; Map interpreter name to a mode. | 1111 | (goto-char (point-min)) |
| 1112 | (setq elt (assoc (file-name-nondirectory interpreter) | 1112 | (if (looking-at "#! *\\([^ \t\n]+\\)") |
| 1113 | interpreter-mode-alist)) | 1113 | (buffer-substring (match-beginning 1) |
| 1114 | (if elt | 1114 | (match-end 1)) |
| 1115 | (funcall (cdr elt)))))))))))) | 1115 | ""))) |
| 1116 | elt) | ||
| 1117 | ;; Map interpreter name to a mode. | ||
| 1118 | (setq elt (assoc (file-name-nondirectory interpreter) | ||
| 1119 | interpreter-mode-alist)) | ||
| 1120 | (if elt | ||
| 1121 | (funcall (cdr elt))))))))))) | ||
| 1116 | 1122 | ||
| 1117 | (defun hack-local-variables-prop-line () | 1123 | (defun hack-local-variables-prop-line () |
| 1118 | ;; Set local variables specified in the -*- line. | 1124 | ;; Set local variables specified in the -*- line. |