1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs calendar continuations debugger
4 definitions io io.launcher io.pathnames kernel namespaces
5 prettyprint sequences source-files.errors splitting strings
6 threads tools.crossref vocabs vocabs.files vocabs.hierarchy
7 vocabs.loader vocabs.metadata words ;
12 : available-editors ( -- seq )
13 "editors" disk-child-vocab-names ;
15 : editor-restarts ( -- alist )
17 [ [ "Load " prepend ] keep ] { } map>assoc ;
19 HOOK: editor-command editor-class ( file line -- command )
22 "Select an editor" editor-restarts throw-restarts reload
25 HOOK: editor-detached? editor-class ( -- ? )
26 M: object editor-detached? t ;
28 HOOK: editor-is-child? editor-class ( -- ? )
29 M: object editor-is-child? f ;
31 : run-and-wait-for-editor ( command -- )
34 editor-detached? >>detached
35 editor-is-child? [ +new-group+ >>group ] unless
37 300 milliseconds sleep
38 dup status>> { 0 f } member?
39 [ drop ] [ process-failed ] if ;
41 ERROR: invalid-location file line ;
43 : edit-location ( file line -- )
44 over [ invalid-location ] unless
46 editor-command [ run-and-wait-for-editor ] when* ;
48 ERROR: cannot-find-source definition ;
50 M: cannot-find-source error.
51 "Cannot find source for ``" write
52 definition>> pprint-short
55 : edit-file ( path -- )
62 : public-vocab-name ( vocab-spec -- name )
63 vocab-name ".private" ?tail drop ;
67 : edit-vocab ( vocab -- )
68 public-vocab-name >vocab-link edit ;
70 GENERIC: edit ( object -- )
73 dup where [ first2 edit-location ] [ cannot-find-source ] ?if ;
75 M: string edit edit-vocab ;
77 : edit-error ( error -- )
78 [ error-file ] [ error-line ] bi
79 over [ 1 or edit-location ] [ 2drop ] if ;
82 error get edit-error ;
84 : edit-each ( seq -- )
86 [ "Editing " write . ]
88 "RETURN moves on to the next usage, C+d stops." print
96 [ "Fixing " write pprint " and all usages..." print nl ]
97 [ [ smart-usage ] keep prefix ] bi
100 GENERIC: edit-docs ( object -- )
103 public-vocab-name vocab-docs-path 1 edit-location ;
106 dup "help-loc" word-prop
107 [ nip first2 edit-location ]
108 [ vocabulary>> edit-docs ]
111 GENERIC: edit-tests ( object -- )
114 public-vocab-name vocab-tests-path 1 edit-location ;
116 M: word edit-tests vocabulary>> edit-tests ;
118 : edit-platforms ( vocab -- )
119 public-vocab-name vocab-platforms-path 1 edit-location ;
121 : edit-authors ( vocab -- )
122 public-vocab-name vocab-authors-path 1 edit-location ;
124 : edit-tags ( vocab -- )
125 public-vocab-name vocab-tags-path 1 edit-location ;
127 : edit-summary ( vocab -- )
128 public-vocab-name vocab-summary-path 1 edit-location ;