Giter VIP home page Giter VIP logo

emacs-solidity's Introduction

Emacs Solidity Mode

https://img.shields.io/badge/License-GPL%20v3-blue.svg http://melpa.org/packages/solidity-mode-badge.svg

A simple language mode for the Solidity language. It is a constant work in progress as the language itself also progresses. For information about Solidity check the Tutorial and the Features wiki pages.

Installation

You can simply load the file in your emacs but the recommended way to install it is either via el-get or MELPA.

El-get

If you don’t know how to use el-get you can find more information on its webpage. First install el-get and then (in emacs), press Alt+x (this is in emacs notation written as M-x ) and then type el-get-install. This will prompt you for a package, type solidity-mode and hit enter, this should install all you need.

Melpa

You can also obtain solidity-mode from Melpa as can be seen here.

Configuration

By default solidity-mode associates itself with any files ending in .sol.

If using el-get then you should have a specific package initializing lisp file. If not then you can put these anywhere in your init.el.

Generic configuration

Regardless of where you installed solidity mode from, you need to require the package:

(require 'solidity-mode)

(append that line to your ~/.emacs file)

You can also set the way the comments are inserted by emacs with commands like comment-region. The default is /* .. */ and you can turn it to using // instead by putting the following into your emacs config:

(setq solidity-comment-style 'slash)
;; or
(setq solidity-comment-style 'star) ;; this is the default

Keymap

You can modify the default keybindings of the solidity mode keymap by adding a new key combination for each command you want to change. For example

(define-key map (kbd "C-c C-g") 'solidity-estimate-gas-at-point)

Interface with linters

Provide path to solc binary

The solc binary is assumed to be part of the PATH. Wherever that is not the case you would have to manually set the location of the binary like below:

(setq solidity-solc-path "/home/lefteris/ew/cpp-ethereum/build/solc/solc")

Note: This better be set before requiring solidity mode.

Provide path to solium binary

The solium binary is assumed to be part of the user’s PATH. If this is not the case then set its location like below:

(setq solidity-solium-path "/home/lefteris/.npm-global/bin/solium")

[Optional] Flycheck interface

Solidity mode can also interface with flycheck if you have it. Make sure to download and install the flycheck package. Then configure it to either work on all modes or enable it only for solidity mode.

Flycheck can interface with solc and/or with solium. You have to specifically set the path to both executables and activate the checker integration by setting the following:

To activate solc checker

(setq solidity-flycheck-solc-checker-active t)

To activate solium checker

(setq solidity-flycheck-solium-checker-active t)

Keep in mind that you need to provide the path to either solc or solium unless emacs can already find it in your environment’s PATH. Even if you can call it from the command line it does not mean that EMACS can see it as emacs may be started by systemd at which point PATH is not fully populated.

Configuring solc checker

You can configure flycheck’s solc invocation with the following arguments

std contracts

By default this is false. If you want to include the standard contracts just add the following to your emacs init file

(setq flycheck-solidity-solc-addstd-contracts t)

Configuring solium checker

You can configure flycheck’s solium incocation with the following arguments

solium RC file

By default solium looks at the current directory of the file you are editing in order to find .soliumrc.json. Having this file is required. But you can point to an external configuration file by putting the following anywhere in your emacs init file.

(setq flycheck-solidity-solium-soliumrcfile "/home/path/to/common/.soliumrc.json")

Chaining both checkers

If you enable both checkers then their results are chained. The variable solidity-flycheck-chaining-error-level controls how they are chained. Its value can be either t, error, warning or info and that controls the maximum error level of the solc checker after which solium will not run. If t is given solium will always run. The default is warning, so if anything over than a warning is found in solc solium will not run.

Commands

Gas estimate of function under point

You can get an estimate of the function under the cursor, by placing the curson on top of the function name and typing C-c C-g.

This will call solidity-estimate-gas-at-point and provide a max gas estimate, if possible, for the function.

Features

  • Syntax highlighting
  • Indentation
  • On the fly syntax checking with flycheck
  • Gas estimation for function under point

emacs-solidity's People

Contributors

juergenhoetzel avatar lefterisjp avatar purcell avatar scbuergel avatar syohex avatar

Watchers

 avatar  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.