[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Forcing a mode
From: |
rgb |
Subject: |
Re: Forcing a mode |
Date: |
1 Sep 2006 06:43:14 -0700 |
User-agent: |
G2/0.2 |
> (Note that Tcl scripts typically begin something like:
>
> #!/bin/sh
> # ....
> # \
> exec tclsh "$0" ${1+"$@"}
>
> so Emacs cannot deduce the mode from the shebang.)
On Tandem platforms there are no filename extensions.
Moreover, because over 90% of source files I work on are
legacy and most Tandem programmers have never heard
of Emacs, I can't go around changing source files to add
these cookies everywhere I consult.
So I had to write something that does just what you want.
I ripped redundant/irrelevent stuff out, below.
Hopefully I didn't break anything in the meanwhile.
Someone interested in the full version should see my
emacswiki page.
(defadvice set-auto-mode ; RGB 2003
(after my-determine-language last () activate)
"If language is fundamental-mode Emacs didn't detect it.
Some 1st line language indicators are used to do recognition."
(if (eq major-mode 'fundamental-mode)
(let ((mode nil))
(save-excursion ; don't trash bookmarks
(goto-char (point-min))
(if (looking-at
(concat
"\\(\\?TACL \\|==\\| *#set\\|\\?SECTION +\\"
"(\\S-+\\s-+\\"
"(macro\\|routine\\|alias\\|text\\)\\)\\b\\)"))
(setq mode 'tacl-mode)
(if (looking-at "\\?SECTION +.+,TANDEM\\b")
(setq mode 'ddl-mode)
(if (looking-at "\\?ANSI\\b")
(setq mode 'cobol-mode)
(if (looking-at "#[-*#=\n]")
(setq mode 'acimake-mode)
(if (or (looking-at "\\?pep")
(looking-at "[!*] SCHEMA")
(looking-at "!FILE CREATED BY GENFWD"))
(setq mode 'tal-mode)))))))
(if mode
(funcall mode)))))