unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Christopher Dimech <dimech@gmx.com>
To: moasenwood@zoho.eu
Cc: help-gnu-emacs@gnu.org
Subject: Re: font-lock as a single command
Date: Sat, 13 Feb 2021 01:58:37 +0100	[thread overview]
Message-ID: <trinity-f2e970a1-71a8-4717-a8c0-e40f7338897a-1613177917426@3c-app-mailcom-bs05> (raw)
In-Reply-To: <87a6s8de2x.fsf@zoho.eu>

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
> 
> 
>



  parent reply	other threads:[~2021-02-13  0:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 23:20 font-lock as a single command Christopher Dimech
2021-02-12 23:44 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-12 23:58   ` Christopher Dimech
2021-02-13  0:06     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  0:17       ` Christopher Dimech
2021-02-13  0:04   ` Christopher Dimech
2021-02-13  0:08     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  0:20       ` Christopher Dimech
2021-02-13  1:50         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  0:58       ` Christopher Dimech [this message]
2021-02-13  1:13         ` Christopher Dimech
2021-02-13  1:54         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  2:43           ` Christopher Dimech
2021-02-13  2:46             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  3:00               ` Christopher Dimech
2021-02-13  3:16                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  3:56                   ` Christopher Dimech
2021-02-13  4:09                     ` Christopher Dimech
2021-02-13  4:21                       ` Christopher Dimech
2021-02-13  4:28                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  4:31                           ` Christopher Dimech
2021-02-13  5:26                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  5:29                               ` Christopher Dimech
2021-02-13  5:39                               ` Christopher Dimech
2021-02-13  5:43                                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  5:51                                   ` Christopher Dimech
2021-02-13  6:07                                   ` Christopher Dimech
2021-02-13  6:20                                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-13  6:55                                       ` Christopher Dimech
2021-02-13  6:58                                         ` Emanuel Berg via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-f2e970a1-71a8-4717-a8c0-e40f7338897a-1613177917426@3c-app-mailcom-bs05 \
    --to=dimech@gmx.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).