1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs continuations debugger definitions
4 help.topics io io.backend io.files io.pathnames kernel lexer
5 namespaces parser prettyprint sequences source-files
6 source-files.errors splitting strings summary tools.crossref
7 vocabs vocabs.files vocabs.hierarchy vocabs.loader
9 FROM: vocabs => vocab-name >vocab-link ;
14 M: no-edit-hook summary
15 drop "You must load one of the below vocabularies before using editor integration:" ;
19 : available-editors ( -- seq )
20 "editors" child-vocab-names ;
22 : editor-restarts ( -- alist )
24 [ [ "Load " prepend ] keep ] { } map>assoc ;
28 editor-restarts throw-restarts
31 : edit-location ( file line -- )
32 [ absolute-path ] dip edit-hook get-global
33 [ call( file line -- ) ] [ no-edit-hook edit-location ] if* ;
35 ERROR: cannot-find-source definition ;
37 M: cannot-find-source error.
38 "Cannot find source for ``" write
39 definition>> pprint-short
42 GENERIC: edit ( object -- )
45 dup where [ first2 edit-location ] [ cannot-find-source ] ?if ;
47 M: link edit name>> edit ;
50 dup lookup-vocab [ edit ] [ cannot-find-source ] ?if ;
52 : edit-error ( error -- )
53 [ error-file ] [ error-line ] bi
54 over [ 1 or edit-location ] [ 2drop ] if ;
57 error get edit-error ;
59 : edit-each ( seq -- )
61 [ "Editing " write . ]
63 "RETURN moves on to the next usage, C+d stops." print
71 [ "Fixing " write pprint " and all usages..." print nl ]
72 [ [ smart-usage ] keep prefix ] bi
75 : edit-docs ( vocab -- )
76 vocab-docs-path 1 edit-location ;
78 : edit-tests ( vocab -- )
79 vocab-tests-file 1 edit-location ;
81 : edit-platforms ( vocab -- )
82 dup vocab-platforms-path vocab-append-path 1 edit-location ;
84 : edit-authors ( vocab -- )
85 dup vocab-authors-path vocab-append-path 1 edit-location ;
87 : edit-tags ( vocab -- )
88 dup vocab-tags-path vocab-append-path 1 edit-location ;
90 : edit-summary ( vocab -- )
91 dup vocab-summary-path vocab-append-path 1 edit-location ;