view lisp/fontcolor.el @ 5634:2014ff433daf

Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion src/ChangeLog addition: 2012-01-01 Aidan Kehoe <kehoea@parhasard.net> Add #'test-completion, API from GNU. Accept hash table COLLECTIONs in it and in the other completion-oriented functions, #'try-completion, #'all-completions, and those Lisp functions implemented in terms of them. * lisp.h: Update the prototype of map_obarray(), making FN compatible with the FUNCTION argument of elisp_maphash(); * abbrev.c (abbrev_match_mapper): * abbrev.c (record_symbol): * doc.c (verify_doc_mapper): * symbols.c (mapatoms_1): * symbols.c (apropos_mapper): Update these mapper functions to reflect the new argument to map_obarray(). * symbols.c (map_obarray): Call FN with two arguments, the string name of the symbol, and the symbol itself, for API (mapper) compatibility with elisp_maphash(). * minibuf.c (map_completion): New. Map a maphash_function_t across a non function COLLECTION, as appropriate for #'try-completion and friends. * minibuf.c (map_completion_list): New. Map a maphash_function_t across a pseudo-alist, as appropriate for the completion functions. * minibuf.c (ignore_completion_p): PRED needs to be called with two args if and only if the collection is a hash table. Implement this. * minibuf.c (try_completion_mapper): New. The loop body of #'try-completion, refactored out. * minibuf.c (Ftry_completion): Use try_completion_mapper(), map_completion(). * minibuf.c (all_completions_mapper): New. The loop body of #'all-completions, refactored out. * minibuf.c (Fall_completions): Use all_completions_mapper(), map_completion(). * minibuf.c (test_completion_mapper): New. The loop body of #'test-completion. * minibuf.c (Ftest_completion): New, API from GNU. * minibuf.c (syms_of_minibuf): Make Ftest_completion available. tests/ChangeLog addition: 2012-01-01 Aidan Kehoe <kehoea@parhasard.net> * automated/completion-tests.el: New. Test #'try-completion, #'all-completion and #'test-completion with list, vector and hash-table COLLECTION arguments.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 01 Jan 2012 15:18:52 +0000
parents 308d34e9f07d
children
line wrap: on
line source

;;; fontcolor.el --- Lisp interface to fonts and colors

;; Copyright (C) 1994, 1997 Free Software Foundation, Inc.
;; Copyright (C) 1995 Ben Wing
;; Copyright (C) 2010 Didier Verna

;; Author: Chuck Thompson <cthomp@xemacs.org>
;; Author: Ben Wing <ben@xemacs.org>
;; Maintainer: XEmacs Development Team
;; Keywords: faces, internal, dumped

;; This file is part of XEmacs.

;; XEmacs is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the
;; Free Software Foundation, either version 3 of the License, or (at your
;; option) any later version.

;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;; for more details.

;; You should have received a copy of the GNU General Public License
;; along with XEmacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Synched up with: Not in FSF.

;;; Commentary:

;; This file is dumped with XEmacs.

;;; Code:

(defun fontcolor-property-1 (function object domain &optional matchspec)
  (let ((instance (if matchspec
		      (specifier-matching-instance object matchspec domain)
		    (specifier-instance object domain))))
    (and instance (funcall function instance))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; font specifiers

(defun make-font-specifier (spec-list)
  "Return a new `font' specifier object with the given specification list.
SPEC-LIST can be a list of specifications (each of which is a cons of a
locale and a list of instantiators), a single instantiator, or a list
of instantiators.  See `make-specifier' for more information about
specifiers.

Valid instantiators for font specifiers are:

-- a string naming a font; syntax is platform dependent.  Some examples for
   a 14-point upright medium-weight Courier font:
   X11 (and GTK1): \"-*-courier-medium-r-*-*-*-140-*-*-*-*-iso8859-*\"
   Xft (and GTK2): \"Courier-14\"
   MS-Windows:     \"Courier:14:Western\"
-- a font instance (use that instance directly if the device matches,
   or use the string that generated it)
-- a vector of no elements (only on TTY's; this means to set no font
   at all, thus using the \"natural\" font of the terminal's text)
-- a vector of one element (a face to inherit from)
"
  (make-specifier-and-init 'font spec-list))

(defun font-name (font &optional domain charset)
  "Return the name of the FONT in the specified DOMAIN, if any.
FONT should be a font specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `font-instance-name' to
the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'font-instance-name font domain charset))

(defun font-ascent (font &optional domain charset)
  "Return the ascent of the FONT in the specified DOMAIN, if any.
FONT should be a font specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `font-instance-ascent' to
the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'font-instance-ascent font domain charset))

(defun font-descent (font &optional domain charset)
  "Return the descent of the FONT in the specified DOMAIN, if any.
FONT should be a font specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `font-instance-descent' to
the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'font-instance-descent font domain charset))

(defun font-width (font &optional domain charset)
  "Return the width of the FONT in the specified DOMAIN, if any.
FONT should be a font specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `font-instance-width' to
the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'font-instance-width font domain charset))

(defun font-height (font &optional domain charset)
  "Return the height of the FONT in the specified DOMAIN, if any.
FONT should be a font specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `font-instance-height' to
the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'font-instance-height font domain charset))

(defun font-proportional-p (font &optional domain charset)
  "Return whether FONT is proportional in the specified DOMAIN, if known.
FONT should be a font specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `font-instance-proportional-p' to
the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'font-instance-proportional-p font domain charset))

(defun font-properties (font &optional domain charset)
  "Return the properties of the FONT in the specified DOMAIN, if any.
FONT should be a font specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `font-instance-properties'
to the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'font-instance-properties font domain charset))

(defun font-truename (font &optional domain charset)
  "Return the truename of the FONT in the specified DOMAIN, if any.
FONT should be a font specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `font-instance-truename'
to the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'font-instance-truename font domain charset))

(defun font-instance-height (font-instance)
  "Return the height in pixels of FONT-INSTANCE.
The returned value is the maximum height for all characters in the font,\n\
and is equivalent to the sum of the font instance's ascent and descent."
  (+ (font-instance-ascent font-instance)
     (font-instance-descent font-instance)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; color specifiers

(defun make-color-specifier (spec-list)
  "Return a new `color' specifier object with the given specification list.
SPEC-LIST can be a list of specifications (each of which is a cons of a
locale and a list of instantiators), a single instantiator, or a list
of instantiators.  See `make-specifier' for a detailed description of
how specifiers work.

Valid instantiators for color specifiers are:

-- a string naming a color (e.g. under X this might be \"lightseagreen2\"
   or \"#F534B2\")
-- a color instance (use that instance directly if the device matches,
   or use the string that generated it)
-- a vector of no elements (only on TTY's; this means to set no color
   at all, thus using the \"natural\" color of the terminal's text)
-- a vector of one or two elements: a face to inherit from, and
   optionally a symbol naming which property of that face to inherit,
   either `foreground' or `background' (if omitted, defaults to the same
   property that this color specifier is used for; if this specifier is
   not part of a face, the instantiator would not be valid)."
  (make-specifier-and-init 'color spec-list))

(defun color-name (color &optional domain)
  "Return the name of the COLOR in the specified DOMAIN, if any.
COLOR should be a color specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `color-instance-name' to
the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'color-instance-name color domain))

(defun color-rgb-components (color &optional domain)
  "Return the RGB components of the COLOR in the specified DOMAIN, if any.
COLOR should be a color specifier object and DOMAIN is normally a window
and defaults to the selected window if omitted.  This is equivalent
to using `specifier-instance' and applying `color-instance-rgb-components'
to the result.  See `make-specifier' for more information about specifiers."
  (fontcolor-property-1 'color-instance-rgb-components color domain))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; face-boolean specifiers

(defun make-face-boolean-specifier (spec-list)
  "Return a new `face-boolean' specifier object with the given spec list.
SPEC-LIST can be a list of specifications (each of which is a cons of a
locale and a list of instantiators), a single instantiator, or a list
of instantiators.  See `make-specifier' for a detailed description of
how specifiers work.

Valid instantiators for face-boolean specifiers are

-- t or nil
-- a vector of one, two or three elements: a face to inherit from,
   optionally a symbol naming the property of that face to inherit from
   (if omitted, defaults to the same property that this face-boolean
   specifier is used for; if this specifier is not part of a face,
   the instantiator would not be valid), and optionally a value which,
   if non-nil, means to invert the sense of the inherited property."
  (make-specifier-and-init 'face-boolean spec-list))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; face-background-placement specifiers

(defun make-face-background-placement-specifier (spec-list)
  "Return a new `face-background-placement' specifier object.
SPEC-LIST can be a list of specifications (each of which is a cons of a
locale and a list of instantiators), a single instantiator, or a list
of instantiators.  See `make-specifier' for a detailed description of
how specifiers work.

Valid instantiators for face-background-placement specifiers are:
-- absolute or relative (symbols),
-- a vector of one element: a face to inherit from."
  (make-specifier-and-init 'face-background-placement spec-list))

;;; fontcolor.el ends here.