<commit_before>! Copyright (C) 2005, 2009 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs continuations debugger definitions
help.topics io io.backend io.files io.launcher io.pathnames
kernel lexer math namespaces parser prettyprint sequences
source-files source-files.errors splitting strings summary
tools.crossref vocabs vocabs.files vocabs.hierarchy
vocabs.loader vocabs.metadata ;
FROM: vocabs => vocab-name >vocab-link ;
IN: editors

SYMBOL: editor-class

: available-editors ( -- seq )
    "editors" child-vocab-names ;

: editor-restarts ( -- alist )
    available-editors
    [ [ "Load " prepend ] keep ] { } map>assoc ;

HOOK: editor-command editor-class ( file line -- command )

M: f editor-command
    "Select an editor" editor-restarts throw-restarts require
    editor-command ;

HOOK: editor-detached? editor-class ( -- ? )
M: object editor-detached? t ;

: run-and-wait-for-editor ( command -- )
    <process>
        swap >>command 
        editor-detached? >>detached
    run-process dup status>> { 0 f } member?
    [ drop ] [ process-failed ] if ;

: edit-location ( file line -- )
    [ absolute-path ] dip
    editor-command [ run-and-wait-for-editor ] when* ;

ERROR: cannot-find-source definition ;

M: cannot-find-source error.
    "Cannot find source for ``" write
    definition>> pprint-short
    "''" print ;

: edit-file ( path -- )
    0 edit-location ;

DEFER: edit

: edit-vocab ( vocab -- )
    dup lookup-vocab [ edit ] [ cannot-find-source ] ?if ;

GENERIC: edit ( object -- )

M: object edit
    dup where [ first2 edit-location ] [ cannot-find-source ] ?if ;

M: link edit name>> edit ;<commit_msg>Make edit-vocab work on an unloaded vocabulary.<commit_after>! Copyright (C) 2005, 2009 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs continuations debugger definitions
help.topics io io.backend io.files io.launcher io.pathnames
kernel lexer math namespaces parser prettyprint sequences
source-files source-files.errors splitting strings summary
tools.crossref vocabs vocabs.files vocabs.hierarchy
vocabs.loader vocabs.metadata ;
FROM: vocabs => vocab-name >vocab-link ;
IN: editors

SYMBOL: editor-class

: available-editors ( -- seq )
    "editors" child-vocab-names ;

: editor-restarts ( -- alist )
    available-editors
    [ [ "Load " prepend ] keep ] { } map>assoc ;

HOOK: editor-command editor-class ( file line -- command )

M: f editor-command
    "Select an editor" editor-restarts throw-restarts require
    editor-command ;

HOOK: editor-detached? editor-class ( -- ? )
M: object editor-detached? t ;

: run-and-wait-for-editor ( command -- )
    <process>
        swap >>command 
        editor-detached? >>detached
    run-process dup status>> { 0 f } member?
    [ drop ] [ process-failed ] if ;

: edit-location ( file line -- )
    [ absolute-path ] dip
    editor-command [ run-and-wait-for-editor ] when* ;

ERROR: cannot-find-source definition ;

M: cannot-find-source error.
    "Cannot find source for ``" write
    definition>> pprint-short
    "''" print ;

: edit-file ( path -- )
    0 edit-location ;

DEFER: edit

: edit-vocab ( vocab -- )
    >vocab-link edit ;

GENERIC: edit ( object -- )

M: object edit
    dup where [ first2 edit-location ] [ cannot-find-source ] ?if ;

M: link edit name>> edit ;
{'fraction_non_alphanumeric': 0.12343470483005367, 'fraction_numerical': 0.00655933214072749, 'mean_word_length': 3.111519607843137, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5753301', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1072, 'n_words': 307}