;;; racket-describe.el -*- lexical-binding: t -*- ;; Copyright (c) 2013-2020 by Greg Hendershott. ;; Portions Copyright (C) 1985-1986, 1999-2013 Free Software Foundation, Inc. ;; Author: Greg Hendershott ;; URL: https://github.com/greghendershott/racket-mode ;; License: ;; This is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. This is distributed in the hope that it will be ;; useful, but without any warranty; without even the implied warranty ;; of merchantability or fitness for a particular purpose. See the GNU ;; General Public License for more details. See ;; http://www.gnu.org/licenses/ for details. (require 'racket-cmd) (require 'racket-util) (require 'racket-visit) (require 'shr) (defun racket--do-describe (how repl-session-id str &optional display-and-pop-to-p visit-thunk doc-thunk) "Create a `racket-describe-mode' buffer. HOW is supplied as the first argument to the back-end \"describe\" command. See it for details that we don't need to know or care about in this function. STR is the string form of an identifier that is to be described. DISPLAY-AND-POP-TO-P should be t for use by direct user commands like `racket-xp-describe' and `racket-repl-describe' -- in which the buffer is displayed -- and nil for use as a :company-doc-buffer function. VISIT-THUNK and DOC-THUNK are, when not nil, used to insert \"Visit Definition\" and \"Documentation in Browser\" buttons. Returns the buffer in which the description was written." ;; Work around what seems to be a bug with `shr-insert-document' -- ;; elements are out of order when an existing Racket Describe buffer ;; hasn't had a `quit-window' -- by re-creating the buffer. (with-current-buffer (racket--get-buffer-recreate "*Racket Describe*") (let* ((html (racket--cmd/await repl-session-id `(describe ,how ,str))) ;; Because shr removes leading from