help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Introducing face in comments for various modes


From: Thibaut Verron
Subject: Re: Introducing face in comments for various modes
Date: Tue, 13 Dec 2022 11:45:19 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2


On 13/12/2022 11:40, Heime wrote:
------- Original Message -------
On Tuesday, December 13th, 2022 at 10:05 AM, Thibaut Verron 
<thibaut.verron@gmail.com> wrote:


On 13/12/2022 10:46, Heime wrote:

------- Original Message -------
On Tuesday, December 13th, 2022 at 9:35 AM, Thibaut Verron 
thibaut.verron@gmail.com wrote:

On 13/12/2022 09:30, Heime wrote:

------- Original Message -------
On Tuesday, December 13th, 2022 at 8:04 AM, Heime heimeborgia@protonmail.com 
wrote:

------- Original Message -------
On Tuesday, December 13th, 2022 at 7:52 AM, Jean Louis bugs@gnu.support wrote:

Heime, I like the idea of highlighting comments, though I do it this
way to specify (syntax comment-start) as that works for multiple
modes.

; one
;; two
;;; three
;;;; and more

;;; Highlighting comments

(setq rcd-regexp-comment (rx line-start
(one-or-more (syntax comment-start))
(one-or-more space)
(group (one-or-more not-newline))
line-end))

;; (highlight-regexp regexp nil 1)
;; (unhighlight-regexp regexp)

Jean
I would like to introduce (syntax comment-start) in place
of ";;" in "^;;\s+\\[.+\\].*$".
It's not something you can "introduce" in your regexp, it only makes
sense within the context of a regexp built with rx:
https://www.gnu.org/software/emacs/manual/html_node/elisp/Rx-Notation.html

Rewriting your regexp as an rx regexp would not be too difficult if you
want to go that route, Jean's example is a good template.

Otherwise, as an approximation of that feature, you could built your
regex string using the value of the variable comment-start ( ";" in
emacs-lisp-mode) instead of hardcoding ;; .
How can one specify two comment characters next to each other?

Using the variable, the same way you would normally do for a regexp, by
putting \{2\} after the matched regexp.

E.g.

ELISP> (format "\\(%s\\)\\{2\\}" comment-start)

"\\(;\\)\\{2\\}"

(don't trust me for the number of escape characters)

But I don't think it's really what you want: for example, in a mode
where comment-start is "# " (e.g. org or python), this will match "# # "
but not "##".
Let's disregard org and python at this time.

Even then, avoiding the need to carefully count string expansions for backslashes would be enough reason to use syntax tables for me.


Using the syntax table is better here, as the character # alone has the
syntax of a comment-start.

I had forgotten about the simplest option, that is the regexp equivalent
of the rx syntax: \s< in a regexp will match exactly a character with
the syntax of a comment-start.

So: "\s<\{2\}" should be exactly what you want (at least in languages
where comments start with a single character).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]