help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: insert-header-preprocessor-definition


From: Emanuel Berg
Subject: Re: insert-header-preprocessor-definition
Date: Thu, 12 Apr 2018 00:07:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Ben Bacarisse wrote:

>> So for color.c, color.h should have
>> H_COLOR_H?
>
> That is safe, yes. Doing it by hand, I think
> most people write H_COLOR but you can't even
> be sure there will be a .h in the name!

(defun insert-header-preprocessor-definition ()
  (interactive)
  (let*((filename (buffer-name))
        (label (upcase (replace-regexp-in-string "\\." "_" filename)))
        (safe-label (concat "H_" label))
        (beg-string (concat
                     "#ifndef " safe-label "\n"
                     "#define " safe-label "\n\n"))
        (end-string "\n#endif") )
    (save-excursion
      (goto-char (point-min))
      (insert beg-string)

      (goto-char (point-max))
      (beginning-of-line)
      (insert end-string) )
    ))
(defalias 'hep #'insert-header-preprocessor-definition)

http://user.it.uu.se/~embe8573/emacs-init/ide/c-and-cpp.el

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]