Skip to content

plai-group/concordance-for-vscode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

concordance-for-vscode

This is a little writing tool I made while procrastinating starting my thesis, based on Concordance from David Deutsch. It is a python script which highlights duplicate words and phrases in order to find and eliminate repetitions.

I've cobbled it together using python and four extensions:

  1. Dendron
  2. Regex highlight
  3. Command runner
  4. Run on save

In a perfect world I would have written this in javascript and it would be a simple vscode extension (accepting pull requests!). I don't know how to do that however, and so instead I've used python to write custom regex, which are then fed to regex highlight. Run on save is used to update the highlights upon save, and command runner saves an .args token which changes the settings. Dendron provides the environment where the markdown notes live.

Setup instructions

  • install python packages
pip install pyjson5 seaborn nltk markdown beautifulsoup4 pandas
  • from the python REPL run
import nltk
nltk.download('punkt')
  • install vscode extensions
    1. Dendron
    2. Regex highlight
    3. Command runner
    4. Run on save
  • git clone this repository and move concordance.py to $dendron_directory/scripts/concordance.py.
    • the script subdirectory should be parallel to your dendron.code-workspace file.
  • change line 11 - 13 of concordance.py to the appropriate paths:
SETTINGS_PATH = '/Users/vmasrani/dev/phd/dendron/dendron.code-workspace'
ARGS_PATH = '/Users/vmasrani/dev/phd/dendron/scripts/.args'
OUT_PATH = '/Users/vmasrani/dev/phd/dendron/vault/assets/concordance.csv'

Modify your workspace settings to configure command-runner and runonsave

Add the following entries to your workspace settings json (command pallet > Preferences: Open Workspace Settings (JSON)), with the paths in emeraldwalk.runonsave.commands.cmd appropriately changed to point to your python interpreter and concordance.py file:

"command-runner.commands": {
    "reset": "echo '0 0 0 1' >! ${config:dendron.rootDir}/scripts/.args && ${config:python.pythonPath} ${config:dendron.rootDir}/scripts/concordance.py '${file}'",
    "words": "echo '1 5 1 0' >! ${config:dendron.rootDir}/scripts/.args && ${config:python.pythonPath} ${config:dendron.rootDir}/scripts/concordance.py '${file}'",
    "phrases": "echo '2 6 0 0' >! ${config:dendron.rootDir}/scripts/.args && ${config:python.pythonPath} ${config:dendron.rootDir}/scripts/concordance.py '${file}'",
    "words_and_phrases": "echo '1 6 0 0' >! ${config:dendron.rootDir}/scripts/.args && ${config:python.pythonPath} ${config:dendron.rootDir}/scripts/concordance.py '${file}'",
    "long": "echo '4 10 0 0' >! ${config:dendron.rootDir}/scripts/.args && ${config:python.pythonPath} ${config:dendron.rootDir}/scripts/concordance.py '${file}'"
},
"emeraldwalk.runonsave": {
    "commands": [
        {
            "match": "\\.md$",
            "isAsync": true,
            "cmd": "/Users/vmasrani/miniconda3/envs/ml3/bin/python /Users/vmasrani/dev/phd/dendron/scripts/concordance.py ${file}",
            "autoClearConsole": true
        }
    ]
},

How to use

Select run command from your command pallet - this should display five options:

  1. words and phrases: highlight duplicate words and phrases
  2. reset: turn off highlighting
  3. phrases: highlight duplicate phrases only
  4. long: highlight long (greater than 10 characters) phrases only
  5. words: highlight duplicate words only

Select one of the options, then the script should automatically run every time you save a markdown file. Looking at the Run on Save output panel should reveal a printout of each duplicate.

About

Writing tool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages