unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19254: 25.0.50; Special characters not stripped on C/C++ header auto-insert
@ 2014-12-02 15:23 Rupert Swarbrick
  2014-12-04  6:14 ` Rüdiger Sonderfeld
  0 siblings, 1 reply; 2+ messages in thread
From: Rupert Swarbrick @ 2014-12-02 15:23 UTC (permalink / raw)
  To: 19254

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)))





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#19254: 25.0.50; Special characters not stripped on C/C++ header auto-insert
  2014-12-02 15:23 bug#19254: 25.0.50; Special characters not stripped on C/C++ header auto-insert Rupert Swarbrick
@ 2014-12-04  6:14 ` Rüdiger Sonderfeld
  0 siblings, 0 replies; 2+ messages in thread
From: Rüdiger Sonderfeld @ 2014-12-04  6:14 UTC (permalink / raw)
  To: 19254-done; +Cc: Rupert Swarbrick

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






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-04  6:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-02 15:23 bug#19254: 25.0.50; Special characters not stripped on C/C++ header auto-insert Rupert Swarbrick
2014-12-04  6:14 ` Rüdiger Sonderfeld

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).