Skip to content

Commit 41afbab

Browse files
committed
User can now customize comment style
Default is /* .. */ Customize through ```emacs-lisp (setq solidity-comment-style 'slash) ;; or (setq solidity-comment-style 'star) ``` Fix #10
1 parent 83a6826 commit 41afbab

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

solidity-mode.el

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

55
;; Author: Lefteris Karapetsas <lefteris@refu.co>
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)