unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Miles Bader <miles@gnu.org>
Subject: reducing defface redundancy
Date: 20 Apr 2002 12:12:57 +0900	[thread overview]
Message-ID: <877kn3qczq.fsf@tc-1-100.kawasaki.gol.ne.jp> (raw)

In order to be optimal on disparate display types, many defface clauses
end up having a bunch of clauses with almost the same contents, but
varying one or two attributes.  With the ability to query individual
features, this might become even worse.  So this is a suggestion on a
way to reduce the redundancy of defface specs.

The basic idea is to allow using a lisp vector ([...]) as a kind of `or'
expression in the attribute part of a defface clause.  Each element of
vector is an attribute list, and the first one that is entirely
`supportable' (that is, `display-capable-p' returns true for all of its
attributes) is used.  [note that this is one reason why I suggested
using face attribute names/values as the argument to
`display-capable-p']

This way, in many cases common attributes could be factored out, and
the variant parts would become just a vector of possibilities with
emacs choosing the first one that works.  I think this style is very
natural, and might even result in better faces because

Currently the grammar of defface specs is something like this:

  SPECS     ::= (CLAUSE ...)
  CLAUSE    ::= (TESTS ATTRIBUTE...)
              | (TESTS (ATTRIBUTE ...))         ; old style attribute list
  ATTRIBUTE ::= ATTR-NAME ATTR-VALUE  
  TESTS     ::= t | (TEST ...)
  TEST      ::= (TEST-NAME TEST-ARG...)

Here's one possibility for a more flexible specification that uses the
`or' vector idea above, and I think should be backward compatible:

  SPECS     ::= (CLAUSE ...)
  CLAUSE    ::= ATTRIBUTE
              | (TESTS CLAUSE...)               ; traditional top-level style
              | [SPECS ...]                     ; `or' vector style
              | (TESTS (ATTRIBUTE ...))         ; old style attribute list
  ATTRIBUTE ::= ATTR-NAME ATTR-VALUE  
  TESTS     ::= t | (TEST ...)
  TEST      ::= (TEST-NAME TEST-ARG...)

In addition to adding the `or' vectors, this makes defface specs
recursive in a way that allows omitting the traditional clause list when
it's not necessary (e.g., when currently you just have `t' as the list
of tests).

Thus _very_ simple defface specs are possible:

  (defface annoying
    '(:foreground "red" :background "yellow"))

which seems very natural.

The `italic' example from my earlier message can become:

  (defface italic
    [(:slant italic) (:underline t)])

And if someone wants a face that's both `emphasized' and yellow, he can do:

  (defface emph-yellow
    '(:foreground "yellow"
      [(:bold t) (:slant italic) (:underline t)]))

which will make either a bold, italic, or underlined yellow face,
depending on what the display is capable of.

Since the new specification is recursive, it's possible to put normal
defface clauses at sub-levels, if that's desirable for factoring out
common attributes; for instance, this is often :

(defface subtle-yet-underlined-mode-line
  '(:inherit mode-line
    :underline t
    (((background light) :background "grey90")
     ((background dark)  :background "grey10"))))

So what'ya think?  It shouldn't be hard to implement, given the
existance of `display-capable-p', it's backward-compatible, and whizzy
as all hell (well, I think so anyway)...

Thanks,

-Miles

-- 
"Most attacks seem to take place at night, during a rainstorm, uphill,
 where four map sheets join."   -- Anon. British Officer in WW I

             reply	other threads:[~2002-04-20  3:12 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-20  3:12 Miles Bader [this message]
2002-04-20  7:14 ` reducing defface redundancy Eli Zaretskii
2002-04-20 15:59 ` Per Abrahamsen
2002-04-20 17:35   ` Eli Zaretskii
2002-04-21  9:12     ` Per Abrahamsen
2002-04-20 17:41   ` Alex Schroeder
2002-04-21  2:00   ` Miles Bader
2002-04-21  9:17     ` Per Abrahamsen
2002-04-21  9:34       ` Miles Bader
2002-04-22  7:47       ` Richard Stallman
2002-04-22  7:47     ` Richard Stallman
2002-04-22  8:15       ` Miles Bader
2002-04-23  0:24         ` Richard Stallman
2002-04-23  1:36           ` Miles Bader
2002-04-24 17:54             ` Richard Stallman
2002-04-24 20:06               ` Miles Bader
2002-04-25  9:52                 ` Per Abrahamsen
2002-04-26  3:18                   ` Richard Stallman
2002-07-03  6:38               ` Miles Bader
2002-07-03  9:31                 ` Kai Großjohann
2002-07-03 14:50                 ` Kim F. Storm
2002-07-08 18:20                 ` Richard Stallman
2002-07-09  1:25                   ` Miles Bader
2002-07-09 18:51                     ` Richard Stallman
2002-07-09 18:51                     ` Richard Stallman
2002-07-09 20:52                       ` Stefan Monnier
2002-07-10 19:20                         ` Richard Stallman
2002-07-11 17:01                           ` Stefan Monnier
2002-07-12  1:28                             ` Miles Bader
2002-07-12 17:37                             ` Richard Stallman
2002-04-21 20:02 ` Richard Stallman
2002-04-22  0:28   ` Miles Bader
2002-04-22 22:37     ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877kn3qczq.fsf@tc-1-100.kawasaki.gol.ne.jp \
    --to=miles@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).