############################################################################# File: FMC.FPL Author: Jesper Skov (+ a bit by Daniel Stenberg) Email: jskov@iesd.auc.dk Short: File Mode Control - switches on modes based on file's ext Version: 2.0 Date: 02.04.95 Local settings: Global settings: Keysequence: Type: Prereq: Copyright: © 1995, Jesper Skov Use/distribute according to the terms of GNU GPL. (See the file 'COPYING.GNU' for more info!) ############################################################################# FUNCTION This package give FrexxEd the powerfull ability of recognizing different file types, and act in a (by you) predefined manner. I think I better give you some examples: You load a file named "test.fpl". Automatically C style indention is switched on, and perhaps some ETags are loaded. I create a file named "text.tex". LaTeX mode gets switched on as does double mode (I'm Danish - we have funky letters :) In both examples some other things may happend without you having to explicitly specify it. This could be the syntax of comments being changed, or needed external ARexx servers being launched. For this to work FMC introduces a new concept - the major and minor modes. What are modes? Major mode: A major mode is a FrexxEd "environment" which will allow communication with external applications. This could be an assembler, compiler or a viewer. Only one major mode is active at a time. Minor mode: A minor mode is a more text oriented interface - making it easier for the user to work with the format of the text/source used by external applications. This could be indention control for C, assembler or Pascal. Maybe some macro packages for LaTeX or HyperText (AmigaGuide format). Also things like word wrap and my DoubleMode are considered minor modes. In short, anything not an interface is a minor mode. Many minor modes may be active at a time. "OK", you ask. "What's the big deal here?" Methaphorically speaking, you may now not only select what's for dinner, but also what spices to use :) This is possible because each major mode has the following information: extensions: What file types should trigger this mode? The extensions are case in-sensitive and separated with stars: Examples: "*c*h*" - could be for a C mode. "*text*txt*readme*" - could be for a text mode. execute: A string that will be executed when the mode is switched on. This string (full FPL syntax) includes the code responsible for switching on minor modes. There may also be calls to (major) mode specific initialization - these should be default settings from the authors side. To make it easier for you to add more spice, you may use a function called ME(string mode_name). It will switch on the minor mode of name "mode_name" (beats writing SetInfo(-1,mode_name,1);). Example: "ME("double_mode");" - default in LaTeX mode. You may change these settings with "Customizing->Program->Major Modes", and the idividual buffer's major mode and minor modes with "Customizing->Buffer Mode->Major/Minor". Whenever you change a buffer's major mode, all minor modes are disabled. It is then the job of the major mode's execute to enable the correct minor modes. Remember to put FMC.FPL early in your USER.FPL file. Preferably first. You may also force a major mode by putting the string "-*--*-" in the first line of a file. For example, if you write many install scripts and have made a LISP major mode (it is LISP code, right? Looks like it to me, anyway!) the first line of the file "Install_english" could be "## -*-lisp_mode-*-" (## represents a comment - I don't know the syntax, sorry). Now the buffer would be in LISP mode, even though the file has no extension (as opposed to "file.lisp"). ------ If you want to make your own major/minor modes all you have to do is to call the function AddMode described below: AddMode(int type, string name, string extensions, string execute) type: 0 = minor mode, 1 = major mode name: name of mode info variable (e.g. "latex_mode") (boolean, "LBH") extensions: name of extensions info variable (e.g. "latex_ext") Only for major mode! (string, "GSWH") execute: name of execute info variable (e.g. "latex_exe") Only for major mode! (string, "GSWH") You must create the info variables yourself. They should have the type strings listed above. If you are making a minor mode, extensions and execute should be empty strings (e.g. AddMode(0,"double_mode","","")). If you have already made something that should be a major/minor mode, and have any questions about how to make it FMC compatible, please let me know. Also, you may find answer to your questions in some of my (or others) modes. Check out DoubleMode (minor mode) and LaTeXCompile (major mode). HISTORY (REV) 02.04.95 (0) Written with experience from LMC and FMC1.1, and after general acceptance of my ideas on the FrexxEd mailing list =) BUGS Be sure to report any bugs you may find! TODO Get old FPL modes prepped to the FMC. Make people use the mode concept in the future. SEE ALSO Larry Niven & Steven Barnes' "The Barsoom Project" (ISBN: 0-330-31670-2)