1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: parser lexer kernel namespaces sequences definitions
4 io.files io.backend io.pathnames io summary continuations
5 tools.crossref vocabs.hierarchy prettyprint source-files
6 source-files.errors assocs vocabs vocabs.loader splitting
7 accessors debugger help.topics ;
12 M: no-edit-hook summary
13 drop "You must load one of the below vocabularies before using editor integration:" ;
17 : available-editors ( -- seq )
18 "editors" all-child-vocabs-seq [ vocab-name ] map ;
20 : editor-restarts ( -- alist )
22 [ [ "Load " prepend ] keep ] { } map>assoc ;
26 editor-restarts throw-restarts
29 : edit-location ( file line -- )
30 [ (normalize-path) ] dip edit-hook get-global
31 [ call( file line -- ) ] [ no-edit-hook edit-location ] if* ;
33 ERROR: cannot-find-source definition ;
35 M: cannot-find-source error.
36 "Cannot find source for ``" write
37 definition>> pprint-short
42 [ first2 edit-location ]
43 [ dup word-link? [ name>> edit ] [ cannot-find-source ] if ]
46 : edit-vocab ( name -- )
49 GENERIC: error-file ( error -- file )
51 GENERIC: error-line ( error -- line )
53 M: lexer-error error-file
56 M: lexer-error error-line
57 [ error>> error-line ] [ line>> ] bi or ;
59 M: source-file-error error-file
60 [ error>> error-file ] [ file>> ] bi or ;
62 M: source-file-error error-line
65 M: condition error-file
68 M: condition error-line
77 : (:edit) ( error -- )
78 [ error-file ] [ error-line ] bi
79 2dup and [ edit-location ] [ 2drop ] if ;
84 : edit-error ( error -- )
85 [ file>> ] [ line#>> ] bi 2dup and [ edit-location ] [ 2drop ] if ;
87 : edit-each ( seq -- )
89 [ "Editing " write . ]
91 "RETURN moves on to the next usage, C+d stops." print
99 [ "Fixing " write pprint " and all usages..." print nl ]
100 [ [ smart-usage ] keep prefix ] bi