Skip to content

Commit e3701bf

Browse files
committed
Starting setting buffer-local variables related to comments in mode (resolves issue #4). Minor refactoring. Incremented version.
1 parent f4c52bc commit e3701bf

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

dotenv-mode.el

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
;; Author: Preetpal S. Sohal
44
;; URL: https://github.com/preetpalS/emacs-dotenv-mode
5-
;; Version: 0.2.4
5+
;; Version: 0.2.5
66
;; Package-Requires: ((emacs "24.3"))
77
;; License: GNU General Public License Version 3
88

@@ -36,6 +36,12 @@
3636
:group 'languages
3737
:prefix "dotenv-")
3838

39+
;; Adapted from code in ruby-mode provided with Emacs
40+
(defcustom dotenv-comment-column (default-value 'comment-column)
41+
"Indentation column of comments."
42+
:type 'integer
43+
:safe 'integerp)
44+
3945
(defvar dotenv-mode-syntax-table
4046
(let ((table (make-syntax-table)))
4147
(modify-syntax-entry ?' "\"'" table) ; ?' is a string delimiter
@@ -78,12 +84,20 @@
7884
("\${[[:alpha:]]+[[:alnum:]_]*}" . font-lock-variable-name-face)
7985
("\$([[:alpha:]]+[[:alnum:]_]*)" . font-lock-variable-name-face)))
8086

87+
(defun dotenv-mode-variables ()
88+
"Initialize buffer-local variables for `dotenv-mode'"
89+
(setq-local comment-start "# ") ;; Added due to suggestion by jscheid (https://github.com/jscheid)
90+
(setq-local comment-end "")
91+
(setq-local comment-column dotenv-comment-column)
92+
(setq-local comment-start-skip "#+ *")
93+
(setq-local font-lock-defaults '((dotenv-mode-keywords))))
94+
8195
;;;###autoload
8296
(define-derived-mode dotenv-mode prog-mode ".env"
8397
"Major mode for `.env' files."
8498
:abbrev-table nil
8599
:syntax-table dotenv-mode-syntax-table
86-
(setq-local font-lock-defaults '((dotenv-mode-keywords))))
100+
(dotenv-mode-variables))
87101

88102
;;;###autoload
89103
(mapc (lambda (s) (add-to-list 'auto-mode-alist `(,s . dotenv-mode)))

0 commit comments

Comments
 (0)