(FILECREATED "30-Sep-85 17:00:23" {ERIS}<TEDIT>TEDITABBREV.;7 6410   

      changes to:  (VARS TEDITABBREVCOMS)

      previous date: "27-Aug-85 15:35:32" {ERIS}<TEDIT>TEDITABBREV.;6)


(* 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 357,146]
						   [CONS "n" (MKSTRING (CHARACTER (CHARCODE 357,44]
						   [CONS "m" (MKSTRING (CHARACTER (CHARCODE 357,45]
						   [CONS "T" (MKSTRING (CHARACTER (CHARCODE 357,57]
						   [CONS "d" (MKSTRING (CHARACTER (CHARCODE 357,60]
						   [CONS "D" (MKSTRING (CHARACTER (CHARCODE 357,61]
						   [CONS "s" (MKSTRING (CHARACTER (CHARCODE 0,247]
						   [CONS "'" (MKSTRING (CHARACTER (CHARCODE 0,271]
						   [CONS "`" (MKSTRING (CHARACTER (CHARCODE 0,251]
						   [CONS "%"" (MKSTRING (PACKC (CHARCODE
										 (0,251 0,251]
						   [CONS "~" (MKSTRING (PACKC (CHARCODE (0,271 0,271]
						   [CONS "1/4" (MKSTRING (CHARACTER (CHARCODE 0,274]
						   [CONS "1/2" (MKSTRING (CHARACTER (CHARCODE 0,275]
						   [CONS "3/4" (MKSTRING (CHARACTER (CHARCODE 0,276]
						   (QUOTE ("DATE" . \TEDIT.EXPAND.DATE))
						   (QUOTE (">>DATE<<" . \TEDIT.EXPAND.DATE])
(FILESLOAD TEDITCOMMAND)
(DEFINEQ

(\TEDIT.ABBREV.EXPAND
  [LAMBDA (STREAM)                                           (* jds "27-Aug-85 15:09")
                                                             (* 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 RIGHT)))
	    (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)
		       (replace \INSERTPCVALID of TEXTOBJ with NIL)
                                                             (* Force it to abandon caching)
		       (TEDIT.DELETE TEXTOBJ SEL)            (* First, delete the thing being expanded.)
		       (TEDIT.INSERT STREAM EXPANSION SEL])

(\TEDIT.EXPAND.DATE
  [LAMBDA (STREAM CH)                                        (* jds "13-Aug-85 09:15")
                                                             (* Provide the date as the expansion for an 
							     abbreviation)
    (PROG* ((DATE (\UNPACKDATE))
	    (YEAR (pop DATE))
	    (MONTH (pop DATE))
	    (DAY (pop DATE)))
           (RETURN (CONCAT (CAR (NTH (QUOTE (January February March April May June July August 
						     September October November December))
				     (ADD1 MONTH)))
			   " " DAY ", " YEAR])

(\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 357,146]
			  [CONS "n" (MKSTRING (CHARACTER (CHARCODE 357,44]
			  [CONS "m" (MKSTRING (CHARACTER (CHARCODE 357,45]
			  [CONS "T" (MKSTRING (CHARACTER (CHARCODE 357,57]
			  [CONS "d" (MKSTRING (CHARACTER (CHARCODE 357,60]
			  [CONS "D" (MKSTRING (CHARACTER (CHARCODE 357,61]
			  [CONS "s" (MKSTRING (CHARACTER (CHARCODE 0,247]
			  [CONS "'" (MKSTRING (CHARACTER (CHARCODE 0,271]
			  [CONS "`" (MKSTRING (CHARACTER (CHARCODE 0,251]
			  [CONS "%"" (MKSTRING (PACKC (CHARCODE (0,251 0,251]
			  [CONS "~" (MKSTRING (PACKC (CHARCODE (0,271 0,271]
			  [CONS "1/4" (MKSTRING (CHARACTER (CHARCODE 0,274]
			  [CONS "1/2" (MKSTRING (CHARACTER (CHARCODE 0,275]
			  [CONS "3/4" (MKSTRING (CHARACTER (CHARCODE 0,276]
			  (QUOTE ("DATE" . \TEDIT.EXPAND.DATE))
			  (QUOTE (">>DATE<<" . \TEDIT.EXPAND.DATE))))
(PUTPROPS TEDITABBREV COPYRIGHT ("John Sybalsky & Xerox Corporation" 1983 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1441 5358 (\TEDIT.ABBREV.EXPAND 1451 . 3322) (\TEDIT.EXPAND.DATE 3324 . 3920) (
\TEDIT.TRY.ABBREV 3922 . 5356)))))
STOP