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.launcher io.pathnames
5 kernel lexer math namespaces parser prettyprint sequences
6 source-files source-files.errors splitting strings summary
7 tools.crossref vocabs vocabs.files vocabs.hierarchy
8 vocabs.loader vocabs.metadata calendar threads words ;
9 FROM: vocabs => vocab-name >vocab-link ;
14 : available-editors ( -- seq )
15 "editors" child-vocab-names ;
17 : editor-restarts ( -- alist )
19 [ [ "Load " prepend ] keep ] { } map>assoc ;
21 HOOK: editor-command editor-class ( file line -- command )
24 "Select an editor" editor-restarts throw-restarts require
27 HOOK: editor-detached? editor-class ( -- ? )
28 M: object editor-detached? t ;
30 : run-and-wait-for-editor ( command -- )
33 editor-detached? >>detached
35 300 milliseconds sleep
36 dup status>> { 0 f } member?
37 [ drop ] [ process-failed ] if ;
39 ERROR: invalid-location file line ;
41 : edit-location ( file line -- )
42 over [ invalid-location ] unless
44 editor-command [ run-and-wait-for-editor ] when* ;
46 ERROR: cannot-find-source definition ;
48 M: cannot-find-source error.
49 "Cannot find source for ``" write
50 definition>> pprint-short
53 : edit-file ( path -- )
58 : edit-vocab ( vocab -- )
59 vocab-name* >vocab-link edit ;
61 GENERIC: edit ( object -- )
64 dup where [ first2 edit-location ] [ cannot-find-source ] ?if ;
66 M: string edit edit-vocab ;
68 : edit-error ( error -- )
69 [ error-file ] [ error-line ] bi
70 over [ 1 or edit-location ] [ 2drop ] if ;
73 error get edit-error ;
75 : edit-each ( seq -- )
77 [ "Editing " write . ]
79 "RETURN moves on to the next usage, C+d stops." print
87 [ "Fixing " write pprint " and all usages..." print nl ]
88 [ [ smart-usage ] keep prefix ] bi
91 GENERIC: edit-docs ( object -- )
94 vocab-name* vocab-docs-path 1 edit-location ;
97 dup "help-loc" word-prop
98 [ nip first2 edit-location ]
99 [ vocabulary>> edit-docs ]
102 GENERIC: edit-tests ( object -- )
105 vocab-name* vocab-tests-path 1 edit-location ;
107 M: word edit-tests vocabulary>> edit-tests ;
109 : edit-platforms ( vocab -- )
110 dup vocab-platforms-path vocab-append-path 1 edit-location ;
112 : edit-authors ( vocab -- )
113 dup vocab-authors-path vocab-append-path 1 edit-location ;
115 : edit-tags ( vocab -- )
116 dup vocab-tags-path vocab-append-path 1 edit-location ;
118 : edit-summary ( vocab -- )
119 dup vocab-summary-path vocab-append-path 1 edit-location ;