all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Question on syntax-propertize-function
@ 2013-06-06 19:26 Marco Maggesi
  2013-06-06 21:23 ` Stefan Monnier
       [not found] ` <mailman.1117.1370553840.22516.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Marco Maggesi @ 2013-06-06 19:26 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I'm trying to improve an old emacs major mode I wrote some years ago (http://web.math.unifi.it/users/maggesi/holl-mode-2006-10-24.tar.gz) for editing HOL Light proof scripts (HOL Light is a theorem prover http://www.cl.cam.ac.uk/~jrh13/hol-light/, its syntax is close to OCaml and SML but with lots of idiosyncrasies).

I have two problems:

1. Comments are delimited by (* and *).  However, (*) should not open nor close a comment.

2. Anything enclosed in blackquotes `...` is a HOL term and follows a different syntax.

I suppose that this kind of issues are normally solved by setting text properties, but so far my attempts failed miserably.  I left aside problem 2 for now because I'm undecided on what to do exactly (e.g., should I set the syntax-table property for the quoted text or should I use syntax-entry "$   "?).

Here is what I did for problem 1.  I set a syntax table for holl mode which includes the following entries:

    (modify-syntax-entry ?\( "()1" st)
    (modify-syntax-entry ?\) ")(4" st)
    (modify-syntax-entry ?\* ". 23n" st)

This works as expected in most cases, but (*) open and close comments.
Then I defined a "propertize" function:

(defun holl-syntax-propertize (start end)
  (goto-char start)
  (funcall
   (syntax-propertize-rules
    ("\\((\\)\\(\\*\\)\\()\\)"
     (1 "()  ")
     (2 ".   ")
     (3 ")(  "))
    )
   start end))

and I set syntax-propertize-function in the initialization of the major mode:

  (set (make-local-variable 'syntax-propertize-function)
       #'holl-syntax-propertize)

However, this doesn't seems to have any effect.  I also played with syntax-propertize-extend-region-functions but with no success.

Can you see what's wrong with this approach?  Or can you suggest a debugging technique?  E.g., how can I run interactively syntax-property-rules?  I defined an interactive function

(defun holl-propertize (start end)
  (interactive "r")
  (funcall
   (syntax-propertize-rules
    ("\\((\\)\\(\\*\\)\\()\\)"
     (1 "()  ")
     (2 ".   ")
     (3 ")(  "))
    )
   start end))

and if I run it on a region containing (*) I get no effect.

Thanks,
Marco


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

* Re: Question on syntax-propertize-function
  2013-06-06 19:26 Question on syntax-propertize-function Marco Maggesi
@ 2013-06-06 21:23 ` Stefan Monnier
       [not found] ` <mailman.1117.1370553840.22516.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2013-06-06 21:23 UTC (permalink / raw)
  To: help-gnu-emacs

>     (modify-syntax-entry ?\( "()1" st)
>     (modify-syntax-entry ?\) ")(4" st)
>     (modify-syntax-entry ?\* ". 23n" st)

Looks good.

> (defun holl-syntax-propertize (start end)
>   (goto-char start)
>   (funcall
>    (syntax-propertize-rules
>     ("\\((\\)\\(\\*\\)\\()\\)"
>      (1 "()  ")
>      (2 ".   ")
>      (3 ")(  "))
>     )
>    start end))

Looks OK (changing the syntax of the * in the middle should be
sufficient, but the extra entries shouldn't hurt).

> and I set syntax-propertize-function in the initialization of the major mode:

>   (set (make-local-variable 'syntax-propertize-function)
>        #'holl-syntax-propertize)

Looks good.

> However, this doesn't seems to have any effect.  I also played with
> syntax-propertize-extend-region-functions but with no success.

> Can you see what's wrong with this approach?

Nope, it looks fine.  Which version of Emacs are you using?
Is the mode using font-lock?  Do you have font-lock-syntactic-keywords maybe?

> and if I run it on a region containing (*) I get no effect.

That might be due to the syntax-table property being immediately reset
by the code that auto-runs syntax-propertize-function or something along
these lines.  Try it first in a fundamental-mode buffer.


        Stefan




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

* Re: Question on syntax-propertize-function
       [not found] ` <mailman.1117.1370553840.22516.help-gnu-emacs@gnu.org>
@ 2013-06-07  9:13   ` Marco Maggesi
  2013-06-08  0:46     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Marco Maggesi @ 2013-06-07  9:13 UTC (permalink / raw)
  To: help-gnu-emacs

Il giorno giovedì 6 giugno 2013 23:23:41 UTC+2, Stefan Monnier ha scritto:
> That might be due to the syntax-table property being immediately reset
> by the code that auto-runs syntax-propertize-function or something along
> these lines.  Try it first in a fundamental-mode buffer.

Thank you Stefan, this clarifies a lot.
Now my code works.

Actually, the syntax for comments in OCaml is even trickier since (* *) can be nested and (*) do not open a comment at top level but do open a comment in the nesting, as this simple interaction shows

[maggesi@virtux:~]$ ocaml
        OCaml version 4.00.1

# (* (*) *)
* 

But I think I will not address this, at lest for now.
BTW: you should have the same problem in tuareg.  How do you solve it?

I noticed that when font-lock-mode is disabled, the text is not propertized.
Is syntax-propertize run only by font-lock or is used also for other purpose?

Thanks for now,
M.


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

* Re: Question on syntax-propertize-function
  2013-06-07  9:13   ` Marco Maggesi
@ 2013-06-08  0:46     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2013-06-08  0:46 UTC (permalink / raw)
  To: help-gnu-emacs

> BTW: you should have the same problem in tuareg.  How do you solve it?

AFAIK we don't.  IIRC the precise commenting rules in OCaml are pretty
subtle, and Tuareg mode doesn't try to obey them all.

> I noticed that when font-lock-mode is disabled, the text is not propertized.
> Is syntax-propertize run only by font-lock or is used also for other purpose?

It is propertized on demand.  So if noone asks for it, it's not run.
When you need it, call syntax-propertize.


        Stefan




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

end of thread, other threads:[~2013-06-08  0:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-06 19:26 Question on syntax-propertize-function Marco Maggesi
2013-06-06 21:23 ` Stefan Monnier
     [not found] ` <mailman.1117.1370553840.22516.help-gnu-emacs@gnu.org>
2013-06-07  9:13   ` Marco Maggesi
2013-06-08  0:46     ` Stefan Monnier

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.