Trying to define comments for SPSS in syntax table - emacs

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

Related

emacs prettify-symbols replacing characters at same point

I am using prettify-symbols to switch between the following words and shortcuts. The problem is that when the replacement is more than a single character, all letters are being inserted at the same point.
For instance when little is replaced I get a single l, rather than ll.
(defvar cluster
'(
("all" . "l") ("as" . "as") ("can" . "k")
("do" . "do") ("for" . "f") ("in" . "n")
("is" . "s") ("it" . "t") ("know" . "no")
("like" . "lk") ("little" . "ll") ("more" . "mo")
("some" . "so") ("than" . "n") ("that" . "ta")
("there" . "tr") ("this" . "th") ("time" . "ti")
("to" . "to") ("we" . "w") ("well" . "l")
("will" . "l") ("work" . "wk") ("you" . "u"))
"List of replacements for specific words.")
(defun prettify-cluster ()
"Set keywords and corresponding glyph."
(setq-local prettify-symbols-alist cluster))
The doc string of variable prettify-symbols-alist tells you that each alist entry is (SYMBOL . CHARACTER), where SYMBOL is a string.
In your alist, you have instead (STRING . STRING) entries.
prettify-symbols-alist is a variable defined in prog-mode.el.
Its value is nil
Automatically becomes buffer-local when set.
Documentation:
Alist of symbol prettifications.
Each element looks like (SYMBOL . CHARACTER), where the symbol
matching SYMBOL (a string, not a regexp) will be shown as
CHARACTER instead.
CHARACTER can be a character, or it can be a list or vector, in
which case it will be used to compose the new symbol as per the
third argument of compose-region.
Furthermore, if you use a list or vector of chars for CHARACTER then those chars are composed.
I think that what you want is maybe something like abbrev-mode?

emacs automatically highlight *E *F etc and highlight to EOL

I am trying to build my major mode for syntax highlighting log files from a certain tool flow.
and I've been using this excellent guide to get started
http://ergoemacs.org/emacs/elisp_syntax_coloring.html
but I would like to highlight "*W", "*E" and "*F"
but I cannot get that to work
here are my font-lock keywords
(setq mylog-font-lock-keywords
(let* (
;; define several category of keywords
(x-warnings '("UVM_ERROR" "UVM_FATAL" "^.*E" "F"))
(x-keywords '("UVM_INFO" "NOTE" "Note"))
(x-types '("UVM_WARNING" "*W," "xmsim"))
(x-constants '("ACTIVE" "AGENT" "ALL_SIDES" "ATTACH_BACK"))
(x-events '("at_rot_target" "at_target" "attach"))
(x-functions '("llAbs" "llAcos" "llAddToLandBanList" "llAddToLandPassList"))
;; generate regex string for each category of keywords
(x-keywords-regexp (regexp-opt x-keywords 'words))
(x-types-regexp (regexp-opt x-types 'words))
(x-constants-regexp (regexp-opt x-constants 'words))
(x-events-regexp (regexp-opt x-events 'words))
(x-functions-regexp (regexp-opt x-functions 'words))
(x-warnings-regexp (regexp-opt x-warnings 'words))
)
`(
(,x-types-regexp . font-lock-type-face)
(,x-constants-regexp . font-lock-constant-face)
(,x-events-regexp . font-lock-builtin-face)
(,x-functions-regexp . font-lock-function-name-face)
(,x-keywords-regexp . font-lock-keyword-face)
(,x-warnings-regexp . font-lock-warning-face)
;; note: order above matters, because once colored, that part won't change.
;; in general, put longer words first
)))
;;;###autoload
(define-derived-mode mylog-mode verilog-mode "log mode"
"Major mode for editing LOG FILES…"
;; code for syntax highlighting
(setq font-lock-defaults '((mylog-font-lock-keywords))))
(set-face-foreground 'font-lock-type-face "yellow")
;; add the mode to the `features' list
(provide 'mylog-mode)
as you can see I've tried a few things with out success.. any other words are highlighted correctly?
as a final touch I would like to for all occurenses of WARNING or ERROR I would like to highlight the entire line until EOL.
I have found some examples but none that show how to highlight until EOL in a major mode lisp file
This is an example (taken from my init.el). Hope it help.
(font-lock-add-keywords nil
'( ; high-light full line ending with "E" or "FATAL"
("^.*\\(E\\|FATAL\\)$" . 'font-lock-function-name-face)
; high-light full line beginning with '*E' '*F' '*W'
("^\\*[EFW]\\b.*$" . 'font-lock-comment-face)
; high-light only ending part of the lines which contain "F"
("\\b\\w*F$" . 'font-lock-function-name-face)
; high-light from "UVM" to end of line
("\\bUVM.*$" . 'font-lock-function-name-face)
; high-light only words that end with "G"
("\\b\\w*G\\b" . 'font-lock-function-name-face)
; bold things between 2 **, like **bold**
("\\*\\*.+?\\*\\*" . 'bold)))

Eclipse java - how to add full line with double quotes

I'm programming in Eclipse and i have a SQL script that got multiple lines:
SELECT * FROM
.... (bla bla)
... (bla bla )..
... (bla bla bla bla)
I have to add the double quotes like this:
" SELECT * FROM "
+ ".... (bla bla) "
+ "... (bla bla ).."
+ "... (bla bla bla bla) "
Is there any SHORTCUT to do this in Eclipse?
EDITED:
I have a SQL script that got like 50 lines (for examp.):
line 1: SELECT * FROM
line 2: HR_EMPLOYEES
line 3: ... (bla bla)
.
.
.
line 50: AND NAME like 'AP%'
I have to do in every line this:
+ " (CODE SQL) "
+ " (CODE SQL) "
MANUALLY.
Is there any shortcut to do this ( + " " ) in eclipse java language?
Use column selection Alt + Shift + A and then select the "beginnings" of the lines and simply type + " then do the same for the end of lines but type ". This will insert typed characters in all of the selected lines.
I attach a short video on how I do it in Eclipse.
So you have this situation
some text
some text
and want to arrive at
"some text"
+ "some text"
The easiest I can imagine is this: replace linebreaks with "(linebreak)+ "
1) write this somewhere
"
+ "
2) mark that from " to " text and copy it
3) open the search/replace dialog
4) paste to the "replace with" field (yes, you can paste strings with new lines there)
5) write a newline somewhere, basically a line and press "enter" immediately
6) mark this line break (start mark in first position in a the first line and end in the first position of the next line)
7) cut and past into the "find" field (mind that nothing will appear there!)
8) mark all the text you want to fix up
9) select scope: selected lines
10) replace all
11) add extra " in the first line and remove extra +" in the last line
"some text"
+ "some text"
Shortcut? Well, if you have many lines to fix up... yes, it can make a difference.
Could you please specify the programming language you're using?
Assuming you meant java, I'd say just use the String class method called "replace"
And you will need to replace the "new line" char (\n) into " \n + ".
Hope this will help you create your solution.
You can type it out in one line like
"SELECT * FROM blah .... (bla bla) .... (bla bla) .... (bla bla bla)"
And then put your cursor where you want to begin on the next line, hit enter, and Eclipse will automatically add the respective ""s and +s
Or as you are typing out the query string, just hit enter when you want to go to the next line. If you are typing a string (with quotes) it will automatically add the "" and +s
Or if you are copying and pasting the query string try this out https://stackoverflow.com/a/2159931/2386700
Simply define a String in Eclipse like private final String selSQL="";
Copy-paste your query between the double quotes
Press Enter key at any end of word, the eclipse automatically appends double quotes "", followed by concatinator + on the same line, and double quotes " in the next line for the continuation.
Use Del and End to continue for the rest, until all lines are concatinated.

Emacs lisp semicolon character?

It's a silly question, really.
I want to do
(position ?; "This is a test; or is it?")
Unfortunately, the font-lock is regex based,
so it highlights a part of the code as a comment.
What's the best way to handle this? At the moment, I've got either
(defconst semicolon (aref ";" 0))
(position semicolon "This is a test; or is it?")
or
(position 59 "This is a test; or is it?")
You should escape the semicolon with a backslash:
(position ?\; "This is a test; or is it?")

Jinja templates syntax hilighting

I'd like to adapt jinja.el to work with one-line comments using ##. But my knowlege of elisp is bad. Who can help me? What do I want: i'd like to hilite
## some text
## {% include "_template.html" %}
as a commented out strings. But it works not fully correct. 1st line of snippet looks like comment out while 2nd - not. Here is what i've got:
And here is a part of jinja.el taken from Jinja's git repo plus my regexp for ##:
(defconst jinja-font-lock-keywords
(list
; (cons (rx "{% comment %}" (submatch (0+ anything))
; "{% endcomment %}") (list 1 font-lock-comment-face))
'("{%-?\\|-?%}\\|{{\\|}}" . font-lock-preprocessor-face)
'("{# ?\\(.*?\\) ?#}" . (1 font-lock-comment-face))
'("## ?\\(.*\\)" . (1 font-lock-comment-face))
'("{#\\|#}" . font-lock-comment-delimiter-face)
'("##" . font-lock-comment-delimiter-face)
;; first word in a block is a command
OK. I found solution. Change
'("## ?\\(.*\\)" . (1 font-lock-comment-face))
to
'("## ?\\(.*\\)" . (1 font-lock-comment-face t))
ie setting 'override' parameter to true solves me question.