2.2 Non-interactive

In addition to the aforementioned interactive methods, Htmlfontify provides the following non-interactive ones:

hfy-face-to-style

(hfy-face-to-style fn)

Take fn, a font or defface style font specification, (as returned by face-attr-construct or hfy-face-attr-for-class) and return a hfy-style-assoc.

See also: hfy-face-to-style-i, hfy-flatten-style.

hfy-fallback-color-values

(hfy-fallback-color-values color-string)

Use a fallback method for obtaining the rgb values for a color. If htmlfontify-load-rgb-file has been called, it uses the color map specified, otherwise it uses Htmlfontify’s built in map.

hfy-combined-face-spec

(hfy-combined-face-spec face)

Return a defface style alist of possible specifications for face, with any entries resulting from user customization (custom-set-faces) taking precedence.

See also: hfy-default-face-def

hfy-word-regex

(hfy-word-regex string)

Return a regex that matches string as the first match-string, with non word characters on either side (vaguely emulating the perl \b regex atom).

hfy-force-fontification

(hfy-force-fontification)

Emacs’s fontification is designed for interactive use. As such, it sometimes does things like deferring fontification until a section of the buffer is exposed and rendered, or until Emacs is idle for a while. Sometimes, in non-interactive circumstances, or if it can’t see X, it doesn’t bother with some of the harder stuff. While this is all great from the perspective of a user waiting for Emacs to load a 20000 line file and colorize it, it’s a pain from the point of view from non-interactive code. This function lies, cheats, steals and generally bullies Emacs into fontifying a buffer from start to finish, with all the extra frills, whether it thinks it needs to or not. Oh yes: it operates on the current buffer.


(hfy-link-style-string style-string)

Replace the end of a CSS style declaration style-string with the contents of the variable hfy-src-doc-link-style, removing text matching the regex hfy-src-doc-link-unstyle first, if necessary.

hfy-prepare-index-i

(hfy-prepare-index-i srcdir dstdir filename &optional stub map)

Prepare a tags index buffer for srcdir. hfy-tags-cache must already have an entry for srcdir for this to work. hfy-page-header, hfy-page-footer, hfy-link-extn and hfy-extn all play a part here.

If stub is set, prepare an (appropriately named) index buffer specifically for entries beginning with stub.

If map is set, use that instead of hfy-tags-cache.

hfy-compile-stylesheet

(hfy-compile-stylesheet)

Trawl the current buffer, construct and return a hfy-sheet-assoc.

hfy-css-name

(hfy-css-name fn)

Strip some of the boring bits from a font-name and return a CSS style name. If fn is a defface attribute list, either construct a name for it, store it in the cache, and return it, or just fetch it from the cache if it’s already there.

hfy-make-directory

(hfy-make-directory dir)

Approximate equivalent of mkdir -p dir.

hfy-triplet

(hfy-triplet color)

Takes a color name (string) and return a CSS rgb(R, G, B) triplet string. Uses the definition of “white” to map the numbers to the 0-255 range, so if you’ve redefined white, (especially if you’ve redefined it to have a triplet member lower than that of the color you are processing, strange things may happen).

hfy-default-footer

(hfy-default-footer file)

Default value for hfy-page-footer

hfy-list-files

(hfy-list-files directory)

Return a list of files under directory. Strips any leading ‘./’ from each filename.

hfy-color-vals

(hfy-color-vals color)

Where color is a color name or #XXXXXX style triplet, return a list of 3 (16 bit) rgb values for said color. If a window system is unavailable, calls hfy-fallback-color-values.

hfy-href-stub

(hfy-href-stub this-file def-files tag)

Return an href stub for a tag href: if def-files (list of files containing definitions for the tag in question) contains only one entry, the href should link straight to that file. Otherwise, the link should be to the index file.

We are not yet concerned with the file extensions/tag line number and so on at this point.

If hfy-split-index is set, and the href will be to an index file rather than a source file, append a ‘.X’ to hfy-index-file, where ‘X’ is the uppercased first character of tag.

See also: hfy-relstub, hfy-index-file.

hfy-line-number

(hfy-line-number)

Returns the line number of the point in the current buffer.

hfy-merge-adjacent-spans

(hfy-merge-adjacent-spans face-map)

Where face-map is a hfy-facemap-assoc for the current buffer, this function merges adjacent style blocks which are of the same value and are separated by nothing more interesting than whitespace.

<span class="foo">narf</span> <span class="foo">brain</span>

(as interpreted from face-map) would become:

<span class="foo">narf brain</span>

Returns a modified copy of face-map (also a hfy-facemap-assoc).

hfy-mark-tag-names

(hfy-mark-tag-names srcdir file)

Mark tags in file (lookup srcdir in hfy-tags-cache) with the hfy-anchor property, with a value of ‘tag.line-number’.

hfy-weight

(hfy-weight weight)

Derive a font-weight CSS specifier from an Emacs weight specification symbol.

hfy-size

(hfy-size height)

Derive a CSS font-size specifier from an Emacs font :height attribute. Does not cope with the case where height is a function to be applied to the height of the underlying font.

hfy-default-header

(hfy-default-header file style)

Default value for hfy-page-header

hfy-family

(hfy-family family)

Derives a CSS font-family specifier from an Emacs :family attribute.

hfy-mark-tag-hrefs

(hfy-mark-tag-hrefs srcdir file)

Mark href start points with the hfy-link property (value: href string).

Mark href end points with the hfy-endl property (value t).

Avoid overlapping links, and mark links in descending length of tag name in order to prevent subtags from usurping supertags; e.g., “term” for “terminal”).

hfy-box

(hfy-box box)

Derive CSS border-* attributes from the Emacs :box attribute.

hfy-box-to-style

(hfy-box-to-style spec)

Convert a complex :box Emacs font attribute set to a list of CSS border-* attributes. Don’t call this directly—it is called by hfy-box when necessary.

hfy-html-enkludge-buffer

(hfy-html-enkludge-buffer)

Mark dangerous ‘["<>]’ characters with the hfy-quoteme property.

See also hfy-html-dekludge-buffer.

hfy-buffer

(hfy-buffer)

Generate and return an Htmlfontify html output buffer for the current buffer. May trample an existing buffer.

hfy-fontified-p

(hfy-fontified-p)

font-lock doesn’t like to say a buffer’s been fontified when in batch mode, but we want to know if we should fontify or raw copy, so in batch mode we check for non-default face properties. Otherwise we test font-lock-mode and font-lock-fontified for truth.

hfy-lookup

(hfy-lookup face style)

Where style is a hfy-sheet-assoc and face is an Emacs face, return the relevant css style name.

hfy-fontify-buffer

(hfy-fontify-buffer &optional srcdir file)

Implement the guts of htmlfontify-buffer.

hfy-color

(hfy-color color)

Convert an Emacs :foreground property to a CSS color property.

hfy-flatten-style

(hfy-flatten-style style)

Take style (see hfy-face-to-style-i, see hfy-face-to-style) and merge any multiple attributes appropriately. Currently only font-size is merged down to a single occurrence—others may need special handling, but I haven’t encountered them yet. Returns a hfy-style-assoc.

hfy-size-to-int

(hfy-size-to-int spec)

Convert spec, a CSS font-size specifier, back to an Emacs :height attribute value. Used while merging multiple font-size attributes.

hfy-sprintf-stylesheet

(hfy-sprintf-stylesheet css file)

Generates a header, via hfy-page-header, for file, containing the stylesheet derived from css, which is a hfy-sheet-assoc. Returns a string containing the same.

hfy-relstub

(hfy-relstub file &optional start)

Return a ‘../’ stub of the appropriate length for the current source tree depth (as determined from file).

hfy-compile-face-map

(hfy-compile-face-map)

Compile and return a hfy-facemap-assoc for the current buffer.

hfy-prepare-index

(hfy-prepare-index srcdir dstdir)

Return as list of index buffer(s), as determined by hfy-split-index. Uses hfy-prepare-index-i to do this.

hfy-prepare-tag-map

(hfy-prepare-tag-map srcdir dstdir)

Prepare the counterpart(s) to the index buffer(s)—a list of buffers with the same structure, but listing (and linking to) instances of tags (as opposed to their definitions).

See also: hfy-prepare-index, hfy-split-index

hfy-subtract-maps

(hfy-subtract-maps srcdir)

Internal function—strips definitions of tags from the instance map. See: hfy-tags-cache and hfy-tags-rmap

hfy-face-to-style-i

(hfy-face-to-style-i fn)

The guts of hfy-face-to-style. fn should be a defface font specification, as returned by face-attr-construct or hfy-face-attr-for-class. Note that this function does not get font-sizes right if they are based on inherited modifiers (via the :inherit) attribute, and any other modifiers that are cumulative if they appear multiple times need to be merged by the user—hfy-flatten-style should do this.

hfy-face-to-css

(hfy-face-to-css fn)

Take fn, a font or defface specification (c.f. face-attr-construct) and return a CSS style specification.

See also: hfy-face-to-style

hfy-html-quote

(hfy-html-quote char-string)

Map a string (usually 1 character long) to an html safe string (entity) if need be.


(hfy-link-style style-string)

Convert the CSS style spec style-string to its equivalent hyperlink style.

See: hfy-link-style-fun.

hfy-p-to-face

(hfy-p-to-face props)

Given props, a list of text-properties, return the value of the face property, or nil.

hfy-box-to-border-assoc

(hfy-box-to-border-assoc spec)

Helper function for hfy-box-to-style.

hfy-face-attr-for-class

(hfy-face-attr-for-class face &optional class)

Return the face attributes for face. If class is set, it must be a defface alist key [see below]. Prior to version 0.18, the first face specification returned by hfy-combined-face-spec which didn’t clash with class was returned. In versions from 0.18 onwards, each font attribute list is scored, and the non-conflicting list with the highest score is returned. (A specification with a class of t is considered to match any class you specify. This matches Emacs’s behavior when deciding on which face attributes to use, to the best of my understanding ).

If class is nil, then you just get whatever face-attr-construct returns; i.e., the current specification in effect for face.

See hfy-display-class for details of valid values for class.

hfy-face-at

(hfy-face-at P)

Find face in effect at point P. If overlays are to be considered (see hfy-optimizations) then this may return a defface style list of face properties instead of a face symbol.

hfy-bgcol

(hfy-bgcol color)

As per hfy-color but for background colors.

hfy-kludge-cperl-mode

(hfy-kludge-cperl-mode)

cperl mode does its best to not do some of its fontification when not in a windowing system—we try to trick it…

hfy-href

(hfy-href this-file def-files tag tag-map)

Return a relative href to the tag in question, based on

this-file hfy-link-extn hfy-extn def-files tag and tag-map

this-file is the current source file def-files is a list of file containing possible link endpoints for tag tag is the tag in question tag-map is the entry in hfy-tags-cache.

hfy-shell

(hfy-shell)

Returns a best guess at a Bourne compatible shell to use: If the current shell doesn’t look promising, fall back to hfy-shell-file-name.

hfy-load-tags-cache

(hfy-load-tags-cache srcdir)

Run hfy-etags-cmd on srcdir: load hfy-tags-cache and hfy-tags-sortl.

hfy-parse-tags-buffer

(hfy-parse-tags-buffer srcdir buffer)

Parse a buffer containing etags formatted output, loading the hfy-tags-cache and hfy-tags-sortl entries for srcdir.

hfy-interq

(hfy-interq set-a set-b)

Return the intersection (using eq) of 2 lists.

hfy-text-p

(hfy-text-p srcdir file)

Is srcdir/file text? Uses hfy-istext-command to determine this.

hfy-opt

(hfy-opt symbol)

Is hfy-optimizations member symbol set or not?

hfy-dirname

(hfy-dirname file)

Return everything preceding the last ‘/’ from a relative filename, on the assumption that this will produce the name of a relative directory. Hardly bombproof, but good enough in the context in which it is being used.

hfy-html-dekludge-buffer

(hfy-html-dekludge-buffer)

Transform all dangerous characters marked with the hfy-quoteme property using hfy-html-quote

See also hfy-html-enkludge-buffer.

hfy-copy-and-fontify-file

(hfy-copy-and-fontify-file srcdir dstdir file)

Open file in srcdir—if fontified, write a fontified copy to dstdir adding an extension of hfy-extn. Fontification is actually done by htmlfontify-buffer. If the buffer is not fontified, just copy it.

hfy-decor

(hfy-decor tag val)

Derive CSS text-decoration specifiers from various Emacs font attributes.

hfy-slant

(hfy-slant slant)

Derive a font-style CSS specifier from the Emacs :slant attribute—CSS does not define the reverse-* styles, so just maps those to the regular specifiers.

hfy-tags-for-file

(hfy-tags-for-file srcdir file)

List of etags tags that have definitions in this file. Looks up the tags cache in hfy-tags-cache using srcdir as the key.

hfy-width

(hfy-width width)

Convert an Emacs :width attribute to a CSS font-stretch attribute.