From 2cccde1e3fb493ae4b1d523029b0b361080902d8 Mon Sep 17 00:00:00 2001 From: Tomas Volf <~@wolfsden.cz> Date: Thu, 14 Mar 2024 17:45:04 +0100 Subject: Allow processing of texinfo in docstrings. This commit adds support for processing texinfo in docstrings. That allows using texinfo in them while still having readable, nicely formatted plain text representation in geiser-doc-symbol-at-point. Fixes #43. * geiser-guile.el (geiser-guile-doc-process-texinfo): New custom controlling the behavior. (geiser-guile-update-doc-process-texinfo): New procedure to apply change of the controlling custom to a current REPL. (geiser-guile--startup): Call it. * geiser-guile.texi (Start up): Document the custom. * src/geiser/doc.scm (%process-texinfo?): New variable. (try-texinfo->plain-text): New procedure. (docstring): Call it on doc iff doc. --- geiser-guile.el | 25 ++++++++++++++++++++++++- geiser-guile.texi | 7 ++++++- src/geiser/doc.scm | 18 ++++++++++++++++-- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/geiser-guile.el b/geiser-guile.el index ac5e6b4..7663b83 100644 --- a/geiser-guile.el +++ b/geiser-guile.el @@ -169,6 +169,14 @@ effect on new REPLs. For existing ones, use the command "List of info nodes that, when present, are used for manual lookups." :type '(repeat string)) +(geiser-custom--defcustom geiser-guile-doc-process-texinfo nil + "Non-nil means try to convert docstrings from texinfo into plain-text. + +Changes to the value of this variable will automatically take +effect on new REPLs. For existing ones, use the command +\\[geiser-guile-update-doc-process-texinfo]." + :type 'boolean) + ;;; REPL support @@ -570,6 +578,17 @@ The new level is set using the value of `geiser-guile-warning-level'." (geiser evaluation)))) (geiser-eval--send/result code))) +(defun geiser-guile-update-doc-process-texinfo () + "Update whether docstrings should be processed as texinfo. +The new value is set using the value of `geiser-guile-doc-process-texinfo'." + (interactive) + (let* ((new-value (if geiser-guile-doc-process-texinfo + '\#t + '\#f)) + (code `(begin (set! (@@ (geiser doc) %process-texinfo?) ,new-value) + 'done))) + (geiser-eval--send/wait code))) + ;;;###autoload (defun connect-to-guile () "Start a Guile REPL connected to a remote process. @@ -619,7 +638,11 @@ See `geiser-guile-use-declarative-modules'." (dolist (dir g-load-path) (let ((dir (expand-file-name dir))) (geiser-eval--send/wait `(:eval (:ge add-to-load-path ,dir))))) - (geiser-guile-update-warning-level))) + (geiser-guile-update-warning-level) + (let ((geiser-guile-doc-process-texinfo + (buffer-local-value 'geiser-guile-doc-process-texinfo + geiser-repl--last-scm-buffer))) + (geiser-guile-update-doc-process-texinfo)))) ;;; Manual lookup diff --git a/geiser-guile.texi b/geiser-guile.texi index af87d34..ae605ab 100644 --- a/geiser-guile.texi +++ b/geiser-guile.texi @@ -73,6 +73,11 @@ loading @samp{~/.guile}, leave @code{geiser-guile-init-file} alone and set One can also provide a global list of paths to add to Guile's @samp{%load-path} via @code{geiser-guile-load-path}. +You can enable processing of texinfo in docstrings by customizing +@code{geiser-guile-doc-process-texinfo} to a non-nil value. If +enabled and docstring is a valid texinfo snippet, it will be converted +into a plain text before being displayed. + @node Debugging support @unnumbered Debugging support @@ -99,4 +104,4 @@ Geiser guile can be used remotely via tramp connections: the REPL process will be run in the machine where the tramp-accessed file lives. Implemented by Felipe Lema. -@bye \ No newline at end of file +@bye diff --git a/src/geiser/doc.scm b/src/geiser/doc.scm index b566b5e..dbd92fa 100644 --- a/src/geiser/doc.scm +++ b/src/geiser/doc.scm @@ -23,7 +23,12 @@ #:use-module (ice-9 regex) #:use-module (ice-9 format) #:use-module (oop goops) - #:use-module (srfi srfi-1)) + #:use-module (srfi srfi-1) + #:use-module (texinfo) + #:use-module (texinfo plain-text)) + +;;; Should texinfo in docstrings be processed? +(define %process-texinfo? #f) (define (autodoc ids) (if (not (list? ids)) @@ -194,6 +199,15 @@ `(("signature" . ,(or (obj-signature sym obj #f) sym)) ("docstring" . ,(docstring sym obj)))))) +(define (try-texinfo->plain-text str) + "Convert STR from texinfo into a plain text, assuming it is a valid texinfo +and %process-texinfo? is #t. + +Return either the resulting plain text or the original STR." + (or (and %process-texinfo? + (false-if-exception (stexi->plain-text (texi-fragment->stexi str)))) + str)) + (define (docstring sym obj) (define (valuable?) (not (or (macro? obj) (procedure? obj) (program? obj)))) @@ -212,7 +226,7 @@ (display modname) (display "."))) (newline) - (if doc (begin (newline) (display doc))) + (if doc (begin (newline) (display (try-texinfo->plain-text doc)))) (if (valuable?) (begin (newline) (display "Value:") (newline) -- cgit v1.2.3