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 05:31:10 +0100 [thread overview]
Message-ID: <trinity-01e96af9-16bf-42e8-813b-1333e21b99fe-1613190669986@3c-app-mailcom-bs05> (raw)
In-Reply-To: <87y2fsa8x9.fsf@zoho.eu>
[-- Attachment #1: Type: text/plain, Size: 735 bytes --]
I have sent the file. I attach again.
> Sent: Saturday, February 13, 2021 at 4:28 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:
>
> > But now I have a problem. Reading a file does not apply
> > supinf. However, hitting "H-t" does nothing, rather than
> > enabling it.
> >
> > It is only with the hook that the functionality is enabled.
> > Perhaps "supinf-enable" is not working, am not sure.
>
> Please include the source when you ask... "ask" :P
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>
[-- Attachment #2: crucible-mode.el --]
[-- Type: text/plain, Size: 16982 bytes --]
;;; crucible-mode.el --- Typeface for texmath -*- lexical-binding:t -*-
;; Copyright (C) 2021 Free Software Foundation
;; Author: Christopher Dimech <email@here.com>
;; URL: https://website-here
;; Version: 0.1.0
;; Package-Requires: ((emacs "27.1"))
;; This file is part of Behistun, a Gnu Behistun.
;; Behistun is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; Behintun is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the Gnu Affero General Public
;; License along with Behistun. If not, see
;; <http://www.gnu.org/licenses/>.
;;; -------------------------------------------------------------------
;;; Commentary:
;; * Setting texmath keywords using rx
;; rx uses regular expressions that are easier to read.
;;
;; * Byte Compilation
;;
;; The Byte Compiler translates functions written in Lisp into
;; byte-code, a special representation that makes functions execute
;; faster. The byte compiler also returns very useful messages.
;;
;; To byte-compile a file named crucible-mode.el, launch Emacs and
;; enter the following command.
;;
;; M-x
;; M-x byte-compile-file Ret crucible-mode.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (require 'rx) ; Is this needed
;; (eval-when-compile
;; (setq byte-compile-function-environment
;; (delq (assq 'crucible-mode byte-compile-function-environment)
;; byte-compile-function-environment)))
;; ---------------------------------------------------------------------
;;; Code:
(defgroup crucible ()
"Groups tools for assisting with superior & inferior typeface."
:prefix "crucible-"
:group 'crucible)
;; ---------------------------------------------------------------------
(defgroup keyword-tfc ()
"Groups tools for typesetting mathematical symbols."
:prefix "crucible-keyword"
:group 'crucible)
;; ---------------------------------------------------------------------
(defvar crucible-mode-hook nil
"Hook called when Crucible Mode is enabled.")
;; ---------------------------------------------------------------------
;;;###autoload
(define-minor-mode crucible-mode
"Minor mode for assisting with superior & inferior typeface."
:init-value nil
:global nil
:lighter " Crucible"
;;(run-hooks 'crucible-mode-hook)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(multic "
* Colour tex keywords")
;; _ _ _
;; __ ___| |___ _ _ _ _ | |____ __ ___ _ __| |
;; / _/ _ \ / _ \ || | '_| | / /\ V V / '_/ _` |
;; \__\___/_\___/\_,_|_| |_\_\ \_/\_/|_| \__,_|
;; ---------------------------------------------------------------------
(defface colour-tex-cruc
'( (default :inherit bold)
( ((class color) (min-colors 88) (background light))
:foreground "#FF0000" )
( ((class color) (min-colors 88) (background dark))
:foreground "#FF0000" )
(t :inherit font-lock-builtin-face) )
"Typeface for tex keywords.")
;; -------------------------------------------------------------------------
(defconst tex-keywords-cruc
`(
;; Greek. Use (0 'colour-tex-cruc) to highlight the leading "\".
(,(rx "\\" word-start (group (or "alpha" "beta" "chi" "delta"
"Delta" "epsilon" "varepsilon" "eta" "gamma" "Gamma" "iota"
"kappa" "lambda" "Lambda" "mu" "nu" "omega" "Omega" "phi"
"varphi" "Phi" "pi" "varpi" "Pi" "psi" "Psi" "rho" "varrho"
"sigma" "varsigma" "Sigma" "tau" "theta" "vartheta" "Theta"
"upsilon" "Upsilon" "xi" "Xi" "zeta")) word-end)
(1 'colour-tex-cruc))
;;
;; Mathematical symbols
(,(rx "\\" word-start (group (or "infty" "Re" "Im" "angle"
"triangle" "backslash" "vert" "Vert" "emptyset" "bot" "top"
"exists" "forall" "hbar" "ell" "aleph" "imath" "jmath"
"nabla" "neg" "lnot" "prime" "partial" "surd" "wp" "flat"
"sharp" "natural" "clubsuit" "diamondsuit" "heartsuit"
"spadesuit")) word-end)
(1 'colour-tex-cruc))
;;
;; Binary operations
(,(rx "\\" word-start (group (or "vee" "wedge" "amalg" "cap" "cup"
"uplus" "sqcap" "sqcup" "dagger" "ddaccer" "land" "lor"
"cdot" "diamond" "bullet" "circ" "bigcirc" "odot" "ominus"
"oplus" "oslash" "otimes" "pm" "mp" "triangleleft"
"triangleright" "bigtriangledown" "bigtriangleup" "ast"
"star" "times" "div" "setminus" "wr")) word-end)
(1 'colour-tex-cruc))
;;
;; Mathematical relations
(,(rx "\\" word-start (group (or "asymp" "cong" "dashv" "vdash"
"perp" "mid" "parallel" "doteq" "equiv" "ge" "geq" "le"
"leq" "gg" "ll" "models" "ne" "neq" "notin" "in" "ni" "owns"
"prec" "preceq" "succ" "succeq" "bowtie" "propto" "approx"
"sim" "simeq" "frown" "smile" "subset" "subseteq" "supset"
"supseteq" "sqsubseteq" "sqsupseteq" "cos" "sin" "tan" "cot"
"csc" "sec" "arccos" "arcsin" "arctan" "cosh" "coth" "sinh"
"tanh" "det" "dim" "exp" "ln" "log" "lg" "arg" "deg" "gcd"
"hom" "ker" "inf" "sup" "lim" "liminf" "limsup" "max" "min"
"Pr")) word-end)
(1 'colour-tex-cruc))
;;
;; Delimeters
(,(rx "\\" word-start (group (or "lbrace" "rbrace" "lbrack"
"rbrack " "langle" "rangle" "lceil" "rceil" "lfloor"
"rfloor")) word-end)
(1 'colour-tex-cruc))
;;
;; Arrows
(,(rx "\\" word-start (group (or "leftarrow" "gets" "Leftarrow"
"rightarrow " "to" "Rightarrow" "leftrightarrow"
"Leftrightarrow" "longleftarrow" "Longleftarrow"
"longrightarrow" "Longrightarrow" "longleftrightarrow"
"Longleftrightarrow" "iff" "hookleftarrow" "hookrightarrow"
"leftharpoondown" "rightharpoondown" "leftharpoonup"
"rightharpoonup" "rightleftharpoons" "mapsto" "longmapsto"
"downarrow" "Downarrow" "uparrow" "Uparrow" "updownarrow"
"Updownarrow" "nearrow" "searrow" "nwarrow" "swarrow"))
word-end)
(1 'colour-tex-cruc))
;;
;; Large mathematical operations
(,(rx "\\" word-start (group (or "bigcap" "bigcup" "bigodot"
"bigoplus" "bigotimes" "bigsqcup" "biguplus" "bigvee"
"bigwedge" "coprod" "smallint" "int" "oint" "prod" "sum"
"limits" "nolimits" "displaylimits")) word-end)
(1 'colour-tex-cruc))
;;
;; Fractions and stacking
(,(rx "\\" word-start (group (or "over" "atop" "above" "choose"
"brace" "cases" "underbrace" "overbrace" "underline"
"overline" "overleftarrow" "overrightarrow" "buildrel"
"ldots" "cdots" "vdots" "ddots" "lgroup" "rgroup" "left"
"right" "delimiter" "delimiterfactor" "delimitershortfall"
"matrix" "pmatrix" "bordermatrix" "sqrt" "root" "of"))
word-end)
(1 'colour-tex-cruc))
;;
;; Punctuation and style
(,(rx "\\" word-start (group (or "cdotp" "ldotp" "colon" "sb" "sp"
"textstyle" "scriptstyle" "scriptscriptstyle"
"displaystyle")) word-end)
(1 'colour-tex-cruc))
;;
;; Mathematical accents
(,(rx "\\" word-start (group (or "acute" "b" "bar" "breve" "check"
"ddot" "dot" "grave" "hat" "widehat" "tilde" "widetilde"
"vec")) word-end)
(1 'colour-tex-cruc))
;;
;; Mathematical class
(,(rx "\\" word-start (group (or "mathord" "mathop" "mathbin"
"mathrel " "mathopen" "mathclose" "mathpunct")) word-end)
(1 'colour-tex-cruc))
;;
;; Equations and multiline display
(,(rx "\\" word-start (group (or "eqno" "leqno" "displaylines"
"eqalign " "eqalignno" "leqalignno")) word-end)
(1 'colour-tex-cruc))
;;
;; Big sizes. Using concat rather than rx.
(,(concat "\\\\\\<\\(big\\|bigl\\|bigm\\|bigr\\|Big\\|Bigl\\|"
"Bigm\\|Bigr\\|bigg\\|biggl\\|biggm\\|biggr\\|"
"Bigg\\|Biggl\\|Biggm\\|Biggr\\|downbracefill\\|"
"upbracefill\\|arrowvert\\|Arrowvert\\|lmoustache\\|"
"rmoustache\\|bracevert\\)\\>")
(1 'colour-tex-cruc)) )
"Fontification for letters and symbols.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; * Positioning of superscripts and subscripts
;; _ __
;; ____ _ _ __(_)_ _ / _| _ __ ___ ____ _
;; (_-< || | '_ \ | ' \| _| | '_ \/ _ (_-< ' \
;; /__/\_,_| .__/_|_||_|_| | .__/\___/__/_||_|
;; |_| |_|
;; ---------------------------------------------------------------------
(defcustom supinf-signal t
"Enables typeface for tex commands."
:type 'boolean
:group 'supinf)
(put 'supinf-signal 'safe-local-variable 'booleanp)
;; ---------------------------------------------------------------------
(defcustom deviat-supinf '(0.18 -0.18)
"Sets the vertical shift for superior and inferior glyphs.
Deviation is measured relative to the text font size."
:group 'supinf
:type '(list (float :tag "superior-deviation")
(float :tag "inferior-deviation")) )
;; ---------------------------------------------------------------------
(defcustom height-scale-supinf 0.8
"Sets relative supinf height ratio with the preceding text.
For nested expressions, the setting is applied repeatedly,
subject to the limit set by `crucible-height-minimum'."
:type 'float
:group 'supinf)
;; ---------------------------------------------------------------------
(defcustom height-minimum-supinf 0.8
"Sets the minimum glyph height.
For integer values, the height is in units of 1/10 point.
Relative height is used for floating point values."
:type '(choice (integer :tag "Font height in 1/10 point units")
(float :tag "Fraction of font height"))
:group 'supinf)
;; ---------------------------------------------------------------------
(defun supinf-height (height)
"Return integer HEIGHT of superior and inferior glyph.
Height is an integer that is 1/10 of point size. Not smaller than the
value set by `crucible-height-minimum'."
(ceiling
(max
(if (integerp height-minimum-supinf)
height-minimum-supinf
(condition-case nil ; For bootstrapping.
(* height-minimum-supinf
(face-attribute 'default :height))
(error 0)))
(* height height-scale-supinf)))) ; assumes height is integer.
;; ---------------------------------------------------------------------
(defface supr-tfc
'((t :height supinf-height))
"Typography for superior glyphs."
:group 'supinf)
;; ---------------------------------------------------------------------
(defface infr-tfc
'((t :height supinf-height))
"Typography for inferior glyphs."
:group 'supinf)
;; ---------------------------------------------------------------------
(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."
(interactive)
(setq-local 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))
;; ---------------------------------------------------------------------
(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))))
;; ---------------------------------------------------------------------
;;(defun tex-typeface-crucible ()
;; "Font-lock setup for mathematical symbols."
;; (font-lock-flush (point-min) (point-max))
;; (if crucible-supinf-enable
;; (progn
;; (font-lock-add-keywords nil tex-keywords-cruc t)
;; (font-lock-add-keywords nil supinf-font-lock-cruc t))
;; (font-lock-remove-keywords nil tex-keywords-cruc)
;; (supinf-disable-cruc (point-min) (point-max)))
;; (font-lock-flush (point-min) (point-max)))
(defun supinf-disable ()
"Disable supinf functionality."
(interactive)
(setq-local supinf-signal nil)
(font-lock-flush))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; * Displays texmath glyphs for the corresponding tex commands.
;; _ _ _ _
;; _ __ __ _| |_| |_ __ _| |_ _ _ __| |_ ___
;; | ' \/ _` | _| ' \ / _` | | || | '_ \ ' \(_-<
;; |_|_|_\__,_|\__|_||_| \__, |_|\_, | .__/_||_/__/
;; |___/ |__/|_|
;;(require 'prog-mode)
(defun texglyph-predicate (start end _match)
"Prettify mathematical expressions defined using tex syntax.
Matches START with a backslash and END with a word constituent
[a-zA-Z0-9]. Uses the prettify functionality provided by
'prog-mode'."
(not (or (memq (char-before start) '(?\\))
(memq (char-syntax (or (char-after end) ?\s)) '(?w))
(nth 8 (syntax-ppss)))))
;; ---------------------------------------------------------------------
(defun texglyph-crucible ()
"Set keywords and corresponding glyph."
(push '("\\alpha" . ?α) prettify-symbols-alist)
(push '("\\beta" . ?β) prettify-symbols-alist)
(setq prettify-symbols-compose-predicate 'texglyph-predicate))
;; ---------------------------------------------------------------------
(defun texglyph-enable ()
"Enables typeface for tex glyphs."
(texglyph-crucible)
(prettify-symbols-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ---------------------------------------------------------------------
(defvar-local texglyph-state-cruc nil)
(defun texglyph-cycle-crucible ()
"Cycles supinf and texglyph functionality."
(interactive)
(pcase texglyph-state-cruc
;; ----------------------------------------------
(1 (setq supinf-signal t)
(supinf-enable)
(message "Supinf Enabled")
(setq-local texglyph-state-cruc (1+ texglyph-state-cruc)))
;; ----------------------------------------------
(2 (texglyph-enable)
(message "Supinf and Glyphs Enabled")
(setq-local texglyph-state-cruc (1+ texglyph-state-cruc)))
;; ----------------------------------------------
(_ (supinf-disable)
(prettify-symbols-mode 0)
(message "Supinf and Glyphs Disabled")
(setq-local texglyph-state-cruc 1)) ))
;; -----------------------------------------------------------------------
;;(defun crucible-prettify-hook ()
;; "Hooks."
;; (add-hook 'crucible-mode-hook #'supinf-enable)
;; (add-hook 'texinfo-mode-hook #'texglyph-crucible))
(global-set-key (kbd "H-t") #'supinf-enable)
;;(global-set-key (kbd "H-t") #'texglyph-cycle-crucible)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;(crucible-prettify-hook)
;;(add-hook 'crucible-mode-hook #'supinf-enable)
(provide 'crucible-mode)
;;; crucible-mode.el ends here
next prev parent reply other threads:[~2021-02-13 4:31 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
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 [this message]
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-01e96af9-16bf-42e8-813b-1333e21b99fe-1613190669986@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).