unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Tom Tromey <tromey@redhat.com>, 4192@emacsbugs.donarmstrong.com
Cc: bug-cc-mode@gnu.org, bug-gnu-emacs@gnu.org
Subject: Re: bug#4192: 23.1; special fontification for "//" in cc-mode
Date: Fri, 21 Aug 2009 21:33:23 +0000	[thread overview]
Message-ID: <20090821213323.GC1897@muc.de> (raw)
In-Reply-To: <m38whhf5ul.fsf@fleche.redhat.com>

Hi, Tom!

On Tue, Aug 18, 2009 at 10:24:02AM -0600, Tom Tromey wrote:

> This is a feature request for cc-mode.

> I work on a number of projects that use C89, not C99.  In these
> projects, it is invalid to use "//"-style comment.  It would be nice if
> cc-mode would optionally flag such comments in a special face, so that
> I can immediately see when I've written a comment incorrectly.

I'm not sure this is important enough to warrant a fully
implemented/documented/QA'd feature, but then again, I'm not sure it's
not.

Here's a quick hack called c-disable-line-comments.el.  Load it into your
Emacs before CC Mode (in particular, before desktop gets loaded).

Toggling c-disable-line-comments doesn't work smoothly with the font
locking, but I'm assuming here you'll not really be wanting to toggle
this.

Criticism is, of course, welcome.  I've set the followup to
bug-cc-mode@gnu.org.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; c-disable-line-comments.el.
;; 
;; A function which disables line comments in C mode and fontifies the
;; delimiter "//" with font-lock-warning-face.
;;
;; It should be loaded before CC Mode.  It will only work in GNU Emacs, and
;; has only been "properly" tested in Emacs 23.1.
;;
;; Written 2009-08-21 by Alan Mackenzie at the request of Tom Tromey.
;;
;; This file isn't part of Emacs.  It's licence is GPL version 2, or (at your
;; option) any later version.  The copyright has been assigned to the FSF.

(defun c-warning-face-on-// ()
  (font-lock-add-keywords 'c-mode
			  '(("//" . font-lock-warning-face))))
(add-hook 'c-initialization-hook 'c-warning-face-on-//)

(defvar c-disable-line-comments t
  "Is t when line comments in C Mode are disabled, nil otherwise.
Note that this variable is NOT buffer local.")

(defun c-disable-line-comments (arg)
  "Toggle the disablement of line comments in every C Mode buffer.
With a non-nil argument \(which must be numeric), disable
comments when it's positive, reenable them when negative.

\(Incidentally, the delimiter \"//\" gets fontified with
font-lock-warning-face when \"//\" is disabled, but this defun
doesn't do this."
  (interactive "P")
  (setq c-disable-line-comments
	(cond
	 ((null arg) (not c-disable-line-comments))
	 ((> (prefix-numeric-value arg) 0) t)
	 (t nil)))

  (if c-disable-line-comments
      (progn
	(modify-syntax-entry ?/  ". 14" c-mode-syntax-table)
	(modify-syntax-entry ?\n "  "  c-mode-syntax-table)
	(modify-syntax-entry ?\r "  "  c-mode-syntax-table))
    (modify-syntax-entry ?/  ". 124b" c-mode-syntax-table)
    (modify-syntax-entry ?\n "> b"  c-mode-syntax-table)
    (modify-syntax-entry ?\r "> b"  c-mode-syntax-table)))

(c-disable-line-comments 1)
;; End of c-disable-line-comments.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

> Tom

-- 
Alan Mackenzie (Nuremberg, Germany).

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july


  reply	other threads:[~2009-08-21 21:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-18 16:24 bug#4192: 23.1; special fontification for "//" in cc-mode Tom Tromey
2009-08-21 21:33 ` Alan Mackenzie [this message]
2016-02-29  3:36   ` Lars Ingebrigtsen
2019-11-01 16:08     ` Lars Ingebrigtsen
2019-11-02 16:35       ` Alan Mackenzie
     [not found]       ` <20191102163513.GC6710@ACM>
2019-11-03 15:55         ` Lars Ingebrigtsen
2019-11-03 17:46           ` Alan Mackenzie
     [not found]           ` <20191103174618.GA11619@ACM>
2019-11-03 17:59             ` Eli Zaretskii
2019-11-03 19:20               ` Alan Mackenzie
2019-11-07 20:11             ` Lars Ingebrigtsen
2019-11-09 12:20               ` Alan Mackenzie

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=20090821213323.GC1897@muc.de \
    --to=acm@muc.de \
    --cc=4192@emacsbugs.donarmstrong.com \
    --cc=bug-cc-mode@gnu.org \
    --cc=bug-gnu-emacs@gnu.org \
    --cc=tromey@redhat.com \
    /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 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).