man.sl 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% MAN -- an online PSL reference manual facility.
  3. %%% Principal features are easy access to the index and
  4. %%% a command to jump directly from a line in the index
  5. %%% to the place in the manual referred to.
  6. %%%
  7. %%% Author: Cris Perdue
  8. %%% Date: 12/1/82
  9. %%%
  10. %%% This package is still under development.
  11. %%% An index browsing mode is contemplated, also use of a specialized
  12. %%% representation of the reference manual.
  13. %%% A concept index browser and a table of contents browser
  14. %%% are contemplated as extensions.
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16. % Edit by Cris Perdue, 8 Feb 1983 1145-PST
  17. % Modified to use functions now defined in their own modules.
  18. (compiletime (load fast-int if extended-char))
  19. (imports '(nmode string-search string-input))
  20. %%% Defines 2 new nondestructive commands for text mode,
  21. %%% which seems to make them apply in LISP mode as well.
  22. %%% One is M-!, which takes you to information about the
  23. %%% subject of interest in the chapter and page referred to
  24. %%% by the next index reference.
  25. %%% The other is C-X I, which does a "Find File" on the file
  26. %%% containing the function index to the PSL manual.
  27. (add-to-command-list
  28. 'read-only-text-command-list (x-char M-!!) 'index-browse-command)
  29. (add-to-command-list
  30. 'read-only-text-command-list (x-chars C-X i) 'get-index-buffer)
  31. (nmode-establish-current-mode)
  32. (fluid '(manual-chapters manual-file-template))
  33. % 0-TITLEPAGE
  34. % 00-PREFACE
  35. % 000-CONTENTS
  36. %%% A list of strings, each containing the base name of a chapter
  37. %%% of the manual. The first member of this list must be
  38. %%% referred to as chapter 1 in index references, and similarly
  39. %%% for other elements of the list.
  40. (setq manual-chapters '(
  41. "01-INTRODUCTION"
  42. "02-GETSTART"
  43. "03-RLISP"
  44. "04-DATATYPES"
  45. "05-NUMBERS"
  46. "06-IDS"
  47. "07-LISTS"
  48. "08-STRINGS"
  49. "09-FLOWOFCONTROL"
  50. "10-FUNCTIONS"
  51. "11-INTERP"
  52. "12-GLOBALS"
  53. "13-IO"
  54. "14-TOPLOOP"
  55. "15-ERRORS"
  56. "16-DEBUG"
  57. "17-EDITOR"
  58. "18-UTILITIES"
  59. "19-COMPLR"
  60. "20-DEC20"
  61. "21-SYSLISP"
  62. "22-IMPLEMENTATION"
  63. "23-PARSER"
  64. "24-BIBLIO"
  65. "25-FUN-INDEX"
  66. "26-TOP-INDEX"
  67. ))
  68. %%% This variable is a template for the name of a file that is
  69. %%% part of the manual. Actual manual file names are obtained by
  70. %%% substituting a name from the name list into this template.
  71. (setq manual-file-template "plpt:%w.lpt")
  72. (defun get-index-buffer ()
  73. (find-file (bldmsg manual-file-template "25-FUN-INDEX")))
  74. %%% This function gets the name that information is desired for,
  75. %%% gets the chapter and page of the "next" index reference after
  76. %%% point, does a "Find File" on the appropriate manual file,
  77. %%% goes to the appropriate page, and searches for an occurrence
  78. %%% of the key string.
  79. (defun index-browse-command ()
  80. (let ((l (=> nmode-current-buffer current-line)))
  81. (let ((key (get-key l))
  82. (dotpos (get-dot-pos l (=> nmode-current-buffer char-pos)))
  83. digitpos endpos chapter page)
  84. %% The first "." coming after point and with a digit on either
  85. %% side is used as the "." of the index entry.
  86. %% Contiguous digits to either side of the "." are taken
  87. %% to be chapter and page of the reference.
  88. %% This allows the user to distinguish between different
  89. %% index references even on the same line.
  90. (if (or (null key) (null dotpos)) then (ding)
  91. else
  92. (setq digitpos
  93. %% Search for non-digit or beginning of line.
  94. %% Position of earliest digit is returned.
  95. (for (from i (- dotpos 2) 0 -1)
  96. (do (if (not (digitp (indx l i))) then
  97. (return (+ i 1))))
  98. (finally (return 0))))
  99. (setq chapter (string-read (substring l digitpos dotpos)))
  100. %% Endpos is set to position of first non-digit after
  101. %% the page number, or end of line position, if all digits
  102. %% to end of line.
  103. (setq endpos (search-in-string-fn 'not-digitp l (+ dotpos 1)))
  104. (if (null endpos) then (setq endpos (+ (isizes l) 1)))
  105. (setq page (string-read (substring l (+ dotpos 1) endpos)))
  106. (find-file (bldmsg manual-file-template
  107. (nth manual-chapters chapter)))
  108. (move-to-buffer-start)
  109. %% Skip over pages preceding the desired one.
  110. (for (from i 1 (- page 1))
  111. (do (forward-search " ")
  112. (move-over-characters 1)))
  113. %% Search for an occurrence of the key string.
  114. %% This part should perhaps be refined to only move to
  115. %% a place within the page of interest.
  116. %% Note that forward-search expects the key to be entirely
  117. %% upper case and leaves point at the beginning of the string
  118. %% if found.
  119. (forward-search (string-upcase key))))))
  120. %%% The key is taken to be a substring of the line string.
  121. %%% The key starts at the first nonblank character and runs
  122. %%% up to the first occurrence of either ". " or " .". This
  123. %%% is dependent on the precise format of index files produced
  124. %%% by Scribe.
  125. %%% This function is capable of returning NIL.
  126. (defun get-key (line)
  127. (let ((p1 (string-search ". " line))
  128. (p2 (string-search " ." line)))
  129. (let ((end-pos (if (and p1 p2) then (min p1 p2)
  130. elseif (and p1 (null p2)) then p1
  131. elseif (and p2 (null p1)) then p2
  132. else nil))
  133. (key-pos (search-in-string-fn 'nonblank line 0)))
  134. (if (and key-pos end-pos) then
  135. (substring line key-pos end-pos)
  136. else nil))))
  137. %%% Searches for a dot which must be at or after "start".
  138. %%% The dot must be surrounded by a digit on either side.
  139. %%% NIL is returned if none found.
  140. (defun get-dot-pos (line start)
  141. (for (for dotpos
  142. (string-search-from "." line start)
  143. (string-search-from "." line (+ dotpos 1)))
  144. (while dotpos)
  145. (do (if (and (digitp (indx line (- dotpos 1)))
  146. (digitp (indx line (+ dotpos 1)))) then
  147. (return dotpos)))))
  148. (defun not-digitp (c)
  149. (not (digitp c)))
  150. (defun nonblank (c)
  151. (neq c #\SPACE))
  152. %%% The position of the first character of the domain for which
  153. %%% testfn returns true and whose index is at least "start" is
  154. %%% returned. If none such exists, NIL is returned.
  155. (defun search-in-string-fn (testfn domain start)
  156. (if (not (stringp domain)) then
  157. (error 0 "Arg to search-in-string-fn not a string"))
  158. (for (from i start (isizes domain))
  159. (do (if (funcall testfn (igets domain i)) then
  160. (return i)))
  161. (finally (return nil))))