Y.A.S.D.

« azusa | Main | 健康診断 »

...

(defun TT:c-header-file-ifndef-encapsulate ()
  (let ((filename buffer-file-name)
        (commentform (if (eq major-mode 'c++-mode) " // %s
" " /* %s */
"))
        (identifier) (p))
    (when (and (null (file-attributes filename))        ; new file
               (string-match "\.\(h\|hh\)$" filename))
      (setq identifier
            (concat "_"
                    (mapconcat
                     'upcase
                     (split-string (file-name-nondirectory filename) "\.")
                     "_")))
      (goto-char (point-min))
      (insert "#ifndef " identifier "
#define " identifier "
")
      (setq p (point-max))
      (insert "
#endif" (format commentform identifier))
      (goto-char p))))
(add-hook 'c-mode-common-hook
          (function (lambda () (TT:c-header-file-ifndef-encapsulate))))

うーん,便利だけどダサいね。 新規 file かどうかの判定って,どうやるのがカッチョいいのかな。

 

Comments:

Post a Comment:
  • HTML Syntax: Allowed

[Masubi]
Copyright © 1998-2009 Tomoaki TSUMURA. Powered by Apache Roller 4.0.1.
tomoaki@tsumura.info