glusterfs

Форк
0
/
glusterfs-mode.el 
113 строк · 5.1 Кб
1
;;; Copyright (C) 2007-2017 Red Hat, Inc. <http://www.redhat.com>
2
;;; Copyright (C) 2007-2011 Gluster Inc. <http://www.gluster.com>
3
;;;
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.
8
;;;
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.
13
;;;
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.
17
;;;
18

19
(defvar glusterfs-mode-hook nil)
20

21
;; (defvar glusterfs-mode-map
22
;;   (let ((glusterfs-mode-map (make-keymap)))
23
;;     (define-key glusterfs-mode-map "\C-j" 'newline-and-indent)
24
;;     glusterfs-mode-map)
25
;;   "Keymap for WPDL major mode")
26

27
(add-to-list 'auto-mode-alist '("\\.vol\\'" . glusterfs-mode))
28

29
(defconst glusterfs-font-lock-keywords-1
30
  (list
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}"
35
					; "storage/posix"
36
					; "encryption/rot-13"
37
					; "debug/trace"
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.")
40

41
(defconst glusterfs-font-lock-keywords-2
42
  (append glusterfs-font-lock-keywords-1
43
	  (list
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.")
50

51
(defconst glusterfs-font-lock-keywords-3
52
  (append glusterfs-font-lock-keywords-2
53
	  (list
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.")
58

59

60
(defvar glusterfs-font-lock-keywords glusterfs-font-lock-keywords-3
61
  "Default highlighting expressions for GlusterFS mode.")
62

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")
70

71
;; TODO: add an indentation table
72

73
(defun glusterfs-indent-line ()
74
  "Indent current line as GlusterFS code"
75
  (interactive)
76
  (beginning-of-line)
77
  (if (bobp)
78
      (indent-line-to 0)   ; First line is always non-indented
79
    (let ((not-indented t) cur-indent)
80
      (if (looking-at "^[ \t]*volume\ ")
81
	  (progn
82
	    (save-excursion
83
	      (forward-line -1)
84
	      (setq not-indented nil)
85
	      (setq cur-indent 0))))
86
      (if (looking-at "^[ \t]*end-volume")
87
	  (progn
88
	    (save-excursion
89
	      (forward-line -1)
90
	      (setq cur-indent 0))
91
	    (if (< cur-indent 0) ; We can't indent past the left margin
92
		(setq cur-indent 0)))
93
	(save-excursion
94
	  (while not-indented ; Iterate backwards until we find an indentation hint
95
	    (progn
96
	      (setq cur-indent 2) ; Do the actual indenting
97
	      (setq not-indented nil)))))
98
      (if cur-indent
99
	  (indent-line-to cur-indent)
100
	(indent-line-to 0)))))
101

102
(defun glusterfs-mode ()
103
  (interactive)
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))
112

113
(provide 'glusterfs-mode)
114

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.