Permalink
Browse files

Add mode for editing fish shell code.

  • Loading branch information...
1 parent 944cb3f commit 217da5cd16db5b41a10496238b3bd9e961e5b308 @bodil committed Dec 29, 2013
Showing with 75 additions and 7 deletions.
  1. +5 −7 bodil-misc-modes.el
  2. +70 −0 site-lisp/misc/fish-mode.el
View
@@ -1,12 +1,10 @@
;;; bodil-misc-modes.el -- Miscellaneous modes.
-;; Puppet config files
-(package-require 'puppet-mode)
-(add-to-list 'auto-mode-alist '("\\.pp$" . puppet-mode))
-
-;; Varnish config files
-(package-require 'vcl-mode)
-(add-to-list 'auto-mode-alist '("\\.vcl$" . vcl-mode))
+;; Fish shell
+(autoload 'fish-mode "fish-mode" nil t)
+(add-to-list 'auto-mode-alist '("\\.fish\\'" . fish-mode))
+(add-to-list 'interpreter-mode-alist '("fish" . fish-mode))
+(add-hook 'fish-mode-hook (lambda () (setq tab-width 2)))
;; Scala
(package-require 'scala-mode2)
@@ -0,0 +1,70 @@
+(defcustom fish-mode-hook nil
+ "Hook of fish-mode")
+
+(defconst fish-font-lock-keywords-1
+ (list
+ '("\\<\\(a\\(?:lias\\|nd\\)\\|b\\(?:egin\\|g\\|ind\\|lock\\|reak\\(?:point\\)?\\|uiltin\\)\\|c\\(?:ase\\|d\\|o\\(?:m\\(?:mand\\(?:line\\)?\\|plete\\)\\|nt\\(?:ains\\|inue\\)\\|unt\\)\\)\\|d\
+ir[hs]\\|e\\(?:cho\\|lse\\|mit\\|nd\\|val\\|x\\(?:ec\\|it\\)\\)\\|f\\(?:g\\|ish\\(?:_\\(?:config\\|indent\\|p\\(?:ager\\|rompt\\)\\|right_prompt\\|update_completions\\)\\|d\\)?\\|or\\|\
+unc\\(?:ed\\|save\\|tions?\\)\\)\\|h\\(?:elp\\|istory\\)\\|i\\(?:f\\|satty\\)\\|jobs\\|m\\(?:ath\\|imedb\\)\\|n\\(?:extd\\|ot\\)\\|o\\(?:pen\\|r\\)\\|p\\(?:opd\\|revd\\|sub\\|\\(?:ush\\
+\|w\\)d\\)\\|r\\(?:andom\\|e\\(?:ad\\|turn\\)\\)\\|s\\(?:et\\(?:_color\\)?\\|ource\\|tatus\\|witch\\)\\|t\\(?:est\\|rap\\|ype\\)\\|u\\(?:limit\\|mask\\)\\|vared\\|while\\)\\>"
+ . font-lock-builtin-face)
+ '("\\$\\([[:alpha:]_][[:alnum:]_]*\\)" . font-lock-variable-name-face)))
+
+(defvar fish-mode-syntax-table
+ (let ((fish-mode-syntax-table (make-syntax-table)))
+ (modify-syntax-entry ?# "<")
+ (modify-syntax-entry ?\n ">")
+ (modify-syntax-entry ?\" "\"\"")
+ (modify-syntax-entry ?\' "\"'")))
+
+(defun fish-indent-line ()
+ "Indent current line."
+ (interactive)
+ (beginning-of-line)
+
+ (if (bobp)
+ (indent-line-to 0)
+ (let ((not-indented t) cur-indent)
+ (if (looking-at "^[ \t]*end")
+ (progn
+ (save-excursion
+ (forward-line -1)
+ (setq cur-indent (- (current-indentation) tab-width)))
+ (if (< cur-indent 0)
+ (setq cur-indent 0)))
+ (save-excursion
+ (while not-indented
+ (forward-line -1)
+ (if (looking-at "^[ \t]*end")
+ (progn
+ (forward-line -1)
+ (setq cur-indent (- (current-indentation) tab-width))
+ (if (< cur-indent 0)
+ (setq cur-indent 0))
+ (forward-line 1)
+ (indent-line-to cur-indent)
+ (setq not-indented nil))
+ ; TODO: one-line function
+ (if (looking-at "[ \t]*\\(begin\\|case\\|else\\|for\\|function \\|if\\|switch\\|while\\)")
+ (progn
+ (setq cur-indent (+ (current-indentation) tab-width))
+ (setq not-indented nil))
+ (if (bobp)
+ (setq not-indented nil)))))))
+ (if cur-indent
+ (indent-line-to cur-indent)
+ (indent-line-to 0)))))
+
+(defun fish-mode ()
+ (interactive)
+ (kill-all-local-variables)
+ (setq-local indent-line-function 'fish-indent-line)
+ (setq-local font-lock-defaults '(fish-font-lock-keywords-1))
+ (setq-local comment-start "# ")
+ (setq-local comment-start-skip "#+[\t ]*")
+ (run-hooks 'fish-mode-hook))
+
+(add-to-list 'auto-mode-alist '("\\.fish\\'" . fish-mode))
+(add-to-list 'interpreter-mode-alist '("fish" . fish-mode))
+
+(provide 'fish-mode)

0 comments on commit 217da5c

Please sign in to comment.