espresso.elのswitch-caseのインデントの修正

http://e-arrows.sakura.ne.jp/2010/12/closure-library-on-js2-mode.htmlを参考に設定していたのだけど,これだとcaseの中身のインデントがうまくいかなかった.

myapp.main = function() {
  var Fruit = some.namespace.Fruit;
  switch (fruit) {
    case Fruit.APPLE:
    print(1);
    case Fruit.BANANA:
    print(2);
    default:
    print(3);
  }
};

こうなってほしいはず.

myapp.main = function() {
  var Fruit = some.namespace.Fruit;
  switch (fruit) {
    case Fruit.APPLE:
      print(1);
    case Fruit.BANANA:
      print(2);
    default:
      print(3);
  }
};

その修正と,ついでにEditing JavaScript with Emacs — js2-mode / Projects / Mishoo's homepageを参考にしてvarの所の修正も取り入れた.

(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

(eval-when-compile
  (require 'espresso))

(eval-after-load 'js2-mode
  '(progn
     (require 'espresso)))

(defun my-js-indent-line ()
  (interactive)
  (let* ((parse-status (save-excursion (syntax-ppss (point-at-bol))))
         (offset (- (current-column) (current-indentation)))
         (indentation (espresso--proper-indentation parse-status)))
    (back-to-indentation)

    ;; switch の中は余分に一つインデント
    (cond ((let ((pos (nth 1 parse-status)))
             (and pos
                  (not (looking-at "}"))
                  (save-excursion
                    (goto-char pos)
                    (back-to-indentation)
                    (looking-at "switch\\W"))))
           (indent-line-to (+ indentation espresso-indent-level)))
          ;; consecutive declarations in a var statement are nice if
          ;; properly aligned, i.e:
          ;;
          ;; var foo = "bar",
          ;;     bar = "foo";
          ((let ((node (js2-node-at-point)))
             (and node
                  (= js2-NAME (js2-node-type node))
                  (= js2-VAR (js2-node-type (js2-node-parent node)))))
           (indent-line-to (+ 4 indentation)))
          (t
           (espresso-indent-line)))
    (when (> offset 0) (forward-char offset))))

(add-hook 'js2-mode-hook
          '(lambda ()
             (setq espresso-indent-level 2
                   espresso-expr-indent-offset 2)
             (set (make-local-variable 'indent-line-function) 'my-js-indent-line)))

これで大丈夫なのか全く自信が無い.