Are there any better alternatives?
Emacs 27 will support a fill column indicator natively by way of the buffer-local minor mode display-fill-column-indicator-mode and its global counterpart global-display-fill-column-indicator-mode.
Here it is in action:
Quoth (emacs) Displaying Boundaries:
14.15 Displaying Boundaries
You can use the package font-lock-profiler. For each font-lock rule, it measures execution time and the number of times the rule matched.
The package supports measuring time for highlighting a buffer or a region. It also allows measuring time during an editing session. Simply run font-lock-profiler-start, edit your text, and run font-lock-profiles-stop-and-...
I don't think "inserting x and seeing the resulting font-lock highlighting" is a good approach in general. You'll likely be better off calling asking directly the code that performs this font-lock highlighting (which should be able to make this decision directly).
But FWIW, here's how you could do it "by asking font-lock" like you suggest:
A way to think about figuring that out is to wonder what code in hi-lock needs to know what has been highlighted. An obvious place is in the code for unhighlighting, since it prompts for a choice of regexps that have already been highlighted. If you look at the function, you can probably chase it down from there.
I noticed that you have found the answer to your question already, by looking at the source code.
The behaviour is in fact documented. The doc string of the variable font-lock-keywords contains the following, in the section describing MATCH-ANCHORED:
The limit of the
MATCHER search defaults to the end of the line after
PRE-MATCH-FORM is evaluated. ...
M-x customize-group RET css RET
would inform you about:
css-fontify-colors is a variable defined in `css-mode.el'.
Its value is t
This variable is safe as a file local variable if its value
satisfies the predicate `booleanp'.
Whether CSS colors should be fontified using the color as the background.
The function c-literal-limits, defined in progmodes/cc-engine.el determines how strings and comments are identified in all c-mode variants. It uses these two definitions to do so:
;; String syntax chars, suitable for skip-syntax-(forward|backward).
(defconst c-string-syntax (if (memq 'gen-string-delim c-emacs-features)
Here's a code snippet that will make all occurrences of " / " appear as " ÷ " in the current buffer:
(add-to-list 'font-lock-extra-managed-props 'display)
'((" \\(/\\) " 1 '(face nil display "÷"))))
The first line makes font-lock manage the display property of text, so that it removes the property when a piece of text no longer ...
I believe what you need to do is check the inheritance of the various faces. This can be done with describe-face. The available options are given in the manual under Face Attributes, but I believe the one you want is unspecified.
Here is what I use in my init.el for highlighting and how I solved the problem of the highlight clobbering other faces:
You need to set font-lock keywords, e.g.,
(1 font-lock-keyword-face nil t)
(2 font-lock-function-name-face nil t))))
the above is adapted from https://github.com/emacs-mirror/emacs/blob/8fe21b03/lisp/emacs-lisp/generator.el#L796. I suggest you to ...
I think you're looking for C-hv hi-lock-interactive-patterns
Following the question edit...
The strange behaviour (for me) of this function is that the STRING 2 highlight is non turned off
Ultimately hi-lock is using the font-lock machinery, and so the patterns get added to (but not removed from) font-lock-keywords with the way your code was working. ...
Since fill-column-indicator is quite heavy, this solution shows a character to the right of the current line.
So when you're typing you can see the line limit before you exceed it.
This defines the minor-mode hl-line-margin-mode:
;; Global, ensures one active margin for the active buffer.
(defvar hl-line-margin--overlay nil)
I've found a solution using the emacs package mmm-mode. Most of the information I got was from this article.
What this package does, is allow multiple major modes in the same buffer. You basically set the opening and closing clauses for whatever nested syntax you have, and that block will be highlighted in a submode.
M-x package-install RET graphql-mode
The main workhorse here is the following:
(add-hook 'org-mode-hook (lambda ()
(font-lock-add-keywords nil tex-font-lock-keywords-3)))
In addition, I had to customize the subscript, superscript, and tex-math faces to get this effect:
You can customize the faces to get them to look how you like.
I also found that I had to remove the org-...