                                 (if coding (format "coding:%s; " coding) "")
                                 (if mode (format "mode:%s; " mode) ""))))
     (if (or coding mode)
-        (insert magic-comment)
-      (message "Both current coding and major-mode are nil."))))
+        (let ()
+          (goto-char (point-min))
+          (if (looking-at "^#!") (beginning-of-line 2))
+          (insert magic-comment)
+          (comment-region (line-beginning-position) (line-end-position))
+          (newline))
+      (message "Error: both current coding and major-mode are nil."))))
 
 ;; 確認なしでバッファの削除
 (defun kui/kill-buffer-with-no-confirmation ()
   (interactive)
   (kill-buffer nil))
 (global-set-key "\C-xk" 'kui/kill-buffer-with-no-confirmation)
-
 
 ;; -------------------------------------------------------------------------
 ;; 便利な感じのマイナーモード

  )

;; yaml-mode
(when (autoload-if-exist 'yaml-mode "yaml-mode"
                         "Major mode for editing yaml files" t)

  (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))

  )

;; coffee-mode
(when (kui/autoload-if-exist 'coffee-mode "coffee-mode"
                         "Major mode for editing coffescript files" t)

  (add-to-list 'auto-mode-alist '("\\.coffee\\'" . coffee-mode))
