[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Speaking of Syntax
David writes:
From: "David Kriegman" <kriegs@coyote.stanford.edu>
Subject: Speaking of Syntax
... I'd like the editor to be "smart" about the
syntax when it formats the s-expression. The default s-expression
puts in too many spaces. My syntax looks something like this:
(def-animal BABOON
:species monkey
:weight (0 100)
:color brown)
...
I'd like zmacs to format it as above but it formats it like this
...
(def-animal BABOON
:species monkey
:weight (0 100)
:color brown)
Your problem is solved, for instance, by the following hack
(push '(def-animal 1 2) ZWEI:*LISP-INDENT-OFFSET-ALIST*)
evaluate and try c-m-q here ->(def-animal BABOON
:species monkey
:weight (0 100)
:color brown)
Satisfied?
Here is how it works. The short doc taken from notes I made for myself,
hope it works like this in your system. It worked in Rel6-7, but I'm pretty sure
Rel7 didn't change in this corner. (Although I remember there was a warning
some weeks ago that SYMBOLICS plans to change the editor drastically in some future
release, anyone who knows more about these plans?)
******************** ******************** ******************** ********************
There are a couple of ZWEI VARIABLES to customize INDENT:
1ZWEI:*LISP-INDENT-OFFSET-ALIST*0 -- the preferred way to customize INDENT,
tells INDENT about indentation offsets;
[And the more esoteric ones which you needn't use but might want to know about:
ZWEI:*DEFINITION-LIST-INDENTATION-RULES*;
ZWEI:*LISP-DEFUN-INDENTATION*;
ZWEI:*FLET-SEARCH-DISABLE*;
ZWEI:*LISP-INDENT-OFFSET*
explained in a moment below.]
1*LISP-INDENT-OFFSET-ALIST* -- an alist of (FUNCTION . OFFSET-LIST)
0 with FUNCTION the thing to indent
and OFFSET-LIST an even-length-list | symbol | function
1EXAMPLES
0In my current world the following are assoc's in *LISP-INDENT-OFFSET-ALIST* ...
(DEFFLAVOR 1 7 3 1)
(UNWIND-PROTECT 0 3 1 1)
(CL:LOOP . ZWEI:INDENT-LOOP)
Let's see how they rule indentation...
1OFFSET-LIST an even-length-list
0First consider OFFSET-LIST = (SEXP-NO OFFSET-TO-USE SEXP-NO OFFSET-TO-USE ...)
where SEXP-NO is 0-based and OFFSET-TO-USE is unit :character.
Example 1: Rule (UNWIND-PROTECT 0 3 1 1) rules the indentations below
(UNWIND-PROTECT
blue ;sexp-no 0 offset-to-use 3 :character
yellow ;sexp-no 1 offset-to-use 1 :character
red ;continue like above
white)
Example 2: Rule (PACKAGE-DECLARE 1 5 5 1) rules the indentation below
(PACKAGE-DECLARE
blue ;start with default rule 0 0, ugly but normally you'll keep
;this on the previous line anyway
yellow ;sexp-no 1 offset-to-use 5
red ;continue like above
white
purple
rose ;sexp-no 5 offset-to-use 1
black) ;continue like above
1OFFSET-LIST a SYMBOL/FUNCTION
0Now consider OFFSET-LIST = symbol | function.
To use this you need beginners' knowledge in writing EMACS/ZMACS extensions
because you only have to look at intervals and don't change them.
(You should know about Buffer-points (BP's), point movements (FORWARD...) and
how to see symbols/forms at points.)
This is the 2specification 0you should meet
(defun your-indent-function
(DEF-FIRST-BP
BEG-LINE-BP-THIS-LINE ; begin of this line
BP-UP-ONE-LEVEL ; open paren that's still unclosed
; i.e. YOUR special syntax
LAST-SEXP-FIRST-BP ; may be nil if there isn't any complete sexp
FONT-SPACE-WIDTH ; if you want to calculate INDENTATION
; in unit :pixel cf. below
SYMBOL ; the symbol at LAST-SEXP-FIRST-BP
)
(declare
(VALUES
INDENTATION-BP ; if non-nil take indentation of that S-EXP
INDENTATION ; else take this indentation value (in :pixel)
; for instance for variable-width fonts
OFFSET))) ; add this value (in :character) to indentation of
; INDENTATION-BP or else DEF-FIRST-BP
; or else ...
This is rather complex, but normally the following 2simple specification0 will do
2(defun mi:indent-def-animal (ignore bp def-animal-paren &rest ignore)
(declare (values bp ignore offset))
0******************** ******************** ******************** ********************
The esoteric ones mentioned above:
* 1ZWEI:*DEFINITION-LIST-INDENTATION-RULES*0 an offset list as described above
current default: (0 2 1 1)
taken when we are in FLET and similar forms
1UNLESS ZWEI:*FLET-SEARCH-DISABLE*
0
* 1ZWEI:*LISP-DEFUN-INDENTATION*0 an offset list as described above
current default: (2 1) -- this is what made your DEF-ANIMAL do what
you didn't like;
taken when we see top-level forms (DEF<FOO> ...) and there's no rule for DEF<FOO>
in *LISP-INDENT-OFFSET-ALIST*;
* 1ZWEI:*LISP-INDENT-OFFSET*0 an offset list as described above
current default: NIL
taken when we get nervous
(but I don't remember when ZMACS gets nervous, something like:
no rule of above applicable plus some understanding of whether inner form
is on a new line compared to the incomplete form being indented.)
Hope this helps
- hws