]> git.donarmstrong.com Git - lib.git/blob - emacs_el/glusterfs-mode.el
fix missing ) for org-mode
[lib.git] / emacs_el / glusterfs-mode.el
1 ;;; Copyright (C) 2007, 2008 Z RESEARCH Inc. <http://www.zresearch.com>\r
2 ;;;  \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
7 ;;;  \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
12 ;;;  \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
16 ;;;  \r
17 \r
18 (defvar glusterfs-mode-hook nil)\r
19 \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
25 \r
26 (add-to-list 'auto-mode-alist '("\\.vol\\'" . glusterfs-mode))\r
27 \r
28 (defconst glusterfs-font-lock-keywords-1\r
29   (list\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
34                                         ; "stroage/posix"\r
35                                         ; "encryption/rot-13"\r
36                                         ; "debug/trace"\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
39 \r
40 (defconst glusterfs-font-lock-keywords-2\r
41   (append glusterfs-font-lock-keywords-1\r
42           (list\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
49 \r
50 (defconst glusterfs-font-lock-keywords-3\r
51   (append glusterfs-font-lock-keywords-2\r
52           (list\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
57 \r
58 \r
59 (defvar glusterfs-font-lock-keywords glusterfs-font-lock-keywords-3\r
60   "Default highlighting expressions for GlusterFS mode.")\r
61 \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
69 \r
70 ;; TODO: add an indentation table\r
71 \r
72 (defun glusterfs-indent-line ()\r
73   "Indent current line as GlusterFS code"\r
74   (interactive)\r
75   (beginning-of-line)\r
76   (if (bobp)\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
80           (progn\r
81             (save-excursion\r
82               (forward-line -1)\r
83               (setq not-indented nil)\r
84               (setq cur-indent 0))))\r
85       (if (looking-at "^[ \t]*end-volume")\r
86           (progn\r
87             (save-excursion\r
88               (forward-line -1)\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
92         (save-excursion\r
93           (while not-indented ; Iterate backwards until we find an indentation hint\r
94             (progn\r
95               (setq cur-indent 4) ; Do the actual indenting\r
96               (setq not-indented nil)))))\r
97       (if cur-indent\r
98           (indent-line-to cur-indent)\r
99         (indent-line-to 0)))))\r
100 \r
101 (defun glusterfs-mode ()\r
102   (interactive)\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
111 \r
112 (provide 'glusterfs-mode)\r