Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active December 11, 2020 10:22
Show Gist options
  • Save Metaxal/f961cb32d4ef38d2e35c38dbaf559614 to your computer and use it in GitHub Desktop.
Save Metaxal/f961cb32d4ef38d2e35c38dbaf559614 to your computer and use it in GitHub Desktop.
How to augment the syntax to make DrRacket display information in a tooltip–LIVE! (without even saving the file!)
#lang racket
;;; License: [MIT](http://opensource.org/licenses/MIT)
;;; Adapted from: https://github.com/samth/fancy-app
(begin-for-syntax
(define (make-tooltip stx id msg)
(define pos (syntax-position id))
(define span (syntax-span id))
(syntax-property
stx
'mouse-over-tooltips
(and pos span (vector id (sub1 pos) (sub1 (+ pos span)) msg)))))
(define-syntax (FOO stx)
(syntax-case stx ()
[(_ id)
(make-tooltip #'(display 'id)
#'id
(format "Identifier: ~a" (syntax-e #'id)))]))
(FOO yo)
@Metaxal
Copy link
Author

Metaxal commented Dec 11, 2020

Also look at the char-span example at the end of the docs on mouse-over-tooltips:

#lang racket
(define-syntax (char-span stx)
  (syntax-case stx ()
    [(_ a)
     (syntax-property
      #'a
      'mouse-over-tooltips
      (vector
       stx
       (sub1 (syntax-position stx))
       (sub1 (+ (syntax-position stx)
             (syntax-span stx)))
       (format "this expression\nspans ~a chars"
               (syntax-span stx))))]))
 
(char-span (+ 1 2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment