<commit_before>path = require "path"
latexmk = require "./latexmk"

module.exports =
  configDefaults:
    texPath: "$PATH:/usr/texbin"
    outputDirectory: ""
    enableShellEscape: false

  activate: ->
    @initialize()
    atom.workspaceView.command "latex:build", => @build()

  initialize: ->
    envPath = process.env.PATH
    texPath = atom.config.get("latex.texPath")
    texPathSansMarker = texPath?.replace("$PATH", "")
    if texPath? and texPath.length == texPathSansMarker.length
      console.error "latex.texPath MUST contain $PATH at some point"
      return -1

    hasAllPaths = texPathSansMarker?.split(":").every (path) ->
      envPath.indexOf(path) > -1

    process.env.PATH = texPath.replace("$PATH", envPath) unless hasAllPaths

  build: ->
    editor = atom.workspace.activePaneItem
    file = editor?.buffer.file
    unless file?
      return -1

    editor.save() if editor.isModified() # NOTE: Should this be configurable?
    args = latexmk.constructArgs(file.path)
    proc = latexmk.run(args) # TODO: Trigger an event instead of returning proc?
<commit_msg>Simplify the code that initializes process.env.PATH<commit_after>path = require "path"
latexmk = require "./latexmk"

module.exports =
  configDefaults:
    texPath: "$PATH:/usr/texbin"
    outputDirectory: ""
    enableShellEscape: false

  activate: ->
    @initialize()
    atom.workspaceView.command "latex:build", => @build()

  initialize: ->
    atom.config.observe "latex.texPath", => @setPath()

  setPath: ->
    texPath = atom.config.get("latex.texPath")
    unless texPath?.indexOf("$PATH") >= 0
      console.error "latex.texPath MUST contain $PATH at some point"
      return
    @envPath = process.env.PATH unless @envPath?
    process.env.PATH = texPath.replace("$PATH", @envPath)

  build: ->
    editor = atom.workspace.activePaneItem
    file = editor?.buffer.file
    unless file?
      return -1

    editor.save() if editor.isModified() # NOTE: Should this be configurable?
    args = latexmk.constructArgs(file.path)
    proc = latexmk.run(args) # TODO: Trigger an event instead of returning proc?

{'fraction_non_alphanumeric': 0.12884888678351492, 'fraction_numerical': 0.0023685457129322598, 'mean_word_length': 3.3817427385892116, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 16, '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': '1727027', 'n_tokens_mistral': 676, 'n_tokens_neox': 651, 'n_words': 157}