Mercurial > emacs
comparison lisp/files.el @ 566:601ba8ba6544
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 27 Feb 1992 23:17:44 +0000 |
parents | a746c1098ea6 |
children | 5f36058e31f9 |
comparison
equal
deleted
inserted
replaced
565:6f08bfb2c11c | 566:601ba8ba6544 |
---|---|
448 (condition-case err | 448 (condition-case err |
449 (set-auto-mode) | 449 (set-auto-mode) |
450 (error (message "File mode specification error: %s" | 450 (error (message "File mode specification error: %s" |
451 (prin1-to-string err)))) | 451 (prin1-to-string err)))) |
452 (condition-case err | 452 (condition-case err |
453 (hack-local-variables (not find-file)) | 453 (let ((enable-local-variables (or (not find-file) |
454 enable-local-variables))) | |
455 (hack-local-variables)) | |
454 (error (message "File local-variables error: %s" | 456 (error (message "File local-variables error: %s" |
455 (prin1-to-string err))))) | 457 (prin1-to-string err))))) |
456 | 458 |
457 ;(defvar auto-mode-alist ...) now in loaddefs.el | 459 (defvar auto-mode-alist (mapcar 'purecopy |
460 '(("\\.text\\'" . text-mode) | |
461 ("\\.c\\'" . c-mode) | |
462 ("\\.h\\'" . c-mode) | |
463 ("\\.tex\\'" . TeX-mode) | |
464 ("\\.ltx\\'" . LaTeX-mode) | |
465 ("\\.el\\'" . emacs-lisp-mode) | |
466 ("\\.mm\\'" . nroff-mode) | |
467 ("\\.me\\'" . nroff-mode) | |
468 ("\\.[12345678]\\'" . nroff-mode) | |
469 ("\\.scm\\'" . scheme-mode) | |
470 ("\\.l\\'" . lisp-mode) | |
471 ("\\.lisp\\'" . lisp-mode) | |
472 ("\\.f\\'" . fortran-mode) | |
473 ("\\.for\\'" . fortran-mode) | |
474 ("\\.mss\\'" . scribe-mode) | |
475 ("\\.pl\\'" . prolog-mode) | |
476 ("\\.cc\\'" . c++-mode) | |
477 ("\\.C\\'" . c++-mode) | |
478 ;;; Less common extensions come here | |
479 ;;; so more common ones above are found faster. | |
480 ("\\.s\\'" . asm-mode) | |
481 ("ChangeLog\\'" . change-log-mode) | |
482 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode) | |
483 ("\\.TeX\\'" . TeX-mode) | |
484 ("\\.sty\\'" . LaTeX-mode) | |
485 ("\\.bbl\\'" . LaTeX-mode) | |
486 ("\\.bib\\'" . bibtex-mode) | |
487 ("\\.article\\'" . text-mode) | |
488 ("\\.letter\\'" . text-mode) | |
489 ("\\.texinfo\\'" . texinfo-mode) | |
490 ("\\.lsp\\'" . lisp-mode) | |
491 ("\\.awk\\'" . awk-mode) | |
492 ("\\.prolog\\'" . prolog-mode) | |
493 ;; Mailer puts message to be edited in | |
494 ;; /tmp/Re.... or Message | |
495 ("^/tmp/Re" . text-mode) | |
496 ("/Message[0-9]*\\'" . text-mode) | |
497 ;; some news reader is reported to use this | |
498 ("^/tmp/fol/" . text-mode) | |
499 ("\\.y\\'" . c-mode) | |
500 ("\\.oak\\'" . scheme-mode) | |
501 ("\\.scm.[0-9]*\\'" . scheme-mode) | |
502 ;; .emacs following a directory delimiter | |
503 ;; in either Unix or VMS syntax. | |
504 ("[]>:/]\\..*emacs\\'" . emacs-lisp-mode) | |
505 ("\\.ml\\'" . lisp-mode))) | |
506 "\ | |
507 Alist of filename patterns vs corresponding major mode functions. | |
508 Each element looks like (REGEXP . FUNCTION). | |
509 Visiting a file whose name matches REGEXP causes FUNCTION to be called.") | |
510 | |
458 (defun set-auto-mode () | 511 (defun set-auto-mode () |
459 "Select major mode appropriate for current buffer. | 512 "Select major mode appropriate for current buffer. |
460 May base decision on visited file name (see variable `auto-mode-alist') | 513 This checks for a -*- mode tag in the buffer's text, or |
461 or on buffer contents (-*- line or local variables spec), but does not look | 514 compares the filename against the entries in auto-mode-alist. It does |
462 for the \"mode:\" local variable. For that, use `hack-local-variables'." | 515 not check for the \"mode:\" local variable in the Local Variables |
516 section of the file; for that, use `hack-local-variables'. | |
517 | |
518 If enable-local-variables is nil, this function will not check for a | |
519 -*- mode tag." | |
463 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- | 520 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- |
464 (let (beg end mode) | 521 (let (beg end mode) |
465 (save-excursion | 522 (save-excursion |
466 (goto-char (point-min)) | 523 (goto-char (point-min)) |
467 (skip-chars-forward " \t\n") | 524 (skip-chars-forward " \t\n") |
468 (if (and (search-forward "-*-" (save-excursion (end-of-line) (point)) t) | 525 (if (and enable-local-variables |
526 (search-forward "-*-" (save-excursion (end-of-line) (point)) t) | |
469 (progn | 527 (progn |
470 (skip-chars-forward " \t") | 528 (skip-chars-forward " \t") |
471 (setq beg (point)) | 529 (setq beg (point)) |
472 (search-forward "-*-" (save-excursion (end-of-line) (point)) t)) | 530 (search-forward "-*-" |
531 (save-excursion (end-of-line) (point)) | |
532 t)) | |
473 (progn | 533 (progn |
474 (forward-char -3) | 534 (forward-char -3) |
475 (skip-chars-backward " \t") | 535 (skip-chars-backward " \t") |
476 (setq end (point)) | 536 (setq end (point)) |
477 (goto-char beg) | 537 (goto-char beg) |
500 (if (string-match (car (car alist)) name) | 560 (if (string-match (car (car alist)) name) |
501 (setq mode (cdr (car alist)))) | 561 (setq mode (cdr (car alist)))) |
502 (setq alist (cdr alist))))))) | 562 (setq alist (cdr alist))))))) |
503 (if mode (funcall mode)))) | 563 (if mode (funcall mode)))) |
504 | 564 |
505 (defun hack-local-variables (&optional force) | 565 (defun hack-local-variables () |
506 "Parse (and bind or evaluate as appropriate) any local variables | 566 "Parse (and bind or evaluate as appropriate) any local variables |
507 for current buffer." | 567 for current buffer." |
508 ;; Look for "Local variables:" line in last page. | 568 ;; Look for "Local variables:" line in last page. |
509 (save-excursion | 569 (save-excursion |
510 (goto-char (point-max)) | 570 (goto-char (point-max)) |
511 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) | 571 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) |
512 (if (let ((case-fold-search t)) | 572 (if (let ((case-fold-search t)) |
513 (and (search-forward "Local Variables:" nil t) | 573 (and (search-forward "Local Variables:" nil t) |
514 (or force (eq enable-local-variables t) | 574 (or (eq enable-local-variables t) |
515 (and enable-local-variables | 575 (and enable-local-variables |
516 (save-window-excursion | 576 (save-window-excursion |
517 (switch-to-buffer (current-buffer)) | 577 (switch-to-buffer (current-buffer)) |
518 (save-excursion | 578 (save-excursion |
519 (beginning-of-line) | 579 (beginning-of-line) |
531 (goto-char (match-beginning 0)) | 591 (goto-char (match-beginning 0)) |
532 (or (bolp) | 592 (or (bolp) |
533 (setq prefix | 593 (setq prefix |
534 (buffer-substring (point) | 594 (buffer-substring (point) |
535 (progn (beginning-of-line) (point))))) | 595 (progn (beginning-of-line) (point))))) |
596 | |
536 (if prefix (setq prefixlen (length prefix) | 597 (if prefix (setq prefixlen (length prefix) |
537 prefix (regexp-quote prefix))) | 598 prefix (regexp-quote prefix))) |
538 (if suffix (setq suffix (concat (regexp-quote suffix) "$"))) | 599 (if suffix (setq suffix (concat (regexp-quote suffix) "$"))) |
539 (while continue | 600 (while continue |
540 ;; Look at next local variable spec. | 601 ;; Look at next local variable spec. |
568 ;; Set the variable. "Variables" mode and eval are funny. | 629 ;; Set the variable. "Variables" mode and eval are funny. |
569 (cond ((eq var 'mode) | 630 (cond ((eq var 'mode) |
570 (funcall (intern (concat (downcase (symbol-name val)) | 631 (funcall (intern (concat (downcase (symbol-name val)) |
571 "-mode")))) | 632 "-mode")))) |
572 ((eq var 'eval) | 633 ((eq var 'eval) |
573 (if (or (and ignore-local-eval (not force)) | 634 (if (or ignore-local-eval |
574 (string= (user-login-name) "root")) | 635 (string= (user-login-name) "root")) |
575 (message "Ignoring `eval:' in file's local variables") | 636 (message "Ignoring `eval:' in file's local variables") |
576 (save-excursion (eval val)))) | 637 (save-excursion (eval val)))) |
577 (t (make-local-variable var) | 638 (t (make-local-variable var) |
578 (set var val)))))))))) | 639 (set var val)))))))))) |