[plt-scheme] tried to fix etags for DrScheme 299

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Tue Apr 5 04:37:27 EDT 2005

Hi everyone,

I've made a few changes to Guillaume Marceau's etags.ss program to make it
work for the upcoming DrScheme release.  Since I'm still a PLT Scheme
newbie, I'd greatly appreciate it if someone can review my diff: if I'm
doing something hideous, I'd rather get it fixed early while my PLT Scheme
skills are malleable.

I downloaded the original code here:


My local modifications should be below.  Thanks in advance!

mumak:~/work/plt dyoo$ svn diff -r 1380:1381 etags.ss
Index: etags.ss
--- etags.ss	(revision 1380)
+++ etags.ss	(revision 1381)
@@ -40,6 +40,11 @@
 (define (string-prefix str len)
   (substring str 0 (min (string-length str) len)))

+;; By default, use the encoding from the default locale.
+(define bytes->string bytes->string/locale)
 (define (id-to-tag-line id port)
   (if (or (not (syntax-source id))
           (not (syntax-position id)))
@@ -66,7 +71,7 @@
            (if (not matched) (string-prefix (get-output-string lead-in)
                (string-append (get-output-string lead-in)
-                              (string-chop (first matched))))
+                              (string-chop (bytes->string (first
            name-sym line rewound-p)))))

 (define (find-defs-in-stx stx)
@@ -80,7 +85,11 @@
        (apply append (map loop (syntax->list (syntax (i ...)))))]

       [_ empty])))
+(define (not-break-exn? x)
+  (not (exn:break? x)))
 (define (for-each-tle-in-file fn target-file)
@@ -94,6 +103,7 @@
                     (path-only (normalize-path target-file))])
       (let ([port (open-input-file target-file)])
+            (skip-magic-line! port)
             (let loop ([stx (read-syntax target-file port)])
               (unless (eof-object? stx)
                 (fn (expand stx))
@@ -101,6 +111,12 @@
           (close-input-port port))))))

+;; Skips the magic header off a port, for files that look like scripts.
+(define (skip-magic-line! port)
+  (when (equal? #"#!" (peek-bytes 2 0 port))
+    (read-line port)))
 (define (process-file target-file output-file)
   (let ([ids empty])

Posted on the users mailing list.