1
;;; Copyright (C) 2007-2017 Red Hat, Inc. <http://www.redhat.com>
2
;;; Copyright (C) 2007-2011 Gluster Inc. <http://www.gluster.com>
4
;;; This program is free software; you can redistribute it and/or
5
;;; modify it under the terms of the GNU General Public License
6
;;; as published by the Free Software Foundation; either version 2
7
;;; of the License, or (at your option) any later version.
9
;;; This program is distributed in the hope that it will be useful,
10
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
;;; GNU General Public License for more details.
14
;;; You should have received a copy of the GNU General Public License
15
;;; along with this program; if not, write to the Free Software
16
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
(defvar glusterfs-mode-hook nil)
21
;; (defvar glusterfs-mode-map
22
;; (let ((glusterfs-mode-map (make-keymap)))
23
;; (define-key glusterfs-mode-map "\C-j" 'newline-and-indent)
25
;; "Keymap for WPDL major mode")
27
(add-to-list 'auto-mode-alist '("\\.vol\\'" . glusterfs-mode))
29
(defconst glusterfs-font-lock-keywords-1
31
; "cluster/{unify,afr,stripe}"
32
; "performance/{io-cache,io-threads,write-behind,read-ahead,stat-prefetch}"
33
; "protocol/{client/server}"
34
; "features/{trash,posix-locks,fixed-id,filter}"
38
'("\\<\\(cluster/\\(unify\\|afr\\|replicate\\|stripe\\|ha\\|dht\\|distribute\\)\\|\\performance/\\(io-\\(cache\\|threads\\)\\|write-behind\\|read-ahead\\|symlink-cache\\)\\|protocol/\\(server\\|client\\)\\|features/\\(trash\\|posix-locks\\|locks\\|path-converter\\|filter\\)\\|storage/\\(posix\\|bdb\\)\\|encryption/rot-13\\|debug/trace\\)\\>" . font-lock-keyword-face))
39
"Additional Keywords to highlight in GlusterFS mode.")
41
(defconst glusterfs-font-lock-keywords-2
42
(append glusterfs-font-lock-keywords-1
44
; "replicate" "namespace" "scheduler" "remote-subvolume" "remote-host"
45
; "auth.addr" "block-size" "remote-port" "listen-port" "transport-type"
46
; "limits.min-free-disk" "directory"
47
; TODO: add all the keys here.
48
'("\\<\\(inode-lru-limit\\|replicate\\|namespace\\|scheduler\\|username\\|password\\|allow\\|reject\\|block-size\\|listen-port\\|transport-type\\|transport-timeout\\|directory\\|page-size\\|page-count\\|aggregate-size\\|non-blocking-io\\|client-volume-filename\\|bind-address\\|self-heal\\|read-only-subvolumes\\|read-subvolume\\|thread-count\\|cache-size\\|window-size\\|force-revalidate-timeout\\|priority\\|include\\|exclude\\|remote-\\(host\\|subvolume\\|port\\)\\|auth.\\(addr\\|login\\)\\|limits.\\(min-disk-free\\|transaction-size\\|ib-verbs-\\(work-request-\\(send-\\|recv-\\(count\\|size\\)\\)\\|port\\|mtu\\|device-name\\)\\)\\)\ \\>" . font-lock-constant-face)))
49
"option keys in GlusterFS mode.")
51
(defconst glusterfs-font-lock-keywords-3
52
(append glusterfs-font-lock-keywords-2
54
; "option" "volume" "end-volume" "subvolumes" "type"
55
'("\\<\\(option\ \\|volume\ \\|subvolumes\ \\|type\ \\|end-volume\\)\\>" . font-lock-builtin-face)))
56
;'((regexp-opt (" option " "^volume " "^end-volume" "subvolumes " " type ") t) . font-lock-builtin-face))
57
"Minimal highlighting expressions for GlusterFS mode.")
60
(defvar glusterfs-font-lock-keywords glusterfs-font-lock-keywords-3
61
"Default highlighting expressions for GlusterFS mode.")
63
(defvar glusterfs-mode-syntax-table
64
(let ((glusterfs-mode-syntax-table (make-syntax-table)))
65
(modify-syntax-entry ?\# "<" glusterfs-mode-syntax-table)
66
(modify-syntax-entry ?* ". 23" glusterfs-mode-syntax-table)
67
(modify-syntax-entry ?\n ">#" glusterfs-mode-syntax-table)
68
glusterfs-mode-syntax-table)
69
"Syntax table for glusterfs-mode")
71
;; TODO: add an indentation table
73
(defun glusterfs-indent-line ()
74
"Indent current line as GlusterFS code"
78
(indent-line-to 0) ; First line is always non-indented
79
(let ((not-indented t) cur-indent)
80
(if (looking-at "^[ \t]*volume\ ")
84
(setq not-indented nil)
85
(setq cur-indent 0))))
86
(if (looking-at "^[ \t]*end-volume")
91
(if (< cur-indent 0) ; We can't indent past the left margin
94
(while not-indented ; Iterate backwards until we find an indentation hint
96
(setq cur-indent 2) ; Do the actual indenting
97
(setq not-indented nil)))))
99
(indent-line-to cur-indent)
100
(indent-line-to 0)))))
102
(defun glusterfs-mode ()
104
(kill-all-local-variables)
105
;; (use-local-map glusterfs-mode-map)
106
(set-syntax-table glusterfs-mode-syntax-table)
107
(set (make-local-variable 'indent-line-function) 'glusterfs-indent-line)
108
(set (make-local-variable 'font-lock-defaults) '(glusterfs-font-lock-keywords))
109
(setq major-mode 'glusterfs-mode)
110
(setq mode-name "GlusterFS")
111
(run-hooks 'glusterfs-mode-hook))
113
(provide 'glusterfs-mode)