ethereum / emacs-solidity Goto Github PK
View Code? Open in Web Editor NEWThe official solidity-mode for EMACS
License: GNU General Public License v3.0
The official solidity-mode for EMACS
License: GNU General Public License v3.0
I'm having issues with flycheck and I believe it's because solc
is not solc-js
as a command. Not sure if it used to be solc
or not I can't remember.
Thank you for solidity-mode!
When using it to automatically indent code, the indentation of lines after the closing curly brace of a struct is increased by one level until after closing another declaration:
c-mode seems to be expecting a semicolon after the closing curly brace of the struct, but Solidity doesn't require one (and complains if one is provided, although doing so fixed the indentation).
I'm not quite sure how to address this, modifying c-offsets-alist for class-close (the syntactic type returned by C-c C-s) affects the indentation of the curly brace, not the lines that follow it.
I addressed similar issues with my desired indentation for events and other constructs with closing parentheses on a new line using:
(add-to-list 'c-offsets-alist
'(arglist-close . c-lineup-close-paren))
I have add following lines into my .emacs
file but emacs-solidity does not work.
(require 'solidity-mode)
(require 'solidity-flycheck)
(setq solidity-solium-path "/Users/avatar/.npm-packages/lib/node_modules/solium/bin/solium.js")
(setq solidity-solc-path "/Users/avatar/.npm-packages/lib/node_modules/solc/solcjs")
(setq solidity-flycheck-solc-checker-active t)
(setq solidity-flycheck-solium-checker-active t)
solidity-mode 20180912.2154 on melpa does not include company-solidity.el, and loading solidity-mode ends with an error "File mode specification error: (file-missing Cannot open load file No such file or directory company-solidity)".
I'm running into the same issue described here. Flycheck never gets past the import. The solution is to call solc with a remapping like:
@openzeppelin/=$(pwd)/node_modules/@openzeppelin/
How can this be achieved?
Hello. I spent some time to set it up. And isolated the error till found what happens in the code.
Versions installed from Melpa with "package" system.
solidity-flycheck: Commit: 5f6ef3156fadae5af6f381d674d20535529a20e4
flyicheck: Version: 20210708.1337
Commit: 21d52264aa80bfa4ede94c59e37a20fb6d033b0c
solidity-mode: Commit: Commit: 5f6ef3156fadae5af6f381d674d20535529a20e4
.emacs init file
(require 'package)
(package-initialize) ;; You might already have this line
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
'(solidity-flycheck solidity-mode))
)
(setq solidity-flycheck-solc-checker-active t)
(setq solidity-solc-path "/home/user/.local/bin/solc")
(add-hook 'solidity-mode-hook
'(lambda()
(require 'solidity-flycheck)
(flycheck-mode +1)
(flycheck-verify-setup)
))
```
then run console command emacs -nw Contract.sol emacs starts but
displays the error: File mode specification error: (void-function
remove-if-not)
I made some research and found that this is the function from the cl
package. Then I added the line (require 'cl) on the top of
solidity-flycheck.el and everything now works.
Version: elpa/solidity-mode-20221119.1735
Default formatting:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// test
contract Test {
// test
function test () public {
}
// bar
function bar () public {
}
// foo
function foo () public {
}
}
I don't have any special configuration.
(setq solidity-solc-path "/home/lefteris/ew/cpp-ethereum/build/solc/solc")
Can exe be added here
When I have a function test(
and press enter, I would expect the next line to start under the n
, like this:
function test(
some code
Instead, it does this:
function test(
some code
I found an answer on stack overflow that suggests to do the following:
(add-hook 'solidity-mode-hook
(lambda ()
(c-set-offset 'arglist-intro '+)
(c-set-offset 'arglist-close 0)))
It worked for me.
/usr/bin/solc
exists but it seems that there something wrong related that prevents the installation from finishing.
Leaving directory `/home/victor/.emacs.d/elpa/solidity-mode-20160426.31'
Compiling file /home/victor/.emacs.d/elpa/solidity-mode-20160426.31/solidity-mode-pkg.el at Fri Apr 29 13:21:06 2016
Entering directory `/home/victor/.emacs.d/elpa/solidity-mode-20160426.31/'
Compiling file /home/victor/.emacs.d/elpa/solidity-mode-20160426.31/solidity-mode.el at Fri Apr 29 13:21:06 2016
solidity-mode.el:383:1:Warning: `"/usr/bin/solc"' is a malformed function
solidity-mode.el:383:1:Warning: `(error line-start (file-name) ":" line ":"
column ":" " Error: " (message))' is a malformed function
solidity-mode.el:386:28:Warning: reference to free variable `solidity'
solidity-mode.el:388:31:Warning: reference to free variable `source-inplace'
solidity-mode.el:391:12:Warning: reference to free variable `solidity-mode'
solidity-mode.el:393:17:Warning: reference to free variable
`flycheck-checkers'
solidity-mode.el:393:17:Warning: assignment to free variable
`flycheck-checkers'
solidity-mode.el:395:30:Warning: assignment to free variable
`flycheck-solidity-executable'
In end of data:
solidity-mode.el:399:1:Warning: the function `flycheck-define-checker' is not
known to be defined.
Compiling no file at Fri Apr 29 13:24:20 2016
emacs 24.5
Spacemacs 0.105.19
solc 0.3.2-81ae2a78
Please just use //
I recently upgraded to solc version 0.4.24, and I have started getting the following error:
Suspicious state from syntax checker solidity-checker: Flycheck checker solidity-checker returned non-zero exit code 1, but its output contained no errors: unrecognised option '--add-std'
This option was removed in version 0.4.22 of Solidity.
I found the following references regarding how other tools are affected. But I'm not sure if there is a fix/workaround for emacs-solidity
References :
ethereum/solidity#3984
ethereum/solidity#3695
Solution seems to be "upgrade go-ethereum", but how does that help a "linter" functionality of emacs-solidity
?
After install solidity mode, press tab to indent code, it's not working and show follow error message:
Error evaluating offset + for defun-block-intro: Got invalid value tab-width
Using c-c c-o (c-set-offset) to set defun-block-intro to a number other than '+', it's working.
The word integers
is higlighted as int
egers
:
Example contract: https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/08_basiciterator.sol
Is it working with the latest version of solidity and emacs?
Feature request: Port Consensys' vscode solidity auditor plugin into this package
It's a solidity plugin that I've dearly missed ever since I've switched over to Emacs and it's very helpful for auditing smart contracts.
I'm getting an error that the remove-if-not
function is void on startup, and flycheck doesn't work for Solidity.
If I update this to cl-remove-if-not
, then the error warning message on startup doesn't show, and flycheck works for Solidity fine.
Trying to use company-solidity
, I'm getting the following error: Symbol’s value as variable is void: company-backends
My config is:
;;; package --- Solidity mode
;;; Commentary:
;;; Code:
(require-package 'solidity-mode)
(require-package 'solidity-flycheck)
(require-package 'company-solidity)
(...)
(add-hook 'solidity-mode-hook
(lambda ()
(set (make-local-variable 'company-backends)
(append '((company-solidity company-capf company-dabbrev-code))
company-backends))))
(provide 'init-solidity)
;;; init-solidity.el ends here
I'm using emacs 25.2.2 on a Debian based distribution.
The document says:
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.
What happened to me is
el-get-install
. It prompts: "Intsall Package:"solidity-mode
. It prompts: "No Match"I tried to run el-get-list-packages
and the result is a long list that does not contain solidity-mode
This may be an el-get issue but would be great if the instruction can help users avoid this issue.
I am unable to make solidity-flycheck-solc
work. I am not sure what I am doing wrong.
$ solc --version
solc, the solidity compiler commandline interface
Version: 0.6.0+commit.26b70077.Darwin.appleclang
$ which solc
/usr/local/bin/solc
I have following setup in .emacs
file:
(require 'flycheck)
(setq solidity-solc-path "/usr/local/bin/solc")
(require 'solidity-flycheck)
(require 'solidity-mode)
(setq flycheck-solidity-solc-addstd-contracts t)
(setq solidity-flycheck-solc-checker-active t)
(custom-set-variables
'(package-selected-packages
(quote
(solidity-flycheck solidity-mode use-package flymake-python-pyflakes flycheck undo-tree jedi dumb-jump))))
(add-hook 'after-init-hook #'global-flycheck-mode)
=> flycheck-verify-setup
and this is what I got:
Syntax checkers for buffer eBlocBroker.sol in solidity-mode:
There are no syntax checkers for this buffer!
Flycheck Mode is enabled. Use C-u C-c ! x to enable disabled
checkers.
--------------------
Flycheck version: 31
Emacs version: 26.3
System: x86_64-apple-darwin19.0.0
Window system: nil
That would be a nice addition to solidity mode!
The following is the output of install-package
followed by solidity-mode
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
Loading /etc/emacs/site-start.d/50el-get.el (source)...done
Loading display-line-numbers...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Saving file /home/a/.emacs...
Wrote /home/a/.emacs [2 times]
Contacting host: melpa.org:443
package-install-from-archive: https://melpa.org/packages/solidity-mode-20200529.1924.tar: Not found
Hi, I have set all the required configuration properties in my ~/.spacemacs
, but when I run flycheck-verify-setup
on a Solidity file, the output is:
Syntax checkers for buffer Foo.sol in solidity-mode:
There are no syntax checkers for this buffer!
Flycheck Mode is enabled. Use SPC u C-c ! x to enable disabled checkers.
--------------------
Flycheck version: 32snapshot (package: 20190108.351)
Emacs version: 26.1
System: x86_64-pc-linux-gnu
Window system: nil
This seems to be a different problem than solc
not being found - it's rather the checker itself that's not found by flycheck.
I'm using Spacemacs develop [email protected] and have recently updated all packages.
Heya.
I code in Emacs, and I did write modes for lll and (old) Serpent. I'd like to not re-invent the wheel if there's an existing Solidity mode. Is it ready for use yet?
Thanks.
I have solc
in /usr/bin/solc
, but the flycheck checker doesn't seem to find it. I ran flycheck-verify-setup
and this is what I got:
solidity-checker (disabled)
- may enable: Automatically disabled!
- predicate: t
- executable: Not found
I tried setting the solc
location manually but that did not work. Any idea of what the problem could be?
I think this is problematic.
I use
(add-hook 'c-mode-hook #'irony-mode)
in init file, so solidity-mode enable irony-mode (undesirable).
Solidity-mode should be
(define-derived-mode solidity-mode prog-mode "solidity"
?
The checks fail because it transfers the contract to the tmp folder and that doesn't work for imports.
For a package that's actually used by many users it's unthinkable we got no tests here.
Create a test suite for the package and slowly add tests in it.
This may not be the right place to ask but I get FIle mode specification error: (void-function solidity-mode)
Currently, the package expects a semicolon after a struct declaration, and also expects semicolons in assembly blocks.
For example
struct s {
uint x;
}
// emacs expects semicolon here
// so automatically does an extra indent here
function f() {
assembly {
sstore(0, 0)
// emacs expects a semicolon in the line before, so automatically makes an extra indent here again.
}
}
I assume the struct
issue is somehow related to c-mode
or cc-mode
that solidity-mode
derives from.
I had a look at https://www.gnu.org/software/emacs/manual/html_mono/ccmode.html. Unfortunately, I can't find an obvious fix.
Any idea how this can be fixed?
I'm receiving this error message:
Suspicious state from syntax checker solidity-checker: Flycheck checker solidity-checker returned 1, but its output contained no errors: unrecognised option '--old-reporter'
It was removed here: ethereum/solidity#10167
Not sure how to reconcile solidity-checker with the new output.
im having trouble to cleanly import contracts from zeppelin-solidity library.
following the instructions from Getting Started in
https://github.com/OpenZeppelin/zeppelin-solidity
the code compiles and run correctly, but flymake flags the import as an error.
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
this is the error message:
Source "zeppelin-solidity/contracts/ownership/Ownable.sol" not found: Unknow exception in read callback (solidity-checker)
Using solidity-mode version 0.1.9, I'm sometimes (maybe 20% of the time) getting the error “No match 4 in highlight (4 font-lock-variable-name-face)”
when I call swiper
. It's intermittent, so it's hard to narrow down to a straightforward reproduction. Someone else is having the same problem in solidity-mode
buffers. Here is the traceback, in case it's useful:
Debugger entered--Lisp error: (error "No match 4 in highlight (4 font-lock-variable-name-face)")
signal(error ("No match 4 in highlight (4 font-lock-variable-name-face)"))
error("No match %d in highlight %S" 4 (4 font-lock-variable-name-face))
font-lock-apply-highlight((4 font-lock-variable-name-face))
(if (numberp (car (car highlights))) (font-lock-apply-highlight (car highlights)) (set-marker pos (point)) (font-lock-fontify-anchored-keywords (car highlights) end) (if (< (point) pos) (goto-char pos)))
(while highlights (if (numberp (car (car highlights))) (font-lock-apply-highlight (car highlights)) (set-marker pos (point)) (font-lock-fontify-anchored-keywords (car highlights) end) (if (< (point) pos) (goto-char pos))) (setq highlights (cdr highlights)))
(while (and (< (point) end) (if (stringp matcher) (re-search-forward matcher end t) (funcall matcher end)) (or (> (point) (match-beginning 0)) (progn (forward-char 1) t))) (if (and font-lock-multiline (>= (point) (save-excursion (goto-char (match-beginning 0)) (forward-line 1) (point)))) (progn (put-text-property (if (= (point) (save-excursion (goto-char ...) (forward-line 1) (point))) (1- (point)) (match-beginning 0)) (point) (quote font-lock-multiline) t))) (setq highlights (cdr keyword)) (while highlights (if (numberp (car (car highlights))) (font-lock-apply-highlight (car highlights)) (set-marker pos (point)) (font-lock-fontify-anchored-keywords (car highlights) end) (if (< (point) pos) (goto-char pos))) (setq highlights (cdr highlights))))
(while keywords (if loudly (message "Fontifying %s... (regexps..%s)" bufname (make-string (setq count (1+ count)) 46))) (setq keyword (car keywords) matcher (car keyword)) (goto-char start) (while (and (< (point) end) (if (stringp matcher) (re-search-forward matcher end t) (funcall matcher end)) (or (> (point) (match-beginning 0)) (progn (forward-char 1) t))) (if (and font-lock-multiline (>= (point) (save-excursion (goto-char (match-beginning 0)) (forward-line 1) (point)))) (progn (put-text-property (if (= (point) (save-excursion ... ... ...)) (1- (point)) (match-beginning 0)) (point) (quote font-lock-multiline) t))) (setq highlights (cdr keyword)) (while highlights (if (numberp (car (car highlights))) (font-lock-apply-highlight (car highlights)) (set-marker pos (point)) (font-lock-fontify-anchored-keywords (car highlights) end) (if (< (point) pos) (goto-char pos))) (setq highlights (cdr highlights)))) (setq keywords (cdr keywords)))
(let ((case-fold-search font-lock-keywords-case-fold-search) (keywords (cdr (cdr font-lock-keywords))) (bufname (buffer-name)) (count 0) (pos (make-marker)) keyword matcher highlights) (while keywords (if loudly (message "Fontifying %s... (regexps..%s)" bufname (make-string (setq count (1+ count)) 46))) (setq keyword (car keywords) matcher (car keyword)) (goto-char start) (while (and (< (point) end) (if (stringp matcher) (re-search-forward matcher end t) (funcall matcher end)) (or (> (point) (match-beginning 0)) (progn (forward-char 1) t))) (if (and font-lock-multiline (>= (point) (save-excursion (goto-char ...) (forward-line 1) (point)))) (progn (put-text-property (if (= ... ...) (1- ...) (match-beginning 0)) (point) (quote font-lock-multiline) t))) (setq highlights (cdr keyword)) (while highlights (if (numberp (car (car highlights))) (font-lock-apply-highlight (car highlights)) (set-marker pos (point)) (font-lock-fontify-anchored-keywords (car highlights) end) (if (< (point) pos) (goto-char pos))) (setq highlights (cdr highlights)))) (setq keywords (cdr keywords))) (set-marker pos nil))
font-lock-fontify-keywords-region(7692 13007 nil)
font-lock-default-fontify-region(7692 13007 nil)
c-font-lock-fontify-region(7725 13007 nil)
font-lock-fontify-region(7725 13007)
#f(compiled-function (fun) #<bytecode 0x4074159>)(font-lock-fontify-region)
run-hook-wrapped(#f(compiled-function (fun) #<bytecode 0x4074159>) font-lock-fontify-region)
jit-lock--run-functions(7725 13007)
jit-lock-fontify-now(1 13007)
font-lock-ensure()
swiper-font-lock-ensure()
swiper--candidates()
swiper()
funcall-interactively(swiper)
call-interactively(swiper nil nil)
command-execute(swiper)
It would be cool if we could get some integration for the new truffle debugger. I'm not sure if that's possible or not.
Truffle Debugging
I'm using irony-mode one of emacs plugin for C/C++ mode. Here are some lines from my emacs init file that hooks C/C++ mode with irony-mode
.
(use-package irony
:init
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
...)
When I open .sol
file with emacs, I get these error messages.
Warning (irony): Major mode is unknown to Irony, see `irony-supported-major-mod\
es'.
Warning (irony): Major mode is unknown to Irony, see `irony-supported-major-mod\
es'.
How can I fix this without disabling the original hooks?
Thank you.
When using a constructor with many arguments, such that each argument should drop to its own line, the body of the constructor has too many levels of indentation.
The same is not true of a function having the same arguments. That is, functions still format the body correctly, regardless of the style of the function declaration.
The following code demonstrates the issue with the style/format of the constructor:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract SolidityModeExample {
IERC20 public tokenA;
IERC20 public tokenB;
IERC20 public tokenC;
IERC20 public tokenD;
/// @dev The body of this constructor is indented too far, by 8 spaces
constructor (
address _tokenA,
address _tokenB,
address _tokenC,
address _tokenD
)
public
{
tokenA = IERC20(_tokenA);
tokenB = IERC20(_tokenB);
tokenC = IERC20(_tokenC);
tokenD = IERC20(_tokenD);
}
/// @dev The body of this function is indented correctly
function updateTokens (
address _tokenA,
address _tokenB,
address _tokenC,
address _tokenD
)
public
{
tokenA = IERC20(_tokenA);
tokenB = IERC20(_tokenB);
tokenC = IERC20(_tokenC);
tokenD = IERC20(_tokenD);
}
}
Many solidity projects use 2 indents now and solidity-mode seems to default to 4. How can it be changed to 2?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.