--- Begin Message ---
Subject: |
25.0.50; Special characters not stripped on C/C++ header auto-insert |
Date: |
Tue, 2 Dec 2014 15:23:37 +0000 |
The default value of auto-insert-alist is rather unhelpful if you have a
C/C++ header file called something like foo-bar.h because the generated
header guard looks something like
#ifndef FOO-BAR_H
#define FOO-BAR_H
#endif
The hyphen is a break in the CPP identifier, which makes the header
guard not work (GCC, at least, ignores everything past FOO and spits out
a warning). I think that something like the following replacement is
probably better:
'(("\\.\\([Hh]\\|hh\\|hpp\\)\\'" . "C / C++ header")
(replace-regexp-in-string
"[^A-Z0-9]" "_"
(upcase (file-name-nondirectory buffer-file-name)) t t)
"#ifndef " str \n
"#define " str "\n\n"
_ "\n\n#endif")
This is basically the same as the definition in Emacs master at the
moment, but doesn't explicitly split basename from extension and instead
replaces non-alphanumeric characters with underscores.
Could the default be changed to this or something like it?
Rupert
PS: I'm not including defaults of the build configuration because
they're pretty irrelevant in this case. I've got a snapshot build
from master last week and the default auto-insert-alist was last
changed in 2012.
PPS: If anyone else has been irritated by this, here's a workaround
until there's a fix in master which makes it to your distribution's
packages:
(defvar rjs-c-hdr-replacement
'(("\\.\\([Hh]\\|hh\\|hpp\\)\\'" . "C / C++ header")
(replace-regexp-in-string
"[^A-Z0-9]" "_"
(upcase (file-name-nondirectory buffer-file-name)) t t)
"#ifndef " str \n
"#define " str "\n\n"
_ "\n\n#endif"))
(unless (member rjs-c-hdr-replacement auto-insert-alist)
(setq auto-insert-alist
(cons rjs-c-hdr-replacement auto-insert-alist)))
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#19254: 25.0.50; Special characters not stripped on C/C++ header auto-insert |
Date: |
Thu, 04 Dec 2014 07:14:52 +0100 |
User-agent: |
KMail/4.13.3 (Linux/3.13.0-40-generic; KDE/4.13.3; x86_64; ; ) |
On Tuesday 02 December 2014 15:23:37 Rupert Swarbrick wrote:
> Could the default be changed to this or something like it?
I have committed a variation of that patch in a0363ff. In the future please
provide patches in a diff format. See etc/CONTRIBUTE in the emacs source.
Regards,
RĂ¼diger
--- End Message ---