質問

I'm trying to modify spss.el to provide accurate fontification for SPSS comments. Below is a summary of how SPSS's syntax highlights and treats comments:

* = an asterisk starts commment at beginning of line

\n\n = two new lines end comments

.\n = period + newline also ends comment

/* = slash and star starts comment, and is ended with a single new line */ ends a comment only if on the same line as a /*

So far my syntax table reads:

(let ((spss-mode-syntax-table (make-syntax-table)))
  (modify-syntax-entry ?* "<" spss-mode-syntax-table)
  (modify-syntax-entry ?. ". 3" spss-mode-syntax-table)
  (modify-syntax-entry ?\n "- 34" spss-mode-syntax-table)
  (modify-syntax-entry ?' "\"" spss-mode-syntax-table)
  (modify-syntax-entry ?\\ "@ " spss-mode-syntax-table)
  spss-mode-syntax-table)

This for the most part works, except that the asterisk only functions as a commment delimiter when it's at the beginning of a line. Is there a way to denote that the asterisk is a comment delimiter only at the line start?

Thank you for reading!

役に立ちましたか?

解決

For the /* ... */ part, you can use

(modify-syntax-entry ?/ ". 14" st)
(modify-syntax-entry ?* ". 23" st)
(modify-syntax-entry ?\n ">" st)

But for the * ... \n\n, you need a different comment style and since it reuses the same chars * and \n as the other comment style, you can't use simple syntax-table settings to explain it to Emacs. Instead, you'll need to use a syntax-propertize-function which will place a "< b" syntax on a * at beginning of line and a "> b" syntax on the \n of \n\n. E.g.

(set (make-local-variable 'syntax-propertize-function)
     (syntax-propertize-rules
       ("^\\(\\*\\)" (1 "< b"))
       ("\n\\(\n\\)" (1 "> b"))
       ("\\(\\.\\)\n" (1 "> b"))))
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top