From: Wade Humeniuk
Subject: CAPI Based Package Browser
Date: 
Message-ID: <9m3pqg$3oh$1@news3.cadvision.com>
This is a multi-part message in MIME format.

------=_NextPart_000_000C_01C12BE0.E3F5F3E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I quickly created a CAPI Package Browser for LispWorks.

I wanted to quickly look at what symbols are around in the internals of CAPI
and LispWorks.

See attached file if you think it would be useful.

Load and type (package-browser:package-browser).

Wade

------=_NextPart_000_000C_01C12BE0.E3F5F3E0
Content-Type: application/octet-stream;
	name="package-browser.lisp"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="package-browser.lisp"

;; Rights reserved Wade Humeniuk August 23, 2001
;;
;; CAPI Based Package Browser Tool for LispWorks

(defpackage "PACKAGE-BROWSER"
  (:use "COMMON-LISP")
  (:export "PACKAGE-BROWSER"))

(in-package :package-browser)

(defun sorted-list-all-packages ()
  (sort (list-all-packages)=20
        (lambda (package1 package2)
          (string< (package-name package1) (package-name package2)))))

(defun sorted-list-shadowing-symbols (package)
  (sort (package-shadowing-symbols package)
        (lambda (symbol1 symbol2)
          (string< (symbol-name symbol1) (symbol-name symbol2)))))

(defun sorted-symbols-in-package (package &key (external nil)
                                          (only-in-package nil)
                                          (substring nil))
  (let ((symbols (if external
                     (loop for symbol being the external-symbol in =
package
                           collect symbol)
                   (loop for symbol being the symbol in package
                         collect symbol))))
    (when only-in-package
      (setf symbols (delete-if-not =20
                     (lambda (symbol) (eq package (symbol-package =
symbol)))
                     symbols)))
    (when substring
      (setf symbols (delete-if-not=20
                     (lambda (symbol)
                       (search substring (symbol-name symbol)
                               :test #'string-equal))
                     symbols)))
    (sort symbols
          (lambda (symbol1 symbol2)
            (string< (symbol-name symbol1) (symbol-name symbol2))))))

(capi:define-interface package-symbol-information ()
  ((symbol :initarg :symbol))
  (:panes
   (info capi:display-pane
         :text (with-output-to-string (string)
                 (describe symbol string))
         :min-width 540
         :max-width t
         :vertical-scroll t))
  (:layouts
   (main capi:simple-layout '(info))))

(capi:define-interface package-browser ()
  ((packages :initform (sorted-list-all-packages))
   (selected-package :initform nil)
   (font :initform (gp:gf nil #+win32"Courier New" #-win32"Courier" =
:normal :roman 8)))
  (:panes
   (package-list-pane capi:list-view :view :report=20
                      :title "Packages"
                      :title-position :top
                      :columns '((:title "Name" :align :left)
                                 (:title "Nicknames" :align :left))
                      :font font
                      :use-large-images nil
                      :use-small-images nil
                      :print-function (lambda (package)=20
                                        (format nil "~A" (package-name =
package)))
                      :subitem-function (lambda (package)=20
                                          (list (package-nicknames =
package)))
                      :subitem-print-functions
                      (lambda (nicknames)
                        (format nil "~S" nicknames))
                      :selection-callback
                      (lambda (package browser)
                        (with-slots (selected-package=20
                                     package-used-list-pane=20
                                     package-used-by-list-pane
                                     symbols-pane
                                     shadowing-symbols-pane)
                            browser
                          (setf selected-package package
                                (capi:collection-items =
package-used-list-pane)
                                (package-use-list package)
                                (capi:collection-items =
package-used-by-list-pane)
                                (package-used-by-list package)
                                (capi:collection-items =
shadowing-symbols-pane)
                                (sorted-list-shadowing-symbols package))
                          (display-symbols-in-browser browser)))
                      :items packages
                      :interaction :single-selection
                      :selection nil)
   (package-used-list-pane capi:list-panel
                           :title "Uses"
                           :title-position :top
                           :items nil
                           :font font
                           :min-height 64 :max-height t
                           :print-function
                           (lambda (package) (package-name package)))
   (package-used-by-list-pane capi:list-panel
                              :title "Used By"
                              :title-position :top
                              :items nil
                              :font font
                              :min-height 64 :max-height t
                              :print-function
                              (lambda (package) (package-name package)))
   (symbol-external-choice capi:radio-button-panel :items '(t nil)
                           :print-function (lambda (item) (if item "Yes" =
"No"))
                           :layout-class 'capi:row-layout
                           :title "External Symbols Only"
                           :title-position :left)

   (symbol-substring-pane capi:text-input-pane
                          :font font)

   (symbols-pane capi:list-panel
                 :font font
                 :print-function (lambda (symbol)
                                   (with-output-to-string (string)
                                     (write symbol :escape t :stream =
string)))
                 :selection-callback
                 (lambda (symbol browser)
                   (with-slots (selected-package) browser
                     (capi:display=20
                      (make-instance 'package-symbol-information
                                     :symbol symbol
                                     :title
                                     (with-output-to-string (string)
                                       (write symbol :escape t :stream =
string)))))))
  =20
   (external-pane capi:option-pane
                  :items '(external external-or-internal)
                  :title "Type"
                  :title-position :left
                  :selected-item 'exported
                  :print-function 'string-capitalize
                  :callback-type :interface
                  :selection-callback 'display-symbols-in-browser)

   (scope-pane capi:option-pane
               :items '(local local-or-imported)
               :title "Definition is"
               :selected-item 'local
               :print-function 'string-capitalize
               :callback-type :interface
               :selection-callback 'display-symbols-in-browser)

   (substring-pane capi:text-input-pane
                   :title "Contains"
                   :title-position :left
                   :font font
                   :callback-type :interface
                   :completion-function 'display-symbols-in-browser
                   :callback 'display-symbols-in-browser)

   (shadowing-symbols-pane capi:list-panel
                           :title "Shawdowing Symbols"
                           :title-position :top
                           :font font
                           :min-height 128 :max-height t
                           :print-function (lambda (symbol)
                                             (with-output-to-string =
(string)
                                               (write symbol :escape t =
:stream string)))))

                           =20
                           =20
                =20
  (:layouts
   (main capi:row-layout '(package-layout package-details-layout))
   (package-details-layout capi:column-layout '(symbols-layout =
shadowing-layout))
   (symbols-layout capi:column-layout '(external-pane scope-pane =
substring-pane symbols-pane)
                   :title "Symbols"
                   :title-position :top)
   (shadowing-layout capi:column-layout '(shadowing-symbols-pane))
   (package-layout capi:column-layout '(package-list-pane=20
                                        package-used-list-pane
                                        package-used-by-list-pane)))
  (:default-initargs
   :title "Package Browser"
   :best-width 640
   :best-height 480))

(defun display-symbols-in-browser (browser)
  (with-slots (selected-package external-pane scope-pane substring-pane =
symbols-pane)
      browser
    (when selected-package
      (setf (capi:collection-items symbols-pane)
            (sorted-symbols-in-package selected-package
                                       :external
                                       (eq (capi:choice-selected-item =
external-pane)
                                           'external)
                                       :only-in-package
                                       (eq (capi:choice-selected-item =
scope-pane)
                                           'local)
                                       :substring
                                       (let ((text =
(capi:text-input-pane-text substring-pane)))
                                         (cond
                                          ((string=3D "" text) nil)
                                          ((string=3D "" =
(string-left-trim " " text)) nil)
                                          (t text))))))))
              =20
(defun package-browser ()
  (capi:display (make-instance 'package-browser)))
                     =20

------=_NextPart_000_000C_01C12BE0.E3F5F3E0--

From: Wade Humeniuk
Subject: Re: CAPI Based Package Browser
Date: 
Message-ID: <9me0uk$al$1@news3.cadvision.com>
This is a multi-part message in MIME format.

------=_NextPart_000_000E_01C12EEB.474CEAE0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I changed the package-browser slightly, it now brings up a
lispworks-tools:inspector to view the selected symbol and now allows
reselection of the same symbol for repeated inspection.

See attached

Wade

"Wade Humeniuk" <········@cadvision.com> wrote in message
·················@news3.cadvision.com...
> I quickly created a CAPI Package Browser for LispWorks.
>
> I wanted to quickly look at what symbols are around in the internals of
CAPI
> and LispWorks.
>
> See attached file if you think it would be useful.
>
> Load and type (package-browser:package-browser).
>
> Wade
>

------=_NextPart_000_000E_01C12EEB.474CEAE0
Content-Type: application/octet-stream;
	name="package-browser.lisp"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="package-browser.lisp"

;; Rights reserved Wade Humeniuk August 27, 2001
;;
;; CAPI Based Package Browser Tool for LispWorks

(defpackage "PACKAGE-BROWSER"
  (:use "COMMON-LISP")
  (:export "PACKAGE-BROWSER"))

(in-package :package-browser)

(defun sorted-list-all-packages ()
  (sort (list-all-packages)=20
        (lambda (package1 package2)
          (string< (package-name package1) (package-name package2)))))

(defun sorted-list-shadowing-symbols (package)
  (sort (package-shadowing-symbols package)
        (lambda (symbol1 symbol2)
          (string< (symbol-name symbol1) (symbol-name symbol2)))))

(defun sorted-symbols-in-package (package &key (external nil)
                                          (only-in-package nil)
                                          (substring nil))
  (let ((symbols (if external
                     (loop for symbol being the external-symbol in =
package
                           collect symbol)
                   (loop for symbol being the symbol in package
                         collect symbol))))
    (when only-in-package
      (setf symbols (delete-if-not =20
                     (lambda (symbol) (eq package (symbol-package =
symbol)))
                     symbols)))
    (when substring
      (setf symbols (delete-if-not=20
                     (lambda (symbol)
                       (search substring (symbol-name symbol)
                               :test #'string-equal))
                     symbols)))
    (sort symbols
          (lambda (symbol1 symbol2)
            (string< (symbol-name symbol1) (symbol-name symbol2))))))

(capi:define-interface package-browser ()
  ((packages :initform (sorted-list-all-packages))
   (selected-package :initform nil)
   (font :initform (gp:gf nil #+win32"Courier New" #-win32"Courier" =
:normal :roman 8)))
  (:panes
   (package-list-pane capi:list-view :view :report=20
                      :title "Packages"
                      :title-position :top
                      :columns '((:title "Name" :align :left)
                                 (:title "Nicknames" :align :left))
                      :font font
                      :use-large-images nil
                      :use-small-images nil
                      :print-function (lambda (package)=20
                                        (format nil "~A" (package-name =
package)))
                      :subitem-function (lambda (package)=20
                                          (list (package-nicknames =
package)))
                      :subitem-print-functions
                      (lambda (nicknames)
                        (format nil "~S" nicknames))
                      :selection-callback
                      (lambda (package browser)
                        (with-slots (selected-package=20
                                     package-used-list-pane=20
                                     package-used-by-list-pane
                                     symbols-pane
                                     shadowing-symbols-pane)
                            browser
                          (setf selected-package package
                                (capi:collection-items =
package-used-list-pane)
                                (package-use-list package)
                                (capi:collection-items =
package-used-by-list-pane)
                                (package-used-by-list package)
                                (capi:collection-items =
shadowing-symbols-pane)
                                (sorted-list-shadowing-symbols package))
                          (display-symbols-in-browser browser)))
                      :items packages
                      :interaction :single-selection
                      :selection nil)
   (package-used-list-pane capi:list-panel
                           :title "Uses"
                           :title-position :top
                           :items nil
                           :font font
                           :min-height 64 :max-height t
                           :print-function
                           (lambda (package) (package-name package)))
   (package-used-by-list-pane capi:list-panel
                              :title "Used By"
                              :title-position :top
                              :items nil
                              :font font
                              :min-height 64 :max-height t
                              :print-function
                              (lambda (package) (package-name package)))
   (symbol-external-choice capi:radio-button-panel :items '(t nil)
                           :print-function (lambda (item) (if item "Yes" =
"No"))
                           :layout-class 'capi:row-layout
                           :title "External Symbols Only"
                           :title-position :left)

   (symbol-substring-pane capi:text-input-pane
                          :font font)

   (symbols-pane capi:list-panel
                 :font font
                 :print-function (lambda (symbol)
                                   (with-output-to-string (string)
                                     (write symbol :escape t :stream =
string)))
                 :selection-callback
                 (lambda (symbol browser)
                   (capi:display=20
                    (make-instance 'lispworks-tools:inspector :object =
symbol))
                   ;; Unselect the current selection to allow =
reselecting the symbol
                   (setf (capi:choice-selected-item (slot-value browser =
'symbols-pane)) nil)))
  =20
   (external-pane capi:option-pane
                  :items '(external external-or-internal)
                  :title "Type"
                  :title-position :left
                  :selected-item 'exported
                  :print-function 'string-capitalize
                  :callback-type :interface
                  :selection-callback 'display-symbols-in-browser)

   (scope-pane capi:option-pane
               :items '(local local-or-imported)
               :title "Definition is"
               :selected-item 'local
               :print-function 'string-capitalize
               :callback-type :interface
               :selection-callback 'display-symbols-in-browser)

   (substring-pane capi:text-input-pane
                   :title "Contains"
                   :title-position :left
                   :font font
                   :callback-type :interface
                   :completion-function 'display-symbols-in-browser
                   :callback 'display-symbols-in-browser)

   (shadowing-symbols-pane capi:list-panel
                           :title "Shawdowing Symbols"
                           :title-position :top
                           :font font
                           :min-height 128 :max-height t
                           :print-function (lambda (symbol)
                                             (with-output-to-string =
(string)
                                               (write symbol :escape t =
:stream string)))))

                           =20
                           =20
                =20
  (:layouts
   (main capi:row-layout '(package-layout package-details-layout))
   (package-details-layout capi:column-layout '(symbols-layout =
shadowing-layout))
   (symbols-layout capi:column-layout '(external-pane scope-pane =
substring-pane symbols-pane)
                   :title "Symbols"
                   :title-position :top)
   (shadowing-layout capi:column-layout '(shadowing-symbols-pane))
   (package-layout capi:column-layout '(package-list-pane=20
                                        package-used-list-pane
                                        package-used-by-list-pane)))
  (:default-initargs
   :title "Package Browser"
   :best-width 640
   :best-height 480))

(defun display-symbols-in-browser (browser)
  (with-slots (selected-package external-pane scope-pane substring-pane =
symbols-pane)
      browser
    (when selected-package
      (setf (capi:collection-items symbols-pane)
            (sorted-symbols-in-package selected-package
                                       :external
                                       (eq (capi:choice-selected-item =
external-pane)
                                           'external)
                                       :only-in-package
                                       (eq (capi:choice-selected-item =
scope-pane)
                                           'local)
                                       :substring
                                       (let ((text =
(capi:text-input-pane-text substring-pane)))
                                         (cond
                                          ((string=3D "" text) nil)
                                          ((string=3D "" =
(string-left-trim " " text)) nil)
                                          (t text))))))))
              =20
(defun package-browser ()
  (capi:display (make-instance 'package-browser)))
                     =20

------=_NextPart_000_000E_01C12EEB.474CEAE0--
From: Kerry Kilbride
Subject: Re: CAPI Based Package Browser
Date: 
Message-ID: <nn57rtgn8sl1gkvofbdipafhj38qp45e4i@4ax.com>
On Thu, 23 Aug 2001 14:35:43 -0600, "Wade Humeniuk"
<········@cadvision.com> wrote:

Thank you.  I find this quite helpful.