[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#19254: 25.0.50; Special characters not stripped on C/C++ header auto
From: |
Rupert Swarbrick |
Subject: |
bug#19254: 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)))
- bug#19254: 25.0.50; Special characters not stripped on C/C++ header auto-insert,
Rupert Swarbrick <=