(FILECREATED " 6-Mar-85 23:42:48" {IVY}<TEDIT>TEDITABBREV.;11 4815   

      changes to:  (FNS \TEDIT.ABBREV.EXPAND)

      previous date: " 1-Feb-85 19:13:33" {IVY}<TEDIT>TEDITABBREV.;10)


(* Copyright (c) 1983, 1984, 1985 by John Sybalsky & Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT TEDITABBREVCOMS)

(RPAQQ TEDITABBREVCOMS [(FILES TEDITCOMMAND)
			(FNS \TEDIT.ABBREV.EXPAND \TEDIT.EXPAND.DATE \TEDIT.TRY.ABBREV)
			(GLOBALVARS TEDIT.ABBREVS)
			(VARS (TEDIT.ABBREVS (LIST [CONS "b" (MKSTRING (CHARACTER (CHARCODE #7]
						   [CONS "n" (MKSTRING (CHARACTER (CHARCODE #↑%[]
						   [CONS "m" (MKSTRING (CHARACTER (CHARCODE #↑\]
						   (QUOTE ("%"" . "``"))
						   (QUOTE ("DATE" . \TEDIT.EXPAND.DATE))
						   (QUOTE (">>DATE<<" . \TEDIT.EXPAND.DATE])
(FILESLOAD TEDITCOMMAND)
(DEFINEQ

(\TEDIT.ABBREV.EXPAND
  [LAMBDA (STREAM)                                           (* jds " 6-Mar-85 22:21")
                                                             (* Expand an abbvreviation)
    (PROG ((TEXTOBJ (fetch (TEXTSTREAM TEXTOBJ) of STREAM))
	   SEL CH# (CH NIL)
	   EXPANSION)
          (SETQ SEL (fetch SEL of TEXTOBJ))
          (SETQ CH# (SELECTQ (fetch POINT of SEL)
			     (LEFT (SUB1 (fetch CH# of SEL)))
			     (RIGHT (SUB1 (fetch CHLIM of SEL)))
			     0))
          [COND
	    ((ZEROP (fetch DCH of SEL))                      (* Point Selection, so use the character to the left)
	      (COND
		((ZEROP CH#)                                 (* If we're off the front of the document, don't bother
							     trying.)
		  (RETURN)))
	      (\SETUPGETCH CH# TEXTOBJ)
	      [SETQ CH (MKSTRING (CHARACTER (\BIN STREAM]
	      (TEDIT.SETSEL STREAM CH# 1 (QUOTE LEFT)))
	    (T                                               (* We have a selection that isn't just a caret.
							     Use it.)
	       (SETQ CH (TEDIT.SEL.AS.STRING STREAM]
          (SETQ EXPANSION (\TEDIT.TRY.ABBREV CH))            (* Find the abbreviation's expansion --first try it 
							     as-is, then try the upper-case version to be safe.)
          (COND
	    (EXPANSION                                       (* It exists, so insert it where the abbrev used to be)
		       (TEDIT.DELETE TEXTOBJ SEL)            (* First, delete the thing being expanded.)
		       (TEDIT.INSERT STREAM EXPANSION SEL])

(\TEDIT.EXPAND.DATE
  [LAMBDA (STREAM CH)                                        (* jds " 2-Jan-85 15:33")
                                                             (* Provide the date as the expansion for an 
							     abbreviation)
    (PROG ((DATE (DATE)))
          (RETURN (SUBSTRING DATE 1 (STRPOS " " (SUBSTRING DATE 2])

(\TEDIT.TRY.ABBREV
  [LAMBDA (ABBREV)                                           (* jds " 2-Jan-85 15:34")
                                                             (* Try expanding ABBREV as an abbreviation.
							     Return the expansion; NIL = no such abbreviation.)
    (PROG (SEL CH# (CH NIL)
	       EXPANSION)
          (SETQ EXPANSION (OR (SASSOC ABBREV TEDIT.ABBREVS)
			      (SASSOC (U-CASE ABBREV)
				      TEDIT.ABBREVS)))       (* Find the abbreviation's expansion --first try it 
							     as-is, then try the upper-case version to be safe.)
          (RETURN (COND
		    (EXPANSION                               (* There's an expansion. Turn it into an insertable 
							     string.)
			       (COND
				 ((OR (STRINGP (CDR EXPANSION))
				      (NUMBERP (CDR EXPANSION)))
                                                             (* The abbreviation expands to a string or a number 
							     (charcode). Insert it.)
				   (CDR EXPANSION))
				 ((AND (LITATOM (CDR EXPANSION))
				       (GETD (CDR EXPANSION)))
                                                             (* It's a function to be called.)
				   (APPLY* (CDR EXPANSION)
					   STREAM CH))
				 (T                          (* Anything else is a form to EVAL.)
				    (EVAL (CDR EXPANSION])
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS TEDIT.ABBREVS)
)

(RPAQ TEDIT.ABBREVS (LIST [CONS "b" (MKSTRING (CHARACTER (CHARCODE #7]
			  [CONS "n" (MKSTRING (CHARACTER (CHARCODE #↑%[]
			  [CONS "m" (MKSTRING (CHARACTER (CHARCODE #↑\]
			  (QUOTE ("%"" . "``"))
			  (QUOTE ("DATE" . \TEDIT.EXPAND.DATE))
			  (QUOTE (">>DATE<<" . \TEDIT.EXPAND.DATE))))
(PUTPROPS TEDITABBREV COPYRIGHT ("John Sybalsky & Xerox Corporation" 1983 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (812 4345 (\TEDIT.ABBREV.EXPAND 822 . 2529) (\TEDIT.EXPAND.DATE 2531 . 2907) (
\TEDIT.TRY.ABBREV 2909 . 4343)))))
STOP