all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Rupert Swarbrick <ruperts@broadcom.com>
To: 19254@debbugs.gnu.org
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	[thread overview]
Message-ID: <889h9xeulc6.fsf@xl-cam-21.cam.broadcom.com> (raw)

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





             reply	other threads:[~2014-12-02 15:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-02 15:23 Rupert Swarbrick [this message]
2014-12-04  6:14 ` bug#19254: 25.0.50; Special characters not stripped on C/C++ header auto-insert Rüdiger Sonderfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=889h9xeulc6.fsf@xl-cam-21.cam.broadcom.com \
    --to=ruperts@broadcom.com \
    --cc=19254@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.