branch: externals/auctex commit 08ab3c10d51f0956e8faca2c85f5e0d38bee4303 Author: Tassilo Horn <t...@gnu.org> Commit: Tassilo Horn <t...@gnu.org>
Allow hiding ^ and _ script signs * font-latex.el (font-latex-fontify-script): Add possible value `multi-level' to allow raising/lowering scripts of scripts, and another value `invisible' which in addition hides the ^ and _ characters in scripts. (font-latex-match-script): Use it. (font-latex-make-user-keywords): Add font-lock entry for script signs. (font-latex-script-invisible): New function. --- ChangeLog | 7 ++++- font-latex.el | 90 +++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3d698b7..703db99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,13 @@ 2015-09-03 Tassilo Horn <t...@gnu.org> * font-latex.el (font-latex-fontify-script): Add possible value - `multi-level' to allow raising/lowering scripts of scripts. + `multi-level' to allow raising/lowering scripts of scripts, and + another value `invisible' which in addition hides the ^ and _ + characters in scripts. (font-latex-match-script): Use it. + (font-latex-make-user-keywords): Add font-lock entry for script + signs. + (font-latex-script-invisible): New function. * tex.el (TeX-tex-mode): Don't ignore case when matching the TeX-format-list regexes. diff --git a/font-latex.el b/font-latex.el index 2a9fc26..0df8a96 100644 --- a/font-latex.el +++ b/font-latex.el @@ -810,7 +810,7 @@ Generated by `font-latex-make-user-keywords'."))) (add-to-list 'font-latex-keywords-1 item) (add-to-list 'font-latex-keywords-2 item)) (dolist (item - '((font-latex-match-math-env + `((font-latex-match-math-env (0 'font-latex-warning-face t t) (1 'font-latex-math-face append t)) (font-latex-match-math-envII @@ -818,7 +818,8 @@ Generated by `font-latex-make-user-keywords'."))) (font-latex-match-simple-command (0 'font-latex-sedate-face append)) (font-latex-match-script - (1 (font-latex-script (match-beginning 0)) append)))) + (1 (font-latex-script (match-beginning 0)) append)) + ("[_^]" (0 (font-latex-script-invisible (match-beginning 0)) t)))) (add-to-list 'font-latex-keywords-2 item t))) (font-latex-make-user-keywords) @@ -856,17 +857,23 @@ This feature does not work in XEmacs. By default, super/subscripts are raised/lowered if this variable is non-nil. This fontification only affects one level of scripts, e.g., in x^y^z, the y and the z have the same size and -are equally raised over x. If this variable is set to the symbol -`multi-level', then y is raised above x, and z is raised above y. -With many script levels, the text might become too small to be -readable." +are equally raised over x. + +If this variable is set to the symbol `multi-level', then y is +raised above x, and z is raised above y. With many script +levels, the text might become too small to be readable. + +If this variable is set to the symbol `invisible', then the +effect is essentially like `multi-level' but additionally the +script operators ^ and _ are not displayed." :type '(choice (boolean :tag "Enabled") - (const :tag "Multiple levels" multi-level)) + (const :tag "Multiple levels" multi-level) + (const :tag "Hide ^ and _" invisible)) :group 'font-latex) (put 'font-latex-fontify-script 'safe-local-variable (lambda (val) (or (TeX-booleanp val) - (eq 'multi-level val)))) + (memq val '(multi-level invisible))))) (defcustom font-latex-script-display '((raise -0.3) . (raise 0.3)) "Display specification for subscript and superscript content. @@ -1096,14 +1103,14 @@ have changed." '(:inherit fixed-pitch) '(:family "courier")))) `((((class grayscale) (background light)) - (:foreground "DimGray" ,@font)) - (((class grayscale) (background dark)) - (:foreground "LightGray" ,@font)) - (((class color) (background light)) - (:foreground "SaddleBrown" ,@font)) - (((class color) (background dark)) - (:foreground "burlywood" ,@font)) - (t (,@font)))) + (:foreground "DimGray" ,@font)) + (((class grayscale) (background dark)) + (:foreground "LightGray" ,@font)) + (((class color) (background light)) + (:foreground "SaddleBrown" ,@font)) + (((class color) (background dark)) + (:foreground "burlywood" ,@font)) + (t (,@font)))) "Face used to highlight TeX verbatim environments." :group 'font-latex-highlighting-faces) @@ -1209,8 +1216,8 @@ triggers Font Lock to recognize the change." ;; `VirTeX-common-initialization' and place it in the different ;; `xxx-mode' calls instead, but _after_ `major-mode' is set. (let ((defaults - `((font-latex-keywords font-latex-keywords-1 font-latex-keywords-2) - nil nil ,font-latex-syntax-alist nil)) + `((font-latex-keywords font-latex-keywords-1 font-latex-keywords-2) + nil nil ,font-latex-syntax-alist nil)) (variables '((font-lock-comment-start-regexp . "%") (font-lock-mark-block-function . mark-paragraph) @@ -1251,21 +1258,21 @@ triggers Font Lock to recognize the change." (defun font-latex-jit-lock-force-redisplay (buf start end) "Compatibility for Emacsen not offering `jit-lock-force-redisplay'." - ;; The following block is an expansion of `jit-lock-force-redisplay' - ;; and involved macros taken from CVS Emacs on 2007-04-28. - (with-current-buffer buf - (let ((modified (buffer-modified-p))) - (unwind-protect - (let ((buffer-undo-list t) - (inhibit-read-only t) - (inhibit-point-motion-hooks t) - (inhibit-modification-hooks t) - deactivate-mark - buffer-file-name - buffer-file-truename) - (put-text-property start end 'fontified t)) - (unless modified - (restore-buffer-modified-p nil)))))) + ;; The following block is an expansion of `jit-lock-force-redisplay' + ;; and involved macros taken from CVS Emacs on 2007-04-28. + (with-current-buffer buf + (let ((modified (buffer-modified-p))) + (unwind-protect + (let ((buffer-undo-list t) + (inhibit-read-only t) + (inhibit-point-motion-hooks t) + (inhibit-modification-hooks t) + deactivate-mark + buffer-file-name + buffer-file-truename) + (put-text-property start end 'fontified t)) + (unless modified + (restore-buffer-modified-p nil)))))) (defun font-latex-fontify-region (beg end &optional loudly) "Fontify region from BEG to END. @@ -1864,7 +1871,7 @@ END marks boundaries for searching for quotation ends." (when (and font-latex-fontify-script (re-search-forward "[_^] *\\([^\n\\{}]\\|\ \\\\\\([a-zA-Z@]+\\|[^ \t\n]\\)\\|\\({\\)\\)" limit t)) - (if (and (not (eq 'multi-level font-latex-fontify-script)) + (if (and (not (memq font-latex-fontify-script '(multi-level invisible))) (font-latex-faces-present-p '(font-latex-subscript-face font-latex-superscript-face))) ;; Apply subscript and superscript highlighting only once (in case @@ -1916,6 +1923,21 @@ END marks boundaries for searching for quotation ends." ,(cdr font-latex-script-display)) 'font-latex-superscript-face))))) +(defun font-latex-script-invisible (pos) + "Make the super/subscript sign invisible." + (when (and (eq font-latex-fontify-script 'invisible) + (font-latex-faces-present-p 'font-latex-math-face pos) + (not (font-latex-faces-present-p '(font-lock-constant-face + font-lock-builtin-face + font-lock-comment-face + font-latex-verbatim-face) pos)) + ;; Check for backslash quoting + (not (let ((odd nil) + (pos pos)) + (while (eq (char-before pos) ?\\) + (setq pos (1- pos) odd (not odd))) + odd))) + `(face nil invisible t))) ;;; docTeX