         path
       (file-name-directory
        (directory-file-name (kui/parent-directory path (- num 1)))))))
+
+(defun kui/traverse-parents-for (filename &optional dirname)
+  "Find FILENAME from parent directories of the current buffer file or DIRNAME"
+  (if dirname
+      (let ((path (concat (file-name-as-directory dirname) filename)))
+        (if (file-exists-p path)
+            path
+          (if (string= "/" dirname)
+              nil
+            (kui/traverse-parents-for filename
+                                      (file-name-directory
+                                       (directory-file-name dirname)))
+            )))
+    (kui/traverse-parents-for filename
+                              (file-name-directory buffer-file-name))))
 
 ;; -------------------------------------------------------------------------
 ;; 便利な感じのマイナーモード

      auto-save-list-file-prefix emacs-bk-dir)

;; http://emacsformacosx.com/ 向け設定
(setq ns-command-modifier (quote meta))
(setq ns-alternate-modifier (quote super))

;; ロックファイル(.#で始まるファイル) を無効化
(setq create-lockfiles nil)

;; js-mode
(kui/after-loaded "js"
  (setq js-indent-level 2)

  (defun kui/find-node-modules-bin (binname)
    "Find executable file named BINNAME from the node_modules directory"
    (let* ((moddir (kui/traverse-parents-for "node_modules"))
           (bin (if moddir (format "%s/.bin/%s" moddir binname))))
      (if (file-executable-p bin) bin)))

  (kui/with-lib "flycheck"
    (defun kui/flycheck-set-node-modules-bin (checker binname)
      (let* ((bin (kui/find-node-modules-bin binname)))
        (when bin
          (message "auto-detect %s: %s" binname bin)
          (flycheck-set-checker-executable checker bin))))
    (defun kui/flycheck-set-checker-executable-from-node-modules ()
      (kui/flycheck-set-node-modules-bin 'javascript-jshint "jshint")
      (kui/flycheck-set-node-modules-bin 'javascript-eslint "eslint"))
    (add-hook 'js-mode-hook 'kui/flycheck-set-checker-executable-from-node-modules))
  )

;; html-mode
