Mercurial > emacs
comparison lisp/files.el @ 6575:9aba6be8e460
(hack-local-variables-prop-line): Search two lines if "#!".
Ignore keyword `mode', since it's already been handled.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 29 Mar 1994 07:08:23 +0000 |
parents | f0e1ed0e82a7 |
children | 76774f82fb36 |
comparison
equal
deleted
inserted
replaced
6574:f0e1ed0e82a7 | 6575:9aba6be8e460 |
---|---|
972 ;; Set local variables specified in the -*- line. | 972 ;; Set local variables specified in the -*- line. |
973 ;; Ignore any specification for `mode:'; | 973 ;; Ignore any specification for `mode:'; |
974 ;; set-auto-mode should already have handled that. | 974 ;; set-auto-mode should already have handled that. |
975 (save-excursion | 975 (save-excursion |
976 (goto-char (point-min)) | 976 (goto-char (point-min)) |
977 (skip-chars-forward " \t\n\r") | 977 (let ((result nil) |
978 (let ((result '()) | 978 (end (save-excursion (end-of-line (and (looking-at "^#!") 2)) (point)))) |
979 (end (save-excursion (end-of-line) (point)))) | |
980 ;; Parse the -*- line into the `result' alist. | 979 ;; Parse the -*- line into the `result' alist. |
981 (cond ((not (search-forward "-*-" end t)) | 980 (cond ((not (search-forward "-*-" end t)) |
982 ;; doesn't have one. | 981 ;; doesn't have one. |
983 nil) | 982 nil) |
984 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") | 983 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") |
985 ;; Simple form: "-*- MODENAME -*-". | 984 ;; Simple form: "-*- MODENAME -*-". Already handled. |
986 (setq result | 985 nil) |
987 (list (cons 'mode | |
988 (intern (buffer-substring | |
989 (match-beginning 1) | |
990 (match-end 1))))))) | |
991 (t | 986 (t |
992 ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' | 987 ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' |
993 ;; (last ";" is optional). | 988 ;; (last ";" is optional). |
994 (save-excursion | 989 (save-excursion |
995 (if (search-forward "-*-" end t) | 990 (if (search-forward "-*-" end t) |
1003 (match-beginning 1) | 998 (match-beginning 1) |
1004 (match-end 1))))) | 999 (match-end 1))))) |
1005 (val (save-restriction | 1000 (val (save-restriction |
1006 (narrow-to-region (point) end) | 1001 (narrow-to-region (point) end) |
1007 (read (current-buffer))))) | 1002 (read (current-buffer))))) |
1008 (setq result (cons (cons key val) result)) | 1003 (or (eq key 'mode) |
1004 (setq result (cons (cons key val) result))) | |
1009 (skip-chars-forward " \t;"))) | 1005 (skip-chars-forward " \t;"))) |
1010 (setq result (nreverse result)))) | 1006 (setq result (nreverse result)))) |
1011 | 1007 |
1012 (if (and result | 1008 (if (and result |
1013 (or (eq enable-local-variables t) | 1009 (or (eq enable-local-variables t) |
1024 (error | 1020 (error |
1025 (switch-to-buffer-other-frame (current-buffer)))))) | 1021 (switch-to-buffer-other-frame (current-buffer)))))) |
1026 (y-or-n-p (format "Set local variables as specified in -*- line of %s? " | 1022 (y-or-n-p (format "Set local variables as specified in -*- line of %s? " |
1027 (file-name-nondirectory buffer-file-name))))))) | 1023 (file-name-nondirectory buffer-file-name))))))) |
1028 (while result | 1024 (while result |
1029 (let ((key (car (car result))) | 1025 (hack-one-local-variable (car (car result)) (cdr (car result))) |
1030 (val (cdr (car result)))) | |
1031 (or (eq key 'mode) | |
1032 (hack-one-local-variable key val))) | |
1033 (setq result (cdr result))))))) | 1026 (setq result (cdr result))))))) |
1034 | 1027 |
1035 (defun hack-local-variables () | 1028 (defun hack-local-variables () |
1036 "Parse and put into effect this buffer's local variables spec." | 1029 "Parse and put into effect this buffer's local variables spec." |
1037 (hack-local-variables-prop-line) | 1030 (hack-local-variables-prop-line) |