1
0
Fork
You've already forked mit
0

edit identifier at point, MIT Scheme #3

Open
opened 2017年02月04日 05:29:55 +01:00 by jaor · 6 comments
jaor commented 2017年02月04日 05:29:55 +01:00 (Migrated from gitlab.com)
Copy link

Created by: feldman4

Similar to jaor/geiser#160, but with MIT Scheme.

I copied the same example into test.scm and compiled/loaded it with C-c C-k. Auto-doc works, but M-. on fbe-fact gives the "Couldn't find edit location for 'fbe-fact'" error.

INFO: REQUEST: <12>: (geiser:load-file "/Users/feldman/Google Drive/docs/classes/6.945/test.scm")

INFO: RETORT: ((error (key . retort-syntax)) (output . "
;Loading "test.scm"... done
;Value: fbe-fact

1 (user) => "))

INFO: <12>: processed

INFO: REQUEST: <13>: (geiser:eval '#f '(geiser:autodoc '(fbe-fact fbe-fact * if define)))

INFO: <13>: processed

INFO: REQUEST: <14>: (geiser:eval '#f '(geiser:symbol-location (quote fbe-fact)))

INFO: RETORT: ((result "(("name" . fbe-fact) ("file") ("line"))") (output . ""))

INFO: <14>: processed

INFO: REQUEST: <15>: (geiser:eval '#f '(geiser:module-location (quote (fbe-fact (fbe-1- n)))))

INFO: RETORT: ((result "(("name" fbe-fact (fbe-1- n)) ("file") ("line"))") (output . ""))

INFO: <15>: processed

*Created by: feldman4* Similar to jaor/geiser#160, but with MIT Scheme. I copied the same example into `test.scm` and compiled/loaded it with C-c C-k. Auto-doc works, but M-. on `fbe-fact` gives the "Couldn't find edit location for 'fbe-fact'" error. INFO: REQUEST: <12>: (geiser:load-file "/Users/feldman/Google Drive/docs/classes/6.945/test.scm") INFO: RETORT: ((error (key . retort-syntax)) (output . " ;Loading \"test.scm\"... done ;Value: fbe-fact 1 (user) => ")) INFO: <12>: processed INFO: REQUEST: <13>: (geiser:eval '#f '(geiser:autodoc '(fbe-fact fbe-fact * if define))) INFO: <13>: processed INFO: REQUEST: <14>: (geiser:eval '#f '(geiser:symbol-location (quote fbe-fact))) INFO: RETORT: ((result "((\"name\" . fbe-fact) (\"file\") (\"line\"))") (output . "")) INFO: <14>: processed INFO: REQUEST: <15>: (geiser:eval '#f '(geiser:module-location (quote (fbe-fact (fbe-1- n))))) INFO: RETORT: ((result "((\"name\" fbe-fact (fbe-1- n)) (\"file\") (\"line\"))") (output . "")) INFO: <15>: processed
jaor commented 2017年02月05日 01:30:38 +01:00 (Migrated from gitlab.com)
Copy link

i'm afraid M-. cannot work in MIT Scheme because MIT Scheme does not
offer source code locations in its runtime, and geiser relies on that
information coming from the scheme process.

i'm afraid `M-.` cannot work in MIT Scheme because MIT Scheme does not offer source code locations in its runtime, and geiser relies on that information coming from the scheme process.
jaor commented 2017年02月05日 15:28:51 +01:00 (Migrated from gitlab.com)
Copy link

Created by: feldman4

Is it possible to apply something like the following (from the docs) to known source files?

Sometimes, the underlying Scheme will tell Geiser only the file where the symbol is defined, but Geiser will use some heuristics (read, regular expressions) to locate the exact line and bring you there.

*Created by: feldman4* Is it possible to apply something like the following (from the docs) to known source files? > Sometimes, the underlying Scheme will tell Geiser only the file where the symbol is defined, but Geiser will use some heuristics (read, regular expressions) to locate the exact line and bring you there.
jaor commented 2017年02月07日 02:59:44 +01:00 (Migrated from gitlab.com)
Copy link

i might be misremembering, but i'm almost sure MIT Scheme cannot even
tell the file...

i might be misremembering, but i'm almost sure MIT Scheme cannot even tell the file...
jaor commented 2017年02月07日 07:58:41 +01:00 (Migrated from gitlab.com)
Copy link

Created by: ecraven

There is a way to get the file for compiled procedures:

(define (find-file+position-of-definition object name)
(let ((file
(if (and (entity? object)
(procedure? object))
(receive (a b) (compiled-entry/filename-and-index (entity-procedure object)) a)
(if (compiled-procedure? object)
(receive (a b) (compiled-entry/filename-and-index object) a)
#f))))
(let ((scm-file (if (and file
(string-suffix? ".inf" file))
(string-append (substring file 0 (- (string-length file) 3)) "scm")
file)))
(if (and scm-file
(file-exists? scm-file))
(find-definition-position-in-file scm-file object name)
(let ((scm-file (if scm-file (find-mit-scheme-sources-file scm-file) #f)))
(if (and scm-file
(file-exists? scm-file))
(find-definition-position-in-file scm-file object name)
'nil))))))

(define (find-definition-position-in-file file object name)
(define (find-pos file object)
(let ((file-lines (read-file-lines file)))
(let loop ((lines file-lines)
(count 0))
(if (null? lines)
(values 0 "")
(let ((match (re-string-search-forward (string-append ".(define. (?" name) (car lines))))
(if match
(values count (car lines))
(loop (cdr lines)
(+ count (string-length (car lines)) 1)))))))) ;; 1 for new-line
(receive (pos snippet)
(find-pos file object)
`((,(string-append "(define " name ")")
(:location
(:file ,file)
(:position ,(+ 1 pos)) ;; extra new-line
(:snippet ,snippet)
)))))

This kind of works for some places in my local swank, but ymmv.

Greetings, Peter

*Created by: ecraven* There is a way to get the file for compiled procedures: (define (find-file+position-of-definition object name) (let ((file (if (and (entity? object) (procedure? object)) (receive (a b) (compiled-entry/filename-and-index (entity-procedure object)) a) (if (compiled-procedure? object) (receive (a b) (compiled-entry/filename-and-index object) a) #f)))) (let ((scm-file (if (and file (string-suffix? ".inf" file)) (string-append (substring file 0 (- (string-length file) 3)) "scm") file))) (if (and scm-file (file-exists? scm-file)) (find-definition-position-in-file scm-file object name) (let ((scm-file (if scm-file (find-mit-scheme-sources-file scm-file) #f))) (if (and scm-file (file-exists? scm-file)) (find-definition-position-in-file scm-file object name) 'nil)))))) (define (find-definition-position-in-file file object name) (define (find-pos file object) (let ((file-lines (read-file-lines file))) (let loop ((lines file-lines) (count 0)) (if (null? lines) (values 0 "") (let ((match (re-string-search-forward (string-append ".*(define.* (?" name) (car lines)))) (if match (values count (car lines)) (loop (cdr lines) (+ count (string-length (car lines)) 1)))))))) ;; 1 for new-line (receive (pos snippet) (find-pos file object) `((,(string-append "(define " name ")") (:location (:file ,file) (:position ,(+ 1 pos)) ;; extra new-line (:snippet ,snippet) ))))) This kind of works for some places in my local swank, but ymmv. Greetings, Peter
jaor commented 2020年07月20日 20:43:30 +02:00 (Migrated from gitlab.com)
Copy link

changed the description

changed the description
jaor commented 2020年07月20日 20:43:30 +02:00 (Migrated from gitlab.com)
Copy link

moved from jaor/geiser#204

moved from jaor/geiser#204
Sign in to join this conversation.
No Branch/Tag specified
master
0.15
0.14
0.13
0.12
0.11.2
0.11.1
0.11
0.10
0.9
0.8.1
0.8
0.7
0.6
0.5
0.4
0.3
0.2.2
0.2.1
0.2
0.1.4
0.1.3
0.1.2
0.1.1
0.1
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
geiser/mit#3
Reference in a new issue
geiser/mit
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?