1 ;;; Copyright (C) 2007, 2008 Z RESEARCH Inc. <http://www.zresearch.com>
\r
3 ;;; This program is free software; you can redistribute it and/or modify
\r
4 ;;; it under the terms of the GNU General Public License as published by
\r
5 ;;; the Free Software Foundation; either version 2 of the License, or
\r
6 ;;; (at your option) any later version.
\r
8 ;;; This program is distributed in the hope that it will be useful,
\r
9 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
10 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
11 ;;; GNU General Public License for more details.
\r
13 ;;; You should have received a copy of the GNU General Public License
\r
14 ;;; along with this program; if not, write to the Free Software
\r
15 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
18 (defvar glusterfs-mode-hook nil)
\r
20 ;; (defvar glusterfs-mode-map
\r
21 ;; (let ((glusterfs-mode-map (make-keymap)))
\r
22 ;; (define-key glusterfs-mode-map "\C-j" 'newline-and-indent)
\r
23 ;; glusterfs-mode-map)
\r
24 ;; "Keymap for WPDL major mode")
\r
26 (add-to-list 'auto-mode-alist '("\\.vol\\'" . glusterfs-mode))
\r
28 (defconst glusterfs-font-lock-keywords-1
\r
30 ; "cluster/{unify,afr,stripe}"
\r
31 ; "performance/{io-cache,io-threads,write-behind,read-ahead,stat-prefetch}"
\r
32 ; "protocol/{client/server}"
\r
33 ; "features/{trash,posix-locks,fixed-id,filter}"
\r
35 ; "encryption/rot-13"
\r
37 '("\\<\\(cluster/\\(unify\\|afr\\|stripe\\)\\|\\performance/\\(io-\\(cache\\|threads\\)\\|write-behind\\|read-ahead\\|stat-prefetch\\|booster\\)\\|protocol/\\(server\\|client\\)\\|features/\\(trash\\|posix-locks\\|fixed-id\\|path-converter\\|filter\\)\\|storage/\\(posix\\|bdb\\)\\|encryption/rot-13\\|debug/trace\\)\\>" . font-lock-keyword-face))
\r
38 "Additional Keywords to highlight in GlusterFS mode.")
\r
40 (defconst glusterfs-font-lock-keywords-2
\r
41 (append glusterfs-font-lock-keywords-1
\r
43 ; "replicate" "namespace" "scheduler" "remote-subvolume" "remote-host"
\r
44 ; "auth.addr" "block-size" "remote-port" "listen-port" "transport-type"
\r
45 ; "limits.min-free-disk" "directory"
\r
46 ; TODO: add all the keys here.
\r
47 '("\\<\\(inode-lru-limit\\|replicate\\|namespace\\|scheduler\\|username\\|password\\|allow\\|reject\\|block-size\\|listen-port\\|transport-type\\|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)))
\r
48 "option keys in GlusterFS mode.")
\r
50 (defconst glusterfs-font-lock-keywords-3
\r
51 (append glusterfs-font-lock-keywords-2
\r
53 ; "option" "volume" "end-volume" "subvolumes" "type"
\r
54 '("\\<\\(option\ \\|volume\ \\|subvolumes\ \\|type\ \\|end-volume\\)\\>" . font-lock-builtin-face)))
\r
55 ;'((regexp-opt (" option " "^volume " "^end-volume" "subvolumes " " type ") t) . font-lock-builtin-face))
\r
56 "Minimal highlighting expressions for GlusterFS mode.")
\r
59 (defvar glusterfs-font-lock-keywords glusterfs-font-lock-keywords-3
\r
60 "Default highlighting expressions for GlusterFS mode.")
\r
62 (defvar glusterfs-mode-syntax-table
\r
63 (let ((glusterfs-mode-syntax-table (make-syntax-table)))
\r
64 (modify-syntax-entry ?\# "<" glusterfs-mode-syntax-table)
\r
65 (modify-syntax-entry ?* ". 23" glusterfs-mode-syntax-table)
\r
66 (modify-syntax-entry ?\n ">#" glusterfs-mode-syntax-table)
\r
67 glusterfs-mode-syntax-table)
\r
68 "Syntax table for glusterfs-mode")
\r
70 ;; TODO: add an indentation table
\r
72 (defun glusterfs-indent-line ()
\r
73 "Indent current line as GlusterFS code"
\r
77 (indent-line-to 0) ; First line is always non-indented
\r
78 (let ((not-indented t) cur-indent)
\r
79 (if (looking-at "^[ \t]*volume\ ")
\r
83 (setq not-indented nil)
\r
84 (setq cur-indent 0))))
\r
85 (if (looking-at "^[ \t]*end-volume")
\r
89 (setq cur-indent 0))
\r
90 (if (< cur-indent 0) ; We can't indent past the left margin
\r
91 (setq cur-indent 0)))
\r
93 (while not-indented ; Iterate backwards until we find an indentation hint
\r
95 (setq cur-indent 4) ; Do the actual indenting
\r
96 (setq not-indented nil)))))
\r
98 (indent-line-to cur-indent)
\r
99 (indent-line-to 0)))))
\r
101 (defun glusterfs-mode ()
\r
103 (kill-all-local-variables)
\r
104 ;; (use-local-map glusterfs-mode-map)
\r
105 (set-syntax-table glusterfs-mode-syntax-table)
\r
106 (set (make-local-variable 'indent-line-function) 'glusterfs-indent-line)
\r
107 (set (make-local-variable 'font-lock-defaults) '(glusterfs-font-lock-keywords))
\r
108 (setq major-mode 'glusterfs-mode)
\r
109 (setq mode-name "GlusterFS")
\r
110 (run-hooks 'glusterfs-mode-hook))
\r
112 (provide 'glusterfs-mode)
\r