* font-lock as a single command @ 2021-02-12 23:20 Christopher Dimech 2021-02-12 23:44 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-12 23:20 UTC (permalink / raw) To: Help Gnu Emacs I want to construct the font-lock as a single command (font-lock-add-keywords nil ...) But I am unsure how to do it. (defconst supinf-font-lock-cruc (append '((supinf-match (1 (supinf-raise-cruc (match-beginning 0))) ))) "Experimental expressions to highlight in TeX modes.") (defun supinf-enable () "Enables a typeface for displaying tex commands." (setq supinf-signal t) (font-lock-add-keywords nil supinf-font-lock-cruc t)) --------------------- Christopher Dimech General Administrator - Naiad Informatics - GNU Project (Geocomputation) - Geophysical Simulation - Geological Subsurface Mapping - Disaster Preparedness and Mitigation - Natural Resource Exploration and Production - Free Software Advocacy ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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:04 ` Christopher Dimech 0 siblings, 2 replies; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-12 23:44 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: > I want to construct the font-lock as a single command > > (font-lock-add-keywords nil ...) > > But I am unsure how to do it. I believe you :) > (defconst supinf-font-lock-cruc > (append > '((supinf-match > (1 (supinf-raise-cruc (match-beginning 0))) ))) > "Experimental expressions to highlight in TeX modes.") ? Here is how to add a single word to Elisp mode: (font-lock-add-keywords 'emacs-lisp-mode '( ("lamersRus" . font-lock-builtin-face) ) t) > (defun supinf-enable () > "Enables a typeface for displaying tex commands." > (setq supinf-signal t) > (font-lock-add-keywords nil supinf-font-lock-cruc t)) M-x font-lock-mode RET or (font-lock-mode 'toggle) -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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:04 ` Christopher Dimech 1 sibling, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-12 23:58 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs > Sent: Saturday, February 13, 2021 at 11:44 AM > 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: > > > I want to construct the font-lock as a single command > > > > (font-lock-add-keywords nil ...) > > > > But I am unsure how to do it. > > I believe you :) Have not understood how to use very well. I find it one serious approach with tremendous functionality. > > (defconst supinf-font-lock-cruc > > (append > > '((supinf-match > > (1 (supinf-raise-cruc (match-beginning 0))) ))) > > "Experimental expressions to highlight in TeX modes.") > > ? > > Here is how to add a single word to Elisp mode: > > (font-lock-add-keywords 'emacs-lisp-mode > '( > ("lamersRus" . font-lock-builtin-face) > ) > t) > > > (defun supinf-enable () > > "Enables a typeface for displaying tex commands." > > (setq supinf-signal t) > > (font-lock-add-keywords nil supinf-font-lock-cruc t)) > > M-x font-lock-mode RET > > or (font-lock-mode 'toggle) How would this help me? Hoh should I use font-lock-mode? > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 0:06 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: >> M-x font-lock-mode RET >> >> or (font-lock-mode 'toggle) > > How would this help me? Hoh should I use font-lock-mode? I don't know. That's hoh I use it, anyway. What are you trying to do? -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 2021-02-13 0:06 ` Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 0:17 ` Christopher Dimech 0 siblings, 0 replies; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 0:17 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs I want to add a special superscript and subscript typeface and also a way to disable it. To enable I have (defun supinf-enable () "Enables a typeface for displaying tex commands." (setq supinf-signal t) (font-lock-add-keywords nil '( (supinf-match (1 (supinf-raise-cruc (match-beginning 0)))) ) t)) > Sent: Saturday, February 13, 2021 at 12:06 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: > > >> M-x font-lock-mode RET > >> > >> or (font-lock-mode 'toggle) > > > > How would this help me? Hoh should I use font-lock-mode? > > I don't know. That's hoh I use it, anyway. > > What are you trying to do? > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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:04 ` Christopher Dimech 2021-02-13 0:08 ` Emanuel Berg via Users list for the GNU Emacs text editor 1 sibling, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 0:04 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs (font-lock-add-keywords MODE KEYWORDS &optional HOW) What does the optional HOW actually do? Regards Christopher > Sent: Saturday, February 13, 2021 at 11:44 AM > 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: > > > I want to construct the font-lock as a single command > > > > (font-lock-add-keywords nil ...) > > > > But I am unsure how to do it. > > I believe you :) > > > (defconst supinf-font-lock-cruc > > (append > > '((supinf-match > > (1 (supinf-raise-cruc (match-beginning 0))) ))) > > "Experimental expressions to highlight in TeX modes.") > > ? > > Here is how to add a single word to Elisp mode: > > (font-lock-add-keywords 'emacs-lisp-mode > '( > ("lamersRus" . font-lock-builtin-face) > ) > t) > > > (defun supinf-enable () > > "Enables a typeface for displaying tex commands." > > (setq supinf-signal t) > > (font-lock-add-keywords nil supinf-font-lock-cruc t)) > > M-x font-lock-mode RET > > or (font-lock-mode 'toggle) > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0:58 ` Christopher Dimech 0 siblings, 2 replies; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 0:08 UTC (permalink / raw) To: help-gnu-emacs 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 ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 1 sibling, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 0:20 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs > 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. I understood none of that. What is "replace the current highlighting list" about? > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 2021-02-13 0:20 ` Christopher Dimech @ 2021-02-13 1:50 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 0 replies; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 1:50 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: >> 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. > > I understood none of that. What is "replace the current > highlighting list" about? nil -> add at beginning (default) set -> replace t -> append -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 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 1 sibling, 2 replies; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 0:58 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs 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 > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 1 sibling, 0 replies; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 1:13 UTC (permalink / raw) To: Christopher Dimech; +Cc: help-gnu-emacs, moasenwood 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 > > > > > > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 1 sibling, 1 reply; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 1:54 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: > (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))) ))) Take it one function at a time. Does this work? -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 2:43 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs --------------------- > Sent: Saturday, February 13, 2021 at 1:54 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: > > > (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))) ))) > > Take it one function at a time. Does this work? Yes the routine works. I made a minor-mode and added a hook to enable. But would also like to enable it using a key-sequence, a task that I have been unable to get working. (add-hook 'crucible-mode-hook #'supinf-enable) > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 2:46 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: > I made a minor-mode and added a hook to enable. But would > also like to enable it using a key-sequence, a task that > I have been unable to get working. > > (add-hook 'crucible-mode-hook #'supinf-enable) Well, bind `supinf-enable' to a key! Is it `interactive'? -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 3:00 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs I have done. One difficulty is that supinf-enable is executed as soon as I read the file. Do not know how it is being enabled automatically after I commented out the line that said "(add-hook 'crucible-mode-hook #'supinf-enable)". (defun supinf-enable () "Enables a typeface for displaying tex commands." (interactive) (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)) (global-set-key (kbd "H-s") #'supinf-enable) > Sent: Saturday, February 13, 2021 at 2:46 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: > > > I made a minor-mode and added a hook to enable. But would > > also like to enable it using a key-sequence, a task that > > I have been unable to get working. > > > > (add-hook 'crucible-mode-hook #'supinf-enable) > > Well, bind `supinf-enable' to a key! > > Is it `interactive'? > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 3:16 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: > I have done. One difficulty is that supinf-enable is > executed as soon as I read the file. Do not know how it is > being enabled automatically after I commented out the line > that said "(add-hook 'crucible-mode-hook #'supinf-enable)". Well, did you examine the hook to see what's there? Hooks are variables, so use C-h v. You can do a hook with this pattern if it makes it more clear. Note the commented-out line, eval the form there to set the hook to zero. (require 'mode-line) ;; (setq conf-space-mode-hook nil) (defun conf-space-mode-hook-f () (enable-line-mode) ) (add-hook 'conf-space-mode-hook #'conf-space-mode-hook-f) -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 3:56 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs FYor the hook, I only did this (defvar crucible-mode-hook nil "Hook called when Crucible Mode is enabled.") > Sent: Saturday, February 13, 2021 at 3:16 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: > > > I have done. One difficulty is that supinf-enable is > > executed as soon as I read the file. Do not know how it is > > being enabled automatically after I commented out the line > > that said "(add-hook 'crucible-mode-hook #'supinf-enable)". > > Well, did you examine the hook to see what's there? > > Hooks are variables, so use C-h v. > > You can do a hook with this pattern if it makes it more clear. > Note the commented-out line, eval the form there to set the > hook to zero. > > (require 'mode-line) > ;; (setq conf-space-mode-hook nil) > (defun conf-space-mode-hook-f () > (enable-line-mode) ) > (add-hook 'conf-space-mode-hook #'conf-space-mode-hook-f) > > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 2021-02-13 3:56 ` Christopher Dimech @ 2021-02-13 4:09 ` Christopher Dimech 2021-02-13 4:21 ` Christopher Dimech 0 siblings, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 4:09 UTC (permalink / raw) To: Christopher Dimech; +Cc: help-gnu-emacs, moasenwood [-- Attachment #1: Type: text/plain, Size: 1603 bytes --] Bugger. I noticed that I had a byte-compiled version .elc and I have a hunch that emacs was loading that one instead of mp updated .el file. > Sent: Saturday, February 13, 2021 at 3:56 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 > > FYor the hook, I only did this > > (defvar crucible-mode-hook nil > "Hook called when Crucible Mode is enabled.") > > > Sent: Saturday, February 13, 2021 at 3:16 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: > > > > > I have done. One difficulty is that supinf-enable is > > > executed as soon as I read the file. Do not know how it is > > > being enabled automatically after I commented out the line > > > that said "(add-hook 'crucible-mode-hook #'supinf-enable)". > > > > Well, did you examine the hook to see what's there? > > > > Hooks are variables, so use C-h v. > > > > You can do a hook with this pattern if it makes it more clear. > > Note the commented-out line, eval the form there to set the > > hook to zero. > > > > (require 'mode-line) > > ;; (setq conf-space-mode-hook nil) > > (defun conf-space-mode-hook-f () > > (enable-line-mode) ) > > (add-hook 'conf-space-mode-hook #'conf-space-mode-hook-f) > > > > > > -- > > underground experts united > > http://user.it.uu.se/~embe8573 > > https://dataswamp.org/~incal > > > > > > > > [-- Attachment #2: crucible-mode.el --] [-- Type: text/plain, Size: 16959 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 nil "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 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) (setq crucible-mode-hook nil) (provide 'crucible-mode) ;;; crucible-mode.el ends here ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 4:21 UTC (permalink / raw) To: Christopher Dimech; +Cc: help-gnu-emacs, moasenwood 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. > Sent: Saturday, February 13, 2021 at 4:09 PM > From: "Christopher Dimech" <dimech@gmx.com> > To: "Christopher Dimech" <dimech@gmx.com> > Cc: help-gnu-emacs@gnu.org, moasenwood@zoho.eu > Subject: Re: font-lock as a single command > > Bugger. I noticed that I had a byte-compiled version .elc and I have > a hunch that emacs was loading that one instead of mp updated .el > file. > > > Sent: Saturday, February 13, 2021 at 3:56 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 > > > > FYor the hook, I only did this > > > > (defvar crucible-mode-hook nil > > "Hook called when Crucible Mode is enabled.") > > > > > Sent: Saturday, February 13, 2021 at 3:16 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: > > > > > > > I have done. One difficulty is that supinf-enable is > > > > executed as soon as I read the file. Do not know how it is > > > > being enabled automatically after I commented out the line > > > > that said "(add-hook 'crucible-mode-hook #'supinf-enable)". > > > > > > Well, did you examine the hook to see what's there? > > > > > > Hooks are variables, so use C-h v. > > > > > > You can do a hook with this pattern if it makes it more clear. > > > Note the commented-out line, eval the form there to set the > > > hook to zero. > > > > > > (require 'mode-line) > > > ;; (setq conf-space-mode-hook nil) > > > (defun conf-space-mode-hook-f () > > > (enable-line-mode) ) > > > (add-hook 'conf-space-mode-hook #'conf-space-mode-hook-f) > > > > > > > > > -- > > > underground experts united > > > http://user.it.uu.se/~embe8573 > > > https://dataswamp.org/~incal > > > > > > > > > > > > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 4:28 UTC (permalink / raw) To: help-gnu-emacs 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 ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 4:31 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs [-- 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 ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 2 replies; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 5:26 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: > I have sent the file. I attach again. Good work getting rid of all warnings and errors. Did you write all that Elisp BTW? I don't know why it doesn't work ... try cleaning up the code and test so that every function works in isolation. -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 1 sibling, 0 replies; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 5:29 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs > Sent: Saturday, February 13, 2021 at 5:26 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: > > > I have sent the file. I attach again. > > Good work getting rid of all warnings and errors. > > Did you write all that Elisp BTW? I hacked it from tex-mode.el > I don't know why it doesn't work ... try cleaning up the code > and test so that every function works in isolation. > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 1 sibling, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 5:39 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs There is something interesting to tell you. When I call "M-x supinf-enable" nothing happens, but when I start writing (e.g. "\alpha_{ij}"), as soon as I enter "_" the suscript functionality gets enabled for the whole buffer. Could you help on what is going on? > Sent: Saturday, February 13, 2021 at 5:26 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: > > > I have sent the file. I attach again. > > Good work getting rid of all warnings and errors. > > Did you write all that Elisp BTW? > > I don't know why it doesn't work ... try cleaning up the code > and test so that every function works in isolation. > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 2 replies; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 5:43 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: > There is something interesting to tell you. When I call "M-x > supinf-enable" nothing happens, but when I start writing > (e.g. "\alpha_{ij}"), as soon as I enter "_" the suscript > functionality gets enabled for the whole buffer. > > Could you help on what is going on? Here is how I would do it, for starters: \alpha^{high} \beta_{low} (progn (font-lock-add-keywords 'emacs-lisp-mode '( ("\\^{\\([[:alnum:]]*\\)}" 1 font-lock-builtin-face) ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face) ) t) (text-mode) (emacs-lisp-mode) ) ;; ^ eval You can see the result in this screenshot: https://dataswamp.org/~incal/figures/emacs/high-low.png -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 1 sibling, 0 replies; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 5:51 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs Have added "font-lock-fontify-region" and supinf gets activated as soon as I enter the key-sequence "H-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) (font-lock-fontify-region (point-min) (point-max)) ) > Sent: Saturday, February 13, 2021 at 5:43 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: > > > There is something interesting to tell you. When I call "M-x > > supinf-enable" nothing happens, but when I start writing > > (e.g. "\alpha_{ij}"), as soon as I enter "_" the suscript > > functionality gets enabled for the whole buffer. > > > > Could you help on what is going on? > > Here is how I would do it, for starters: > > \alpha^{high} > \beta_{low} > > (progn > (font-lock-add-keywords > 'emacs-lisp-mode > '( > ("\\^{\\([[:alnum:]]*\\)}" 1 font-lock-builtin-face) > ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face) > ) > t) > (text-mode) > (emacs-lisp-mode) ) > ;; ^ eval > > You can see the result in this screenshot: > > https://dataswamp.org/~incal/figures/emacs/high-low.png > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 1 sibling, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 6:07 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs I am quite confident that I can use "(font-lock-fontify-buffer)". Do you agree? (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) (font-lock-fontify-buffer) ) > Sent: Saturday, February 13, 2021 at 5:43 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: > > > There is something interesting to tell you. When I call "M-x > > supinf-enable" nothing happens, but when I start writing > > (e.g. "\alpha_{ij}"), as soon as I enter "_" the suscript > > functionality gets enabled for the whole buffer. > > > > Could you help on what is going on? > > Here is how I would do it, for starters: > > \alpha^{high} > \beta_{low} > > (progn > (font-lock-add-keywords > 'emacs-lisp-mode > '( > ("\\^{\\([[:alnum:]]*\\)}" 1 font-lock-builtin-face) > ("_{\\([[:alnum:]]*\\)}" 1 font-lock-function-name-face) > ) > t) > (text-mode) > (emacs-lisp-mode) ) > ;; ^ eval > > You can see the result in this screenshot: > > https://dataswamp.org/~incal/figures/emacs/high-low.png > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 6:20 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: > I am quite confident that I can use > "(font-lock-fontify-buffer)". Do you agree? The docstring says: This function is for interactive use only; in Lisp code use `font-lock-ensure' or `font-lock-flush' instead. Probably introduced at or before Emacs version 19.29. So I'd say use (font-lock-flush) instead... -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 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 0 siblings, 1 reply; 30+ messages in thread From: Christopher Dimech @ 2021-02-13 6:55 UTC (permalink / raw) To: moasenwood; +Cc: help-gnu-emacs I have solved my problem. I just needed "(font-lock-flush)". To disable, I am simply resetting "deviat-supinf" and "height-scale-supinf". > Sent: Saturday, February 13, 2021 at 6:20 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: > > > I am quite confident that I can use > > "(font-lock-fontify-buffer)". Do you agree? > > The docstring says: > > This function is for interactive use only; in Lisp code use > `font-lock-ensure' or `font-lock-flush' instead. > Probably introduced at or before Emacs version 19.29. > > So I'd say use (font-lock-flush) instead... > > -- > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal > > > ^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: font-lock as a single command 2021-02-13 6:55 ` Christopher Dimech @ 2021-02-13 6:58 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 0 replies; 30+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-13 6:58 UTC (permalink / raw) To: help-gnu-emacs Christopher Dimech wrote: > I have solved my problem. I just needed "(font-lock-flush)". > > To disable, I am simply resetting "deviat-supinf" and > "height-scale-supinf". \o/ -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2021-02-13 6:58 UTC | newest] Thread overview: 30+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
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).