doc.sl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Doc.SL - NMODE On-line Documentation
  4. %
  5. % Author: Jeffrey Soreff
  6. % Hewlett-Packard/CRC
  7. % Date: 15 February 1983
  8. %
  9. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10. (BothTimes (load objects
  11. extended-char
  12. fast-vectors
  13. fast-strings
  14. fast-int
  15. stringx))
  16. % External variables:
  17. (fluid '(
  18. nmode-current-buffer
  19. nmode-current-window
  20. doc-obj-list
  21. ))
  22. (setf doc-obj-list nil)
  23. % Internal static variables:
  24. (fluid '(view-mode
  25. doc-browser-mode
  26. doc-browser-command-list
  27. doc-filter-argument-list
  28. doc-text-file
  29. reference-text-file
  30. doc-text-buffer))
  31. (setf doc-text-file "SS:<PSL.NMODE-DOC>FRAMES.LPT")
  32. (setf reference-text-file "SS:<PSL.NMODE-DOC>COSTLY.SL")
  33. (de set-up-documentation ()
  34. (setf doc-text-buffer (buffer-create-default "+DOCTEXT"))
  35. (insert-file-into-buffer doc-text-buffer doc-text-file)
  36. (let ((ref-chan (open reference-text-file 'input)))
  37. (eval (channelread ref-chan))
  38. (close ref-chan)))
  39. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  40. %
  41. % Documentation Browser Commands
  42. %
  43. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  44. (setf view-mode
  45. (nmode-define-mode
  46. "View"
  47. '((nmode-define-commands Read-Only-Text-Command-List)
  48. (nmode-define-commands Read-Only-Terminal-Command-List)
  49. (nmode-define-commands Window-Command-List)
  50. (nmode-define-commands Essential-Command-List)
  51. (nmode-define-commands Basic-Command-List)
  52. (nmode-define-commands
  53. (list (cons (x-char Q) 'select-previous-buffer-command)))
  54. )))
  55. (setf Doc-Browser-Mode (nmode-define-mode "Doc-Browser" '(
  56. (nmode-define-commands Doc-Browser-Command-List)
  57. (nmode-establish-mode Read-Only-Text-Mode)
  58. )))
  59. (setf Doc-Browser-Command-List
  60. (list
  61. (cons (x-char ?) 'doc-browser-help)
  62. (cons (x-char F) 'doc-filter-command)
  63. (cons (x-char E) 'browser-edit-command)
  64. (cons (x-char I) 'browser-ignore-command)
  65. (cons (x-char N) 'browser-undo-filter-command)
  66. (cons (x-char V) 'browser-view-command)
  67. (cons (x-char Q) 'browser-exit-command)
  68. (cons (x-char SPACE) 'move-down-command)
  69. ))
  70. (de doc-obj-compare (obj1 obj2)
  71. (let ((indx1 (doc-browse-obj$index obj1))
  72. (indx2 (doc-browse-obj$index obj2)))
  73. (< indx1 indx2)))
  74. (de doc-browser-help ()
  75. (write-message "Quit Edit Filter uNdo-filter Ignore View"))
  76. (de doc-filter-command ()
  77. (let ((browser (=> nmode-current-buffer get 'browser))
  78. (doc-filter-argument-list
  79. (list (prompt-for-string
  80. "Search for what string in a command's name or references?"
  81. ""))))
  82. (=> browser filter-items #'doc-filter-predicate)))
  83. (de doc-filter-predicate (old-name ref-list)
  84. (let* ((pattern (string-upcase (first doc-filter-argument-list)))
  85. (pattern-length (string-length pattern))
  86. (name-list (cons old-name
  87. (for (in ref ref-list)
  88. (with name-list)
  89. (collect (=> (eval ref) name) name-list)
  90. (returns name-list)))))
  91. (for (in name name-list)
  92. (with found)
  93. (do (when (let ((limit (- (string-length name) pattern-length))
  94. (char-pos 0))
  95. (while (<= char-pos limit)
  96. (if (pattern-matches-in-line pattern name char-pos)
  97. (exit char-pos))
  98. (incr char-pos)))
  99. (setf found t)))
  100. (returns found))))
  101. (de apropos-command ()
  102. (let* ((doc-filter-argument-list
  103. (list (prompt-for-string
  104. "Search for what string in a command's name or references?"
  105. "")))
  106. (blist (buffer-create "+DOCLIST" doc-browser-mode))
  107. (bitem (buffer-create "+DOCITEM" view-mode))
  108. (jnk (if (null doc-obj-list) (set-up-documentation)))
  109. (browser
  110. (create-browser blist bitem
  111. ["Documentation Browser Subsystem"
  112. ""] doc-obj-list #'doc-obj-compare)))
  113. (=> browser select-item (car doc-obj-list))
  114. (=> browser filter-items #'doc-filter-predicate)
  115. (browser-enter blist)
  116. (doc-browser-help)))
  117. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  118. %
  119. % The doc-browse-obj (documentation-browser-object) flavor:
  120. %
  121. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  122. (defflavor doc-browse-obj
  123. (
  124. name
  125. type
  126. index
  127. (start-line NIL)
  128. (end-line NIL)
  129. (ref-list ())
  130. )
  131. ()
  132. initable-instance-variables
  133. gettable-instance-variables
  134. )
  135. (defmethod (doc-browse-obj display-text) ()
  136. (string-concat (id2string type) ": " name))
  137. (defmethod (doc-browse-obj view-buffer) (buffer)
  138. (unless buffer
  139. (setf buffer (buffer-create-default "+DOCITEM")))
  140. (=> buffer reset)
  141. (if (not (and start-line end-line))
  142. (=> buffer insert-string
  143. "Sorry, no documentation is availible on this topic.")
  144. (=> buffer insert-text
  145. (cdr (=> doc-text-buffer extract-region
  146. NIL (cons start-line 0) (cons end-line 0)))))
  147. (=> buffer move-to-buffer-start)
  148. (=> buffer set-modified? nil)
  149. buffer)
  150. (defmethod (doc-browse-obj cleanup) ()
  151. NIL)
  152. (defmethod (doc-browse-obj apply-filter) (filter)
  153. (apply filter (list name ref-list)))