<commit_before>! Copyright (C) 2005, 2007 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: parser kernel namespaces sequences definitions io.files
inspector continuations tuples tools.crossref tools.vocabs 
io prettyprint source-files assocs vocabs vocabs.loader ;
IN: editors

TUPLE: no-edit-hook ;

M: no-edit-hook summary
    drop "You must load one of the below vocabularies before using editor integration:" ;

SYMBOL: edit-hook

: available-editors ( -- seq )
    "editors" all-child-vocabs-seq [ vocab-name ] map ;

: editor-restarts ( -- alist )
    available-editors
    [ "Load " over append swap ] { } map>assoc ;

: no-edit-hook ( -- )
    \ no-edit-hook construct-empty
    editor-restarts throw-restarts
    require ;

: edit-location ( file line -- )
    edit-hook get [
        call
    ] [
        no-edit-hook edit-location
    ] if* ;

: edit ( defspec -- )
    where [ first2 edit-location ] when* ;

: edit-vocab ( name -- )
    vocab-source-path 1 edit-location ;

: :edit ( -- )
    error get delegates [ parse-error? ] find-last nip [
        dup parse-error-file source-file-path
        swap parse-error-line edit-location
    ] when* ;

: fix ( word -- )
    "Fixing " write dup pprint " and all usages..." print nl
    dup usage swap add* [
        "Editing " write dup .
        "RETURN moves on to the next usage, C+d stops." print
        flush
        edit
        readln
    ] all? drop ;
<commit_msg>Fix editor integration<commit_after>! Copyright (C) 2005, 2007 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: parser kernel namespaces sequences definitions io.files
inspector continuations tuples tools.crossref tools.vocabs 
io prettyprint source-files assocs vocabs vocabs.loader ;
IN: editors

TUPLE: no-edit-hook ;

M: no-edit-hook summary
    drop "You must load one of the below vocabularies before using editor integration:" ;

SYMBOL: edit-hook

: available-editors ( -- seq )
    "editors" all-child-vocabs-seq [ vocab-name ] map ;

: editor-restarts ( -- alist )
    available-editors
    [ "Load " over append swap ] { } map>assoc ;

: no-edit-hook ( -- )
    \ no-edit-hook construct-empty
    editor-restarts throw-restarts
    require ;

: edit-location ( file line -- )
    >r current-directory get prepend-path r>
    edit-hook get [ call ] [ no-edit-hook edit-location ] if* ;

: edit ( defspec -- )
    where [ first2 edit-location ] when* ;

: edit-vocab ( name -- )
    vocab-source-path 1 edit-location ;

: :edit ( -- )
    error get delegates [ parse-error? ] find-last nip [
        dup parse-error-file source-file-path
        swap parse-error-line edit-location
    ] when* ;

: fix ( word -- )
    "Fixing " write dup pprint " and all usages..." print nl
    dup usage swap add* [
        "Editing " write dup .
        "RETURN moves on to the next usage, C+d stops." print
        flush
        edit
        readln
    ] all? drop ;

{'fraction_non_alphanumeric': 0.11413043478260869, 'fraction_numerical': 0.006793478260869565, 'mean_word_length': 2.4647058823529413, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3368722', 'n_tokens_mistral': 965, 'n_tokens_neox': 936, 'n_words': 283}