[slime-devel] sub & superscript faces in .lisp files

Mirko Vukovic mirko.vukovic at gmail.com
Tue Apr 20 00:30:11 UTC 2010


Hello,

Apologies for this slightly off-topic question, but it may relate to
slime's `group' settings
(Much off this email is a copy of a post to gnu.emacs.help)

I am trying to display text following an underscore as a subscript and
following a caret as a superscript.  By looking at various pieces of
code (tex-mode.el  and pretty-greek.el from Pascal Bourgignon), I came
up with the following (which, of course does not work):

(defvar suscript-height-minimum 0)
(defvar suscript-height-ratio 0.8)

(defun suscript-height (height)
  "Return the integer height of subscript/superscript font in 1/10
points.
Not smaller than the value set by `tex-suscript-height-minimum'."
  (ceiling (max (if (integerp suscript-height-minimum)
                    suscript-height-minimum
                    ;; For bootstrapping.
                    (condition-case nil
                        (* suscript-height-minimum
                           (face-attribute 'default :height))
                      (error 0)))
                ;; NB assumes height is integer.
                (* height suscript-height-ratio))))

(defface superscript
  '((t :height suscript-height))
  "Face used for superscripts.")

(defface subscript
  '((t :height suscript-height))
  "Face used for subscripts.")

(defun suscript-match-regexp (escape-char)
  "regexp for suscripted text match in common-lisp code"
  (let ((terminating-string (format "_^    )$-")))
    (format "%s\\(.*?\\)[%s]" escape-char
            terminating-string terminating-string)))

(defvar subscript-match (suscript-match-regexp "_")
  "Matches _whatever[_|^|SPACE|TAB|)")
(defvar superscript-match (suscript-match-regexp "\\^")
  "Matches ^whatever[_|^|SPACE|TAB|)")

(defun pretty-suscript ()
  "Load super&subscript keywords into `suscript-flk' and
load that into `font-lock-keywords'"
  (interactive)
  (setq suscript-flk
        `((,subscript-match
           (1 (face subscript display (raise 0.2))))
          (,superscript-match
           (1 (face superscript display (raise -0.2))))))
  (font-lock-add-keywords nil suscript-flk))

(defun cancel-pretty-suscript ()
  "Remove `suscript-flk' keywords from `font-lock-keywords'"
  (interactive)
  (font-lock-remove-keywords nil suscript-flk))

The contents `font-lock-keywords' are as follows:

(t
 (("_\\(.*?\\)[_^  )$-]"
   (1
    (face subscript display
          (raise 0.2))))
  ("\\^\\(.*?\\)[_^        )$-]"
   (1
    (face superscript display
          (raise -0.2))))
 ...)

My question is whether I need to specify a group in the `defface'
commands.  For example:
(defface superscript
  '((t :height 0.8));;suscript-height))
  "Face used for superscripts."
  :group 'slime-mode-faces)

I found several groups in slime.el, and I am not sure which one to
apply in defface.

Thanks,

Mirko




More information about the slime-devel mailing list