
@adrien.k.tateno has joined the channel

@mflatt Can I ask you to take a look at this PR at some point? Or, alternatively, let me know if you think someone else would be better suited to reviewing it? https://github.com/racket/racket/pull/2188

I am confused by the result of running: #lang racket
(define sexp "(define foo 42) (define (bar x) (+ x 1))")
(define in (open-input-string sexp))
(file-position in 16)
(require syntax-color/racket-lexer)
(racket-lexer in)
(racket-lexer in)
(racket-lexer in)
(racket-lexer in)
(racket-lexer in)
(racket-lexer in)

The example uses the standard racket-lexer to lex from the beginning of (define (bar x) ...)
which is position 16.

The lexer produces the correct tokens.

However the start-end positions of the tokens doesn’t start at 16 - they start at 0 ?

Make that 1 instead of 0.

What am I missing?

@soegaard2 I believe the internal position counter is distinct from the seek position within the file (which is confusing, and I think I have been confused by it before). Try using set-port-next-location!
as well?

You might also want port-count-lines!
depending on what you’re doing.

@lexi.lambda Could be it, but I can’t get the expected result. The lexer still counts from 1. #lang racket
(define sexp "(define foo 42) (define (bar x) (+ x 1))")
(define in (open-input-string sexp))
(port-count-lines-enabled #t)
(file-position in 16)
(set-port-next-location! in 1 0 16)
(require syntax-color/racket-lexer)
(racket-lexer in)
(racket-lexer in)
(racket-lexer in)
(racket-lexer in)
(racket-lexer in)
(racket-lexer in)

Ah! (port-count-lines! in)

@soegaard2 You need to use either (port-count-lines! in)
or set port-count-lines-enabled
to #t
before creating the input port (or, more specifically, during the dynamic extent of the port’s creation).

It’s still a bit odd - I don’t need line numbers.

Yeah, I’m not sure why it wouldn’t respect the position!

Thanks for the help.

Oh, hm: “If line counting has not been enabled for port
or if port
is a custom port that defines its own counting function, then set-port-next-location!
has no effect.”

Yes, but file-postion
should have an effect.

Well, also see this sentence at the top of that documentation section: “By default, Racket keeps track of the position in a port as the number of bytes that have been read from or written to any port (independent of the read/write position, which is accessed or changed with file-position
).”

I’ll be honest, I have no idea why the API works the way it does, and I find it confusing, too, but there’s probably a reason. :)

Oh - the number of bytes read !. Yeah, then changing the position has no effect.

@mflatt It looks like pango supports creating fonts from ttf (true type font) files (without them being installed in the user’s fontbook), but it doesn’t look like Racket’s font facilities do that. Is there any particular reason you can’t do it in Racket, or did it just not come up?

(I ask because I’m tired have having to make sure my users install a font, and would like to embed a ttf font in the slideshow/paper/pict, etc.

@leif The last time I looked into that, there were various obstacles to making it work on all platforms. Things may have changed.

Mmm…okay.

I’ll take another look at it in a bit then, thanks.

(Basically, as it currently stands, I can’t really give coauthors a pict program and assume that they will be able to run it without much effort. :disappointed: So I want to fix that. :slightly_smiling_face: Anyway, thanks.)