emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lisp-font-lock-syntactic-face-function


From: Stefan Monnier
Subject: Re: lisp-font-lock-syntactic-face-function
Date: Wed, 18 May 2005 19:49:38 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> In `lisp-font-lock-syntactic-face-function' the expression

> (eq n (or (get sym 'doc-string-elt) 3))

> causes to paint _every_ third string subexpression of a top-level
> expression with `font-lock-doc-face'.  That's annoying in a number of
> cases like, for example, `define-abbrev'.  Why not simplify this to

> (eq n (get sym 'doc-string-elt))

> and provide the necessary additional doc-string-elts like,

> (put 'defgroup 'doc-string-elt 3)
> (put 'defface 'doc-string-elt 3)

> (put 'defalias 'doc-string-elt 3)
> (put 'defvaralias 'doc-string-elt 3)
> (put 'define-obsolete-function-alias 'doc-string-elt 4)
> (put 'define-obsolete-variable-alias 'doc-string-elt 4)

> (put 'defimage 'doc-string-elt 3)
> (put 'define-category 'doc-string-elt 2)
> (put 'define-widget 'doc-string-elt 3)

[ I wrote the code ]
I have no opinion on this.

> Also, the while loop in `lisp-font-lock-syntactic-face-function' seems
> overly expensive: For example, any top-level expression terminating with
> a string requires to backward-sexp from the start of the string to the
> start of the expression just to find out that the string is not a
> doc-string.

> I tried the following with the puts from above and encountered no
> problems so far:

> (defun lisp-font-lock-syntactic-face-function (state)
>    (if (nth 3 state)
>        (if (and (eq (nth 0 state) 1)
>                 (nth 1 state)            ; is this needed ???
>                 (save-excursion
>                   (let* ((from (1+ (nth 1 state))) ; is 1+ OK here ???
>                          (sym (intern-soft
>                                (buffer-substring
>                                 from
>                                 (progn
>                                   (goto-char from) (forward-sexp 1) 
> (point)))))
>                          (doc-string-elt (get sym 'doc-string-elt)))
>                     (and (numberp doc-string-elt) ; check for > 0 too ???
>                          (condition-case nil
>                              (progn
>                                (forward-sexp (1- doc-string-elt))
>                                (forward-comment (buffer-size))
>                                ;; the last two lines could be replaced by:
>                                ;; (forward-sexp doc-string-elt)
>                                ;; (backward-sexp)
>                                (= (point) (nth 8 state)))
>                            (scan-error nil))))))
>         font-lock-doc-face
>       font-lock-string-face)
>      font-lock-comment-face))

I don't have time to look into it in detail, but the approach looks fine.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]