unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* lisp-font-lock-syntactic-face-function
@ 2005-05-18  9:11 martin rudalics
  2005-05-18 23:49 ` lisp-font-lock-syntactic-face-function Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2005-05-18  9:11 UTC (permalink / raw)


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)

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))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: lisp-font-lock-syntactic-face-function
  2005-05-18  9:11 lisp-font-lock-syntactic-face-function martin rudalics
@ 2005-05-18 23:49 ` Stefan Monnier
  2005-10-21  8:05   ` lisp-font-lock-syntactic-face-function martin rudalics
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2005-05-18 23:49 UTC (permalink / raw)
  Cc: emacs-devel

> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: lisp-font-lock-syntactic-face-function
  2005-05-18 23:49 ` lisp-font-lock-syntactic-face-function Stefan Monnier
@ 2005-10-21  8:05   ` martin rudalics
  2005-10-24 16:48     ` lisp-font-lock-syntactic-face-function Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2005-10-21  8:05 UTC (permalink / raw)
  Cc: emacs-devel

Thanks for the careful revision.  However, a number of doc-strings don't
get highlighted properly anymore due to the "Don't mark as docstring the
3rd elem of an unknown toplevel form" change - among them those for
`defface' and `defalias'.  I earlier proposed to add

(put 'defadvice 'doc-string-elt 3)
(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)

Maybe this is the moment to do that.  You might also consider replacing
the remaining (nth 8 state) with `startpos'.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: lisp-font-lock-syntactic-face-function
  2005-10-21  8:05   ` lisp-font-lock-syntactic-face-function martin rudalics
@ 2005-10-24 16:48     ` Stefan Monnier
  2005-11-18 10:49       ` lisp-font-lock-syntactic-face-function martin rudalics
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2005-10-24 16:48 UTC (permalink / raw)
  Cc: emacs-devel

> Thanks for the careful revision.  However, a number of doc-strings don't
> get highlighted properly anymore due to the "Don't mark as docstring the
> 3rd elem of an unknown toplevel form" change - among them those for
> `defface' and `defalias'.  I earlier proposed to add

This should be fixed now,


        Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: lisp-font-lock-syntactic-face-function
  2005-10-24 16:48     ` lisp-font-lock-syntactic-face-function Stefan Monnier
@ 2005-11-18 10:49       ` martin rudalics
  2005-11-21  0:02         ` lisp-font-lock-syntactic-face-function Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2005-11-18 10:49 UTC (permalink / raw)
  Cc: emacs-devel

Please add `(declare (doc-string 3))' to the definition of `defgroup'.
Please use also `(put 'define-widget 'doc-string-elt 3)' instead of
`(declare (doc-string 3))' since `define-widget' is a function and not a
macro.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: lisp-font-lock-syntactic-face-function
  2005-11-18 10:49       ` lisp-font-lock-syntactic-face-function martin rudalics
@ 2005-11-21  0:02         ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2005-11-21  0:02 UTC (permalink / raw)
  Cc: emacs-devel

> Please add `(declare (doc-string 3))' to the definition of `defgroup'.
> Please use also `(put 'define-widget 'doc-string-elt 3)' instead of
> `(declare (doc-string 3))' since `define-widget' is a function and not a
> macro.

Thank you, installed.


        Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-11-21  0:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-18  9:11 lisp-font-lock-syntactic-face-function martin rudalics
2005-05-18 23:49 ` lisp-font-lock-syntactic-face-function Stefan Monnier
2005-10-21  8:05   ` lisp-font-lock-syntactic-face-function martin rudalics
2005-10-24 16:48     ` lisp-font-lock-syntactic-face-function Stefan Monnier
2005-11-18 10:49       ` lisp-font-lock-syntactic-face-function martin rudalics
2005-11-21  0:02         ` lisp-font-lock-syntactic-face-function Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).