[comp.emacs] Programming language modes

savage@ssc-vax.UUCP (Lowell Savage) (05/19/87)

I am trying to develop a programming language mode for a language similar to
Ada.  What I want to know is: are there any such modes for Pascal or Ada?  I
have looked at c-mode and the problem I have is that it seems to depend on
very simple syntax expressions (sexp's) of one or two characters to do much of
its work.  Has anyone come up with an "electronic" mode which has sexp's that
are longer, or which uses some other mechanism to do general "parsing" to
figure out such things as how far to indent something?

Let me see if I can explain the problem a little less abstractly.  c-mode
looks for braces ("{" and "}") to determine the nesting level of pieces of
code.  I.e. when you type a "{" the nesting level gets incremented by the
indent amount.  Unfortunately (for emacs users anyway), other programming
languages use keywords to do the work of these braces (like "begin" and "end",
or "for ..." and "end for").  Now, I don't want to bind 'n' to a function
which checks to see if the preceding 4 letters are "begi" and increments the
indent level if true.  Nor do I want to bind "be" to a function which writes
"begin" and increments the indent level (that would make it a pain to write an
assignment to the variable "beginrun", for instance).  Nor do I want to bind
such a function to "Meta-{" or some other similar monstrosity, although that
may turn out to be the thing to do.  And, even if I do, I will still need to
write a function to determine the indent level of a piece of code using
keywords that already exist in code which I am editing.

From my cursory look at electric.el, there doesn't seem to be any general
provision for such keywords.  Has anyone done anything of a general (or
specific) nature that would handle something like Pascal, Ada, or Modula2
which they might be willing to share?  I have a few ideas on what I want to
do, but I would be most grateful for anything: code, tips, ideas, ruminations,
pointers, pointers to pointers....  Please mail to me (I do watch the emacs
newsgroup, but I am not sure how much others would want to see of this topic),
and I will post summaries if that seems appropriate.

What I would most like to see is some sort of general Program-mode which can
be customized to the different languages by changing the values of lisp
variables.  So, for instance, there might be a variable prog-block-begin that
has the value: ( ( "f" "for" 'for-hook ) ( "b" "begin" 'begin-hook ) ( "c"
"case" 'case-hook ) ( "i" "if" 'if-hook ) ( "l" "loop" 'loop-hook ) ( "w"
"while" 'while-hook ) ).  The first string (which in some languages may need
to be longer than one character) would be typed in after some block-begin
monstrosity like Meta-{, the function referenced by the variable would be
executed at the end of executing the generic "begin-block" function.  Thus,
for example, if the user types "Meta-{-f", the indent level for the next line
is incremented and then the function referenced by for-hook is executed.  That
function might do a recursive edit, and output "for _ in to loop" (where the
'_' denotes the cursor).  Then, under the recursive edit, the space bar would
skip to the next field to fill in text.  Thus, typing "Meta-{-f-i- -1- -10- "
would output: "for i in 1 to 10 loop" and place the cursor at the end of the
line.  Then, a carriage return would properly indent the cursor for beginning
the next line.  The second item in the list would be used by other functions
to (re)format code which is already written using a different style or is
being modified.

Whew! I know that this is long.  So I'll stop now and give my net address, etc.

Spoken:			Lowell Savage
Net:			uw-beaver!ssc-vax!savage
Bell:			(206) 773-0664
Mail:			Boeing Aerospace Company
			M/S 8H-57
			P.O.Box 3999
			Seattle, WA 98124-2499

Onions expressoed reflection only on myself, not on my company, boss, SA, CPU
or my cola.