[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 02:13:19 +0100 |
I do not know how good the following defun is to disable the lowering
and raising typeface. I got it from "tex-mode.el" but do not really
know how to use it.
(defun supinf-disable-cruc (beg end)
"Set typeface for text between BEG and END."
(font-lock-default-unfontify-region beg end)
(while (< beg end)
(let ((next (next-single-property-change beg 'display nil end))
(prop (get-text-property beg 'display)))
(if (and (eq (car-safe prop) 'raise)
(member (car-safe (cdr prop)) deviat-supinf)
(null (cddr prop)))
(put-text-property beg next 'display nil))
(setq beg next))))
> Sent: Saturday, February 13, 2021 at 12:58 PM
> From: "Christopher Dimech" <dimech@gmx.com>
> To: moasenwood@zoho.eu
> Cc: help-gnu-emacs@gnu.org
> Subject: Re: font-lock as a single command
>
> 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, 2021/02/12
- Re: font-lock as a single command,
Christopher Dimech <=
- 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
- Re: font-lock as a single command, Christopher Dimech, 2021/02/12