(FILECREATED "11-Jul-85 15:04:16" {ERIS}<TEDIT>TEDITABBREV.;3 4833   

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

      previous date: "13-Jun-85 19:10:37" {ERIS}<TEDIT>TEDITABBREV.;2)


(* 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 "11-Jul-85 12:46")
                                                             (* 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 STREAM))     (* 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 STREAM)                                    (* jds "11-Jul-85 12:46")
                                                             (* 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 (830 4363 (\TEDIT.ABBREV.EXPAND 840 . 2547) (\TEDIT.EXPAND.DATE 2549 . 2925) (
\TEDIT.TRY.ABBREV 2927 . 4361)))))
STOP