;;; -*- Mode:Common-Lisp; Package:System; Base:10; Patch-file:T -*-

;;; Reason: Fix PPRINT handling of CLOS DEFMETHOD forms.  [SPR 9719]


;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 149149, M/S 2151             
;;;   AUSTIN, TEXAS 78714
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Patch file for SYSTEM version 6.11
;;; Written 07/07/89 16:06:24 by GRAY,
;;; while running on Kelvin from band LOD2
;;; With SYSTEM 6.10, VIRTUAL-MEMORY 6.1, EH 6.3, MAKE-SYSTEM 6.0, MICRONET 6.0, LOCAL-FILE 6.0,
;;;  BASIC-PATHNAME 6.1, NETWORK-SUPPORT-COLD 6.0, BASIC-NAMESPACE 6.1, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.0, DISK-LABEL 6.0, BASIC-FILE 6.2, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  Inconsistent COMPILER 6.8, TV 6.12, DATALINK 6.0, CHAOSNET 6.0, GC 6.3, MEMORY-AUX 6.0,
;;;  NVRAM 6.1, SYSLOG 6.1, STREAMER-TAPE 6.4, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1,
;;;  ZWEI 6.3, DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.1, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.1,
;;;  IMAGEN 6.0, SUGGESTIONS 6.0, MAIL-DAEMON 6.2, MAIL-READER 6.0, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.0, PROFILE 6.1, VISIDOC 6.2, Inconsistent TI-CLOS 6.16, CLEH 6.4,
;;;  IP 3.47, Experimental BUG 11.10, Experimental CLX 6.2, CLUE 6.8, X11M 6.1, Experimental DOCUMENTER 619.0,
;;;   microcode 429, Band Name: 6.0 SLE 6/5 + u429 6/8

;;; BUG REPORT NUMBER:  9719
;;;
;;; PROBLEM:  When pretty-printing a CLOS DEFMETHOD form, the argument list is 
;;;	put on the second line like a body form since the pretty-printer is 
;;;	assuming Flavors syntax.
;;;
;;; SOLUTION:  Add a pretty-print handler for DEFMETHOD that will end the 
;;;	first line after the arglist in all cases.

#!C
; From file PPRINT.LISP#> KERNEL; MR-X:
#10R SYSTEM#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "SYSTEM"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* *COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: KERNEL; PPRINT.#"


;;  7/7/89 DNG - Original, adapted from code submitted by J.R. [SPR 9719]
(defun defmethod-grind (object charpos)
  ;; Counts along the pp objects for the DEFMETHOD form until it finds the arglist.
  ;; We don't know where this will be because of the possibility of qualifiers in
  ;; CLOS methods.  We start at the nthcdr of the pp form because the first forms
  ;; are (, defmethod, space, and the name.  Flavors methods will have a cons for the
  ;; name, so we have to start looking for the arglist after this.
  (let ((count 1))
    ;;; Initialize the index to 1 because we're skipping the beginning of
    ;;; the list.
    (dolist (elt (nthcdr 4 (pp-obj-object object)))
      (when (or (locativep (pp-obj-location elt))
		;;; We have to allow here for the null arglist case.  This is
		;;; treated specially by the grinder.
		(eq elt pp-nil-obj)
		(eq elt pp-null-list))
	;;; Count the index of actual tokens as we look at them.
	(incf count)
	(when (or (eq elt pp-nil-obj)
		  (eq elt pp-null-list)
		  ;;; We check listp here because flavors methods might have
		  ;;; null arglists [CLOS ones will never be null].
		  (listp (contents (pp-obj-location elt))))
	  ;; Found what looks like the arglist.
	  (return-from defmethod-grind
	    ;; Equivalent to SPECIALLY-GRIND with negative of count.
	    (top-line-grind (pp-obj-object object) count charpos))))))
  ;; Here if it fails to look like a method at all.
  (basically-grind object nil t 'past-name charpos))
))

#!C
; From file PPRINT.LISP#> KERNEL; MR-X:
#10R SYSTEM#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "SYSTEM"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* *COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: KERNEL; PPRINT.#"


(defprint defmethod (hairily-grind defmethod-grind))
))

(remprop 'defmethod 'specially-grind) ; remove the old property