all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* new major mode doubts
@ 2013-01-17  8:07 Luca Ferrari
  2013-01-17  8:14 ` Luca Ferrari
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Luca Ferrari @ 2013-01-17  8:07 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,
as an exercise I'm trying to implement my own major mode for a
programming language (dataflex, for what it matters). I'm following
the Mode Tutorial http://emacswiki.org/emacs/ModeTutorial and so far
I've the skeleton of the mode to work for me.
However, I've got a couple of doubts:

1) in the keyword list I specified a regexp for uppercase keywords as follows:

 (defconst dataflex-font-lock-keywords-minimal
  (list
   '("\\<\\(BEGIN\\|E\\(?:LSE\\|ND\\)\\|FOR\\|IF\\|LOOP\\|MOVE\\|||T\\(?:HEN\\|O\\)\\|WHILE\\)\\>"
. font-lock-builtin-face )
   '("\\('\\w*'\\)" . font-lock-variable-name-face) )
  "Main (and minimal) highlighting for the Dataflex mode keywords" )

however my keywords could be camel case (therefore BEGIN, begin, bEgin
are all the same). Do I have to specify upper and lower case words
individually (avoiding the mess of the camel case) or is there a
smarter way to do it (e.g., checking the font lock against lowercased
words)?

2) the commenting is behaving in a strange manner: I've c++ comments,
therefore // .... and so I've defined the following:
(defun dataflex-comment-dwim (arg)
  "Comment (in/out) a Dataflex piece of source code. It is based on comment-dwin
of newcomment.el"
  (interactive "*P")
  (require 'newcomment)
  (let ( (comment-start "//") (comment-end "") )
    (comment-dwim arg)))

but while it works for M-; comment, commenting out  awhole region
causes each line to be included into a couple of // as

a line of code

becoming

// a line of code        //

it seems as it comments out the region and for each line places an
empty comment at the end. Any idea on what I'm missing?

Thanks,
Luca



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

* Re: new major mode doubts
  2013-01-17  8:07 new major mode doubts Luca Ferrari
@ 2013-01-17  8:14 ` Luca Ferrari
  2013-01-17 14:53 ` Doug Lewan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Luca Ferrari @ 2013-01-17  8:14 UTC (permalink / raw)
  To: help-gnu-emacs

> 2) the commenting is behaving in a strange manner: I've c++ comments,
> therefore // .... and so I've defined the following:
> (defun dataflex-comment-dwim (arg)
>   "Comment (in/out) a Dataflex piece of source code. It is based on comment-dwin
> of newcomment.el"
>   (interactive "*P")
>   (require 'newcomment)
>   (let ( (comment-start "//") (comment-end "") )
>     (comment-dwim arg)))

I found a problem with another assignment to comment-start and
comment-end that clashes with the above, so now this problem is fixed!

Luca



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

* RE: new major mode doubts
  2013-01-17  8:07 new major mode doubts Luca Ferrari
  2013-01-17  8:14 ` Luca Ferrari
@ 2013-01-17 14:53 ` Doug Lewan
  2013-01-17 15:52 ` Aurélien Aptel
  2013-01-18  3:03 ` Dmitry Gutov
  3 siblings, 0 replies; 6+ messages in thread
From: Doug Lewan @ 2013-01-17 14:53 UTC (permalink / raw)
  To: Luca Ferrari, help-gnu-emacs

WRT Possible camel case: RE-matching in emacs is generally case-insensitive unless you make case-fold-search nil. So, you should get what you want for free.

,Douglas
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224

When I do good, I feel good. When I do bad, I feel bad and that's my religion. - Abraham Lincoln

> -----Original Message-----
> From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On
> Behalf Of Luca Ferrari
> Sent: Thursday, 2013 January 17 03:08
> To: help-gnu-emacs
> Subject: new major mode doubts
> 
> Hi all,
> as an exercise I'm trying to implement my own major mode for a
> programming language (dataflex, for what it matters). I'm following
> the Mode Tutorial http://emacswiki.org/emacs/ModeTutorial and so far
> I've the skeleton of the mode to work for me.
> However, I've got a couple of doubts:
> 
> 1) in the keyword list I specified a regexp for uppercase keywords as
> follows:
> 
>  (defconst dataflex-font-lock-keywords-minimal
>   (list
> 
> '("\\<\\(BEGIN\\|E\\(?:LSE\\|ND\\)\\|FOR\\|IF\\|LOOP\\|MOVE\\|||T\\(?:H
> EN\\|O\\)\\|WHILE\\)\\>"
> . font-lock-builtin-face )
>    '("\\('\\w*'\\)" . font-lock-variable-name-face) )
>   "Main (and minimal) highlighting for the Dataflex mode keywords" )
> 
> however my keywords could be camel case (therefore BEGIN, begin, bEgin
> are all the same). Do I have to specify upper and lower case words
> individually (avoiding the mess of the camel case) or is there a
> smarter way to do it (e.g., checking the font lock against lowercased
> words)?
> 
> 2) the commenting is behaving in a strange manner: I've c++ comments,
> therefore // .... and so I've defined the following:
> (defun dataflex-comment-dwim (arg)
>   "Comment (in/out) a Dataflex piece of source code. It is based on
> comment-dwin
> of newcomment.el"
>   (interactive "*P")
>   (require 'newcomment)
>   (let ( (comment-start "//") (comment-end "") )
>     (comment-dwim arg)))
> 
> but while it works for M-; comment, commenting out  awhole region
> causes each line to be included into a couple of // as
> 
> a line of code
> 
> becoming
> 
> // a line of code        //
> 
> it seems as it comments out the region and for each line places an
> empty comment at the end. Any idea on what I'm missing?
> 
> Thanks,
> Luca




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

* Re: new major mode doubts
  2013-01-17  8:07 new major mode doubts Luca Ferrari
  2013-01-17  8:14 ` Luca Ferrari
  2013-01-17 14:53 ` Doug Lewan
@ 2013-01-17 15:52 ` Aurélien Aptel
  2013-01-18  3:03 ` Dmitry Gutov
  3 siblings, 0 replies; 6+ messages in thread
From: Aurélien Aptel @ 2013-01-17 15:52 UTC (permalink / raw)
  To: Luca Ferrari; +Cc: help-gnu-emacs

On Thu, Jan 17, 2013 at 9:07 AM, Luca Ferrari <fluca1978@infinito.it> wrote:
>   (list
>    '("\\<\\(BEGIN\\|E\\(?:LSE\\|ND\\)\\|FOR\\|IF\\|LOOP\\|MOVE\\|||T\\(?:HEN\\|O\\)\\|WHILE\\)\\>"
> . font-lock-builtin-face )
>    '("\\('\\w*'\\)" . font-lock-variable-name-face) )
>   "Main (and minimal) highlighting for the Dataflex mode keywords" )

I don't know much about writing modes but I think you should use
either `rx' or `regexp-opt` for this kind of regex.



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

* Re: new major mode doubts
  2013-01-17  8:07 new major mode doubts Luca Ferrari
                   ` (2 preceding siblings ...)
  2013-01-17 15:52 ` Aurélien Aptel
@ 2013-01-18  3:03 ` Dmitry Gutov
  2013-01-19  9:40   ` Luca Ferrari
  3 siblings, 1 reply; 6+ messages in thread
From: Dmitry Gutov @ 2013-01-18  3:03 UTC (permalink / raw)
  To: Luca Ferrari; +Cc: help-gnu-emacs

Luca Ferrari <fluca1978@infinito.it> writes:

> Hi all,
> as an exercise I'm trying to implement my own major mode for a
> programming language (dataflex, for what it matters). I'm following
> the Mode Tutorial http://emacswiki.org/emacs/ModeTutorial and so far
> I've the skeleton of the mode to work for me.
> However, I've got a couple of doubts:
>
> 1) in the keyword list I specified a regexp for uppercase keywords as follows:
>
>  (defconst dataflex-font-lock-keywords-minimal
>   (list
>    '("\\<\\(BEGIN\\|E\\(?:LSE\\|ND\\)\\|FOR\\|IF\\|LOOP\\|MOVE\\|||T\\(?:HEN\\|O\\)\\|WHILE\\)\\>"
> . font-lock-builtin-face )
>    '("\\('\\w*'\\)" . font-lock-variable-name-face) )
>   "Main (and minimal) highlighting for the Dataflex mode keywords" )
>
> however my keywords could be camel case (therefore BEGIN, begin, bEgin
> are all the same). Do I have to specify upper and lower case words
> individually (avoiding the mess of the camel case) or is there a
> smarter way to do it (e.g., checking the font lock against lowercased
> words)?

See the `font-lock-defaults' doc. The third element is CASE-FOLD, and
this value is assigned to `font-lock-keywords-case-fold-search', which
also see.



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

* Re: new major mode doubts
  2013-01-18  3:03 ` Dmitry Gutov
@ 2013-01-19  9:40   ` Luca Ferrari
  0 siblings, 0 replies; 6+ messages in thread
From: Luca Ferrari @ 2013-01-19  9:40 UTC (permalink / raw)
  To: help-gnu-emacs

> See the `font-lock-defaults' doc. The third element is CASE-FOLD, and
> this value is assigned to `font-lock-keywords-case-fold-search', which
> also see.

Thanks, I missed it.

Luca



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

end of thread, other threads:[~2013-01-19  9:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-17  8:07 new major mode doubts Luca Ferrari
2013-01-17  8:14 ` Luca Ferrari
2013-01-17 14:53 ` Doug Lewan
2013-01-17 15:52 ` Aurélien Aptel
2013-01-18  3:03 ` Dmitry Gutov
2013-01-19  9:40   ` Luca Ferrari

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.