1 ! Copyright (C) 2005, 2008 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 tools.vocabs prettyprint source-files assocs
6 vocabs vocabs.loader splitting accessors ;
11 M: no-edit-hook summary
12 drop "You must load one of the below vocabularies before using editor integration:" ;
16 : available-editors ( -- seq )
17 "editors" all-child-vocabs-seq [ vocab-name ] map ;
19 : editor-restarts ( -- alist )
21 [ [ "Load " prepend ] keep ] { } map>assoc ;
25 editor-restarts throw-restarts
28 : edit-location ( file line -- )
29 [ (normalize-path) ] dip edit-hook get-global
30 [ call ] [ no-edit-hook edit-location ] if* ;
33 where [ first2 edit-location ] when* ;
35 : edit-vocab ( name -- )
36 vocab-source-path 1 edit-location ;
38 GENERIC: error-file ( error -- file )
40 GENERIC: error-line ( error -- line )
42 M: lexer-error error-file
45 M: lexer-error error-line
46 [ error>> error-line ] [ line>> ] bi or ;
48 M: source-file-error error-file
49 [ error>> error-file ] [ file>> path>> ] bi or ;
51 M: source-file-error error-line
54 M: condition error-file
57 M: condition error-line
66 : (:edit) ( error -- )
67 [ error-file ] [ error-line ] bi
68 2dup and [ edit-location ] [ 2drop ] if ;
73 : edit-each ( seq -- )
75 [ "Editing " write . ]
77 "RETURN moves on to the next usage, C+d stops." print
85 [ "Fixing " write pprint " and all usages..." print nl ]
86 [ [ smart-usage ] keep prefix ] bi