]> gitweb.factorcode.org Git - factor.git/blob - misc/fuel/fuel-markup.el
#2845 : Platform specific documentation responders
[factor.git] / misc / fuel / fuel-markup.el
1 ;;; fuel-markup.el -- printing factor help markup -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2009 Jose Antonio Ortega Ruiz
4 ;; See https://factorcode.org/license.txt for BSD license.
5
6 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
7 ;; Keywords: languages, fuel, factor
8 ;; Start date: Thu Jan 01, 2009 21:43
9
10 ;;; Comentary:
11
12 ;; Utilities for printing Factor's help markup.
13
14 ;;; Code:
15
16 (require 'fuel-eval)
17 (require 'fuel-base)
18 (require 'fuel-table)
19
20 (require 'button)
21
22 \f
23 ;;; Customization:
24
25 (defface fuel-font-lock-markup-title '((t (:inherit bold)))
26   "article titles in help buffers"
27   :group 'fuel-help
28   :group 'fuel-faces
29   :group 'faces)
30
31 (defface fuel-font-lock-markup-heading '((t (:inherit bold)))
32   "headlines in help buffers"
33   :group 'fuel-help
34   :group 'fuel-faces
35   :group 'faces)
36
37 (defface fuel-font-lock-markup-link '((t (:inherit link)))
38   "links to topics in help buffers"
39   :group 'fuel-help
40   :group 'fuel-faces
41   :group 'faces)
42
43 (defface fuel-font-lock-markup-emphasis '((t (:inherit italic)))
44   "emphasized words in help buffers"
45   :group 'fuel-help
46   :group 'fuel-faces
47   :group 'faces)
48
49 (defface fuel-font-lock-markup-strong '((t (:inherit link)))
50   "bold words in help buffers"
51   :group 'fuel-help
52   :group 'fuel-faces
53   :group 'faces)
54
55 \f
56 ;;; Links:
57
58 (defvar-local fuel-markup--follow-link-function 'fuel-markup--echo-link)
59
60 (define-button-type 'fuel-markup--button
61   'action 'fuel-markup--follow-link
62   'face 'fuel-font-lock-markup-link
63   'follow-link t)
64
65 (defun fuel-markup--follow-link (button)
66   (when fuel-markup--follow-link-function
67     (funcall fuel-markup--follow-link-function
68              (button-get button 'markup-link)
69              (button-get button 'markup-label)
70              (button-get button 'markup-link-type))))
71
72 (defun fuel-markup--echo-link (link label type)
73   (message "Link %s pointing to %s named %s" label type link))
74
75 (defun fuel-markup--insert-button (label link type)
76   (let ((label (format "%s" label))
77         (link (if (listp link) link (format "%s" link))))
78     (insert-text-button label
79                         :type 'fuel-markup--button
80                         'markup-link link
81                         'markup-label label
82                         'markup-link-type type
83                         'help-echo (format "%s (%s)" label type))))
84
85 (defun fuel-markup--article-title (name)
86   (let ((name (if (listp name) (cons :seq name) name)))
87     (fuel-eval--retort-result
88      (fuel-eval--send/wait `(:fuel* ((,name fuel-get-article-title)) "fuel")))))
89
90 (defun fuel-markup--link-at-point ()
91   (let ((button (condition-case nil (forward-button 0) (error nil))))
92     (when button
93       (list (button-get button 'markup-link)
94             (button-get button 'markup-label)
95             (button-get button 'markup-link-type)))))
96
97 (defun fuel-markup--nav-crumbs (e)
98   (fuel-markup--links e " > ")
99   (newline))
100
101 ;;; Markup printers:
102
103 (defconst fuel-markup--printers
104   '(($all-tags . fuel-markup--all-tags)
105     ($all-authors . fuel-markup--all-authors)
106     ($author . fuel-markup--author)
107     ($authors . fuel-markup--authors)
108     ($class-description . fuel-markup--class-description)
109     ($code . (lambda (e) (fuel-markup--code e t)))
110     ($command . fuel-markup--command)
111     ($command-map . fuel-markup--null)
112     ($contract . fuel-markup--contract)
113     ($curious . fuel-markup--curious)
114     ($definition . fuel-markup--definition)
115     ($description . fuel-markup--description)
116     ($doc-path . fuel-markup--doc-path)
117     ($emphasis . fuel-markup--emphasis)
118     ($error-description . fuel-markup--error-description)
119     ($errors . fuel-markup--errors)
120     ($example . (lambda (e) (fuel-markup--code e t)))
121     ($examples . fuel-markup--examples)
122     ($fuel-nav-crumbs . fuel-markup--nav-crumbs)
123     ($heading . fuel-markup--heading)
124     ($index . fuel-markup--index)
125     ($instance . fuel-markup--instance)
126     ($io-error . fuel-markup--io-error)
127     ($link . fuel-markup--link)
128     ($links . (lambda (e) (fuel-markup--links e ", ")))
129     ($list . fuel-markup--list)
130     ($low-level-note . fuel-markup--low-level-note)
131     ($markup-example . fuel-markup--markup-example)
132     ($maybe . fuel-markup--maybe)
133     ($sequence . fuel-markup--sequence)
134     ($methods . fuel-markup--methods)
135     ($next-link . (lambda (e) (fuel-markup--prefixed-link "Next:" e)))
136     ($nl . fuel-markup--newline)
137     ($notes . fuel-markup--notes)
138     ($operation . fuel-markup--link)
139     ($or . fuel-markup--or)
140     ($parsing-note . fuel-markup--parsing-note)
141     ($predicate . fuel-markup--predicate)
142     ($prettyprinting-note . fuel-markup--prettyprinting-note)
143     ($prev-link . (lambda (e) (fuel-markup--prefixed-link "Prev:" e)))
144     ($quotation . fuel-markup--quotation)
145     ($references . fuel-markup--references)
146     ($related . fuel-markup--related)
147     ($see . fuel-markup--word-info)
148     ($see-also . fuel-markup--see-also)
149     ($shuffle . fuel-markup--shuffle)
150     ($side-effects . fuel-markup--side-effects)
151     ($slot . fuel-markup--snippet)
152     ($snippet . fuel-markup--snippet)
153     ($strong . fuel-markup--strong)
154     ($subheading . fuel-markup--subheading)
155     ($subsection . fuel-markup--subsection)
156     ($subsections . fuel-markup--subsections)
157     ($synopsis . fuel-markup--word-info)
158     ($syntax . fuel-markup--syntax)
159     ($table . fuel-markup--table)
160     ($tag . fuel-markup--tag)
161     ($tags . fuel-markup--tags)
162     ($unchecked-example . (lambda (e) (fuel-markup--code e t)))
163     ($url . fuel-markup--url)
164     ($value . fuel-markup--value)
165     ($values . fuel-markup--values)
166     ($values-x/y . fuel-markup--values-x/y)
167     ($var-description . fuel-markup--var-description)
168     ($vocab . fuel-markup--vocab)
169     ($vocab-link . fuel-markup--vocab-link)
170     ($vocab-links . fuel-markup--vocab-links)
171     ($vocab-subsection . fuel-markup--vocab-subsection)
172     ($warning . fuel-markup--warning)
173     (article . fuel-markup--article)
174     (describe-words . fuel-markup--describe-words)
175     (vocab-list . fuel-markup--vocab-list)))
176
177 (defvar-local fuel-markup--maybe-nl nil)
178
179 (defun fuel-markup--print (e)
180   (cond ((null e) (insert "f"))
181         ((stringp e) (fuel-markup--insert-string e))
182         ((and (listp e) (symbolp (car e))
183               (assoc (car e) fuel-markup--printers))
184          (funcall (alist-get (car e) fuel-markup--printers) e))
185         ((and (symbolp e)
186               (assoc e fuel-markup--printers))
187          (funcall (alist-get e fuel-markup--printers) e))
188         ((listp e) (mapc 'fuel-markup--print e))
189         ((symbolp e) (fuel-markup--print (list '$link e)))
190         (t (insert (format "\n%S\n" e)))))
191
192 (defun fuel-markup--print-str (e)
193   (with-temp-buffer
194     (fuel-markup--print e)
195     (buffer-string)))
196
197 (defun fuel-markup--maybe-nl ()
198   (setq fuel-markup--maybe-nl (point)))
199
200 (defun fuel-markup--insert-newline (&optional justification nosqueeze)
201   (fill-region (save-excursion (beginning-of-line) (point))
202                (point)
203                (or justification 'left)
204                nosqueeze)
205   (newline))
206
207 (defsubst fuel-markup--insert-nl-if-nb (&optional no-fill)
208   (unless (eq (save-excursion (beginning-of-line) (point)) (point))
209     (if no-fill (newline) (fuel-markup--insert-newline))))
210
211 (defsubst fuel-markup--put-face (txt face)
212   (put-text-property 0 (length txt) 'font-lock-face face txt)
213   txt)
214
215 (defun fuel-markup--insert-heading (txt &optional no-nl)
216   (fuel-markup--insert-nl-if-nb)
217   (delete-blank-lines)
218   (unless (bobp) (newline))
219   (fuel-markup--put-face txt 'fuel-font-lock-markup-heading)
220   (fuel-markup--insert-string txt)
221   (unless no-nl (newline)))
222
223 (defun fuel-markup--insert-string (str)
224   (when fuel-markup--maybe-nl
225     (newline 2)
226     (setq fuel-markup--maybe-nl nil))
227   (insert str))
228
229 (defun fuel-markup--article (e)
230   (setq fuel-markup--maybe-nl nil)
231   (insert (fuel-markup--put-face (cadr e) 'fuel-font-lock-markup-title))
232   (newline 1)
233   (fuel-markup--print (car (cddr e))))
234
235 (defun fuel-markup--heading (e)
236   (fuel-markup--insert-heading (cadr e)))
237
238 (defun fuel-markup--subheading (e)
239   (fuel-markup--insert-heading (cadr e)))
240
241 (defun fuel-markup--subsection (e)
242   (fuel-markup--insert-nl-if-nb)
243   (insert "  - ")
244   (fuel-markup--link (cons '$link (cdr e)))
245   (fuel-markup--maybe-nl))
246
247 (defun fuel-markup--subsections (e)
248   (dolist (link (cdr e))
249     (fuel-markup--insert-nl-if-nb)
250     (insert "  - ")
251     (fuel-markup--link (list '$link link))
252     (fuel-markup--maybe-nl)))
253
254 (defun fuel-markup--vocab-subsection (e)
255   (fuel-markup--insert-nl-if-nb)
256   (insert "  - ")
257   (fuel-markup--vocab-link (cons '$vocab-link (cdr e)))
258   (fuel-markup--maybe-nl))
259
260 (defun fuel-markup--newline (e)
261   (fuel-markup--insert-newline)
262   (newline))
263
264 (defun fuel-markup--doc-path (e)
265   (fuel-markup--insert-heading "Related topics")
266   (insert "  ")
267   (dolist (art (cdr e))
268     (fuel-markup--insert-button (car art) (cadr art) 'article)
269     (insert ", "))
270   (delete-char -2)
271   (fuel-markup--insert-newline 'left))
272
273 (defun fuel-markup--emphasis (e)
274   (when (stringp (cadr e))
275     (fuel-markup--put-face (cadr e) 'fuel-font-lock-markup-emphasis)
276     (insert (cadr e))))
277
278 (defun fuel-markup--strong (e)
279   (when (stringp (cadr e))
280     (fuel-markup--put-face (cadr e) 'fuel-font-lock-markup-strong)
281     (insert (cadr e))))
282
283 (define-button-type 'fuel-markup--url
284   'action 'fuel-markup--follow-url
285   'face 'fuel-font-lock-markup-link
286   'follow-link nil)
287
288 (defun fuel-markup--follow-url (button)
289   (browse-url (button-get button 'markup-link)))
290
291 (defun fuel-markup--url (e)
292   (let ((url (cadr e)))
293     (insert-text-button url
294                         :type 'fuel-markup--url
295                         'markup-link url)))
296
297 (defun fuel-markup--snippet (e)
298   (insert (mapconcat #'(lambda (s)
299                         (if (stringp s)
300                             (factor-font-lock-string s)
301                           (fuel-markup--print-str s)))
302                      (cdr e)
303                      " ")))
304
305 (defun fuel-markup--code (e indent)
306   (fuel-markup--insert-nl-if-nb)
307   (newline)
308   (dolist (snip (cdr e))
309     (unless (stringp snip)
310       (error "snip is not a string"))
311     (dolist (line (split-string (factor-font-lock-string snip) "\n"))
312       (when indent (insert "    "))
313       (insert line)
314       (newline)))
315   (newline))
316
317 (defun fuel-markup--command (e)
318   (fuel-markup--snippet (list '$snippet (nth 3 e))))
319
320 (defun fuel-markup--syntax (e)
321   (fuel-markup--insert-heading "Syntax")
322   (fuel-markup--print (cons '$code (cdr e)))
323   (newline))
324
325 (defun fuel-markup--markup-example (e)
326   (fuel-markup--insert-newline)
327   (fuel-markup--snippet (cons '$snippet (cdr e))))
328
329 (defun fuel-markup--link (e)
330   (let* ((link (or (nth 1 e) 'f))
331          (type (or (nth 3 e) (if (symbolp link) 'word 'article)))
332          (label (or (nth 2 e)
333                     (and (eq type 'article)
334                          (fuel-markup--article-title link))
335                     link)))
336     (fuel-markup--insert-button label link type)))
337
338 (defun fuel-markup--links (e sep)
339   "Inserts a sequence of links. Used for rendering see also lists
340 and breadcrumb navigation. The items in e can either be strings
341 or lists."
342   (let ((links (cdr e)))
343     (when links
344       (dolist (link links)
345         (message (format "link %s" link))
346         (fuel-markup--link
347          (if (listp link)
348              (cons '$link link)
349            (list '$link link)))
350         (insert sep))
351       (delete-char (- (length sep))))))
352
353 (defun fuel-markup--index-quotation (q)
354   (cond ((null q) nil)
355         ((listp q) (vconcat (mapcar 'fuel-markup--index-quotation q)))
356         (t q)))
357
358 (defun fuel-markup--index (e)
359   (let* ((q (fuel-markup--index-quotation (cadr e)))
360          (cmd `(:fuel* ((,q fuel-index)) "fuel"
361                        ("assocs" "builtins" "classes" "classes.builtin"
362                         "classes.intersection" "classes.predicate"
363                         "classes.singleton"  "classes.tuple" "classes.union"
364                         "help" "help.topics" "namespaces" "sequences"
365                         "vocabs" "words")))
366          (subs (fuel-eval--retort-result (fuel-eval--send/wait cmd 200))))
367     (when subs
368       (let ((start (point))
369             (sort-fold-case nil))
370         (fuel-markup--print subs)
371         (sort-lines nil start (point))))))
372
373 (defun fuel-markup--vocab-link (e)
374   (fuel-markup--insert-button (cadr e) (or (car (cddr e)) (cadr e)) 'vocab))
375
376 (defun fuel-markup--vocab-links (e)
377   (dolist (link (cdr e))
378     (insert " ")
379     (fuel-markup--vocab-link (list '$vocab-link link))
380     (insert " ")))
381
382 (defun fuel-markup--vocab-list (e)
383   (let ((rows (mapcar #'(lambda (elem)
384                          (list (list '$vocab-link (car elem))
385                                (cadr elem)))
386                       (cdr e))))
387     (fuel-markup--table (cons '$table rows))))
388
389 (defun fuel-markup--vocab (e)
390   (fuel-markup--insert-nl-if-nb)
391   (let* ((cmd `(:fuel* ((,(cadr e) fuel-vocab-help)) "fuel" t))
392          (res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
393     (when res (fuel-markup--print res))))
394
395 (defun fuel-markup--parse-classes ()
396   (let ((elems))
397     (while (looking-at ".+ classes$")
398       (let ((heading `($heading ,(match-string-no-properties 0)))
399             (rows))
400         (forward-line)
401         (when (looking-at "Class *.+$")
402           (push (split-string (match-string-no-properties 0) nil t) rows)
403           (forward-line))
404         (while (not (looking-at "$"))
405           (let* ((objs (split-string (thing-at-point 'line) nil t))
406                  (class (list '$link (car objs) (car objs) 'word))
407                  (super (and (cadr objs)
408                              (list (list '$link (cadr objs) (cadr objs) 'word))))
409                  (slots (when (cddr objs)
410                           (list (mapcar #'(lambda (s) (list s " ")) (cddr objs))))))
411             (push `(,class ,@super ,@slots) rows))
412           (forward-line))
413         (push `(,heading ($table ,@(reverse rows))) elems))
414       (forward-line))
415     (reverse elems)))
416
417 (defun fuel-markup--parse-words ()
418   (let ((elems))
419     (while (looking-at ".+ words\\|Primitives$")
420       (let ((heading `($heading ,(match-string-no-properties 0)))
421             (rows))
422         (forward-line)
423         (when (looking-at "Word *\\(Stack effect\\|Syntax\\)$")
424           (push (list "Word" (match-string-no-properties 1)) rows)
425           (forward-line))
426         (while (looking-at " ?\\(.+?\\)\\( +\\(.+\\)\\)?$")
427           (let ((word `($link ,(match-string-no-properties 1)
428                               ,(match-string-no-properties 1)
429                               word))
430                 (se (and (match-string-no-properties 3)
431                          `(($snippet ,(match-string-no-properties 3))))))
432             (push `(,word ,@se) rows))
433           (forward-line))
434         (push `(,heading ($table ,@(reverse rows))) elems))
435       (forward-line))
436     (reverse elems)))
437
438 (defun fuel-markup--parse-words-desc (desc)
439   "This function parses the text description of the vocab that
440 the 'words.' word emits."
441   (with-temp-buffer
442     (insert desc)
443     (goto-char (point-min))
444     (when (re-search-forward "^Words$" nil t)
445       (forward-line 2)
446       (let ((elems '(($heading "Words"))))
447         (push (fuel-markup--parse-classes) elems)
448         (push (fuel-markup--parse-words) elems)
449         (reverse (remove nil elems))))))
450
451 (defun fuel-markup--describe-words (e)
452   (when (cadr e)
453     (fuel-markup--print (fuel-markup--parse-words-desc (cadr e)))))
454
455 (defun fuel-markup--tag (e)
456   (fuel-markup--link (list '$link (cadr e) (cadr e) 'tag)))
457
458 (defun fuel-markup--tags (e)
459   (when (cdr e)
460     (fuel-markup--insert-heading "Tags: " t)
461     (dolist (tag (cdr e))
462       (fuel-markup--tag (list '$tag tag))
463       (insert ", "))
464     (delete-char -2)
465     (fuel-markup--insert-newline)))
466
467 (defun fuel-markup--all-tags (e)
468   (let* ((cmd `(:fuel* (all-tags) "fuel" t))
469          (tags (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
470     (fuel-markup--list
471      (cons '$list (mapcar (lambda (tag) (list '$link tag tag 'tag)) tags)))))
472
473 (defun fuel-markup--author (e)
474   (fuel-markup--link (list '$link (cadr e) (cadr e) 'author)))
475
476 (defun fuel-markup--authors (e)
477   (when (cdr e)
478     (fuel-markup--insert-heading "Authors: " t)
479     (dolist (a (cdr e))
480       (fuel-markup--author (list '$author a))
481       (insert ", "))
482     (delete-char -2)
483     (fuel-markup--insert-newline)))
484
485 (defun fuel-markup--all-authors (e)
486   (let* ((cmd `(:fuel* (all-authors) "fuel" t))
487          (authors (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
488     (fuel-markup--list
489      (cons '$list (mapcar (lambda (a) (list '$link a a 'author)) authors)))))
490
491 (defun fuel-markup--list (e)
492   (fuel-markup--insert-nl-if-nb)
493   (dolist (elt (cdr e))
494     (insert " - ")
495     (fuel-markup--print elt)
496     (fuel-markup--insert-newline)))
497
498 (defun fuel-markup--table (e)
499   (fuel-markup--insert-newline)
500   (delete-blank-lines)
501   (newline)
502   (fuel-table--insert
503    (mapcar #'(lambda (row) (mapcar 'fuel-markup--print-str row)) (cdr e)))
504   (newline))
505
506 (defun fuel-markup--instance (e)
507   (insert " an instance of ")
508   (fuel-markup--print (cadr e)))
509
510 (defun fuel-markup--maybe (e)
511   (fuel-markup--instance (cons '$instance (cdr e)))
512   (insert " or f "))
513
514 (defun fuel-markup--sequence (e)
515   (insert "a ")
516   (fuel-markup--link (list '$link 'sequence 'sequence 'word))
517   (insert " of ")
518   (fuel-markup--print (cadr e))
519   (insert "s"))
520
521 (defun fuel-markup--or (e)
522   (let ((fst (car (cdr e)))
523         (mid (butlast (cddr e)))
524         (lst (car (last (cdr e)))))
525     (insert (format "%s" fst))
526     (dolist (m mid) (insert (format ", %s" m)))
527     (insert (format " or %s" lst))))
528
529 (defun fuel-markup--values (e)
530   (fuel-markup--insert-heading "Inputs and outputs")
531   (dolist (val (cdr e))
532     (insert " " (car val) " - ")
533     (fuel-markup--print (cdr val))
534     (newline)))
535
536 (defun fuel-markup--predicate (e)
537   (fuel-markup--values '($values ("object" object) ("?" "a boolean")))
538   (let ((word (make-symbol (substring (format "%s" (cadr e)) 0 -1))))
539   (fuel-markup--description
540    `($description "Tests if the object is an instance of the "
541                   ($link ,word) " class."))))
542
543 (defun fuel-markup--side-effects (e)
544   (fuel-markup--insert-heading "Side effects")
545   (insert "Modifies ")
546   (fuel-markup--print (cdr e))
547   (fuel-markup--insert-newline))
548
549 (defun fuel-markup--definition (e)
550   (fuel-markup--insert-heading "Definition")
551   (fuel-markup--code (cons '$code (cdr e)) nil))
552
553 (defun fuel-markup--methods (e)
554   (fuel-markup--insert-heading "Methods")
555   (fuel-markup--code (cons '$code (cdr e)) nil))
556
557 (defun fuel-markup--value (e)
558   (fuel-markup--insert-heading "Variable value")
559   (insert "Current value in global namespace: ")
560   (fuel-markup--snippet (cons '$snippet (cdr e)))
561   (newline))
562
563 (defun fuel-markup--values-x/y (e)
564   (fuel-markup--values '($values ("x" "number") ("y" "number"))))
565
566 (defun fuel-markup--curious (e)
567   (fuel-markup--insert-heading "For the curious...")
568   (fuel-markup--print (cdr e)))
569
570 (defun fuel-markup--references (e)
571   (fuel-markup--insert-heading "References")
572   (dolist (ref (cdr e))
573     (if (listp ref)
574         (fuel-markup--print ref)
575       (fuel-markup--subsection (list '$subsection ref)))))
576
577 (defun fuel-markup--see-also (e)
578   (fuel-markup--insert-heading "See also")
579   (fuel-markup--links (cons '$links (cdr e)) ", "))
580
581 (defun fuel-markup--related (e)
582   (fuel-markup--insert-heading "See also")
583   (fuel-markup--links (cons '$links (cadr e)) ", "))
584
585 (defun fuel-markup--shuffle (e)
586   (insert "\nShuffle word. Re-arranges the stack "
587           "according to the stack effect pattern.")
588   (fuel-markup--insert-newline))
589
590 (defun fuel-markup--low-level-note (e)
591   (fuel-markup--print '($notes "Calling this word directly is not necessary "
592                                "in most cases. "
593                                "Higher-level words call it automatically.")))
594
595 (defun fuel-markup--parsing-note (e)
596   (fuel-markup--insert-nl-if-nb)
597   (insert "This word should only be called from parsing words.")
598   (fuel-markup--insert-newline))
599
600 (defun fuel-markup--io-error (e)
601   (fuel-markup--errors '($errors "Throws an error if the I/O operation fails.")))
602
603 (defun fuel-markup--prettyprinting-note (e)
604   (fuel-markup--print '($notes ("This word should only be called within the "
605                                 ($link with-pprint) " combinator."))))
606
607 (defun fuel-markup--prefixed-link (prefix e)
608   (insert (format "  %s " prefix))
609   (fuel-markup--link e)
610   (newline))
611
612 (defun fuel-markup--elem-with-heading (elem heading)
613   (fuel-markup--insert-heading heading)
614   (fuel-markup--print (cdr elem))
615   (fuel-markup--insert-newline))
616
617 (defun fuel-markup--stack-effect (e)
618   (let* ((in (mapconcat 'identity (nth 1 e) " "))
619          (out (mapconcat 'identity (nth 2 e) " "))
620          (str (format "( %s -- %s )" in out)))
621     (fuel-markup--snippet (list '$snippet str))))
622
623 (defun fuel-markup--quotation (e)
624   (insert "a ")
625   (fuel-markup--link (list '$link 'quotation 'quotation 'word))
626   (insert " with stack effect ")
627   (fuel-markup--stack-effect (nth 1 e)))
628
629 (defun fuel-markup--warning (e)
630   (fuel-markup--elem-with-heading e "Warning"))
631
632 (defun fuel-markup--description (e)
633   (fuel-markup--elem-with-heading e "Word description"))
634
635 (defun fuel-markup--class-description (e)
636   (fuel-markup--elem-with-heading e "Class description"))
637
638 (defun fuel-markup--error-description (e)
639   (fuel-markup--elem-with-heading e "Error description"))
640
641 (defun fuel-markup--var-description (e)
642   (fuel-markup--elem-with-heading e "Variable description"))
643
644 (defun fuel-markup--contract (e)
645   (fuel-markup--elem-with-heading e "Generic word contract"))
646
647 (defun fuel-markup--errors (e)
648   (fuel-markup--elem-with-heading e "Errors"))
649
650 (defun fuel-markup--examples (e)
651   (fuel-markup--elem-with-heading e "Examples"))
652
653 (defun fuel-markup--notes (e)
654   (fuel-markup--elem-with-heading e "Notes"))
655
656 (defun fuel-markup--word-info (e)
657   "Uses the 'see' word to lookup info about a given word. Note
658 that this function is called in contexts where it is impossible
659 to guess the correct usings, so a static using list is used."
660   (let* ((word (nth 1 e))
661          (cmd `(:fuel* ((:quote ,(symbol-name word)) see)
662                        "fuel" ("kernel" "lexer" "see" "sequences")))
663          (ret (and cmd (fuel-eval--send/wait cmd)))
664          (res (and (not (fuel-eval--retort-error ret))
665                    (fuel-eval--retort-output ret))))
666     (if res
667         (fuel-markup--code (list '$code res) nil)
668       (fuel-markup--snippet (list '$snippet " " word)))))
669
670 (defun fuel-markup--null (e))
671
672 \f
673 (provide 'fuel-markup)
674
675 ;;; fuel-markup.el ends here