Skip to main content

A utility to create a simple C source file with a main and open it in an editor.

Project description

make_c

A script to generate a simple C program with a few basic includes and a main(). Then it opens the file in your editor of choice placing the cursor at the proper line and column to start adding code.

Supported editors include:

  • vim
  • SublimeText (subl)
  • TextMate (mate)
  • Visual Studio Code (code)
  • nano
  • emacs

Installing

$ cd make_c
$ python3 setup.py install

Running

Help output:

$ make_c --help
usage: make_c [-h] [--list-editors] [--version] [--editor EDITOR]
              [--skip-editor] [--tabs] [--generate-makefile]
              [filename]

make_c: A utility to create a simple C source file with a main and open it in
an editor. version 0.1.5

positional arguments:
  filename             Name of the source file to create.

optional arguments:
  -h, --help           show this help message and exit
  --list-editors       List known editors.
  --version            Print version string and exit.
  --editor EDITOR      Editor to use to open the resulting source file.
  --skip-editor        Create the source file but don't open it in an editor.
  --tabs               Use tabs instead of spaces.
  --generate-makefile  Create a makefile to build the program.

List available editors:

$ make_c --list-editors
Known editors:

vim: Vi IMproved, a programmer's text editor
subl: Sublime Text 3
mate: TextMate 2
code: Visual Studio Code
emacs: GNU project Emacs editor
nano: Nano's ANOther editor, an enhanced free Pico clone

If an editor isn't provided on the command line, it can be specified using an environment. The variables that are used are, in the following order:

  1. MAKE_C_EDITOR
  2. EDITOR
  3. VISUAL

Creating and editing a file:

# Create foo.c and edit in the default editor, VIM:
$ make_c foo.c

# Edit using $MAKE_C_EDITOR environment variable to specify editor:
$ export MAKE_C_EDITOR=/usr/local/bin/emacs
$ make_c foo.c

# If MAKE_C_EDITOR isn't set, EDITOR and VISUAL respected, in that order:
$ unset MAKE_C_EDITOR
$ export EDITOR=/usr/bin/vim

#Edit in SublimeText instead:

$ make_c foo.c --editor=subl

#Generate a makefile in addition to the C file.

$ make_c foo.c --generate-makefile

Adding editor support

To add additional editors, extend the CProgram class and override:

  • The EDITOR class variable
  • The DESCRIPTION class variable
  • The generate_editor_command() instance method

The string representation for --list-editors is automatically generated by the superclass from EDITOR and DESCRIPTION.

The generate_editor_command() method should return an argv that represents that editor's commandline incantation in list form suitable for consumption by subprocess.Popen(). For example, if your editor takes a --line and --column argument, you would return:

def generate_editor_command(self):
    return [self.generate_editor_arg0(),
            "--line",
            "%d" % self.edit_line,
            "--column",
            "%d" % self.edit_column,
            self.filename]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

make_c-0.1.5.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

make_c-0.1.5-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file make_c-0.1.5.tar.gz.

File metadata

  • Download URL: make_c-0.1.5.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.6

File hashes

Hashes for make_c-0.1.5.tar.gz
Algorithm Hash digest
SHA256 5e96508511f104ee83b210086205b0adc93c5bc86f392a64a8ab4b3f84225183
MD5 c2261c72074a132d3c004334e359999d
BLAKE2b-256 947010ad69f1085f32157e45ddfff206cfb96ee59e6bbdd7b7ea440352a3d3a6

See more details on using hashes here.

File details

Details for the file make_c-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: make_c-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.6

File hashes

Hashes for make_c-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1b8ecbccd5f33b62fd577fddfb096db2097b2e3ab4e36f14d6516f3e4d188e81
MD5 c75e422bb6a3d79d73f1dfd0488ab2b3
BLAKE2b-256 0dc14f9249ed02afa3463c534363578f7d979b41ef6084965989b927291add16

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page