Skip to content

EllKyGr/Pycro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pycro

A tailored Micro Editor for Python development

This are a set of several files, tips and recommendations using Micro while developing in Python.

Syntax

Micro currently can highlight more than 100 languages and users can customize their editor with several methods. Although the repository counts with several syntax files, and it's stated how can be improved to better suit the user experience, at the present it addresses general group statements and keywords. Thus the expanded syntax file present here adds type hint, function calls and several other new handy highlighted cases. This isn't by any means a full fledged error prove file: either by current Micro limitations, statement overruling, missing regex statements (or isn't specific enough) some words might not be highlighted as expected (i.e urls).

Color schemes

Present color schemes are designed to comply with the syntax file. Custom color schemes should follow the same rules in order to work properly. Both files contain commentary enough explaining which command is responsible for the specific color scheme. For instance darcula.micro in this repository extends/modifies the original color scheme in vanilla Micro to adjust for the new statements.

Sample

Several simple lines of code which encompasses the most common highlighted cases for fast checking or test.

Although the present files are specific for Python, the overall code template present in here for both syntax and color scheme can be adjusted to meet the specifics of any other language. Refer to the Micro syntax repository if the language is already supported and modify it as desired.

Requirements:

  • Python 3 installed
  • Either conda, venv or any tool for environment setup (recommended)

How to set

TL;DR

  1. Create a new Python environment and activate it. (optional but recommended)*

  2. git clone [email protected]:EllKyGr/Pycro.git then make

    • make u-pycro removes all Pycro related files, i.e. all color schemes within this repository and the python3.yaml. NOTE: although several color schemes are extended versions of default ones, you can still use them through set command or added directly to the settings.json after deleting the extended version. If a Micro session is open during removal process, exit once deleted, then reload to use default version, assuming the current colorscheme matches the same file name.
    • make u-micro removes all Pycro and Micro related files from your system. NOTE: if your Micro bin is located anywhere but /usr/bin this command won't be able to delete it.
    • After the setup is complete you can run make clean to remove this repository since its content will no longer be necessary. The makefile would be relocated to the parent directory so the previous commands are available. If deleted the removal of Pycro (and/ or Micro) should be perform manually. Refer to the step by step section if that's the case.

Termux

  1. Install git then shasum with pkg install perl
  2. git clone [email protected]:EllKyGr/Pycro.git
  3. Open the makefile and change (-)
    micro: checksum
    	- cd /usr/bin/; echo "\nInstalling Micro at => $$PWD\n"; \
    	+ cd /data/data/com.termux/files/usr/bin/; echo "\nInstalling Micro at => $$PWD\n"; \
    	- curl https://getmic.ro | sudo bash;
    	+ curl https://getmic.ro | bash;
    
  4. Then make. The same commands apply to remove Pycro files and Micro however to remove Micro through make u-micro, the following line should be changed:
    u-micro:
    	- cd /usr/bin; echo "Attempting to remove Micro from $$PWD"; sudo rm -i micro; \
    	+ cd /data/data/com.termux/files/usr/bin; echo "Attempting to remove Micro from $$PWD"; rm -i micro; \
    

Micro already installed?

  1. Although not necessary for the present settings, be aware of the micro bin file location. (The makefile can only remove Micro entirely if located at /usr/bin)
  2. Create a new Python environment and activate it. (optional but recommended)*
  3. git clone [email protected]:EllKyGr/Pycro.git then make pycro

* The main reason for using a Python environment is just for containment sake. On the other hand the plugins related to this packages will not work as intended if the latter are missing. Meaning to use Micro's full capacity (while developing Python) these two packages should be present.

Step by Step

  1. Installing Micro:

    • Micro 2.0.XX => https://github.com/benweissmann/getmic.ro
    • Add to ~/.config/micro/syntax/ the python3.yaml after installing Micro.
    • Add to ~/.config/micro/colorschemes/ the color_scheme_file.micro either from here, the Micro repo or a custom one.
    • Optional: create a Python environment with your favorite tool before proceeding.
  2. Plugins micro -plugin install <plugin>:

    • aspell: spell checking. addpersonal adds word to personal dictionary when cursor is placed under said word.

    • filemanager: adds a tree to visualize, open, create files and directories:

      • Ctrl + e then tree: open the file tree
      • left key or right key: closes or collapses the directory
      • rename: new name for selected file inside tree
      • rm: deletes file inside tree
      • touch: creates file in the current path
      • mkdir: creates directory in current path
    • lsp: adds language server for better coding style and formatting

      • Run pip install python-lsp-server for the lsp plugin to work
      • Alt + d: with cursor under a function returns the documentation
      • Alt + k: with cursor under function, object, etc returns brief description at status line
      • Ctrl + _: comments out the line. Repeat to undo previous action
      • Ctrl + space: limited auto complete; all possible keywords are listed yet not cleanly stated
    • autofmt: formats file content at save based on language. Until the current autofmt repository is updated with a -plugin command, do this instead:

      1. git clone [email protected]:a11ce/micro-autofmt.git
      2. cd to micro-autofmt/ then make. The cloned repository is no longer needed after installing the plugin files so it can be removed aftewards.
      3. Currently only C/C++/C#, Python, Racket, JavaScript, Rust and Go are supported. Every language require its specific formatter
      4. For Python run: pip install git+https://github.com/google/yapf.git either directly or within environment.
    • runit: allows to run, compile and make files on the go.

      • F5: saves and run
      • F12: makes
      • F5: makes in the background
    • manipulator: add commands inside Micro for alternative edition, i.e. Ctrl + e followed by:

      • dquote wraps selected text within double quotes
      • curly wraps selected text within {}
      • camel turns text into camelCase format

      NOTE: Refer to the main page of the repository, or the manipulator.md after installed, to learn all the available commands. The plugin installs version 1.4.0, version 1.4.1 is needed for camel, snake, kebab, etc to work otherwise Micro won't recognize them.

    • quoter: wraps the lines with double or single quotes.

    • cheat: pressing F1 opens a new tab with a cheatsheet of concepts from the current working language. Although mostly basic concepts of the language, the file can be modify and expand upon as needed.
      NOTE: the path stated in main.lua at line 11 => local cheatdir = config.ConfigDir.."/plug/micro-cheat/cheatsheets/" conflicts with the actual path installed for the plugin, instead of micro-cheat change it to cheat

    • snippets: adds vim like snippets capabilities to Micro, i.e. right next def:

      • Alt + s: inserts the snippet
      • Alt + w: toggle between elements from the snippet
      • Alt + d: removes snippet
      • Alt + a: exists snippet edition mode
  3. Settings and key bindings: after installing plugins edit, or create, the settings.json at ~/.config/micro with the following options (the lines preceded by # are meant to be deleted):

    # settings.json
    {
        "aspell.check": "on",
        "aspell.lang": "en",       # Native or any language
        "colorcolumn": 80,         # Rule
        "colorscheme": "darcula",  # Or any color scheme fitting the Python syntax file
        "diffgutter": true,        # Visual cue for changes in current file
        "fmt-onsave": true,        # Format on save
        "hlsearch": true,          # Matched letters and background color
        "hltrailingws": true,      # Any type of white space is highlighted
        "savecursor": true,        # Cursor locates in its last position from previous session
        "scrollbar": true          # Optional
    
        # lsp plugin will update file with the following options
    
        "lsp.ignoreMessages": "LS message1 to ignore|LS message 2 to ignore|...",
        "lsp.ignoreTriggerCharacters": "completion,signature",
        "lsp.server": "python=pylsp",
    
    }
    Enter `Ctrl + e` inside Micro and then `set` followed by any additional option you may want in addition to the recommended ones.
    

    Check the Micro options tab for further information

    # Expected key bindings in `bindings.json` after plugin install
    {
        "Alt-/": "lua:comment.comment",
        "Alt-a": "lua:snippets.Accept",
        "Alt-d": "lua:snippets.Cancel",
        "Alt-f": "command:format",
        "Alt-k": "command:hover",
        "Alt-r": "command:references",
        "Alt-s": "lua:snippets.Insert",
        "Alt-w": "lua:snippets.Next",
        "CtrlSpace": "command:lspcompletion",
        "CtrlUnderscore": "lua:comment.comment",
        "F1": "command:cheat",
        "F12": "command:makeup",
        "F5": "command:runit",
        "F9": "command:makeupbg"
    }
    

    Check the Micro keybindings tab for further information

What's next?

  • Add guidelines for windows
  • Adapt makefile for windows
  • Add new color schemes (at least up to ten)
  • Expand and improve syntax file

About

Python focus settings for the Micro Editor

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published