Skip to content

Commit 4cde56c

Browse files
authored
Merge pull request #20 from ethereum/option_to_customize_comment_style
Option to customize comment style
2 parents 83a6826 + 0e3dbb6 commit 4cde56c

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

README.org

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ Regardless of where you installed solidity mode from, you need to require the pa
3030
#+END_SRC
3131
(append that line to your =~/.emacs= file)
3232

33+
You can also set the way the comments are inserted by emacs with commands like =comment-region=. The default is
34+
=/* .. */= and you can turn it to using =//= instead by putting the following into your emacs config:
35+
36+
#+BEGIN_SRC lisp
37+
(setq solidity-comment-style 'slash)
38+
;; or
39+
(setq solidity-comment-style 'star) ;; this is the default
40+
#+END_SRC
41+
3342
** Keymap
3443
You can modify the default keybindings of the solidity mode keymap by adding
3544
a new key combination for each command you want to change. For example

changelog.MD

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

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

5+
## Version 0.1.7
6+
7+
- Allow for customization of the way that emacs inserts comments into the source file via
8+
9+
```emacs-lisp
10+
(setq solidity-comment-style 'slash)
11+
;; or
12+
(setq solidity-comment-style 'star) ;; this is the default
13+
```
14+
515
## Version 0.1.6
616

717
- Add gas estimation code. User facing function is `solidity-estimate-gas-at-point`.

solidity-mode.el

+28-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;; Author: Lefteris Karapetsas <[email protected]>
66
;; Keywords: languages
7-
;; Version: 0.1.6
7+
;; Version: 0.1.7
88

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

100+
(defcustom solidity-comment-style 'star
101+
"Denotes the style of comments to use for solidity when commenting.
102+
103+
This option will define what kind of comments will be input into the buffer by
104+
commands like `comment-region'. The default value is 'star.
105+
Possible values are:
106+
107+
`star'
108+
Follow the same styling as C mode does by default having all comments
109+
obey the /* .. */ style.
110+
111+
`slash'
112+
All comments will start with //."
113+
:group 'solidity
114+
:type '(choice (const :tag "Commenting starts with /* and ends with */" star)
115+
(const :tag "Commenting starts with //" slash))
116+
:package-version '(solidity . "0.1.7")
117+
:safe #'symbolp)
118+
100119
(defvar solidity-mode-map
101120
(let ((map (make-sparse-keymap)))
102121
(define-key map "\C-j" 'newline-and-indent)
@@ -529,9 +548,13 @@ Cursor must be at the function's name. Does not currently work for constructors
529548
(set-syntax-table solidity-mode-syntax-table)
530549
;; specify syntax highlighting
531550
(setq font-lock-defaults '(solidity-font-lock-keywords))
532-
;; register indentation functions, basically the c-mode ones
533-
(make-local-variable 'comment-start)
534-
(make-local-variable 'comment-end)
551+
552+
;; register indentation and other langue mode functions, basically the c-mode ones with some modifications
553+
(let ((start-value (if (eq solidity-comment-style 'star) "/* " "// "))
554+
(end-value (if (eq solidity-comment-style 'star) " */" "")))
555+
(set (make-local-variable 'comment-start) start-value)
556+
(set (make-local-variable 'comment-end) end-value))
557+
535558
(make-local-variable 'comment-start-skip)
536559

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

544-
;; now set their values
567+
;; set values for some other variables
545568
(set (make-local-variable 'parse-sexp-ignore-comments) t)
546569
(set (make-local-variable 'indent-line-function) 'c-indent-line)
547570
(set (make-local-variable 'indent-region-function) 'c-indent-region)

0 commit comments

Comments
 (0)