all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: How does one set up a syntax table for (* and //?
Date: Thu, 12 Jan 2017 20:33:19 -0500	[thread overview]
Message-ID: <b7f9a362-dd69-719f-717c-4c71d0a78299@gmail.com> (raw)
In-Reply-To: <jwvwpe0wfs4.fsf-monnier+gmane.emacs.devel@gnu.org>


[-- Attachment #1.1.1: Type: text/plain, Size: 473 bytes --]

On 2017-01-12 08:55, Stefan Monnier wrote:
>> Is there code that depends on this (a mixing with c)? If not, could we
>> consider changing the semantics of "c" instead? This mixing isn't clear from
>> the documentation, AFAICT.
> 
> `c` is a fairly recent introduction (introduced for opascal.el, FWIW),
> so maybe it's not too late to change its semantics.

That would be nice :) In the meantime, I implemented Noam's suggestion in the attached patch.

Clément.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 0001-Use-a-syntax-propertize-function-to-properly-handle-.patch --]
[-- Type: text/x-diff; name="0001-Use-a-syntax-propertize-function-to-properly-handle-.patch", Size: 2733 bytes --]

From 3a9be64827bbed8e34d38803b5c44d8d4f6cd688 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Pit--Claudel?= <clement.pitclaudel@live.com>
Date: Thu, 12 Jan 2017 20:26:04 -0500
Subject: [PATCH] Use a syntax-propertize-function to properly handle '(//'
 comments

Fixes #42.
---
 fstar-mode.el | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/fstar-mode.el b/fstar-mode.el
index b9d1899..8582f9e 100755
--- a/fstar-mode.el
+++ b/fstar-mode.el
@@ -423,15 +423,30 @@ If MUST-FIND-TYPE is nil, the :type part is not necessary."
     ;; Comments and strings
     (modify-syntax-entry ?\\ "\\" table)
     (modify-syntax-entry ?\" "\"" table)
-    (modify-syntax-entry ?*  ". 23" table)
-    (modify-syntax-entry ?/  ". 12b" table)
-    (modify-syntax-entry ?\n  "> b" table)
-    (modify-syntax-entry ?\^m "> b" table)
-    (modify-syntax-entry ?\( "()1n" table)
-    (modify-syntax-entry ?\) ")(4n" table)
+    ;; ‘/’ is handled by a `syntax-propertize-function'.  For background on this
+    ;; see http://lists.gnu.org/archive/html/emacs-devel/2017-01/msg00144.html.
+    ;; The comment enders are left here, since they don't match the ‘(*’ openers.
+    ;; (modify-syntax-entry ?/ ". 12c" table)
+    (modify-syntax-entry ?\n  ">" table)
+    (modify-syntax-entry ?\^m ">" table)
+    (modify-syntax-entry ?\( "()1nb" table)
+    (modify-syntax-entry ?*  ". 23b" table)
+    (modify-syntax-entry ?\) ")(4nb" table)
     table)
   "Syntax table for F*.")
 
+(defconst fstar-mode-syntax-propertize-function
+  (let ((opener-1 (string-to-syntax ". 1"))
+        (opener-2 (string-to-syntax ". 2")))
+    (syntax-propertize-rules
+     ("//" (0 (let* ((pt (match-beginning 0))
+                     (state (syntax-ppss pt)))
+                (goto-char (match-end 0)) ;; syntax-ppss adjusts point
+                (unless (or (nth 3 state) (nth 4 state))
+                  (put-text-property pt (+ pt 1) 'syntax-table opener-1)
+                  (put-text-property (+ pt 1) (+ pt 2) 'syntax-table opener-2)
+                  (ignore (goto-char (point-at-eol))))))))))
+
 ;;; Mode map
 
 (defvar fstar-mode-map
@@ -1228,7 +1243,8 @@ into blocks; process it as one large block instead."
   (setq-local comment-continue   " *")
   (setq-local comment-end        "*)")
   (setq-local comment-start-skip "\\(//+\\|(\\*+\\)[ \t]*")
-  (setq-local font-lock-syntactic-face-function #'fstar-syntactic-face-function))
+  (setq-local font-lock-syntactic-face-function #'fstar-syntactic-face-function)
+  (setq-local syntax-propertize-function fstar-mode-syntax-propertize-function))
 
 ;;; Main mode
 
-- 
2.7.4


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

      reply	other threads:[~2017-01-13  1:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-11 15:44 How does one set up a syntax table for (* and //? Clément Pit--Claudel
2017-01-12  1:19 ` Noam Postavsky
2017-01-12  1:31   ` Clément Pit--Claudel
2017-01-12 13:55     ` Stefan Monnier
2017-01-13  1:33       ` Clément Pit--Claudel [this message]

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

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

  git send-email \
    --in-reply-to=b7f9a362-dd69-719f-717c-4c71d0a78299@gmail.com \
    --to=clement.pit@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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 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.