all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* cc-mode in emacs 23.2 goes into infinte loop
@ 2011-01-22 22:41 jdiamond
  2011-01-23  9:54 ` rusi
  0 siblings, 1 reply; 7+ messages in thread
From: jdiamond @ 2011-01-22 22:41 UTC (permalink / raw)
  To: help-gnu-emacs

I have the following file (which is actually my real mode file with
almost everything removed):

----------------- zsd-c-mode.el -------------------
(require 'cc-mode)

(eval-and-compile
   (c-add-language 'zsd-c-mode 'c-mode))

(defvar zsd-c-mode-syntax-table nil
    "Syntax table in use in zsd-c-mode buffers."
)

(defun
    zsd-c-mode ()
    "Major mode for editing C source code.
    Based loosely upon the Unipress Emacs electric-c mode."
    (interactive)
    (c-init-language-vars zsd-c-mode)
    (c-common-init 'zsd-c-mode)
    (setq zsd-c-font-lock-keywords-3 nil)
)
---------------------------------------------------

If I start up emacs 23.2 with
	emacs -Q qqq.q
and them
	M-x load-file RET ~/emacs/zsd-c-mode.el
and then
	M-x zsd-c-mode RET
and then in the buffer I type
	#define as(
when I hit the '(' emacs goes into an (apparently) infinite loop.
(The '(' does not actually appear in the buffer until I hit ^G.)

Tracking it down (a bit), I see that in cc-mode c-neutralize-CPP-line
is not doing The Right Thing any more.  Specifically,
	(c-put-char-property (nth 1 s) 'syntax-table '(1))
is not changing anything in the result of the following call to
	(parse-partial-sexp beg end -1)
and so c-neutralize-CPP-line loops.

Before I file this as a bug, are there any cc-mode experts here who
can comment on whether I am committing some grievous sin with the code
above?  (This worked in earlier versions of emacs, but perhaps the
above has suffered from bit rot by changes to emacs.)

Thanks.
				Jim


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

* Re: cc-mode in emacs 23.2 goes into infinte loop
  2011-01-22 22:41 cc-mode in emacs 23.2 goes into infinte loop jdiamond
@ 2011-01-23  9:54 ` rusi
  2011-01-23 14:05   ` foo-font-lock-keywords (was Re: cc-mode in emacs 23.2 goes into infinte loop) Jorgen Grahn
  2011-01-23 16:47   ` cc-mode in emacs 23.2 goes into infinte loop Jim Diamond
  0 siblings, 2 replies; 7+ messages in thread
From: rusi @ 2011-01-23  9:54 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 23, 3:41 am, jdiam...@snipthis.AcadiaU.ca wrote:
> I have the following file...

snipped

>     (setq zsd-c-font-lock-keywords-3 nil)

No I dont have an answer (and please excuse my hijacking your question
for mine :-) )
but do you know where I can find out about things like
foo-font-lock-keywords-{1,2,3}?

Both C and lisp modes are too deep-structured for me to easily figure
out...

IOW just looking for a typical, simple language mode that uses font-
lock correctly...


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

* foo-font-lock-keywords (was Re: cc-mode in emacs 23.2 goes into infinte loop)
  2011-01-23  9:54 ` rusi
@ 2011-01-23 14:05   ` Jorgen Grahn
  2011-01-23 16:49     ` rusi
  2011-01-23 16:47   ` cc-mode in emacs 23.2 goes into infinte loop Jim Diamond
  1 sibling, 1 reply; 7+ messages in thread
From: Jorgen Grahn @ 2011-01-23 14:05 UTC (permalink / raw)
  To: help-gnu-emacs

On Sun, 2011-01-23, rusi wrote:
> On Jan 23, 3:41 am, jdiam...@snipthis.AcadiaU.ca wrote:
>> I have the following file...
>
> snipped
>
>>     (setq zsd-c-font-lock-keywords-3 nil)
>
> No I dont have an answer (and please excuse my hijacking your question
> for mine :-) )

You should at least have changed the subject line.

> but do you know where I can find out about things like
> foo-font-lock-keywords-{1,2,3}?
>
> Both C and lisp modes are too deep-structured for me to easily figure
> out...
>
> IOW just looking for a typical, simple language mode that uses font-
> lock correctly...

Here is a really simple one. Works for me -- if major things are
missing or wrong, I haven't noticed.  I had to google around and
experiment a lot to get it to this state.

;;; refer-mode.el -- Major mode for refer(1) files
;;
;; Copyright (C) 2005 Jörgen Grahn <jgrahn@algonet.se>
;; All right reserved.
;;
;; $Id: refer-mode.el,v 1.3 2005/10/30 17:08:15 grahn Exp $
;; $Name:  $

(defconst refer-font-lock-keywords
  '(("^%Z.*$" . font-lock-comment-face)
    ("^%[ATQ] .+$" . font-lock-keyword-face)
    ("^%[K] .+$" . font-lock-string-face)
    )
  "Syntax highlighting for Refer mode.")

(define-derived-mode refer-mode text-mode "Refer"
  "Major mode for editing refer(1) bibliographies.
This is merely text mode, plus some colorization.

A subjective quick guide to the keywords:

%T title                 %D year of publication
%A author                %I issuer/publisher
%Q corporate author      %C city of publication
[...]
Compare with the standard, but obsolete, bib-mode, which handles the
approximately same file format. (Oddly enough, Bib-mode handles
refer(1) files; refbib and refer.el handle BibTeX.)"

  (setq comment-start "%Z")
  (setq comment-start-skip "%Z\\s-*")

  (set (make-local-variable 'font-lock-defaults)
       '((refer-font-lock-keywords
 	  refer-font-lock-keywords
 	  refer-font-lock-keywords
 	  refer-font-lock-keywords)
 	 t)))

(provide 'refer-mode)

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .  .
\X/     snipabacken.se>   O  o   .


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

* Re: cc-mode in emacs 23.2 goes into infinte loop
  2011-01-23  9:54 ` rusi
  2011-01-23 14:05   ` foo-font-lock-keywords (was Re: cc-mode in emacs 23.2 goes into infinte loop) Jorgen Grahn
@ 2011-01-23 16:47   ` Jim Diamond
  2011-01-23 17:57     ` rusi
  1 sibling, 1 reply; 7+ messages in thread
From: Jim Diamond @ 2011-01-23 16:47 UTC (permalink / raw)
  To: help-gnu-emacs

On 2011-01-23 at 05:54 AST, rusi <rustompmody@gmail.com> wrote:
> On Jan 23, 3:41 am, jdiam...@snipthis.AcadiaU.ca wrote:
>> I have the following file...
>
> snipped
>
>>     (setq zsd-c-font-lock-keywords-3 nil)
>
> No I dont have an answer (and please excuse my hijacking your question
> for mine :-) )
> but do you know where I can find out about things like
> foo-font-lock-keywords-{1,2,3}?
>
> Both C and lisp modes are too deep-structured for me to easily figure
> out...
>
> IOW just looking for a typical, simple language mode that uses font-
> lock correctly...

Jorgen has maybe already answered your question.  In addition to his
message...

The -1, -2, -3 jazz for cc mode can be explained by this relatively
short snippet from cc-fonts.el:

(defconst c-font-lock-keywords-1 (c-lang-const c-matchers-1 c)
  "Minimal font locking for C mode.
Fontifies only preprocessor directives (in addition to the syntactic
fontification of strings and comments).")

(defconst c-font-lock-keywords-2 (c-lang-const c-matchers-2 c)
  "Fast normal font locking for C mode.
In addition to `c-font-lock-keywords-1', this adds fontification of
keywords, simple types, declarations that are easy to recognize, the
user defined types on `c-font-lock-extra-types', and the doc comment
styles specified by `c-doc-comment-style'.")

(defconst c-font-lock-keywords-3 (c-lang-const c-matchers-3 c)
  "Accurate normal font locking for C mode.
Like `c-font-lock-keywords-2' but detects declarations in a more
accurate way that works in most cases for arbitrary types without the
need for `c-font-lock-extra-types'.")

(defvar c-font-lock-keywords c-font-lock-keywords-3
  "Default expressions to highlight in C mode.")


So not every mode needs 3 choices, there are three choices in cc mode
to suit different tastes.

Cheers.
				Jim


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

* Re: foo-font-lock-keywords (was Re: cc-mode in emacs 23.2 goes into infinte loop)
  2011-01-23 14:05   ` foo-font-lock-keywords (was Re: cc-mode in emacs 23.2 goes into infinte loop) Jorgen Grahn
@ 2011-01-23 16:49     ` rusi
  2011-01-23 19:22       ` Jim Diamond
  0 siblings, 1 reply; 7+ messages in thread
From: rusi @ 2011-01-23 16:49 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 23, 7:05 pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
> On Sun, 2011-01-23, rusi wrote:
> > On Jan 23, 3:41 am, jdiam...@snipthis.AcadiaU.ca wrote:
> >> I have the following file...
>
> > snipped
>
> >>     (setq zsd-c-font-lock-keywords-3 nil)
>
> > No I dont have an answer (and please excuse my hijacking your question
> > for mine :-) )
>
> You should at least have changed the subject line.
>
> > but do you know where I can find out about things like
> > foo-font-lock-keywords-{1,2,3}?
>
> > Both C and lisp modes are too deep-structured for me to easily figure
> > out...
>
> > IOW just looking for a typical, simple language mode that uses font-
> > lock correctly...
>
> Here is a really simple one. Works for me -- if major things are
> missing or wrong, I haven't noticed.  I had to google around and
> experiment a lot to get it to this state.
>
> ;;; refer-mode.el -- Major mode for refer(1) files
> ;;
> ;; Copyright (C) 2005 Jörgen Grahn <jgr...@algonet.se>
> ;; All right reserved.
> ;;
> ;; $Id: refer-mode.el,v 1.3 2005/10/30 17:08:15 grahn Exp $
> ;; $Name:  $
>
> (defconst refer-font-lock-keywords
>   '(("^%Z.*$" . font-lock-comment-face)
>     ("^%[ATQ] .+$" . font-lock-keyword-face)
>     ("^%[K] .+$" . font-lock-string-face)
>     )
>   "Syntax highlighting for Refer mode.")
>
> (define-derived-mode refer-mode text-mode "Refer"
>   "Major mode for editing refer(1) bibliographies.
> This is merely text mode, plus some colorization.
>
> A subjective quick guide to the keywords:
>
> %T title                 %D year of publication
> %A author                %I issuer/publisher
> %Q corporate author      %C city of publication
> [...]
> Compare with the standard, but obsolete, bib-mode, which handles the
> approximately same file format. (Oddly enough, Bib-mode handles
> refer(1) files; refbib and refer.el handle BibTeX.)"
>
>   (setq comment-start "%Z")
>   (setq comment-start-skip "%Z\\s-*")
>
>   (set (make-local-variable 'font-lock-defaults)
>        '((refer-font-lock-keywords
>           refer-font-lock-keywords
>           refer-font-lock-keywords
>           refer-font-lock-keywords)
>          t)))
>
> (provide 'refer-mode)
>
> --
>   // Jorgen Grahn <grahn@  Oo  o.   .  .
> \X/     snipabacken.se>   O  o   .

Well Thanks for the efforts Jorgen
But I am specifically interested in whats with the
font-lock-keywords-{1,2,3}
what are the differences, what should go in each etc.


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

* Re: cc-mode in emacs 23.2 goes into infinte loop
  2011-01-23 16:47   ` cc-mode in emacs 23.2 goes into infinte loop Jim Diamond
@ 2011-01-23 17:57     ` rusi
  0 siblings, 0 replies; 7+ messages in thread
From: rusi @ 2011-01-23 17:57 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 23, 9:47 pm, Jim Diamond <Jim.Diam...@deletethis.AcadiaU.ca>
wrote:
> On 2011-01-23 at 05:54 AST, rusi <rustompm...@gmail.com> wrote:
>
>
>
> > On Jan 23, 3:41 am, jdiam...@snipthis.AcadiaU.ca wrote:
> >> I have the following file...
>
> > snipped
>
> >> (setq zsd-c-font-lock-keywords-3 nil)
>
> > No I dont have an answer (and please excuse my hijacking your question
> > for mine :-) )
> > but do you know where I can find out about things like
> > foo-font-lock-keywords-{1,2,3}?
>
> > Both C and lisp modes are too deep-structured for me to easily figure
> > out...
>
> > IOW just looking for a typical, simple language mode that uses font-
> > lock correctly...
>
> Jorgen has maybe already answered your question.  In addition to his
> message...
>
> The -1, -2, -3 jazz for cc mode can be explained by this relatively
> short snippet from cc-fonts.el:
>
> (defconst c-font-lock-keywords-1 (c-lang-const c-matchers-1 c)
>   "Minimal font locking for C mode.
> Fontifies only preprocessor directives (in addition to the syntactic
> fontification of strings and comments).")
>
> (defconst c-font-lock-keywords-2 (c-lang-const c-matchers-2 c)
>   "Fast normal font locking for C mode.
> In addition to `c-font-lock-keywords-1', this adds fontification of
> keywords, simple types, declarations that are easy to recognize, the
> user defined types on `c-font-lock-extra-types', and the doc comment
> styles specified by `c-doc-comment-style'.")
>
> (defconst c-font-lock-keywords-3 (c-lang-const c-matchers-3 c)
>   "Accurate normal font locking for C mode.
> Like `c-font-lock-keywords-2' but detects declarations in a more
> accurate way that works in most cases for arbitrary types without the
> need for `c-font-lock-extra-types'.")
>
> (defvar c-font-lock-keywords c-font-lock-keywords-3
>   "Default expressions to highlight in C mode.")
>
> So not every mode needs 3 choices, there are three choices in cc mode
> to suit different tastes.
>
> Cheers.
>                                 Jim

Well thanks Jim!

But I dont get how they are used...
Who/what/where are these variable passed in to the cc-mode so that it
knows what to do with it?
Here is a sample of my problem

http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/6e10d0eb871b4951/f68d42fe89a6d1c4?#f68d42fe89a6d1c4


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

* Re: foo-font-lock-keywords (was Re: cc-mode in emacs 23.2 goes into infinte loop)
  2011-01-23 16:49     ` rusi
@ 2011-01-23 19:22       ` Jim Diamond
  0 siblings, 0 replies; 7+ messages in thread
From: Jim Diamond @ 2011-01-23 19:22 UTC (permalink / raw)
  To: help-gnu-emacs

On 2011-01-23 at 12:49 AST, rusi <rustompmody@gmail.com> wrote:
> On Jan 23, 7:05 pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
>> On Sun, 2011-01-23, rusi wrote:
>> > On Jan 23, 3:41 am, jdiam...@snipthis.AcadiaU.ca wrote:
>> >> I have the following file...
>>
>> > snipped
>>
>> >>     (setq zsd-c-font-lock-keywords-3 nil)
>>
>> > No I dont have an answer (and please excuse my hijacking your question
>> > for mine :-) )
>>
>> You should at least have changed the subject line.
>>
>> > but do you know where I can find out about things like
>> > foo-font-lock-keywords-{1,2,3}?
>>
>> > Both C and lisp modes are too deep-structured for me to easily figure
>> > out...
>>
>> > IOW just looking for a typical, simple language mode that uses font-
>> > lock correctly...
>>
>> Here is a really simple one. Works for me -- if major things are
>> missing or wrong, I haven't noticed.  I had to google around and
>> experiment a lot to get it to this state.
>>
>> ;;; refer-mode.el -- Major mode for refer(1) files
>> ;;
>> ;; Copyright (C) 2005 Jörgen Grahn <jgr...@algonet.se>
>> ;; All right reserved.
>> ;;
>> ;; $Id: refer-mode.el,v 1.3 2005/10/30 17:08:15 grahn Exp $
>> ;; $Name:  $
>>
>> (defconst refer-font-lock-keywords
>>   '(("^%Z.*$" . font-lock-comment-face)
>>     ("^%[ATQ] .+$" . font-lock-keyword-face)
>>     ("^%[K] .+$" . font-lock-string-face)
>>     )
>>   "Syntax highlighting for Refer mode.")
>>
>> (define-derived-mode refer-mode text-mode "Refer"
>>   "Major mode for editing refer(1) bibliographies.
>> This is merely text mode, plus some colorization.
>>
>> A subjective quick guide to the keywords:
>>
>> %T title                 %D year of publication
>> %A author                %I issuer/publisher
>> %Q corporate author      %C city of publication
>> [...]
>> Compare with the standard, but obsolete, bib-mode, which handles the
>> approximately same file format. (Oddly enough, Bib-mode handles
>> refer(1) files; refbib and refer.el handle BibTeX.)"
>>
>>   (setq comment-start "%Z")
>>   (setq comment-start-skip "%Z\\s-*")
>>
>>   (set (make-local-variable 'font-lock-defaults)
>>        '((refer-font-lock-keywords
>>           refer-font-lock-keywords
>>           refer-font-lock-keywords
>>           refer-font-lock-keywords)
>>          t)))
>>
>> (provide 'refer-mode)
>>
>> --
>>   // Jorgen Grahn <grahn@  Oo  o.   .  .
>> \X/     snipabacken.se>   O  o   .
>
> Well Thanks for the efforts Jorgen
> But I am specifically interested in whats with the
> font-lock-keywords-{1,2,3}
> what are the differences, what should go in each etc.

The answer to this question is, I think, shorter than the one you
asked me.

As I said in my previous reply to you (IIRC), the 3 versions of the
font-lock-keywords in cc mode are different "levels" of fontification.
ONLY ONE (ok, at most one) is used at any given time.  You can
customize cc mode by picking the one you like (or by making up your
own from scratch).  The code I showed you picked ...-3 as the default,
but any cc mode user can change that.

Jorgen gave you a complete (I think) example of using font-lock and
setting up some keywords for his "refer" model, just as you had asked
for.  Forget about -1, -2 and -3 and if you understand what he did,
you can set up your own keywords as you see fit for whatever you want
to do.  (I'm not claiming that is trivial, by the way.)

Cheers.
			Jim


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

end of thread, other threads:[~2011-01-23 19:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-22 22:41 cc-mode in emacs 23.2 goes into infinte loop jdiamond
2011-01-23  9:54 ` rusi
2011-01-23 14:05   ` foo-font-lock-keywords (was Re: cc-mode in emacs 23.2 goes into infinte loop) Jorgen Grahn
2011-01-23 16:49     ` rusi
2011-01-23 19:22       ` Jim Diamond
2011-01-23 16:47   ` cc-mode in emacs 23.2 goes into infinte loop Jim Diamond
2011-01-23 17:57     ` rusi

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.