Giter Club home page Giter Club logo

macrosonsave's Introduction

Macros On Save

A minimal python script you can use anywhere to perform substitutions of your specifications on save.

demo

Setup and installation

  1. git clone / git submodule this repository into the project folder
  2. Ensure you have python3 installed
  3. While at the root of your project folder, run the following command.
python macroOnSave/main.py
  1. If this is your first time, a macro_config.json file would be created.
  2. Edit the macro_config.json file to your requirement.
    1. watch_dir is the directory which macros will be enabled.
    2. macro_dir is the directory where you define your macros.
    3. marker is the tag before the file name to be substituted.
    4. replace_start is the tag to mark the start of a macro.
    5. replace_end is the tag to mark the end of a macro.
    6. refresh_time is the period which the program will check file saves
  3. Re-run python macrosOnSave/main.py to start the program.

Usage

Suppose you set your watch_dir as src/ and macro_dir as macro/.

And you are working on a file src/A/main.cpp which has the following content.

// src/A/main.cpp
#include <iostream>

int main() {
    std::cout << "Hello World\n";
}

And you have defined a macro in macro/B/bye.cpp. Note that only the lines between ...MACRO-START... and ...MACRO-END... will be used.

// macro/B/bye.cpp - Start
#include <iostream>

// MACRO-START
void bye() {
    std::cout << "Goodbye\n";
}
// MACRO-END

Then simply by typing >>> <substring of macro file name> like >>> by or >>> bye.c,

// src/A/main.cpp
#include <iostream>

>>> by

int main() {
    std::cout << "Hello World\n";
}

Turns into the following on save

// src/A/main.cpp
#include <iostream>

void bye() {
    std::cout << "Goodbye\n";
}

int main() {
    std::cout << "Hello World\n";
}

Its just that simple.

Notes

  1. Macros are line level replacements. So expect the line containing >>> <filename> to be replaced with the file contents of the macro.
  2. You can define macros in subdirectories, of macro_dir as the program will scour the directory for a suitable file.

macrosonsave's People

Contributors

stanleyneoh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.