[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: font-lock as a single command
From: |
Christopher Dimech |
Subject: |
Re: font-lock as a single command |
Date: |
Sat, 13 Feb 2021 01:58:37 +0100 |
I have the following three defun
"supinf-match" matches superscript and subscript code structures.
In the following example "\alpha^{ijk} \beta_{pqr}", {ijk} is
rained in height, whereas {pqr} is lowered in height.
The raising and lowering is achieved by calling "supinf-raise-cruc".
"supinf-enable" sets the new typeface using "font-lock-add-keywords".
I also want a function that disables the raising and lowering, returning
the buffer to how it was before "supinf-enable" was called.
(defun supinf-raise-cruc (pos)
"Raise and lower typeface at position POS."
(unless (or (memq (get-text-property pos 'face)
'(font-lock-constant-face font-lock-builtin-face))
;; Check for backslash quoting
(let ((odd nil) (pos pos))
(while (eq (char-before pos) ?\\)
(setq pos (1- pos) odd (not odd)))
odd))
(if (eq (char-after pos) ?^)
`(face supr-tfc display (raise ,(car deviat-supinf)))
`(face infr-tfc display (raise ,(cadr deviat-supinf))) )))
(defun supinf-match (limit)
"Match superior and inferior glyph patterns up to LIMIT."
(when (and supinf-signal
(re-search-forward "[_^] *\\([^\n\\{}]\\|\
\\\\\\([a-zA-Z@]+\\|[^ \t\n]\\)\\|\\({\\)\\)" limit t))
(when (match-end 3)
(let ((beg (match-beginning 3))
(end (save-restriction
(narrow-to-region (point-min) limit)
(condition-case nil
(scan-lists (point) 1 1) (error nil)))))
;; body of let
(store-match-data
(if end
(list (match-beginning 0) end beg end)
(list beg beg beg beg)))))
t))
(defun supinf-enable ()
"Enables a typeface for displaying tex commands."
(setq supinf-signal t)
;; Syntax for font-lock-add-keywords is
;; (font-lock-add-keywords MODE KEYWORDS &optional HOW)
(font-lock-add-keywords nil
'( (supinf-match (1 (supinf-raise-cruc (match-beginning 0)))) )
t))
> Sent: Saturday, February 13, 2021 at 12:08 PM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor"
> <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: font-lock as a single command
>
> Christopher Dimech wrote:
>
> > (font-lock-add-keywords MODE KEYWORDS &optional HOW)
> >
> > What does the optional HOW actually do?
>
> It is actually described in the docstring:
>
> If optional argument HOW is ‘set’, they are used to replace
> the current highlighting list. If HOW is any other non-nil
> value, they are added at the end of the current
> highlighting list.
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>
- font-lock as a single command, Christopher Dimech, 2021/02/12
- Re: font-lock as a single command, Emanuel Berg, 2021/02/12
- Re: font-lock as a single command, Christopher Dimech, 2021/02/12
- Re: font-lock as a single command,
Christopher Dimech <=
- Re: font-lock as a single command, Christopher Dimech, 2021/02/12
- Re: font-lock as a single command, Emanuel Berg, 2021/02/12
- Re: font-lock as a single command, Christopher Dimech, 2021/02/12
- Re: font-lock as a single command, Emanuel Berg, 2021/02/12
- Re: font-lock as a single command, Christopher Dimech, 2021/02/12
- Re: font-lock as a single command, Emanuel Berg, 2021/02/12
- Re: font-lock as a single command, Christopher Dimech, 2021/02/12
- Re: font-lock as a single command, Christopher Dimech, 2021/02/12
- Re: font-lock as a single command, Christopher Dimech, 2021/02/12
- Re: font-lock as a single command, Emanuel Berg, 2021/02/12