Racket plugin access the path of a file

42 views
Skip to first unread message

Kshitij Sachan

unread,
Jun 25, 2019, 4:10:28 PM6/25/19
to Racket Users
I'm trying to make a language-specific toolbar button that when clicked prints the path of the file the button is clicked from. I've been able to set up the button, but how I don't know how to access the path of the current file.

I've basically got two different files, let's call them button.rkt and important.rktbutton.rkt contains my implentation of the button and needs some way to print the path to important.rkt (and any other file that the button may be clicked in). What is the best way to access that file path?

Matthew Butterick

unread,
Jun 25, 2019, 10:05:02 PM6/25/19
to Kshitij Sachan, Racket Users
In your `get-info` function for your #lang, if `ip` is the input port passed as the first argument to `get-info`, then you can get the current document filename like so:

(send (object-name ip) get-filename)

And pass it as an argument to your button function.

Kshitij Sachan

unread,
Jun 26, 2019, 10:56:49 AM6/26/19
to Racket Users
Currently, my `lang/reader.rkt` file uses #lang s-exp syntax/module-reader:
#lang s-exp syntax/module-reader
hypothetical-lang
#:read read
#:read-syntax read-syntax
#:info make-info
  
(define (make-info key default use-default)
  (case key
    [(drracket:toolbar-buttons)
     (list (dynamic-require 'hypothetical-lang/button 'button))]
    [else (use-default key default)]))

Is the `get-info` function you described the same as the `make-info` that is currently in my code? I'm pretty confused on how to write a `get-info` function and where it would go. How can I go about setting this up? 

If you have any other style suggestions about how to change this button, I would appreciate them.
Reply all
Reply to author
Forward
0 new messages