Skip to content

Commit

Permalink
Merge pull request #20 from ethereum/option_to_customize_comment_style
Browse files Browse the repository at this point in the history
Option to customize comment style
  • Loading branch information
LefterisJP authored Dec 30, 2017
2 parents 83a6826 + 0e3dbb6 commit 4cde56c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ Regardless of where you installed solidity mode from, you need to require the pa
#+END_SRC
(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:

#+BEGIN_SRC lisp
(setq solidity-comment-style 'slash)
;; or
(setq solidity-comment-style 'star) ;; this is the default
#+END_SRC

** 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
Expand Down
10 changes: 10 additions & 0 deletions changelog.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

The changelog starts from version 0.1.4 as too much was added in each version before that.

## Version 0.1.7

- Allow for customization of the way that emacs inserts comments into the source file via

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

## Version 0.1.6

- Add gas estimation code. User facing function is `solidity-estimate-gas-at-point`.
Expand Down
33 changes: 28 additions & 5 deletions solidity-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

;; Author: Lefteris Karapetsas <[email protected]>
;; Keywords: languages
;; Version: 0.1.6
;; Version: 0.1.7

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -97,6 +97,25 @@ Possible values are:
:package-version '(solidity . "0.1.5")
:safe #'symbolp)

(defcustom solidity-comment-style 'star
"Denotes the style of comments to use for solidity when commenting.
This option will define what kind of comments will be input into the buffer by
commands like `comment-region'. The default value is 'star.
Possible values are:
`star'
Follow the same styling as C mode does by default having all comments
obey the /* .. */ style.
`slash'
All comments will start with //."
:group 'solidity
:type '(choice (const :tag "Commenting starts with /* and ends with */" star)
(const :tag "Commenting starts with //" slash))
:package-version '(solidity . "0.1.7")
:safe #'symbolp)

(defvar solidity-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-j" 'newline-and-indent)
Expand Down Expand Up @@ -529,9 +548,13 @@ Cursor must be at the function's name. Does not currently work for constructors
(set-syntax-table solidity-mode-syntax-table)
;; specify syntax highlighting
(setq font-lock-defaults '(solidity-font-lock-keywords))
;; register indentation functions, basically the c-mode ones
(make-local-variable 'comment-start)
(make-local-variable 'comment-end)

;; register indentation and other langue mode functions, basically the c-mode ones with some modifications
(let ((start-value (if (eq solidity-comment-style 'star) "/* " "// "))
(end-value (if (eq solidity-comment-style 'star) " */" "")))
(set (make-local-variable 'comment-start) start-value)
(set (make-local-variable 'comment-end) end-value))

(make-local-variable 'comment-start-skip)

(make-local-variable 'paragraph-start)
Expand All @@ -541,7 +564,7 @@ Cursor must be at the function's name. Does not currently work for constructors
(make-local-variable 'adaptive-fill-regexp)
(make-local-variable 'fill-paragraph-handle-comment)

;; now set their values
;; set values for some other variables
(set (make-local-variable 'parse-sexp-ignore-comments) t)
(set (make-local-variable 'indent-line-function) 'c-indent-line)
(set (make-local-variable 'indent-region-function) 'c-indent-region)
Expand Down

0 comments on commit 4cde56c

Please sign in to comment.