unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* changing string delimiter character to be matching curly brackets
@ 2007-09-12 21:31 stuart
  2007-09-14  3:05 ` Kevin Rodgers
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: stuart @ 2007-09-12 21:31 UTC (permalink / raw)
  To: help-gnu-emacs

I am creating a custom mode and I want to make curly brackets an
alternative way of delimiting string, so that a string 'foo' bould be
either {foo} or "foo". I am able to override the comment and escape
chars, as follows:

;; Change the interpretation of particular chars in Emacs' syntax
table
(defvar fst-mode-syntax-table
  (let ((fst-mode-syntax-table (make-syntax-table)))
    (modify-syntax-entry  ?#   "<"  fst-mode-syntax-table)  ; start
comment
    (modify-syntax-entry  ?\n  ">"  fst-mode-syntax-table)  ; end
comment
    (modify-syntax-entry  ?\\  "_"  fst-mode-syntax-table)  ; don't
escape quote
    (modify-syntax-entry  ?%   "/"  fst-mode-syntax-table)  ;
functions as escape char
    fst-mode-syntax-table)
  "Syntax table for fst-mode")

But if I add in these lines, it doesn't do what I hoped it would:

    (modify-syntax-entry  ?{   '"'  fst-mode-syntax-table)  ; start
string
    (modify-syntax-entry  ?}   '"'  fst-mode-syntax-table)  ; end
string

Either the syntax is wrong or the strategy is. (I'm guessing the
latter.)

Any suggestions? (Please include the obfuscated email below in your
reply since I don't regularly check this list. Thanks.

s t u a r t | AT | z a p a t a | DOT | o r g

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

* Re: changing string delimiter character to be matching curly brackets
  2007-09-12 21:31 changing string delimiter character to be matching curly brackets stuart
@ 2007-09-14  3:05 ` Kevin Rodgers
       [not found] ` <mailman.836.1189739162.18990.help-gnu-emacs@gnu.org>
  2007-09-18  3:46 ` Stefan Monnier
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2007-09-14  3:05 UTC (permalink / raw)
  To: help-gnu-emacs

stuart wrote:
> I am creating a custom mode and I want to make curly brackets an
> alternative way of delimiting string, so that a string 'foo' bould be
> either {foo} or "foo". I am able to override the comment and escape
> chars, as follows:
> 
> ;; Change the interpretation of particular chars in Emacs' syntax
> table
> (defvar fst-mode-syntax-table
>   (let ((fst-mode-syntax-table (make-syntax-table)))
>     (modify-syntax-entry  ?#   "<"  fst-mode-syntax-table)  ; start
> comment
>     (modify-syntax-entry  ?\n  ">"  fst-mode-syntax-table)  ; end
> comment
>     (modify-syntax-entry  ?\\  "_"  fst-mode-syntax-table)  ; don't
> escape quote
>     (modify-syntax-entry  ?%   "/"  fst-mode-syntax-table)  ;
> functions as escape char
>     fst-mode-syntax-table)
>   "Syntax table for fst-mode")
> 
> But if I add in these lines, it doesn't do what I hoped it would:
> 
>     (modify-syntax-entry  ?{   '"'  fst-mode-syntax-table)  ; start
> string
>     (modify-syntax-entry  ?}   '"'  fst-mode-syntax-table)  ; end
> string
> 
> Either the syntax is wrong or the strategy is. (I'm guessing the
> latter.)

The syntax is wrong: '"' should be "\""

> Any suggestions? (Please include the obfuscated email below in your
> reply since I don't regularly check this list. Thanks.

Too bad.

> s t u a r t | AT | z a p a t a | DOT | o r g

-- 
Kevin Rodgers
Denver, Colorado, USA

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

* Re: changing string delimiter character to be matching curly brackets
       [not found] ` <mailman.836.1189739162.18990.help-gnu-emacs@gnu.org>
@ 2007-09-14  6:17   ` stuart
  0 siblings, 0 replies; 4+ messages in thread
From: stuart @ 2007-09-14  6:17 UTC (permalink / raw)
  To: help-gnu-emacs

Thanks. I tried it with the proper escaping of the double quote, but
it treats the curly brackets like double quotes, and expects either
'{foo{' or '}foo}' but not '{foo}'. So i think that was the wrong
strategy.

> The syntax is wrong: '"' should be "\""

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

* Re: changing string delimiter character to be matching curly brackets
  2007-09-12 21:31 changing string delimiter character to be matching curly brackets stuart
  2007-09-14  3:05 ` Kevin Rodgers
       [not found] ` <mailman.836.1189739162.18990.help-gnu-emacs@gnu.org>
@ 2007-09-18  3:46 ` Stefan Monnier
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2007-09-18  3:46 UTC (permalink / raw)
  To: help-gnu-emacs

> Either the syntax is wrong or the strategy is. (I'm guessing the
> latter.)

Both.  Emacs's syntax tables have no support for nestable string syntax.
The start and end of a string need to be the same char.  The closest you can
get without going through significantly more efforts is to mark them as
string-fence such that both { and } can start or end a string, i.e. }hello}
and }hello{ are both strings.


        Stefan

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

end of thread, other threads:[~2007-09-18  3:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-12 21:31 changing string delimiter character to be matching curly brackets stuart
2007-09-14  3:05 ` Kevin Rodgers
     [not found] ` <mailman.836.1189739162.18990.help-gnu-emacs@gnu.org>
2007-09-14  6:17   ` stuart
2007-09-18  3:46 ` Stefan Monnier

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