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.
Related
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?
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)))
Currently, I have my global TODO list shown as follows thanks to erikstokes:
(org-agenda-prefix-format " %i %?-12(concat \"[ \"(org-format-outline-path (list (nth 1 (org-get-outline-path)))) \" ]\") ")))
which outputs:
for org layout:
However, as you can see, for Task A, even though there is nothing in the project, it still shows up on the list.
describe-variable for org-agenda-prefix-format says :
If the first character after `%' is a question mark, the entire field
will only be included if the corresponding value applies to the current
entry. This is useful for fields which should have fixed width when
present, but zero width when absent.
So I feel like by using %?, [ ] shouldn't be there for Task A, yet it still shows up.
The problem is that the field is never empty: it will always contain at least the left and right square brackets plus the white space to bring it to a width of 12.
The solution is to write a function that returns either an empty string or the bracketed project and use that in the format:
(defun foo ()
(let ((x (nth 1 (org-get-outline-path))))
(if x
(concat "[ " (org-format-outline-path (list x)) " ]")
"")))
(setq org-agenda-prefix-format " %i %?-12(foo) "
I'm trying to write a skeleton-function to output expressions in a loop. Out of a loop I can do,
(define-skeleton test
""
> "a")
When I evaluate this function it outputs "a" into the working buffer as desired. However, I'm having issues when inserting this into a loop. I now have,
(define-skeleton test
"A test skeleton"
(let ((i 1))
(while (< i 5)
>"a"
(setq i (1+ i)))))
I would expect this to output "aaaaa". However, instead nothing is outputted into the working buffer in this case. What is happening when I insert the loop?
The > somestring skeleton dsl does not work inside lisp forms.
You can however concatenate the string inside a loop:
(define-skeleton barbaz
""
""
(let ((s ""))
(dotimes (i 5)
(setq s (concat s "a")))
s)
)
My understanding is that code such as
> "a"
only works at the first nesting level inside a skeleton.
[EDIT] Regarding your question
What is happening when I insert the loop?
The return value of the let form (that is, the return value of the while form)is inserted. I do not know why it does not raise an error when evaluating > "a", but the return value of a while form is nil, so nothing is inserted.
I do agree that there's not much point using define-skeleton if you're going to need an (insert function within the skeleton.
This is also a rather trivial example to be using define-skeleton.
That said, they are often easier to read than a defun and useful when you want to create a function that inserts text (and optionally, takes input).
For example you may wish to have a different character repeated a set no. of times... Below, str refers to the argument supplied with the function (usually a string) and v1, v2 are the default names for local variables in a skeleton. Thus:
(define-skeleton s2 ""
nil ; don't prompt for value of 'str'
'(set 'v1 (make-string 5 (string-to-char str)))
\n v1 \n \n)
Below, calling the function leads to a newline, the string, then leaves the cursor at the position indicated by the square brackets [].
(s2 "a")
aaaaa
[]
I have a function that uses (case (read-event) . . .) -- I have been unable to get down-mouse-1 to equal an integer for the duration of the function. The following is an example where down-mouse-1 yields a result of Try again instead of Hello world. All of the following examples work, except for down-mouse-1: ('f12 516); (?\s-k 517); ('f3 518); ('C-tab 519); ('C-M-s-right 520); (?m 522).
(let* (
(test (case (read-event)
('down-mouse-1 9999))))
(cond
((eq test 9999)
(message "Hello world."))
(t (message "Try again."))))
read-event never returns down-mouse-1. For a mouse click, the first event it will return will look like (down-mouse-1 ...). So you could do:
(pcase (read-event)
(`(down-mouse-1 . ,_) 9999))
Note that in my experience, 99% of the uses of read-event would be better rewritten some other way.
Not clear to me what you are trying to do. But you should not quote the keys in a case clause. E.g, use down-mouse-1, not 'down-mouse-1.