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 require
25 HOOK: editor-detached? editor-class ( -- ? )
26 M: object editor-detached? t ;
28 : run-and-wait-for-editor ( command -- )
31 editor-detached? >>detached
33 300 milliseconds sleep
34 dup status>> { 0 f } member?
35 [ drop ] [ process-failed ] if ;
37 ERROR: invalid-location file line ;
39 : edit-location ( file line -- )
40 over [ throw-invalid-location ] unless
42 editor-command [ run-and-wait-for-editor ] when* ;
44 ERROR: cannot-find-source definition ;
46 M: cannot-find-source error.
47 "Cannot find source for ``" write
48 definition>> pprint-short
51 : edit-file ( path -- )
58 : public-vocab-name ( vocab-spec -- name )
59 vocab-name ".private" ?tail drop ;
63 : edit-vocab ( vocab -- )
64 public-vocab-name >vocab-link edit ;
66 GENERIC: edit ( object -- )
69 dup where [ first2 edit-location ] [ throw-cannot-find-source ] ?if ;
71 M: string edit edit-vocab ;
73 : edit-error ( error -- )
74 [ error-file ] [ error-line ] bi
75 over [ 1 or edit-location ] [ 2drop ] if ;
78 error get edit-error ;
80 : edit-each ( seq -- )
82 [ "Editing " write . ]
84 "RETURN moves on to the next usage, C+d stops." print
92 [ "Fixing " write pprint " and all usages..." print nl ]
93 [ [ smart-usage ] keep prefix ] bi
96 GENERIC: edit-docs ( object -- )
99 public-vocab-name vocab-docs-path 1 edit-location ;
102 dup "help-loc" word-prop
103 [ nip first2 edit-location ]
104 [ vocabulary>> edit-docs ]
107 GENERIC: edit-tests ( object -- )
110 public-vocab-name vocab-tests-path 1 edit-location ;
112 M: word edit-tests vocabulary>> edit-tests ;
114 : edit-platforms ( vocab -- )
115 dup vocab-platforms-path vocab-append-path 1 edit-location ;
117 : edit-authors ( vocab -- )
118 dup vocab-authors-path vocab-append-path 1 edit-location ;
120 : edit-tags ( vocab -- )
121 dup vocab-tags-path vocab-append-path 1 edit-location ;
123 : edit-summary ( vocab -- )
124 dup vocab-summary-path vocab-append-path 1 edit-location ;