Mercurial > emacs
annotate lisp/htmlfontify.el @ 108254:7d3e117cb7a7
Synch with Gnus trunk.
(mml-generate-mime-1,mml-compute-boundary-1): Update 'mml
handles on recursive mml-to-mime translation and check them for
boundary delimiter collisions. Reported by: Greg Troxel.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Thu, 06 May 2010 03:28:13 +0000 |
parents | 3040d386675c |
children | 9b941507a02c |
rev | line source |
---|---|
106126 | 1 ;;; htmlfontify.el --- htmlise a buffer/source tree with optional hyperlinks |
2 | |
106815 | 3 ;; Copyright (C) 2002, 2003, 2009, 2010 Free Software Foundation, Inc. |
106126 | 4 |
5 ;; Emacs Lisp Archive Entry | |
6 ;; Package: htmlfontify | |
7 ;; Filename: htmlfontify.el | |
8 ;; Version: 0.21 | |
9 ;; Keywords: html, hypermedia, markup, etags | |
10 ;; Author: Vivek Dasmohapatra <vivek@etla.org> | |
11 ;; Maintainer: Vivek Dasmohapatra <vivek@etla.org> | |
12 ;; Created: 2002-01-05 | |
13 ;; Description: htmlise a buffer/source tree with optional hyperlinks | |
14 ;; URL: http://rtfm.etla.org/emacs/htmlfontify/ | |
15 ;; Compatibility: Emacs23, Emacs22 | |
16 ;; Incompatibility: Emacs19, Emacs20, Emacs21 | |
17 ;; Last Updated: Thu 2009-11-19 01:31:21 +0000 | |
18 | |
19 ;; This file is part of GNU Emacs. | |
20 | |
21 ;; GNU Emacs is free software: you can redistribute it and/or modify | |
22 ;; it under the terms of the GNU General Public License as published by | |
23 ;; the Free Software Foundation, either version 3 of the License, or | |
24 ;; (at your option) any later version. | |
25 | |
26 ;; GNU Emacs is distributed in the hope that it will be useful, | |
27 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29 ;; GNU General Public License for more details. | |
30 | |
31 ;; You should have received a copy of the GNU General Public License | |
32 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
33 | |
34 ;;; Commentary: | |
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
36 ;; I have made some changes to make it work for Emacs 22. A lot of | |
37 ;; small bug fixes related to the format of text and overlay | |
38 ;; properties (which might have changed since the beginning of 2003 | |
39 ;; when this file was originally written). | |
40 ;; | |
41 ;; The function `hfy-face-at' currently carries much of the burden of | |
42 ;; my lacking understanding of the formats mentioned above and should | |
43 ;; need some knowledgeable help. | |
44 ;; | |
45 ;; Another thing that maybe could be fixed is that overlay background | |
46 ;; colors which are now only seen where there is text (in the XHTML | |
47 ;; output). A bit of CSS tweaking is necessary there. | |
48 ;; | |
49 ;; The face 'default has a value :background "SystemWindow" for the | |
50 ;; background color. There is no explicit notion that this should be | |
51 ;; considered transparent, but I have assumed that it could be handled | |
52 ;; like if it was here. (I am unsure that background and foreground | |
53 ;; priorities are handled ok, but it looks ok in my tests now.) | |
54 ;; | |
55 ;; 2007-12-27 Lennart Borgman | |
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
57 | |
58 ;; Here's some elisp code to html-pretty-print an Emacs buffer, preserving | |
59 ;; the Emacs syntax/whatever highlighting. It also knows how to drive etags | |
60 ;; (exuberant-ctags or Emacs etags) and hyperlink the code according | |
61 ;; to its (etags') output. | |
62 | |
63 ;; NOTE: Currently the hyperlinking code only knows how to drive GNU find | |
64 ;; and the exuberant and GNU variants of etags : I do not know of any other | |
65 ;; etags variants, but mechanisms have been provided to allow htmlfontify | |
66 ;; to be taught how to drive them. As long as your version of find has | |
67 ;; the -path test and is reasonably sane, you should be fine. | |
68 | |
69 ;; A sample of the htmlfontified / hyperlinked output of this module can be | |
70 ;; found at http://rtfm.etla.org/sql/dbishell/src/ - it's not perfect, but | |
71 ;; it's a hell of a lot faster and more thorough than I could hope to be | |
72 ;; doing this by hand. | |
73 | |
74 ;; some user / horrified onlooker comments: | |
75 ;; What? No! There's something deeply wrong here... (R. Shufflebotham) | |
76 ;; You're a freak. (D. Silverstone) | |
77 ;; Aren't we giving you enough to do? (J. Busuttil) | |
78 ;; You're almost as messed up as Lexx is! (N. Graves-Morris) | |
79 | |
80 ;;; History: | |
81 ;; Changes: moved to changelog (CHANGES) file. | |
82 | |
83 ;;; Code: | |
84 (eval-when-compile (require 'cl)) | |
85 (require 'faces) | |
86 ;; (`facep' `face-attr-construct' `x-color-values' `color-values' `face-name') | |
87 (require 'custom) | |
88 ;; (`defgroup' `defcustom') | |
89 (require 'font-lock) | |
90 ;; (`font-lock-fontify-region') | |
91 (require 'cus-edit) | |
92 | |
93 (defconst htmlfontify-version 0.21) | |
94 | |
95 (defconst hfy-meta-tags | |
96 (format "<meta name=\"generator\" content=\"emacs %s; htmlfontify %0.2f\" />" | |
97 emacs-version htmlfontify-version) | |
98 "The generator meta tag for this version of htmlfontify.") | |
99 | |
100 (defconst htmlfontify-manual "Htmlfontify Manual" | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
101 "Copy and convert buffers and files to HTML, adding hyperlinks between files |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
102 \(driven by etags) if requested. |
106126 | 103 \nInteractive functions: |
104 `htmlfontify-buffer' | |
105 `htmlfontify-run-etags' | |
106 `htmlfontify-copy-and-link-dir' | |
107 `htmlfontify-load-rgb-file' | |
108 `htmlfontify-unload-rgb-file'\n | |
109 In order to:\n | |
110 fontify a file you have open: M-x htmlfontify-buffer | |
111 prepare the etags map for a directory: M-x htmlfontify-run-etags | |
112 copy a directory, fontifying as you go: M-x htmlfontify-copy-and-link-dir\n | |
113 The following might be useful when running non-windowed or in batch mode: | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
114 \(note that they shouldn't be necessary - we have a built in map)\n |
106126 | 115 load an X11 style rgb.txt file: M-x htmlfontify-load-rgb-file |
116 unload the current rgb.txt file: M-x htmlfontify-unload-rgb-file\n | |
117 And here's a programmatic example:\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
118 \(defun rtfm-build-page-header (file style) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
119 (format \"#define TEMPLATE red+black.html |
106126 | 120 #define DEBUG 1 |
121 #include <build/menu-dirlist|>\\n | |
122 html-css-url := /css/red+black.css | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
123 title := rtfm.etla.org ( %s / src/%s ) |
106126 | 124 bodytag := |
125 head <=STYLESHEET;\\n | |
126 %s | |
127 STYLESHEET | |
128 main-title := rtfm / %s / src/%s\\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
129 main-content <=MAIN_CONTENT;\\n\" rtfm-section file style rtfm-section file)) |
106126 | 130 |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
131 \(defun rtfm-build-page-footer (file) \"\\nMAIN_CONTENT\\n\") |
106126 | 132 |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
133 \(defun rtfm-build-source-docs (section srcdir destdir) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
134 (interactive |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
135 \"s section[eg- emacs / p4-blame]:\\nD source-dir: \\nD output-dir: \") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
136 (require 'htmlfontify) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
137 (hfy-load-tags-cache srcdir) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
138 (let ((hfy-page-header 'rtfm-build-page-header) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
139 (hfy-page-footer 'rtfm-build-page-footer) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
140 (rtfm-section section) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
141 (hfy-index-file \"index\")) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
142 (htmlfontify-run-etags srcdir) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
143 (htmlfontify-copy-and-link-dir srcdir destdir \".src\" \".html\")))") |
106126 | 144 |
145 (defgroup htmlfontify nil | |
107207 | 146 "Convert buffers and files to HTML." |
106126 | 147 :group 'applications |
107207 | 148 :link '(variable-link htmlfontify-manual) |
106126 | 149 :prefix "hfy-") |
150 | |
151 (defcustom hfy-page-header 'hfy-default-header | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
152 "Function called with two arguments (the filename relative to the top |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
153 level source directory being etag'd and fontified), and a string containing |
106126 | 154 the <style>...</style> text to embed in the document- the string returned will |
155 be used as the header for the htmlfontified version of the source file.\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
156 See also `hfy-page-footer'." |
106126 | 157 :group 'htmlfontify |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
158 ;; FIXME: Why place such a :tag everywhere? Isn't it imposing your |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
159 ;; own Custom preference on your users? --Stef |
106126 | 160 :tag "page-header" |
161 :type '(function)) | |
162 | |
163 (defcustom hfy-split-index nil | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
164 "Whether or not to split the index `hfy-index-file' alphabetically |
106126 | 165 on the first letter of each tag. Useful when the index would otherwise |
166 be large and take a long time to render or be difficult to navigate." | |
167 :group 'htmlfontify | |
168 :tag "split-index" | |
169 :type '(boolean)) | |
170 | |
171 (defcustom hfy-page-footer 'hfy-default-footer | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
172 "As `hfy-page-header', but generates the output footer |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
173 \(and takes only one argument, the filename)." |
106126 | 174 :group 'htmlfontify |
175 :tag "page-footer" | |
176 :type '(function)) | |
177 | |
178 (defcustom hfy-extn ".html" | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
179 "File extension used for output files." |
106126 | 180 :group 'htmlfontify |
181 :tag "extension" | |
182 :type '(string)) | |
183 | |
184 (defcustom hfy-src-doc-link-style "text-decoration: underline;" | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
185 "String to add to the '<style> a' variant of an htmlfontify CSS class." |
106126 | 186 :group 'htmlfontify |
187 :tag "src-doc-link-style" | |
188 :type '(string)) | |
189 | |
190 (defcustom hfy-src-doc-link-unstyle " text-decoration: none;" | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
191 "Regex to remove from the <style> a variant of an htmlfontify CSS class." |
106126 | 192 :group 'htmlfontify |
193 :tag "src-doc-link-unstyle" | |
194 :type '(string)) | |
195 | |
196 (defcustom hfy-link-extn nil | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
197 "File extension used for href links. |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
198 Useful where the htmlfontify output files are going to be processed |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
199 again, with a resulting change in file extension. If nil, then any |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
200 code using this should fall back to `hfy-extn'." |
106126 | 201 :group 'htmlfontify |
202 :tag "link-extension" | |
203 :type '(choice string (const nil))) | |
204 | |
205 (defcustom hfy-link-style-fun 'hfy-link-style-string | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
206 "Set this to a function, which will be called with one argument |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
207 \(a \"{ foo: bar; ...}\" CSS style-string) - it should return a copy of |
106126 | 208 its argument, altered so as to make any changes you want made for text which |
209 is a hyperlink, in addition to being in the class to which that style would | |
210 normally be applied." | |
211 :group 'htmlfontify | |
212 :tag "link-style-function" | |
213 :type '(function)) | |
214 | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
215 (defcustom hfy-index-file "hfy-index" |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
216 "Name (sans extension) of the tag definition index file produced during |
106126 | 217 fontification-and-hyperlinking." |
218 :group 'htmlfontify | |
219 :tag "index-file" | |
220 :type '(string)) | |
221 | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
222 (defcustom hfy-instance-file "hfy-instance" |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
223 "Name (sans extension) of the tag usage index file produced during |
106126 | 224 fontification-and-hyperlinking." |
225 :group 'htmlfontify | |
226 :tag "instance-file" | |
227 :type '(string)) | |
228 | |
229 (defcustom hfy-html-quote-regex "\\(<\\|\"\\|&\\|>\\)" | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
230 "Regex to match (with a single back-reference per match) strings in HTML |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
231 which should be quoted with `hfy-html-quote' (and `hfy-html-quote-map') |
106126 | 232 to make them safe." |
233 :group 'htmlfontify | |
234 :tag "html-quote-regex" | |
235 :type '(regexp)) | |
236 | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
237 (define-obsolete-variable-alias 'hfy-init-kludge-hooks 'hfy-init-kludge-hook |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
238 "23.2") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
239 (defcustom hfy-init-kludge-hook '(hfy-kludge-cperl-mode) |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
240 "List of functions to call when starting `htmlfontify-buffer' to do any |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
241 kludging necessary to get highlighting modes to behave as you want, even |
106126 | 242 when not running under a window system." |
243 :group 'htmlfontify | |
244 :tag "init-kludge-hooks" | |
245 :type '(hook)) | |
246 | |
247 (defcustom hfy-post-html-hooks nil | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
248 "List of functions to call after creating and filling the HTML buffer. |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
249 These functions will be called with the html buffer as the current buffer." |
106126 | 250 :group 'htmlfontify |
251 :tag "post-html-hooks" | |
252 :options '(set-auto-mode) | |
253 :type '(hook)) | |
254 | |
255 (defcustom hfy-default-face-def nil | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
256 "Fallback `defface' specification for the face 'default, used when |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
257 `hfy-display-class' has been set (the normal htmlfontify way of extracting |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
258 potentially non-current face information doesn't necessarily work for |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
259 'default).\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
260 Example: I customize this to:\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
261 \((t :background \"black\" :foreground \"white\" :family \"misc-fixed\"))" |
106126 | 262 :group 'htmlfontify |
263 :tag "default-face-definition" | |
264 :type '(alist)) | |
265 | |
266 (defcustom hfy-etag-regex (concat ".*" | |
267 "\x7f" "\\([^\x01\n]+\\)" | |
268 "\x01" "\\([0-9]+\\)" | |
269 "," "\\([0-9]+\\)$" | |
270 "\\|" ".*\x7f[0-9]+,[0-9]+$") | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
271 "Regex used to parse an etags entry: must have 3 subexps, corresponding, |
106126 | 272 in order, to:\n |
273 1 - The tag | |
274 2 - The line | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
275 3 - The char (point) at which the tag occurs." |
106126 | 276 :group 'htmlfontify |
277 :tag "etag-regex" | |
278 :type '(regexp)) | |
279 | |
280 (defcustom hfy-html-quote-map '(("\"" """) | |
281 ("<" "<" ) | |
282 ("&" "&" ) | |
283 (">" ">" )) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
284 "Alist of char -> entity mappings used to make the text HTML-safe." |
106126 | 285 :group 'htmlfontify |
286 :tag "html-quote-map" | |
287 :type '(alist :key-type (string))) | |
288 (eval-and-compile | |
289 (defconst hfy-e2x-etags-cmd "for src in `find . -type f`; | |
290 do | |
291 ETAGS=%s; | |
292 case ${src} in | |
293 *.ad[absm]|*.[CFHMSacfhlmpsty]|*.def|*.in[cs]|*.s[as]|*.src|*.cc|\\ | |
294 *.hh|*.[chy]++|*.[ch]pp|*.[chy]xx|*.pdb|*.[ch]s|*.[Cc][Oo][Bb]|\\ | |
295 *.[eh]rl|*.f90|*.for|*.java|*.[cem]l|*.clisp|*.lisp|*.[Ll][Ss][Pp]|\\ | |
296 [Mm]akefile*|*.pas|*.[Pp][LlMm]|*.psw|*.lm|*.pc|*.prolog|*.oak|\\ | |
297 *.p[sy]|*.sch|*.scheme|*.[Ss][Cc][Mm]|*.[Ss][Mm]|*.bib|*.cl[os]|\\ | |
298 *.ltx|*.sty|*.TeX|*.tex|*.texi|*.texinfo|*.txi|*.x[bp]m|*.yy|\\ | |
299 *.[Ss][Qq][Ll]) | |
300 ${ETAGS} -o- ${src}; | |
301 ;; | |
302 *) | |
303 FTYPE=`file ${src}`; | |
304 case ${FTYPE} in | |
305 *script*text*) | |
306 ${ETAGS} -o- ${src}; | |
307 ;; | |
308 *text*) | |
309 SHEBANG=`head -n1 ${src} | grep '#!' -c`; | |
310 if [ ${SHEBANG} -eq 1 ]; | |
311 then | |
312 ${ETAGS} -o- ${src}; | |
313 fi; | |
314 ;; | |
315 esac; | |
316 ;; | |
317 esac; | |
318 done;") | |
319 | |
320 (defconst hfy-etags-cmd-alist-default | |
321 `(("emacs etags" . ,hfy-e2x-etags-cmd) | |
322 ("exuberant ctags" . "%s -R -f -" ))) | |
323 | |
324 (defcustom hfy-etags-cmd-alist | |
325 hfy-etags-cmd-alist-default | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
326 "Alist of possible shell commands that will generate etags output that |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
327 `htmlfontify' can use. '%s' will be replaced by `hfy-etags-bin'." |
106126 | 328 :group 'htmlfontify |
329 :tag "etags-cmd-alist" | |
330 :type '(alist :key-type (string) :value-type (string)) )) | |
331 | |
332 (defcustom hfy-etags-bin "etags" | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
333 "Location of etags binary (we begin by assuming it's in your path).\n |
106126 | 334 Note that if etags is not in your path, you will need to alter the shell |
335 commands in `hfy-etags-cmd-alist'." | |
336 :group 'htmlfontify | |
337 :tag "etags-bin" | |
338 :type '(file)) | |
339 | |
340 (defcustom hfy-shell-file-name "/bin/sh" | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
341 "Shell (bourne or compatible) to invoke for complex shell operations." |
106126 | 342 :group 'htmlfontify |
343 :tag "shell-file-name" | |
344 :type '(file)) | |
345 | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
346 (defcustom hfy-ignored-properties '(read-only |
106505
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
347 intangible |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
348 modification-hooks |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
349 insert-in-front-hooks |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
350 insert-behind-hooks |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
351 point-entered |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
352 point-left) |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
353 "Properties to omit when copying a fontified buffer for HTML transformation." |
106505
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
354 :group 'htmlfontify |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
355 :tag "ignored-properties" |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
356 :type '(repeat symbol)) |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
357 |
106126 | 358 (defun hfy-which-etags () |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
359 "Return a string indicating which flavour of etags we are using." |
106126 | 360 (let ((v (shell-command-to-string (concat hfy-etags-bin " --version")))) |
361 (cond ((string-match "exube" v) "exuberant ctags") | |
362 ((string-match "GNU E" v) "emacs etags" )) )) | |
363 | |
364 (defcustom hfy-etags-cmd | |
365 (eval-and-compile (cdr (assoc (hfy-which-etags) hfy-etags-cmd-alist))) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
366 "The etags equivalent command to run in a source directory to generate a tags |
106126 | 367 file for the whole source tree from there on down. The command should emit |
368 the etags output on stdout.\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
369 Two canned commands are provided - they drive Emacs' etags and |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
370 exuberant-ctags' etags respectively." |
106126 | 371 :group 'htmlfontify |
372 :tag "etags-command" | |
373 :type (eval-and-compile | |
374 (let ((clist (list '(string)))) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
375 (dolist (C hfy-etags-cmd-alist) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
376 (push (list 'const :tag (car C) (cdr C)) clist)) |
106126 | 377 (cons 'choice clist)) )) |
378 | |
379 (defcustom hfy-istext-command "file %s | sed -e 's@^[^:]*:[ \t]*@@'" | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
380 "Command to run with the name of a file, to see whether it is a text file |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
381 or not. The command should emit a string containing the word 'text' if |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
382 the file is a text file, and a string not containing 'text' otherwise." |
106126 | 383 :group 'htmlfontify |
384 :tag "istext-command" | |
385 :type '(string)) | |
386 | |
387 (defcustom hfy-find-cmd | |
388 "find . -type f \\! -name \\*~ \\! -name \\*.flc \\! -path \\*/CVS/\\*" | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
389 "Find command used to harvest a list of files to attempt to fontify." |
106126 | 390 :group 'htmlfontify |
391 :tag "find-command" | |
392 :type '(string)) | |
393 | |
394 (defcustom hfy-display-class nil | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
395 "Display class to use to determine which display class to use when |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
396 calculating a face's attributes. This is useful when, for example, you |
106126 | 397 are running Emacs on a tty or in batch mode, and want htmlfontify to have |
398 access to the face spec you would use if you were connected to an X display.\n | |
399 Some valid class specification elements are:\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
400 '(class color) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
401 '(class grayscale) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
402 '(background dark) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
403 '(background light) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
404 '(type x-toolkit) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
405 '(type tty) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
406 '(type motif) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
407 '(type lucid) |
106126 | 408 Multiple values for a tag may be combined, to indicate that any one or more |
409 of these values in the specification key constitutes a match, eg:\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
410 '((class color grayscale) (type tty)) would match any of:\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
411 '((class color)) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
412 '((class grayscale)) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
413 '((class color grayscale)) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
414 '((class color foo)) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
415 '((type tty)) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
416 '((type tty) (class color))\n |
106126 | 417 and so on." |
418 :type '(alist :key-type (symbol) :value-type (symbol)) | |
419 :group 'htmlfontify | |
420 :tag "display-class" | |
421 :options '((type (choice (const :tag "X11" x-toolkit) | |
422 (const :tag "Terminal" tty ) | |
423 (const :tag "Lucid Toolkit" lucid ) | |
424 (const :tag "Motif Toolkit" motif ))) | |
425 | |
426 (class (choice (const :tag "Colour" color ) | |
427 (const :tag "Greyscale" grayscale))) | |
428 | |
429 (background (choice (const :tag "Dark" dark ) | |
430 (const :tag "Bright" light ))) )) | |
431 | |
432 (defcustom hfy-optimisations (list 'keep-overlays) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
433 "Optimizations to turn on: So far, the following have been implemented:\n |
106126 | 434 merge-adjacent-tags: If two (or more) span tags are adjacent, identical and |
435 separated by nothing more than whitespace, they will | |
436 be merged into one span. | |
437 zap-comment-links : Suppress hyperlinking of tags found in comments. | |
438 zap-string-links : Suppress hyperlinking of tags found in strings. | |
439 div-wrapper : Add <div class=\"default\"> </div> tags around the | |
440 output. | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
441 keep-overlays : More of a bell (or possibly whistle) than an |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
442 optimization - If on, preserve overlay highlighting |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
443 (cf ediff or goo-font-lock) as well as basic faces.\n |
106126 | 444 And the following are planned but not yet available:\n |
445 kill-context-leak : Suppress hyperlinking between files highlighted by | |
446 different modes.\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
447 Note: like compiler optimizations, these optimize the _output_ of the code, |
106126 | 448 not the processing of the source itself, and are therefore likely to slow |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
449 htmlfontify down, at least a little. Except for skip-refontification, |
106126 | 450 which can never slow you down, but may result in incomplete fontification." |
451 :type '(set (const :tag "merge-adjacent-tags" merge-adjacent-tags ) | |
452 (const :tag "zap-comment-links" zap-comment-links ) | |
453 (const :tag "zap-string-links" zap-string-links ) | |
454 (const :tag "skip-refontification" skip-refontification) | |
455 (const :tag "kill-context-leak" kill-context-leak ) | |
456 (const :tag "div-wrapper" div-wrapper ) | |
457 (const :tag "keep-overlays" keep-overlays )) | |
458 :group 'htmlfontify | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
459 :tag "optimizations") |
106126 | 460 |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
461 (defvar hfy-tags-cache nil |
106126 | 462 "Alist of the form:\n |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
463 \((\"/src/dir/0\" . tag-hash0) (\"/src/dir/1\" tag-hash1) ...)\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
464 Each tag hash entry then contains entries of the form:\n |
106126 | 465 \"tag_string\" => ((\"file/name.ext\" line char) ... )\n |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
466 ie an alist mapping (relative) file paths to line and character offsets.\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
467 See also `hfy-load-tags-cache'.") |
106126 | 468 |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
469 (defvar hfy-tags-sortl nil |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
470 "Alist of the form ((\"/src/dir\" . (tag0 tag1 tag2)) ... )\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
471 where the tags are stored in descending order of length.\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
472 See also `hfy-load-tags-cache'.") |
106126 | 473 |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
474 (defvar hfy-tags-rmap nil |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
475 "Alist of the form ((\"/src/dir\" . tag-rmap-hash))\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
476 where tag-rmap-hash has entries of the form: |
106126 | 477 \"tag_string\" => ( \"file/name.ext\" line char ) |
478 Unlike `hfy-tags-cache' these are the locations of occurrences of | |
479 tagged items, not the locations of their definitions.") | |
480 | |
481 (defvar hfy-style-assoc 'please-ignore-this-line | |
482 "An assoc representing/describing an Emacs face. | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
483 Properties may be repeated, in which case later properties should be |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
484 treated as if they were inherited from a 'parent' font. |
106126 | 485 \(For some properties, only the first encountered value is of any importance, |
486 for others the values might be cumulative, and for others they might be | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
487 cumulative in a complex way.)\n |
106126 | 488 Some examples:\n |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
489 \(hfy-face-to-style 'default) => |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
490 ((\"background\" . \"rgb(0, 0, 0)\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
491 (\"color\" . \"rgb(255, 255, 255)\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
492 (\"font-style\" . \"normal\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
493 (\"font-weight\" . \"500\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
494 (\"font-stretch\" . \"normal\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
495 (\"font-family\" . \"misc-fixed\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
496 (\"font-size\" . \"13pt\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
497 (\"text-decoration\" . \"none\"))\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
498 \(hfy-face-to-style 'Info-title-3-face) => |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
499 ((\"font-weight\" . \"700\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
500 (\"font-family\" . \"helv\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
501 (\"font-size\" . \"120%\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
502 (\"text-decoration\" . \"none\"))\n") |
106126 | 503 |
504 (defvar hfy-sheet-assoc 'please-ignore-this-line | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
505 "An assoc with elements of the form (face-name style-name . style-string):\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
506 '((default \"default\" . \"{background: black; color: white}\") |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
507 (font-lock-string-face \"string\" . \"{color: rgb(64,224,208)}\"))" ) |
106126 | 508 |
509 (defvar hfy-facemap-assoc 'please-ignore-this-line | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
510 "An assoc of (point . FACE-SYMBOL) or (point . DEFFACE-LIST) |
106126 | 511 and (point . 'end) elements, in descending order of point value |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
512 \(ie from the file's end to its beginning).\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
513 The map is in reverse order because inserting a <style> tag (or any other |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
514 string) at `point' invalidates the map for all entries with a greater value of |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
515 point. By traversing the map from greatest to least point, we still invalidate |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
516 the map as we go, but only those points we have already dealt with (and |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
517 therefore no longer care about) will be invalid at any time.\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
518 '((64820 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
519 (64744 . font-lock-comment-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
520 (64736 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
521 (64722 . font-lock-string-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
522 (64630 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
523 (64623 . font-lock-string-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
524 (64449 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
525 (64446 . font-lock-keyword-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
526 (64406 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
527 (64395 . font-lock-constant-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
528 (64393 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
529 (64386 . font-lock-keyword-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
530 (64379 . end) |
106126 | 531 ;; big similar section elided. You get the idea. |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
532 (4285 . font-lock-constant-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
533 (4285 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
534 (4221 . font-lock-comment-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
535 (4221 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
536 (4197 . font-lock-constant-face) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
537 (4197 . end) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
538 (1 . font-lock-comment-face))") |
106126 | 539 |
540 (defvar hfy-tmpfont-stack nil | |
541 "An alist of derived fonts resulting from overlays.") | |
542 | |
543 (defconst hfy-hex-regex "[0-9A-Fa-f]") | |
544 | |
545 (defconst hfy-triplet-regex | |
546 (concat | |
547 "\\(" hfy-hex-regex hfy-hex-regex "\\)" | |
548 "\\(" hfy-hex-regex hfy-hex-regex "\\)" | |
549 "\\(" hfy-hex-regex hfy-hex-regex "\\)")) | |
550 | |
551 (defun hfy-interq (set-a set-b) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
552 "Return the intersection (using `eq') of two lists SET-A and SET-B." |
106126 | 553 (let ((sa set-a) (interq nil) (elt nil)) |
554 (while sa | |
555 (setq elt (car sa) | |
556 sa (cdr sa)) | |
557 (if (memq elt set-b) (setq interq (cons elt interq)))) interq)) | |
558 | |
559 (defun hfy-colour-vals (colour) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
560 "Where COLOUR is a color name or #XXXXXX style triplet, return a |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
561 list of three (16 bit) rgb values for said color.\n |
106126 | 562 If a window system is unavailable, calls `hfy-fallback-colour-values'." |
563 (if (string-match hfy-triplet-regex colour) | |
564 (mapcar | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
565 (lambda (x) (* (string-to-number (match-string x colour) 16) 257)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
566 '(1 2 3)) |
106126 | 567 ;;(message ">> %s" colour) |
568 (if window-system | |
569 (if (fboundp 'color-values) | |
570 (color-values colour) | |
571 ;;(message "[%S]" window-system) | |
572 (x-color-values colour)) | |
573 ;; blarg - tty colours are no good - go fetch some X colours: | |
574 (hfy-fallback-colour-values colour)))) | |
575 | |
576 (defvar hfy-cperl-mode-kludged-p nil) | |
577 | |
578 (defun hfy-kludge-cperl-mode () | |
579 "CPerl mode does its damndest not to do some of its fontification when not | |
580 in a windowing system - try to trick it..." | |
581 (if (not hfy-cperl-mode-kludged-p) | |
582 (progn (if (not window-system) | |
583 (let ((window-system 'htmlfontify)) | |
584 (eval-and-compile (require 'cperl-mode)) | |
585 (setq cperl-syntaxify-by-font-lock t))) | |
586 (setq hfy-cperl-mode-kludged-p t))) ) | |
587 | |
588 (defun hfy-opt (symbol) "Is option SYMBOL set." (memq symbol hfy-optimisations)) | |
589 | |
590 (defun hfy-default-header (file style) | |
591 "Default value for `hfy-page-header'. | |
592 FILE is the name of the file. | |
593 STYLE is the inline CSS stylesheet (or tag referring to an external sheet)." | |
594 ;; (format "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"> | |
595 ;; <html>\n <head>\n <title>%s</title>\n %s\n </head>\n <body>\n" file style)) | |
596 (format "<?xml version=\"1.0\" encoding=\"utf-8\"?> | |
597 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" | |
598 \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"> | |
599 <html xmlns=\"http://www.w3.org/1999/xhtml\"> | |
600 <head> | |
601 <title>%s</title> | |
602 %s | |
603 <script type=\"text/javascript\"><!-- | |
604 // this function is needed to work around | |
605 // a bug in IE related to element attributes | |
606 function hasClass(obj) | |
607 { | |
608 var result = false; | |
609 if (obj.getAttributeNode(\"class\") != null) | |
610 { | |
611 result = obj.getAttributeNode(\"class\").value; | |
612 } | |
613 return result; | |
614 } | |
615 | |
616 function stripe(id) | |
617 { | |
618 // the flag we'll use to keep track of | |
619 // whether the current row is odd or even | |
620 var even = false; | |
621 | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
622 // if arguments are provided to specify the colors |
106126 | 623 // of the even & odd rows, then use the them; |
624 // otherwise use the following defaults: | |
625 var evenColor = arguments[1] ? arguments[1] : \"#fff\"; | |
626 var oddColor = arguments[2] ? arguments[2] : \"#ddd\"; | |
627 | |
628 // obtain a reference to the desired table | |
629 // if no such table exists, abort | |
630 var table = document.getElementById(id); | |
631 if (! table) { return; } | |
632 | |
633 // by definition, tables can have more than one tbody | |
634 // element, so we'll have to get the list of child | |
635 // <tbody>s | |
636 var tbodies = table.getElementsByTagName(\"tbody\"); | |
637 | |
638 // and iterate through them... | |
639 for (var h = 0; h < tbodies.length; h++) | |
640 { | |
641 // find all the <tr> elements... | |
642 var trs = tbodies[h].getElementsByTagName(\"tr\"); | |
643 | |
644 // ... and iterate through them | |
645 for (var i = 0; i < trs.length; i++) | |
646 { | |
647 // avoid rows that have a class attribute | |
648 // or backgroundColor style | |
649 if (! hasClass(trs[i]) && | |
650 ! trs[i].style.backgroundColor) | |
651 { | |
652 // get all the cells in this row... | |
653 var tds = trs[i].getElementsByTagName(\"td\"); | |
654 | |
655 // and iterate through them... | |
656 for (var j = 0; j < tds.length; j++) | |
657 { | |
658 var mytd = tds[j]; | |
659 | |
660 // avoid cells that have a class attribute | |
661 // or backgroundColor style | |
662 if (! hasClass(mytd) && | |
663 ! mytd.style.backgroundColor) | |
664 { | |
665 mytd.style.backgroundColor = | |
666 even ? evenColor : oddColor; | |
667 } | |
668 } | |
669 } | |
670 // flip from odd to even, or vice-versa | |
671 even = ! even; | |
672 } | |
673 } | |
674 } | |
106270
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
675 |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
676 function toggle_invis( name ) |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
677 { |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
678 var filter = |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
679 { acceptNode: |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
680 function( node ) |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
681 { var classname = node.id; |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
682 if( classname ) |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
683 { var classbase = classname.substr( 0, name.length ); |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
684 if( classbase == name ) { return NodeFilter.FILTER_ACCEPT; } } |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
685 return NodeFilter.FILTER_SKIP; } }; |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
686 var walker = document.createTreeWalker( document.body , |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
687 NodeFilter.SHOW_ELEMENT , |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
688 filter , |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
689 false ); |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
690 while( walker.nextNode() ) |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
691 { |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
692 var e = walker.currentNode; |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
693 if( e.style.display == \"none\" ) { e.style.display = \"inline\"; } |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
694 else { e.style.display = \"none\"; } |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
695 } |
d059492ca39b
Various minor fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106128
diff
changeset
|
696 } |
106126 | 697 --> </script> |
698 </head> | |
699 <body onload=\"stripe('index'); return true;\">\n" | |
700 file style)) | |
701 | |
702 (defun hfy-default-footer (file) | |
703 "Default value for `hfy-page-footer'. | |
704 FILE is the name of the file being rendered, in case it is needed." | |
705 "\n </body>\n</html>\n") | |
706 | |
707 (defun hfy-link-style-string (style-string) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
708 "Replace the end of a CSS style declaration STYLE-STRING with the contents |
106126 | 709 of the variable `hfy-src-doc-link-style', removing text matching the regex |
710 `hfy-src-doc-link-unstyle' first, if necessary." | |
711 ;;(message "hfy-colour-vals");;DBUG | |
712 (if (string-match hfy-src-doc-link-unstyle style-string) | |
713 (setq style-string (replace-match "" 'fixed-case 'literal style-string))) | |
714 (if (and (not (string-match hfy-src-doc-link-style style-string)) | |
715 (string-match "} *$" style-string)) | |
716 (concat (replace-match hfy-src-doc-link-style | |
717 'fixed-case | |
718 'literal | |
719 style-string) " }") style-string)) | |
720 | |
721 ;; utility functions - cast emacs style specification values into their | |
722 ;; css2 equivalents: | |
723 (defun hfy-triplet (colour) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
724 "Takes a COLOUR name (string) and return a CSS rgb(R, G, B) triplet string. |
106126 | 725 Uses the definition of \"white\" to map the numbers to the 0-255 range, so |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
726 if you've redefined white, (esp. if you've redefined it to have a triplet |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
727 member lower than that of the color you are processing) strange things |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
728 may happen." |
106126 | 729 ;;(message "hfy-colour-vals");;DBUG |
730 (let ((white (mapcar (lambda (I) (float (1+ I))) (hfy-colour-vals "white"))) | |
731 (rgb16 (mapcar (lambda (I) (float (1+ I))) (hfy-colour-vals colour)))) | |
732 (if rgb16 | |
733 ;;(apply 'format "rgb(%d, %d, %d)" | |
734 ;; Use #rrggbb instead, it is smaller | |
735 (apply 'format "#%02x%02x%02x" | |
736 (mapcar (lambda (X) | |
737 (* (/ (nth X rgb16) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
738 (nth X white)) 255)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
739 '(0 1 2)))))) |
106126 | 740 |
741 (defun hfy-family (family) (list (cons "font-family" family))) | |
742 (defun hfy-bgcol (colour) (list (cons "background" (hfy-triplet colour)))) | |
743 (defun hfy-colour (colour) (list (cons "color" (hfy-triplet colour)))) | |
744 (defun hfy-width (width) (list (cons "font-stretch" (symbol-name width)))) | |
745 | |
746 (defcustom hfy-font-zoom 1.05 | |
747 "Font scaling from Emacs to HTML." | |
748 :type 'float | |
749 :group 'htmlfontify) | |
750 | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
751 (defun hfy-size (height) |
106126 | 752 "Derive a CSS font-size specifier from an Emacs font :height attribute HEIGHT. |
753 Does not cope with the case where height is a function to be applied to | |
754 the height of the underlying font." | |
755 (list | |
756 (cond | |
757 ;;(t (cons "font-size" ": 1em")) | |
758 ((floatp height) | |
759 (cons "font-size" (format "%d%%" (* (* hfy-font-zoom height) 100)))) | |
760 ((integerp height) | |
761 (cons "font-size" (format "%dpt" (/ (* hfy-font-zoom height) 10 )))) )) ) | |
762 | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
763 (defun hfy-slant (slant) |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
764 "Derive a font-style CSS specifier from the Emacs :slant attribute SLANT: |
106126 | 765 CSS does not define the reverse-* styles, so just maps those to the |
766 regular specifiers." | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
767 (list (cons "font-style" |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
768 (or (cdr (assq slant '((italic . "italic") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
769 (reverse-italic . "italic" ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
770 (oblique . "oblique") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
771 (reverse-oblique . "oblique")))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
772 "normal")))) |
106126 | 773 |
774 (defun hfy-weight (weight) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
775 "Derive a font-weight CSS specifier from an Emacs weight spec symbol WEIGHT." |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
776 (list (cons "font-weight" (cdr (assq weight '((ultra-bold . "900") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
777 (extra-bold . "800") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
778 (bold . "700") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
779 (semi-bold . "600") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
780 (normal . "500") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
781 (semi-light . "400") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
782 (light . "300") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
783 (extra-light . "200") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
784 (ultra-light . "100"))))))) |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
785 |
106126 | 786 (defun hfy-box-to-border-assoc (spec) |
787 (if spec | |
788 (let ((tag (car spec)) | |
789 (val (cadr spec))) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
790 (cons (case tag |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
791 (:color (cons "colour" val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
792 (:width (cons "width" val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
793 (:style (cons "style" val))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
794 (hfy-box-to-border-assoc (cddr spec)))))) |
106126 | 795 |
796 (defun hfy-box-to-style (spec) | |
797 (let* ((css (hfy-box-to-border-assoc spec)) | |
798 (col (cdr (assoc "colour" css))) | |
799 (s (cdr (assoc "style" css)))) | |
800 (list | |
801 (if col (cons "border-color" (cdr (assoc "colour" css)))) | |
802 (cons "border-width" (format "%dpx" (or (cdr (assoc "width" css)) 1))) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
803 (cons "border-style" (case s |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
804 (released-button "outset") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
805 (pressed-button "inset" ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
806 (t "solid" )))))) |
106126 | 807 |
808 (defun hfy-box (box) | |
809 "Derive CSS border-* attributes from the Emacs :box attribute BOX." | |
810 (if box | |
811 (cond | |
812 ((integerp box) (list (cons "border-width" (format "%dpx" box)))) | |
813 ((stringp box) (list (cons "border" (format "solid %s 1px" box)))) | |
814 ((listp box) (hfy-box-to-style box) ))) ) | |
815 | |
816 (defun hfy-decor (tag val) | |
817 "Derive CSS text-decoration specifiers from various Emacs font attributes. | |
818 TAG is an Emacs font attribute key (eg :underline). | |
819 VAL is ignored." | |
820 (list | |
106128
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
821 ;; FIXME: Why not '("text-decoration" . "underline")? --Stef |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
822 (case tag |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
823 (:underline (cons "text-decoration" "underline" )) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
824 (:overline (cons "text-decoration" "overline" )) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
825 (:strike-through (cons "text-decoration" "line-through"))))) |
106126 | 826 |
827 (defun hfy-invisible (&optional val) | |
828 "This text should be invisible. | |
829 Do something in CSS to make that happen. | |
830 VAL is ignored here." | |
831 '(("display" . "none"))) | |
832 | |
833 (defun hfy-combined-face-spec (face) | |
834 "Return a `defface' style alist of possible specifications for FACE. | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
835 Entries resulting from customization (`custom-set-faces') will take |
106126 | 836 precedence." |
837 (let ((spec nil)) | |
838 (setq spec (append (or (get face 'saved-face) (list)) | |
839 (or (get face 'face-defface-spec) (list)))) | |
840 (if (and hfy-display-class hfy-default-face-def (eq face 'default)) | |
841 (setq spec (append hfy-default-face-def spec))) spec)) | |
842 | |
843 (defun hfy-face-attr-for-class (face &optional class) | |
844 "Return the face attributes for FACE. | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
845 If CLASS is set, it must be a `defface' alist key [see below], |
106126 | 846 in which case the first face specification returned by `hfy-combined-face-spec' |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
847 which *doesn't* clash with CLASS is returned.\n |
106126 | 848 \(A specification with a class of t is considered to match any class you |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
849 specify - this matches Emacs' behavior when deciding on which face attributes |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
850 to use, to the best of my understanding).\n |
106126 | 851 If CLASS is nil, then you just get get whatever `face-attr-construct' returns, |
852 ie the current specification in effect for FACE.\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
853 *NOTE*: This function forces any face that is not 'default and which has |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
854 no :inherit property to inherit from 'default (this is because 'default |
106126 | 855 is magical in that Emacs' fonts behave as if they inherit implicitly from |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
856 'default, but no such behavior exists in HTML/CSS).\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
857 See also `hfy-display-class' for details of valid values for CLASS." |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
858 (let ((face-spec |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
859 (if class |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
860 (let ((face-props (hfy-combined-face-spec face)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
861 (face-specn nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
862 (face-class nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
863 (face-attrs nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
864 (face-score -1) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
865 (face-match nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
866 (while face-props |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
867 (setq face-specn (car face-props) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
868 face-class (car face-specn) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
869 face-attrs (cdr face-specn) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
870 face-props (cdr face-props)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
871 ;; if the current element CEL of CLASS is t we match |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
872 ;; if the current face-class is t, we match |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
873 ;; if the cdr of CEL has a non-nil |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
874 ;; intersection with the cdr of the first member of |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
875 ;; the current face-class with the same car as CEL, we match |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
876 ;; if we actually clash, then we can't match |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
877 (let ((cbuf class) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
878 (cel nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
879 (key nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
880 (val nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
881 (x nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
882 (next nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
883 (score 0)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
884 (while (and cbuf (not next)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
885 (setq cel (car cbuf) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
886 cbuf (cdr cbuf) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
887 key (car cel) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
888 val (cdr cel) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
889 val (if (listp val) val (list val))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
890 (cond |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
891 ((or (eq cel t) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
892 (memq face-class '(t default))) ;Default match. |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
893 (setq score 0) (ignore "t match")) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
894 ((not (cdr (assq key face-class))) ;Neither good nor bad. |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
895 nil (ignore "non match, non collision")) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
896 ((setq x (hfy-interq val (cdr (assq key face-class)))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
897 (setq score (+ score (length x))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
898 (ignore "intersection")) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
899 (t ;; nope. |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
900 (setq next t score -10) (ignore "collision")) )) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
901 (if (> score face-score) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
902 (progn |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
903 (setq face-match face-attrs |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
904 face-score score ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
905 (ignore "%d << %S/%S" score face-class class)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
906 (ignore "--- %d ---- (insufficient)" score)) )) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
907 ;; matched ? last attrs : nil |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
908 (if face-match |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
909 (if (listp (car face-match)) (car face-match) face-match) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
910 nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
911 ;; Unfortunately the default face returns a |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
912 ;; :background. Fortunately we can remove it, but how do we do |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
913 ;; that in a non-system specific way? |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
914 (let ((spec (face-attr-construct face)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
915 (new-spec nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
916 (if (not (memq :background spec)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
917 spec |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
918 (while spec |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
919 (let ((a (nth 0 spec)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
920 (b (nth 1 spec))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
921 (unless (and (eq a :background) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
922 (stringp b) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
923 (string= b "SystemWindow")) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
924 (setq new-spec (cons a (cons b new-spec))))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
925 (setq spec (cddr spec))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
926 new-spec))))) |
106126 | 927 (if (or (memq :inherit face-spec) (eq 'default face)) |
928 face-spec | |
929 (nconc face-spec (list :inherit 'default))) )) | |
930 | |
931 ;; construct an assoc of (css-tag-name . css-tag-value) pairs | |
932 ;; from a face or assoc of face attributes: | |
933 | |
934 ;; Some tests etc: | |
935 ;; (mumamo-message-with-face "testing face" 'highlight) | |
936 ;; (mumamo-message-with-face "testing face" '(:foreground "red" :background "yellow")) | |
937 ;; (hfy-face-to-style-i '(:inherit default foreground-color "red")) | |
938 ;; default face=(:stipple nil :background "SystemWindow" :foreground | |
939 ;; "SystemWindowText" :inverse-video nil :box nil :strike-through | |
940 ;; nil :overline nil :underline nil :slant normal :weight normal | |
941 ;; :height 98 :width normal :family "outline-courier new") | |
942 (defun hfy-face-to-style-i (fn) | |
943 "The guts of `hfy-face-to-style': FN should be a `defface' font spec, | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
944 as returned by `face-attr-construct' or `hfy-face-attr-for-class'. |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
945 Note that this function does not get font-sizes right if they are based |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
946 on inherited modifiers (via the :inherit) attribute, and any other |
106126 | 947 modifiers that are cumulative if they appear multiple times need to be |
948 merged by the user - `hfy-flatten-style' should do this." | |
949 ;;(message "hfy-face-to-style-i");;DBUG | |
950 | |
951 ;; fn's value could be something like | |
952 ;; (:inherit | |
953 ;; ((foreground-color . "blue")) | |
954 ;; (foreground-color . "blue") | |
955 ;; nil) | |
956 | |
957 (when fn | |
958 (let ((key (car fn)) | |
959 (val (cadr fn)) | |
960 (next (cddr fn)) | |
961 (that nil) | |
962 (this nil) | |
963 (parent nil)) | |
964 (if (eq key :inherit) | |
965 (let ((vs (if (listp val) val (list val)))) | |
966 ;; (let ((x '(a b))) (setq x (append '(c d) x))) | |
967 ;; (let ((x '(a b))) (setq x (append '(c d) x))) | |
968 (dolist (v vs) | |
969 (setq parent | |
970 (append | |
971 parent | |
972 (hfy-face-to-style-i | |
973 (hfy-face-attr-for-class v hfy-display-class)) )))) | |
974 (setq this | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
975 (if val (case key |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
976 (:family (hfy-family val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
977 (:width (hfy-width val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
978 (:weight (hfy-weight val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
979 (:slant (hfy-slant val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
980 (:foreground (hfy-colour val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
981 (:background (hfy-bgcol val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
982 (:box (hfy-box val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
983 (:height (hfy-size val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
984 (:underline (hfy-decor key val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
985 (:overline (hfy-decor key val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
986 (:strike-through (hfy-decor key val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
987 (:invisible (hfy-invisible val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
988 (:bold (hfy-weight 'bold)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
989 (:italic (hfy-slant 'italic)))))) |
106126 | 990 (setq that (hfy-face-to-style-i next)) |
991 ;;(lwarn t :warning "%S => %S" fn (nconc this that parent)) | |
992 (nconc this that parent))) ) | |
993 | |
994 (defun hfy-size-to-int (spec) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
995 "Convert SPEC, a CSS font-size specifier, to an Emacs :height attribute value. |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
996 Used while merging multiple font-size attributes." |
106126 | 997 ;;(message "hfy-size-to-int");;DBUG |
998 (list | |
999 (if (string-match "\\([0-9]+\\)\\(%\\|pt\\)" spec) | |
1000 (cond ((string= "%" (match-string 2 spec)) | |
1001 (/ (string-to-number (match-string 1 spec)) 100.0)) | |
1002 ((string= "pt" (match-string 2 spec)) | |
1003 (* (string-to-number (match-string 1 spec)) 10))) | |
1004 (string-to-number spec))) ) | |
1005 | |
1006 ;; size is different, in that in order to get it right at all, | |
1007 ;; we have to trawl the inheritance path, accumulating modifiers, | |
1008 ;; _until_ we get to an absolute (pt) specifier, then combine the lot | |
1009 (defun hfy-flatten-style (style) | |
1010 "Take STYLE (see `hfy-face-to-style-i', `hfy-face-to-style') and merge | |
1011 any multiple attributes appropriately. Currently only font-size is merged | |
1012 down to a single occurrence - others may need special handling, but I | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1013 haven't encountered them yet. Returns a `hfy-style-assoc'." |
106126 | 1014 ;;(message "(hfy-flatten-style %S)" style) ;;DBUG |
1015 (let ((n 0) | |
1016 (m (list 1)) | |
1017 (x nil) | |
1018 (r nil)) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1019 (dolist (css style) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1020 (if (string= (car css) "font-size") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1021 (progn |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1022 (when (not x) (setq m (nconc m (hfy-size-to-int (cdr css))))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1023 (when (string-match "pt" (cdr css)) (setq x t))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1024 (setq r (nconc r (list css))))) |
106126 | 1025 ;;(message "r: %S" r) |
1026 (setq n (apply '* m)) | |
1027 (nconc r (hfy-size (if x (round n) (* n 1.0)))) )) | |
1028 | |
1029 (defun hfy-face-to-style (fn) | |
1030 "Take FN, a font or `defface' style font specification, | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1031 \(as returned by `face-attr-construct' or `hfy-face-attr-for-class') |
106126 | 1032 and return a `hfy-style-assoc'.\n |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1033 See also `hfy-face-to-style-i', `hfy-flatten-style'." |
106126 | 1034 ;;(message "hfy-face-to-style");;DBUG |
1035 (let ((face-def (if (facep fn) | |
1036 (hfy-face-attr-for-class fn hfy-display-class) fn)) | |
1037 (final-style nil)) | |
1038 | |
1039 (setq final-style (hfy-flatten-style (hfy-face-to-style-i face-def))) | |
1040 ;;(message "%S" final-style) | |
1041 (if (not (assoc "text-decoration" final-style)) | |
1042 (progn (setq final-style | |
1043 ;; Fix-me: there is no need for this since | |
1044 ;; text-decoration is not inherited. | |
1045 ;; but it's not wrong and if this ever changes it will | |
1046 ;; be needed, so I think it's better to leave it in? -- v | |
1047 (nconc final-style '(("text-decoration"."none")))))) | |
1048 final-style)) | |
1049 | |
1050 ;; strip redundant bits from a name. Technically, this could result in | |
1051 ;; a collision, but it is pretty unlikely - will fix later... | |
1052 ;; also handle ephemeral fonts created by overlays, which don't actually | |
1053 ;; have names: | |
1054 (defun hfy-face-or-def-to-name (fn) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1055 "Render a font symbol or `defface' font spec FN into a name (string)." |
106126 | 1056 ;;(message "generating name for %s" fn) |
1057 (if (not (listp fn)) | |
1058 (format "%s" fn) | |
1059 (let* ((key (format "%s" fn)) | |
1060 (entry (assoc key hfy-tmpfont-stack)) | |
1061 (base (cadr (memq :inherit fn))) | |
1062 (tag (cdr entry))) | |
1063 ;;(message "checking for key «%s» in font stack [%d]" | |
1064 ;; key (if entry 1 0)) | |
1065 (if entry nil ;; noop | |
1066 (setq tag (format "%04d" (length hfy-tmpfont-stack)) | |
1067 entry (cons key tag) | |
1068 hfy-tmpfont-stack (cons entry hfy-tmpfont-stack))) | |
1069 ;;(message " -> name: %s-%s" (or base 'default) tag) | |
1070 (format "%s-%s" (or base 'default) tag)) )) | |
1071 | |
1072 (defun hfy-css-name (fn) | |
1073 "Strip the boring bits from a font-name FN and return a CSS style name." | |
1074 ;;(message "hfy-css-name");;DBUG | |
1075 (let ((face-name (hfy-face-or-def-to-name fn))) | |
1076 (if (or (string-match "font-lock-\\(.*\\)" face-name) | |
1077 (string-match "cperl-\\(.*\\)" face-name) | |
1078 (string-match "^[Ii]nfo-\\(.*\\)" face-name)) | |
1079 (progn | |
1080 (setq face-name (match-string 1 face-name)) | |
1081 (if (string-match "\\(.*\\)-face$" face-name) | |
1082 (setq face-name (match-string 1 face-name))) face-name) | |
1083 face-name)) ) | |
1084 | |
1085 ;; construct an assoc of (stripped-name . "{ css-stuff-here }") pairs | |
1086 ;; from a face: | |
1087 (defun hfy-face-to-css (fn) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1088 "Take FN, a font or `defface' specification (cf `face-attr-construct') |
106126 | 1089 and return a CSS style specification.\n |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1090 See also `hfy-face-to-style'." |
106126 | 1091 ;;(message "hfy-face-to-css");;DBUG |
1092 (let ((css-list nil) | |
1093 (css-text nil) | |
1094 (seen nil)) | |
1095 ;;(message "(hfy-face-to-style %S)" fn) | |
1096 (setq css-list (hfy-face-to-style fn)) | |
1097 (setq css-text | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1098 (mapcar |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1099 (lambda (E) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1100 (if (car E) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1101 (unless (member (car E) seen) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1102 (push (car E) seen) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1103 (format " %s: %s; " (car E) (cdr E))))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1104 css-list)) |
106126 | 1105 (cons (hfy-css-name fn) (format "{%s}" (apply 'concat css-text)))) ) |
1106 | |
1107 ;; extract a face from a list of char properties, if there is one: | |
1108 (defun hfy-p-to-face (props) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1109 "Given PROPS, a list of text properties, return the value of the face |
106126 | 1110 property, or nil." |
1111 (if props | |
1112 (if (string= (car props) "face") | |
1113 (let ((propval (cadr props))) | |
1114 (if (and (listp propval) (not (cdr propval))) | |
1115 (car propval) | |
1116 propval)) | |
1117 (hfy-p-to-face (cddr props))) | |
1118 nil)) | |
1119 | |
1120 (defun hfy-p-to-face-lennart (props) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1121 "Given PROPS, a list of text properties, return the value of the face |
106126 | 1122 property, or nil." |
1123 (when props | |
1124 (let ((face (plist-get props 'face)) | |
1125 (font-lock-face (plist-get props 'font-lock-face)) | |
1126 (button (plist-get props 'button)) | |
1127 ;;(face-rec (memq 'face props)) | |
1128 ;;(button-rec (memq 'button props))) | |
1129 ) | |
1130 (if button | |
1131 (let* ((category (plist-get props 'category)) | |
1132 (face (when category (plist-get (symbol-plist category) 'face)))) | |
1133 face) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1134 (or font-lock-face |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1135 face))))) |
106126 | 1136 |
1137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1138 ;; (defun hfy-get-face-at (pos) | |
1139 ;; ;; (let ((face (get-char-property-and-overlay pos 'face))) | |
1140 ;; ;; (when (and face (listp face)) (setq face (car face))) | |
1141 ;; ;; (unless (listp face) | |
1142 ;; ;; face))) | |
1143 ;; ;;(get-char-property pos 'face) | |
1144 ;; ;; Overlays are handled later | |
1145 ;; (if (or (not show-trailing-whitespace) | |
1146 ;; (not (get-text-property pos 'hfy-show-trailing-whitespace))) | |
1147 ;; (get-text-property pos 'face) | |
1148 ;; (list 'trailing-whitespace (get-text-property pos 'face))) | |
1149 ;; ) | |
1150 | |
1151 (defun hfy-prop-invisible-p (prop) | |
1152 "Is text property PROP an active invisibility property?" | |
1153 (or (and (eq buffer-invisibility-spec t) prop) | |
1154 (or (memq prop buffer-invisibility-spec) | |
1155 (assq prop buffer-invisibility-spec)))) | |
1156 | |
1157 (defun hfy-find-invisible-ranges () | |
1158 "Return a list of (start-point . end-point) cons cells of invisible regions." | |
1159 (let (invisible p i e s) ;; return-value pos invisible end start | |
1160 (save-excursion | |
1161 (setq p (goto-char (point-min))) | |
1162 (when (invisible-p p) (setq s p i t)) | |
1163 (while (< p (point-max)) | |
1164 (if i ;; currently invisible | |
1165 (when (not (invisible-p p)) ;; but became visible | |
1166 (setq e p | |
1167 i nil | |
1168 invisible (cons (cons s e) invisible))) | |
1169 ;; currently visible: | |
1170 (when (invisible-p p) ;; but have become invisible | |
1171 (setq s p i t))) | |
1172 (setq p (next-char-property-change p))) | |
1173 ;; still invisible at buffer end? | |
1174 (when i | |
1175 (setq e (point-max) | |
1176 invisible (cons (cons s e) invisible))) ) invisible)) | |
1177 | |
1178 (defun hfy-invisible-name (point map) | |
1179 "Generate a CSS style name for an invisible section of the buffer. | |
1180 POINT is the point inside the invisible region. | |
1181 MAP is the invisibility map as returned by `hfy-find-invisible-ranges'." | |
1182 ;;(message "(hfy-invisible-name %S %S)" point map) | |
1183 (let (name) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1184 (dolist (range map) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1185 (when (and (>= point (car range)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1186 (< point (cdr range))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1187 (setq name (format "invisible-%S-%S" (car range) (cdr range))))) |
106126 | 1188 name)) |
1189 | |
1190 ;; Fix-me: This function needs some cleanup by someone who understand | |
1191 ;; all the formats that face properties can have. | |
1192 ;; | |
1193 ;; overlay handling should be fine. haven't tested multiple stacked overlapping | |
1194 ;; overlays recently, but the common case of a text property face + an overlay | |
1195 ;; face produces the correct merged css style (or as close to it as css can get) | |
1196 ;; -- v | |
1197 (defun hfy-face-at (p) | |
1198 "Find face in effect at point P. | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1199 If overlays are to be considered (see `hfy-optimisations') then this may |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1200 return a `defface' style list of face properties instead of a face symbol." |
106126 | 1201 ;;(message "hfy-face-at");;DBUG |
1202 ;; Fix-me: clean up, remove face-name etc | |
1203 ;; not sure why we'd want to remove face-name? -- v | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1204 (let ((overlay-data nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1205 (base-face nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1206 ;; restored hfy-p-to-face as it handles faces like (bold) as |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1207 ;; well as face like 'bold - hfy-get-face-at doesn't dtrt -- v |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1208 (face-name (hfy-p-to-face (text-properties-at p))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1209 ;; (face-name (hfy-get-face-at p)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1210 (prop-seen nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1211 (extra-props nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1212 (text-props (text-properties-at p))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1213 ;;(message "face-name: %S" face-name) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1214 (when (and face-name (listp face-name) (facep (car face-name))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1215 ;;(message "face-name is a list %S" face-name) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1216 ;;(setq text-props (cons 'face face-name)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1217 (dolist (f face-name) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1218 (setq extra-props (if (listp f) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1219 ;; for things like (variable-pitch |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1220 ;; (:foreground "red")) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1221 (cons f extra-props) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1222 (cons :inherit (cons f extra-props))))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1223 (setq base-face (car face-name) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1224 face-name nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1225 ;; text-properties-at => (face (:foreground "red" ...)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1226 ;; or => (face (compilation-info underline)) list of faces |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1227 ;; overlay-properties |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1228 ;; format= (evaporate t face ((foreground-color . "red"))) |
106126 | 1229 |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1230 ;; SO: if we have turned overlays off, |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1231 ;; or if there's no overlay data |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1232 ;; just bail out and return whatever face data we've accumulated so far |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1233 (if (or (not (hfy-opt 'keep-overlays)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1234 (not (setq overlay-data (hfy-overlay-props-at p)))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1235 (progn |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1236 ;;(message "· %d: %s; %S; %s" |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1237 ;; p face-name extra-props text-props) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1238 (or face-name base-face)) ;; no overlays or extra properties |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1239 ;; collect any face data and any overlay data for processing: |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1240 (when text-props |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1241 (push text-props overlay-data)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1242 (setq overlay-data (nreverse overlay-data)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1243 ;;(message "- %d: %s; %S; %s; %s" |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1244 ;; p face-name extra-props text-props overlay-data) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1245 ;; remember the basic face name so we don't keep repeating its specs: |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1246 (when face-name (setq base-face face-name)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1247 (dolist (P overlay-data) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1248 (let ((iprops (cadr (memq 'invisible P)))) ;FIXME: plist-get? |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1249 ;;(message "(hfy-prop-invisible-p %S)" iprops) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1250 (when (and iprops (hfy-prop-invisible-p iprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1251 (setq extra-props |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1252 (cons :invisible (cons t extra-props))) )) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1253 (let ((fprops (cadr (or (memq 'face P) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1254 (memq 'font-lock-face P))))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1255 ;;(message "overlay face: %s" fprops) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1256 (if (not (listp fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1257 (let ((this-face (if (stringp fprops) (intern fprops) fprops))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1258 (when (not (eq this-face base-face)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1259 (setq extra-props |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1260 (cons :inherit |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1261 (cons this-face extra-props))) )) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1262 (while fprops |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1263 (if (facep (car fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1264 (let ((face (car fprops))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1265 (when (stringp face) (setq face (intern fprops))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1266 (setq extra-props |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1267 (cons :inherit |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1268 (cons face |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1269 extra-props))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1270 (setq fprops (cdr fprops))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1271 (let (p v) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1272 ;; Sigh. |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1273 (if (listp (car fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1274 (if (nlistp (cdr (car fprops))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1275 (progn |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1276 ;; ((prop . val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1277 (setq p (caar fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1278 (setq v (cdar fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1279 (setq fprops (cdr fprops))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1280 ;; ((prop val)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1281 (setq p (caar fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1282 (setq v (cadar fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1283 (setq fprops (cdr fprops))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1284 (if (listp (cdr fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1285 (progn |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1286 ;; (:prop val :prop val ...) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1287 (setq p (car fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1288 (setq v (cadr fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1289 (setq fprops (cddr fprops))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1290 (if (and (listp fprops) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1291 (not (listp (cdr fprops)))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1292 ;;(and (consp x) (cdr (last x))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1293 (progn |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1294 ;; (prop . val) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1295 (setq p (car fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1296 (setq v (cdr fprops)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1297 (setq fprops nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1298 (error "Eh... another format! fprops=%s" fprops) ))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1299 (setq p (case p |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1300 ;; These are all the properties handled |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1301 ;; in `hfy-face-to-style-i'. |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1302 ;; |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1303 ;; Are these translations right? |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1304 ;; yes, they are -- v |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1305 (family :family ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1306 (width :width ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1307 (height :height ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1308 (weight :weight ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1309 (slant :slant ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1310 (underline :underline ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1311 (overline :overline ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1312 (strike-through :strike-through) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1313 (box :box ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1314 (foreground-color :foreground) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1315 (background-color :background) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1316 (bold :bold ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1317 (italic :italic ) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1318 (t p))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1319 (if (memq p prop-seen) nil ;; noop |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1320 (setq prop-seen (cons p prop-seen) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1321 extra-props (cons p (cons v extra-props)))))))))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1322 ;;(message "+ %d: %s; %S" p face-name extra-props) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1323 (if extra-props |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1324 (if (listp face-name) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1325 (nconc extra-props face-name) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1326 (nconc extra-props (face-attr-construct face-name))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1327 face-name)) )) |
106126 | 1328 |
1329 (defun hfy-overlay-props-at (p) | |
1330 "Grab overlay properties at point P. | |
1331 The plists are returned in descending priority order." | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1332 (sort (mapcar #'overlay-properties (overlays-at p)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1333 (lambda (A B) (> (or (cadr (memq 'priority A)) 0) ;FIXME: plist-get? |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1334 (or (cadr (memq 'priority B)) 0))))) |
106126 | 1335 |
1336 ;; construct an assoc of (face-name . (css-name . "{ css-style }")) elements: | |
1337 (defun hfy-compile-stylesheet () | |
1338 "Trawl the current buffer, construct and return a `hfy-sheet-assoc'." | |
1339 ;;(message "hfy-compile-stylesheet");;DBUG | |
1340 (let ((pt (point-min)) | |
1341 ;; Make the font stack stay: | |
1342 ;;(hfy-tmpfont-stack nil) | |
1343 (fn nil) | |
1344 (style nil)) | |
1345 (save-excursion | |
1346 (goto-char pt) | |
1347 (while (< pt (point-max)) | |
1348 (if (and (setq fn (hfy-face-at pt)) (not (assoc fn style))) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1349 (push (cons fn (hfy-face-to-css fn)) style)) |
106126 | 1350 (setq pt (next-char-property-change pt))) ) |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1351 (push (cons 'default (hfy-face-to-css 'default)) style))) |
106126 | 1352 |
1353 (defun hfy-fontified-p () | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1354 "`font-lock' doesn't like to say it's been fontified when in batch |
106126 | 1355 mode, but we want to know if we should fontify or raw copy, so in batch |
1356 mode we check for non-default face properties. Otherwise we test | |
1357 variable `font-lock-mode' and variable `font-lock-fontified' for truth." | |
1358 ;;(message "font-lock-fontified: %S" font-lock-fontified) | |
1359 ;;(message "noninteractive : %S" noninteractive) | |
1360 ;;(message "font-lock-mode : %S" font-lock-mode) | |
1361 (and font-lock-fontified | |
1362 (if noninteractive | |
1363 (let ((pt (point-min)) | |
1364 (face-name nil)) | |
1365 (save-excursion | |
1366 (goto-char pt) | |
1367 (while (and (< pt (point-max)) (not face-name)) | |
1368 (setq face-name (hfy-face-at pt)) | |
1369 (setq pt (next-char-property-change pt)))) face-name) | |
1370 font-lock-mode))) | |
1371 | |
1372 ;; remember, the map is in reverse point order: | |
1373 ;; I wrote this while suffering the effects of a cold, and maybe a | |
1374 ;; mild fever - I think it's correct, but it might be a little warped | |
1375 ;; as my minfd keeps ... where was I? Oh yes, the bunnies... | |
1376 (defun hfy-merge-adjacent-spans (face-map) | |
1377 "Where FACE-MAP is a `hfy-facemap-assoc' for the current buffer, | |
1378 this function merges adjacent style blocks which are of the same value | |
1379 and are separated by nothing more interesting than whitespace.\n | |
1380 <span class=\"foo\">narf</span> <span class=\"foo\">brain</span>\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1381 \(as interpreted from FACE-MAP) would become:\n |
106126 | 1382 <span class=\"foo\">narf brain</span>\n |
1383 Returns a modified copy of FACE-MAP." | |
1384 (let ((tmp-map face-map) | |
1385 (map-buf nil) | |
1386 (first-start nil) | |
1387 (first-stop nil) | |
1388 (last-start nil) | |
1389 (last-stop nil) | |
1390 (span-stop nil) | |
1391 (span-start nil) | |
1392 (reduced-map nil)) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1393 ;;(push (car tmp-map) reduced-map) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1394 ;;(push (cadr tmp-map) reduced-map) |
106126 | 1395 (while tmp-map |
1396 (setq first-start (cadddr tmp-map) | |
1397 first-stop (caddr tmp-map) | |
1398 last-start (cadr tmp-map) | |
1399 last-stop (car tmp-map) | |
1400 map-buf tmp-map | |
1401 span-start last-start | |
1402 span-stop last-stop ) | |
1403 (while (and (equal (cdr first-start) | |
1404 (cdr last-start)) | |
1405 (save-excursion | |
1406 (goto-char (car first-stop)) | |
1407 (not (re-search-forward "[^ \t\n\r]" (car last-start) t)))) | |
1408 (setq map-buf (cddr map-buf) | |
1409 span-start first-start | |
1410 first-start (cadddr map-buf) | |
1411 first-stop (caddr map-buf) | |
1412 last-start (cadr map-buf) | |
1413 last-stop (car map-buf))) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1414 (push span-stop reduced-map) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1415 (push span-start reduced-map) |
106126 | 1416 (setq tmp-map (memq last-start tmp-map)) |
1417 (setq tmp-map (cdr tmp-map))) | |
1418 (setq reduced-map (nreverse reduced-map)))) | |
1419 | |
1420 ;; remember to generate 'synthetic' </span> entries - | |
1421 ;; emacs copes by just having a stack of styles in effect | |
1422 ;; and only using the top one: html has a more simplistic approach - | |
1423 ;; we have to explicitly end a style, there's no way of temporarily | |
1424 ;; overriding it w. another one... (afaik) | |
1425 (defun hfy-compile-face-map () | |
1426 ;; no need for special <a> version. | |
1427 ;; IME hyperlinks don't get underlined, esp when you htmlfontify a whole | |
1428 ;; source tree, so the <a> version is needed -- v | |
1429 ;; Fix-me: save table for multi-buffer | |
1430 "Compile and return a `hfy-facemap-assoc' for the current buffer." | |
1431 ;;(message "hfy-compile-face-map");;DBUG | |
1432 (let ((pt (point-min)) | |
1433 (pt-narrow 1) | |
1434 (fn nil) | |
1435 (map nil) | |
1436 (prev-tag nil)) ;; t if the last tag-point was a span-start | |
1437 ;; nil if it was a span-stop | |
1438 (save-excursion | |
1439 (goto-char pt) | |
1440 (while (< pt (point-max)) | |
1441 (if (setq fn (hfy-face-at pt)) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1442 (progn (if prev-tag (push (cons pt-narrow 'end) map)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1443 (push (cons pt-narrow fn) map) |
106126 | 1444 (setq prev-tag t)) |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1445 (if prev-tag (push (cons pt-narrow 'end) map)) |
106126 | 1446 (setq prev-tag nil)) |
1447 (setq pt (next-char-property-change pt)) | |
1448 (setq pt-narrow (1+ (- pt (point-min))))) | |
1449 (if (and map (not (eq 'end (cdar map)))) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1450 (push (cons (- (point-max) (point-min)) 'end) map))) |
106126 | 1451 (if (hfy-opt 'merge-adjacent-tags) (hfy-merge-adjacent-spans map) map))) |
1452 | |
1453 (defun hfy-buffer () | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1454 "Generate a buffer to hold the HTML output. |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1455 The filename of this buffer is derived from the source (current) buffer's |
106126 | 1456 variable `buffer-file-name', if it is set, plus `hfy-extn'. |
1457 Otherwise a plausible filename is constructed from `default-directory', | |
1458 `buffer-name' and `hfy-extn'." | |
1459 (let* ((name (concat (buffer-name) hfy-extn)) | |
1460 (src (buffer-file-name)) | |
1461 (buf (get-buffer-create name))) | |
106128
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1462 (with-current-buffer buf |
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1463 (setq buffer-file-name |
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1464 (if src (concat src hfy-extn) |
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1465 (expand-file-name (if (string-match "^.*/\\([^/]*\\)$" name) |
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1466 (match-string 1 name) |
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1467 name)))) |
106126 | 1468 buf))) |
1469 | |
1470 (defun hfy-lookup (face style) | |
1471 "Get a CSS style name for FACE from STYLE." | |
1472 (cadr (assoc face style))) | |
1473 | |
1474 (defun hfy-link-style (style-string) | |
1475 "Copy, alter and return a STYLE-STRING to make it suitable for a hyperlink. | |
1476 Uses `hfy-link-style-fun' to do this." | |
1477 (if (functionp hfy-link-style-fun) | |
1478 (funcall hfy-link-style-fun style-string) | |
1479 style-string)) | |
1480 | |
1481 (defun hfy-sprintf-stylesheet (css file) | |
1482 "Return the inline CSS style sheet for FILE as a string." | |
1483 (let ((stylesheet nil)) | |
1484 (setq stylesheet | |
1485 (concat | |
1486 hfy-meta-tags | |
1487 "\n<style type=\"text/css\"><!-- \n" | |
1488 ;; Fix-me: Add handling of page breaks here + scan for ^L | |
1489 ;; where appropriate. | |
1490 (format "body %s\n" (cddr (assq 'default css))) | |
1491 (apply 'concat | |
1492 (mapcar | |
1493 (lambda (style) | |
1494 (format | |
1495 "span.%s %s\nspan.%s a %s\n" | |
1496 (cadr style) (cddr style) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1497 (cadr style) (hfy-link-style (cddr style)))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1498 css)) |
106126 | 1499 " --></style>\n")) |
1500 (funcall hfy-page-header file stylesheet))) | |
1501 | |
1502 ;; tag all the dangerous characters we want to escape | |
1503 ;; (ie any "<> chars we _didn't_ put there explicitly for css markup) | |
1504 (defun hfy-html-enkludge-buffer () | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1505 "Mark dangerous [\"<>] characters with the `hfy-quoteme' property.\n |
106126 | 1506 See also `hfy-html-dekludge-buffer'." |
1507 ;;(message "hfy-html-enkludge-buffer");;DBUG | |
1508 (save-excursion | |
1509 (goto-char (point-min)) | |
1510 (while (re-search-forward hfy-html-quote-regex nil t) | |
1511 (put-text-property (match-beginning 0) (point) 'hfy-quoteme t))) ) | |
1512 | |
1513 ;; dangerous char -> &entity; | |
1514 (defun hfy-html-quote (char-string) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1515 "Map CHAR-STRING to an HTML safe string (entity) if need be." |
106126 | 1516 ;;(message "hfy-html-quote");;DBUG |
1517 (or (cadr (assoc char-string hfy-html-quote-map)) char-string) ) | |
1518 | |
1519 ;; actually entity-ise dangerous chars. | |
1520 ;; note that we can't do this until _after_ we have inserted the css | |
1521 ;; markup, since we use a position-based map to insert this, and if we | |
1522 ;; enter any other text before we do this, we'd have to track another | |
1523 ;; map of offsets, which would be tedious... | |
1524 (defun hfy-html-dekludge-buffer () | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1525 "Transform all dangerous characters marked with the `hfy-quoteme' property |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1526 using `hfy-html-quote'.\n |
106126 | 1527 See also `hfy-html-enkludge-buffer'." |
1528 ;;(message "hfy-html-dekludge-buffer");;DBUG | |
1529 (save-excursion | |
1530 (goto-char (point-min)) | |
1531 (while (re-search-forward hfy-html-quote-regex nil t) | |
1532 (if (get-text-property (match-beginning 0) 'hfy-quoteme) | |
1533 (replace-match (hfy-html-quote (match-string 1))) )) )) | |
1534 | |
1535 ;; Borrowed from font-lock.el | |
1536 (defmacro hfy-save-buffer-state (varlist &rest body) | |
1537 "Bind variables according to VARLIST and eval BODY restoring buffer state. | |
1538 Do not record undo information during evaluation of BODY." | |
1539 (declare (indent 1) (debug let)) | |
1540 (let ((modified (make-symbol "modified"))) | |
1541 `(let* ,(append varlist | |
1542 `((,modified (buffer-modified-p)) | |
1543 (buffer-undo-list t) | |
1544 (inhibit-read-only t) | |
1545 (inhibit-point-motion-hooks t) | |
1546 (inhibit-modification-hooks t) | |
1547 deactivate-mark | |
1548 buffer-file-name | |
1549 buffer-file-truename)) | |
1550 (progn | |
1551 ,@body) | |
1552 (unless ,modified | |
1553 (restore-buffer-modified-p nil))))) | |
1554 | |
1555 (defun hfy-mark-trailing-whitespace () | |
1556 "Tag trailing whitespace with a hfy property if it is currently highlighted." | |
1557 (when show-trailing-whitespace | |
1558 (let ((inhibit-read-only t)) | |
1559 (save-excursion | |
1560 (goto-char (point-min)) | |
1561 (hfy-save-buffer-state nil | |
1562 (while (re-search-forward "[ \t]+$" nil t) | |
1563 (put-text-property (match-beginning 0) (match-end 0) | |
1564 'hfy-show-trailing-whitespace t))))))) | |
1565 | |
1566 (defun hfy-unmark-trailing-whitespace () | |
1567 "Undo the effect of `hfy-mark-trailing-whitespace'." | |
1568 (when show-trailing-whitespace | |
1569 (hfy-save-buffer-state nil | |
1570 (remove-text-properties (point-min) (point-max) | |
1571 '(hfy-show-trailing-whitespace))))) | |
1572 | |
1573 (defun hfy-fontify-buffer (&optional srcdir file) | |
1574 "Implement the guts of `htmlfontify-buffer'. | |
1575 SRCDIR, if set, is the directory being htmlfontified. | |
1576 FILE, if set, is the file name." | |
1577 (if srcdir (setq srcdir (directory-file-name srcdir))) | |
106128
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1578 (let* ( (html-buffer (hfy-buffer)) |
106126 | 1579 (css-sheet nil) |
1580 (css-map nil) | |
1581 (invis-ranges nil) | |
1582 (rovl nil) | |
1583 (orig-ovls (overlays-in (point-min) (point-max))) | |
1584 (rmin (when mark-active (region-beginning))) | |
1585 (rmax (when mark-active (region-end ))) ) | |
1586 (when (and mark-active | |
1587 transient-mark-mode) | |
1588 (unless (and (= rmin (point-min)) | |
1589 (= rmax (point-max))) | |
1590 (setq rovl (make-overlay rmin rmax)) | |
1591 (overlay-put rovl 'priority 1000) | |
1592 (overlay-put rovl 'face 'region))) | |
1593 ;; copy the buffer, including fontification, and switch to it: | |
1594 (hfy-mark-trailing-whitespace) | |
1595 (setq css-sheet (hfy-compile-stylesheet ) | |
1596 css-map (hfy-compile-face-map ) | |
1597 invis-ranges (hfy-find-invisible-ranges)) | |
1598 (hfy-unmark-trailing-whitespace) | |
1599 (when rovl | |
1600 (delete-overlay rovl)) | |
1601 (copy-to-buffer html-buffer (point-min) (point-max)) | |
1602 (set-buffer html-buffer) | |
106505
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
1603 ;; rip out props that could interfere with our htmlisation of the buffer: |
7287842d7e07
Drop some properties to avoid surprises.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106352
diff
changeset
|
1604 (remove-text-properties (point-min) (point-max) hfy-ignored-properties) |
106126 | 1605 ;; Apply overlay invisible spec |
1606 (setq orig-ovls | |
1607 (sort orig-ovls | |
1608 (lambda (A B) | |
1609 (> (or (cadr (memq 'priority (overlay-properties A))) 0) | |
1610 (or (cadr (memq 'priority (overlay-properties B))) 0))))) | |
1611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1612 ;; at this point, html-buffer retains the fontification of the parent: | |
1613 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1614 ;; we don't really need or want text in the html buffer to be invisible, as | |
1615 ;; that can make it look like we've rendered invalid xhtml when all that's | |
1616 ;; happened is some tags are in the invisible portions of the buffer: | |
1617 (setq buffer-invisibility-spec nil) | |
1618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1619 ;; ##################################################################### | |
1620 ;; if we are in etags mode, add properties to mark the anchors and links | |
1621 (if (and srcdir file) | |
1622 (progn | |
1623 (hfy-mark-tag-names srcdir file) ;; mark anchors | |
1624 (hfy-mark-tag-hrefs srcdir file))) ;; mark links | |
1625 ;; ##################################################################### | |
1626 ;; mark the 'dangerous' characters | |
1627 ;;(message "marking dangerous characters") | |
1628 (hfy-html-enkludge-buffer) | |
1629 ;; trawl the position-based face-map, inserting span tags as we go | |
1630 ;; note that we cannot change any character positions before this point | |
1631 ;; or we will invalidate the map: | |
1632 ;; NB: This also means we have to trawl the map in descending file-offset | |
1633 ;; order, obviously. | |
1634 ;; --------------------------------------------------------------------- | |
1635 ;; Remember, inserting pushes properties to the right, which we don't | |
1636 ;; actually want to happen for link properties, so we have to flag | |
1637 ;; them and move them by hand - if you don't, you end up with | |
1638 ;; | |
1639 ;; <span class="foo"><a href="bar">texta</span><span class="bletch"></a>... | |
1640 ;; | |
1641 ;; instead of: | |
1642 ;; | |
1643 ;; <span class="foo"><a href="bar">texta</a></span><span class="bletch">... | |
1644 ;; | |
1645 ;; If my analysis of the problem is correct, we can detect link-ness by | |
1646 ;; either hfy-linkp or hfy-endl properties at the insertion point, but I | |
1647 ;; think we only need to relocate the hfy-endl property, as the hfy-linkp | |
1648 ;; property has already served its main purpose by this point. | |
1649 ;;(message "mapcar over the CSS-MAP") | |
1650 (message "invis-ranges:\n%S" invis-ranges) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1651 (dolist (point-face css-map) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1652 (let ((pt (car point-face)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1653 (fn (cdr point-face)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1654 (move-link nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1655 (goto-char pt) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1656 (setq move-link |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1657 (or (get-text-property pt 'hfy-linkp) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1658 (get-text-property pt 'hfy-endl ))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1659 (if (eq 'end fn) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1660 (insert "</span>") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1661 (if (not (and srcdir file)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1662 nil |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1663 (when move-link |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1664 (remove-text-properties (point) (1+ (point)) '(hfy-endl nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1665 (put-text-property pt (1+ pt) 'hfy-endl t) )) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1666 ;; if we have invisible blocks, we need to do some extra magic: |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1667 (if invis-ranges |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1668 (let ((iname (hfy-invisible-name pt invis-ranges)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1669 (fname (hfy-lookup fn css-sheet ))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1670 (when (assq pt invis-ranges) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1671 (insert |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1672 (format "<span onclick=\"toggle_invis('%s');\">" iname)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1673 (insert "…</span>")) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1674 (insert |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1675 (format "<span class=\"%s\" id=\"%s-%d\">" fname iname pt))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1676 (insert (format "<span class=\"%s\">" (hfy-lookup fn css-sheet)))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1677 (if (not move-link) nil |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1678 ;;(message "removing prop2 @ %d" (point)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1679 (if (remove-text-properties (point) (1+ (point)) '(hfy-endl nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1680 (put-text-property pt (1+ pt) 'hfy-endl t)))))) |
106126 | 1681 ;; ##################################################################### |
1682 ;; Invisibility | |
1683 ;; Maybe just make the text invisible in XHTML? | |
1684 ;; DONE -- big block of obsolete invisibility code elided here -- v | |
1685 ;; ##################################################################### | |
1686 ;; (message "checking to see whether we should link...") | |
1687 (if (and srcdir file) | |
1688 (let ((lp 'hfy-link) | |
1689 (pt nil) | |
1690 (pr nil) | |
1691 (rr nil)) | |
1692 ;; (message " yes we should.") | |
1693 ;; translate 'hfy-anchor properties to anchors | |
1694 (setq pt (point-min)) | |
1695 (while (setq pt (next-single-property-change pt 'hfy-anchor)) | |
1696 (if (setq pr (get-text-property pt 'hfy-anchor)) | |
1697 (progn (goto-char pt) | |
1698 (remove-text-properties pt (1+ pt) '(hfy-anchor nil)) | |
1699 (insert (concat "<a name=\"" pr "\"></a>"))))) | |
1700 ;; translate alternate 'hfy-link and 'hfy-endl props to opening | |
1701 ;; and closing links. (this should avoid those spurious closes | |
1702 ;; we sometimes get by generating only paired tags) | |
1703 (setq pt (point-min)) | |
1704 (while (setq pt (next-single-property-change pt lp)) | |
1705 (if (not (setq pr (get-text-property pt lp))) nil | |
1706 (goto-char pt) | |
1707 (remove-text-properties pt (1+ pt) (list lp nil)) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1708 (case lp |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1709 (hfy-link |
106126 | 1710 (if (setq rr (get-text-property pt 'hfy-inst)) |
1711 (insert (format "<a name=\"%s\"></a>" rr))) | |
1712 (insert (format "<a href=\"%s\">" pr)) | |
1713 (setq lp 'hfy-endl)) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1714 (hfy-endl |
106126 | 1715 (insert "</a>") (setq lp 'hfy-link)) ))) )) |
1716 | |
1717 ;; ##################################################################### | |
1718 ;; transform the dangerous chars. This changes character positions | |
1719 ;; since entities have > char length. | |
1720 ;; note that this deletes the dangerous characters, and therefore | |
1721 ;; destroys any properties they may contain (such as 'hfy-endl), | |
1722 ;; so we have to do this after we use said properties: | |
1723 ;; (message "munging dangerous characters") | |
1724 (hfy-html-dekludge-buffer) | |
1725 ;; insert the stylesheet at the top: | |
1726 (goto-char (point-min)) | |
1727 ;;(message "inserting stylesheet") | |
1728 (insert (hfy-sprintf-stylesheet css-sheet file)) | |
1729 (if (hfy-opt 'div-wrapper) (insert "<div class=\"default\">")) | |
1730 (insert "\n<pre>") | |
1731 (goto-char (point-max)) | |
1732 (insert "</pre>\n") | |
1733 (if (hfy-opt 'div-wrapper) (insert "</div>")) | |
1734 ;;(message "inserting footer") | |
1735 (insert (funcall hfy-page-footer file)) | |
1736 ;; call any post html-generation hooks: | |
1737 (run-hooks 'hfy-post-html-hooks) | |
1738 ;; return the html buffer | |
1739 (set-buffer-modified-p nil) | |
1740 html-buffer)) | |
1741 | |
1742 (defun hfy-force-fontification () | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1743 "Try to force font-locking even when it is optimized away." |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1744 (run-hooks 'hfy-init-kludge-hook) |
106126 | 1745 (eval-and-compile (require 'font-lock)) |
1746 (if (boundp 'font-lock-cache-position) | |
1747 (or font-lock-cache-position | |
1748 (set 'font-lock-cache-position (make-marker)))) | |
1749 (if (not noninteractive) | |
1750 (progn | |
1751 (message "hfy interactive mode (%S %S)" window-system major-mode) | |
1752 (when (and font-lock-defaults | |
1753 font-lock-mode) | |
1754 (font-lock-fontify-region (point-min) (point-max) nil))) | |
1755 (message "hfy batch mode (%s:%S)" | |
1756 (or (buffer-file-name) (buffer-name)) major-mode) | |
1757 (when font-lock-defaults | |
1758 (font-lock-fontify-buffer)) )) | |
1759 | |
107971 | 1760 ;;;###autoload |
106126 | 1761 (defun htmlfontify-buffer (&optional srcdir file) |
1762 "Create a new buffer, named for the current buffer + a .html extension, | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1763 containing an inline CSS-stylesheet and formatted CSS-markup HTML |
106126 | 1764 that reproduces the look of the current Emacs buffer as closely |
1765 as possible. | |
1766 | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1767 Dangerous characters in the existing buffer are turned into HTML |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1768 entities, so you should even be able to do HTML-within-HTML |
106126 | 1769 fontified display. |
1770 | |
1771 You should, however, note that random control or eight-bit | |
1772 characters such as ^L (\x0c) or ¤ (\xa4) won't get mapped yet. | |
1773 | |
1774 If the SRCDIR and FILE arguments are set, lookup etags derived | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1775 entries in the `hfy-tags-cache' and add HTML anchors and |
106126 | 1776 hyperlinks as appropriate." |
1777 (interactive) | |
1778 ;; pick up the file name in case we didn't receive it | |
1779 (if (not file) | |
1780 (progn (setq file (or (buffer-file-name) (buffer-name))) | |
1781 (if (string-match "/\\([^/]*\\)$" file) | |
1782 (setq file (match-string 1 file)))) ) | |
1783 | |
1784 (if (not (hfy-opt 'skip-refontification)) | |
1785 (save-excursion ;; Keep region | |
1786 (hfy-force-fontification))) | |
1787 (if (interactive-p) ;; display the buffer in interactive mode: | |
1788 (switch-to-buffer (hfy-fontify-buffer srcdir file)) | |
1789 (hfy-fontify-buffer srcdir file))) | |
1790 | |
1791 ;; recursive file listing | |
1792 (defun hfy-list-files (directory) | |
1793 "Return a list of files under DIRECTORY. | |
1794 Strips any leading \"./\" from each filename." | |
1795 ;;(message "hfy-list-files");;DBUG | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1796 ;; FIXME: this changes the dir of the currrent buffer. Is that right?? |
106126 | 1797 (cd directory) |
1798 (mapcar (lambda (F) (if (string-match "^./\\(.*\\)" F) (match-string 1 F) F)) | |
1799 (split-string (shell-command-to-string hfy-find-cmd))) ) | |
1800 | |
1801 ;; strip the filename off, return a directiry name | |
1802 ;; not a particularly thorough implementaion, but it will be | |
1803 ;; fed pretty carefully, so it should be Ok: | |
1804 (defun hfy-dirname (file) | |
1805 "Return everything preceding the last \"/\" from a relative filename FILE, | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1806 on the assumption that this will produce a relative directory name. |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1807 Hardly bombproof, but good enough in the context in which it is being used." |
106126 | 1808 ;;(message "hfy-dirname");;DBUG |
1809 (let ((f (directory-file-name file))) | |
1810 (and (string-match "^\\(.*\\)/" f) (match-string 1 f)))) | |
1811 | |
1812 ;; create a directory, cf mkdir -p | |
1813 (defun hfy-make-directory (dir) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1814 "Approx. equivalent of mkdir -p DIR." |
106126 | 1815 ;;(message "hfy-make-directory");;DBUG |
1816 (if (file-exists-p dir) | |
1817 (if (file-directory-p dir) t) | |
1818 (make-directory dir t))) | |
1819 | |
1820 (defun hfy-text-p (srcdir file) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1821 "Is SRCDIR/FILE text? Uses `hfy-istext-command' to determine this." |
106128
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1822 (let* ((cmd (format hfy-istext-command (expand-file-name file srcdir))) |
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1823 (rsp (shell-command-to-string cmd))) |
106126 | 1824 (if (string-match "text" rsp) t nil))) |
1825 | |
1826 ;; open a file, check fontification, if fontified, write a fontified copy | |
1827 ;; to the destination directory, otherwise just copy the file: | |
1828 (defun hfy-copy-and-fontify-file (srcdir dstdir file) | |
1829 "Open FILE in SRCDIR - if fontified, write a fontified copy to DSTDIR | |
1830 adding an extension of `hfy-extn'. Fontification is actually done by | |
1831 `htmlfontify-buffer'. If the buffer is not fontified, just copy it." | |
1832 ;;(message "hfy-copy-and-fontify-file");;DBUG | |
1833 (let (;;(fast-lock-minimum-size hfy-fast-lock-save) | |
1834 ;;(font-lock-support-mode 'fast-lock-mode) | |
1835 ;;(window-system (or window-system 'htmlfontify)) | |
1836 (target nil) | |
1837 (source nil) | |
1838 (html nil)) | |
1839 (cd srcdir) | |
106128
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1840 (with-current-buffer (setq source (find-file-noselect file)) |
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1841 ;; FIXME: Shouldn't this use expand-file-name? --Stef |
106126 | 1842 (setq target (concat dstdir "/" file)) |
1843 (hfy-make-directory (hfy-dirname target)) | |
1844 (if (not (hfy-opt 'skip-refontification)) (hfy-force-fontification)) | |
1845 (if (or (hfy-fontified-p) (hfy-text-p srcdir file)) | |
1846 (progn (setq html (hfy-fontify-buffer srcdir file)) | |
1847 (set-buffer html) | |
1848 (write-file (concat target hfy-extn)) | |
1849 (kill-buffer html)) | |
1850 ;; #o0200 == 128, but emacs20 doesn't know that | |
1851 (if (and (file-exists-p target) (not (file-writable-p target))) | |
1852 (set-file-modes target (logior (file-modes target) 128))) | |
1853 (copy-file (buffer-file-name source) target 'overwrite)) | |
1854 (kill-buffer source)) )) | |
1855 | |
1856 ;; list of tags in file in srcdir | |
1857 (defun hfy-tags-for-file (srcdir file) | |
1858 "List of etags tags that have definitions in this FILE. | |
1859 Looks up the tags cache in `hfy-tags-cache' using SRCDIR as the key." | |
1860 ;;(message "hfy-tags-for-file");;DBUG | |
1861 (let ((cache-entry (assoc srcdir hfy-tags-cache)) | |
1862 (cache-hash nil) | |
1863 (tag-list nil)) | |
1864 (if (setq cache-hash (cadr cache-entry)) | |
1865 (maphash | |
1866 (lambda (K V) | |
1867 (if (assoc file V) | |
1868 (setq tag-list (cons K tag-list)))) cache-hash)) | |
1869 tag-list)) | |
1870 | |
1871 ;; mark the tags native to this file for anchors | |
1872 (defun hfy-mark-tag-names (srcdir file) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1873 "Mark tags in FILE (lookup SRCDIR in `hfy-tags-cache') with the `hfy-anchor' |
106126 | 1874 property, with a value of \"tag.line-number\"." |
1875 ;;(message "(hfy-mark-tag-names %s %s)" srcdir file);;DBUG | |
1876 (let ((cache-entry (assoc srcdir hfy-tags-cache)) | |
1877 (cache-hash nil)) | |
1878 (if (setq cache-hash (cadr cache-entry)) | |
1879 (mapcar | |
1880 (lambda (TAG) | |
1881 (mapcar | |
1882 (lambda (TLIST) | |
1883 (if (string= file (car TLIST)) | |
1884 (let* ((line (cadr TLIST) ) | |
1885 (chr (caddr TLIST) ) | |
1886 (link (format "%s.%d" TAG line) )) | |
1887 (put-text-property (+ 1 chr) | |
1888 (+ 2 chr) | |
1889 'hfy-anchor link)))) | |
1890 (gethash TAG cache-hash))) | |
1891 (hfy-tags-for-file srcdir file))))) | |
1892 | |
1893 (defun hfy-relstub (file &optional start) | |
1894 "Return a \"../\" stub of the appropriate length for the current source | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1895 tree depth, as determined from FILE (a filename). |
106126 | 1896 START is the offset at which to start looking for the / character in FILE." |
1897 ;;(message "hfy-relstub");;DBUG | |
1898 (let ((c "")) | |
1899 (while (setq start (string-match "/" file start)) | |
1900 (setq start (1+ start)) (setq c (concat c "../"))) c)) | |
1901 | |
1902 (defun hfy-href-stub (this-file def-files tag) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1903 "Return an href stub for a tag href in THIS-FILE. |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1904 If DEF-FILES (list of files containing definitions for the tag in question) |
106126 | 1905 contains only one entry, the href should link straight to that file. |
1906 Otherwise, the link should be to the index file.\n | |
1907 We are not yet concerned with the file extensions/tag line number and so on at | |
1908 this point.\n | |
1909 If `hfy-split-index' is set, and the href wil be to an index file rather than | |
1910 a source file, append a .X to `hfy-index-file', where X is the uppercased | |
1911 first character of TAG.\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1912 See also `hfy-relstub', `hfy-index-file'." |
106126 | 1913 ;;(message "hfy-href-stub");;DBUG |
106128
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1914 ;; FIXME: Why not use something like |
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1915 ;; (file-relative-name (if ...) (file-name-directory this-file)) ? --Stef |
106126 | 1916 (concat |
1917 (hfy-relstub this-file) | |
1918 (if (= 1 (length def-files)) (car def-files) | |
1919 (if (not hfy-split-index) hfy-index-file | |
1920 (concat hfy-index-file "." (upcase (substring tag 0 1)))))) ) | |
1921 | |
1922 (defun hfy-href (this-file def-files tag tag-map) | |
1923 "Return a relative href to the tag in question, based on\n | |
1924 THIS-FILE `hfy-link-extn' `hfy-extn' DEF-FILES TAG and TAG-MAP\n | |
1925 THIS-FILE is the current source file | |
1926 DEF-FILES is a list of file containing possible link endpoints for TAG | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1927 TAG is the tag in question |
106126 | 1928 TAG-MAP is the entry in `hfy-tags-cache'." |
1929 ;;(message "hfy-href");;DBUG | |
1930 (concat | |
1931 (hfy-href-stub this-file def-files tag) | |
1932 (or hfy-link-extn hfy-extn) "#" tag ;;(.src -> .html) | |
1933 (if (= 1 (length def-files)) | |
1934 (concat "." (format "%d" (cadr (assoc (car def-files) tag-map)))))) ) | |
1935 | |
1936 (defun hfy-word-regex (string) | |
1937 "Return a regex that matches STRING as the first `match-string', with non | |
1938 word characters on either side." | |
106128
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
1939 ;; FIXME: Should this use [^$[:alnum:]_] instead? --Stef |
106126 | 1940 (concat "[^$A-Za-z_0-9]\\(" (regexp-quote string) "\\)[^A-Za-z_0-9]")) |
1941 | |
1942 ;; mark all tags for hyperlinking, except the tags at | |
1943 ;; their own points of definition, iyswim: | |
1944 (defun hfy-mark-tag-hrefs (srcdir file) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1945 "Mark href start points with the `hfy-link' prop (value: href string).\n |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
1946 Mark href end points with the `hfy-endl' prop (value t).\n |
106126 | 1947 Avoid overlapping links, and mark links in descending length of |
1948 tag name in order to prevent subtags from usurping supertags, | |
1949 \(eg \"term\" for \"terminal\"). | |
1950 SRCDIR is the directory being \"published\". | |
1951 FILE is the specific file we are rendering." | |
1952 ;;(message "hfy-mark-tag-hrefs");;DBUG | |
1953 (let ((cache-entry (assoc srcdir hfy-tags-cache)) | |
1954 (list-cache (assoc srcdir hfy-tags-sortl)) | |
1955 (rmap-cache (assoc srcdir hfy-tags-rmap )) | |
1956 (no-comment (hfy-opt 'zap-comment-links)) | |
1957 (no-strings (hfy-opt 'zap-string-links )) | |
1958 (cache-hash nil) | |
1959 (tags-list nil) | |
1960 (tags-rmap nil) | |
1961 (case-fold-search nil)) | |
1962 ;; extract the tag mapping hashes (fwd and rev) and the tag list: | |
1963 (if (and (setq cache-hash (cadr cache-entry)) | |
1964 (setq tags-rmap (cadr rmap-cache )) | |
1965 (setq tags-list (cadr list-cache ))) | |
1966 (mapcar | |
1967 (lambda (TAG) | |
1968 (let* ((start nil) | |
1969 (stop nil) | |
1970 (href nil) | |
1971 (name nil) | |
1972 (case-fold-search nil) | |
1973 (tmp-point nil) | |
1974 (maybe-start nil) | |
1975 (face-at nil) | |
1976 (rmap-entry nil) | |
1977 (rnew-elt nil) | |
1978 (rmap-line nil) | |
1979 (tag-regex (hfy-word-regex TAG)) | |
1980 (tag-map (gethash TAG cache-hash)) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
1981 (tag-files (mapcar #'car tag-map))) |
106126 | 1982 ;; find instances of TAG and do what needs to be done: |
1983 (goto-char (point-min)) | |
1984 (while (search-forward TAG nil 'NOERROR) | |
1985 (setq tmp-point (point) | |
1986 maybe-start (- (match-beginning 0) 1)) | |
1987 (goto-char maybe-start) | |
1988 (if (not (looking-at tag-regex)) | |
1989 nil | |
1990 (setq start (match-beginning 1)) | |
1991 (setq stop (match-end 1)) | |
1992 (setq face-at | |
1993 (and (or no-comment no-strings) (hfy-face-at start))) | |
1994 (if (listp face-at) | |
1995 (setq face-at (cadr (memq :inherit face-at)))) | |
1996 (if (or (text-property-any start (1+ stop) 'hfy-linkp t) | |
1997 (and no-comment (eq 'font-lock-comment-face face-at)) | |
1998 (and no-strings (eq 'font-lock-string-face face-at))) | |
1999 nil ;; already a link, NOOP | |
2000 | |
2001 ;; set a reverse map entry: | |
2002 (setq rmap-line (line-number-at-pos) | |
2003 rmap-entry (gethash TAG tags-rmap) | |
2004 rnew-elt (list file rmap-line start) | |
2005 rmap-entry (cons rnew-elt rmap-entry) | |
2006 name (format "%s.%d" TAG rmap-line)) | |
2007 (put-text-property start (1+ start) 'hfy-inst name) | |
2008 (puthash TAG rmap-entry tags-rmap) | |
2009 | |
2010 ;; mark the link. link to index if the tag has > 1 def | |
2011 ;; add the line number to the #name if it does not: | |
2012 (setq href (hfy-href file tag-files TAG tag-map)) | |
2013 (put-text-property start (1+ start) 'hfy-link href) | |
2014 (put-text-property stop (1+ stop ) 'hfy-endl t ) | |
2015 (put-text-property start (1+ stop ) 'hfy-linkp t ))) | |
2016 (goto-char tmp-point)) )) | |
2017 tags-list) ))) | |
2018 | |
2019 (defun hfy-shell () | |
2020 "Return `shell-file-name', or \"/bin/sh\" if it is a non-bourne shell." | |
2021 (if (string-match "\\<bash\\>\\|\\<sh\\>\\|\\<dash\\>" shell-file-name) | |
2022 shell-file-name | |
2023 (or hfy-shell-file-name "/bin/sh"))) | |
2024 | |
2025 ;; cache the #(tag => file line point) entries for files under srcdir | |
2026 ;; and cache the descending sorted list of tags in the relevant alist, | |
2027 ;; also keyed by srcdir: | |
2028 (defun hfy-load-tags-cache (srcdir) | |
2029 "Run `hfy-etags-cmd' on SRCDIR, then call `hfy-parse-tags-buffer'." | |
2030 ;;(message "hfy-load-tags-cache");;DBUG | |
2031 (let ((etags-buffer (get-buffer-create "*hfy-tags*")) | |
2032 (etags-command (format hfy-etags-cmd hfy-etags-bin)) | |
2033 (shell-file-name (hfy-shell))) | |
2034 (cd srcdir) | |
2035 (shell-command etags-command etags-buffer) | |
2036 (hfy-parse-tags-buffer srcdir etags-buffer)) ) | |
2037 | |
2038 ;; break this out from `hfy-load-tags-cache' to make the tar file | |
2039 ;; functionality easier to implement. | |
2040 ;; ( tar file functionality not merged here because it requires a | |
2041 ;; hacked copy of etags capable of tagging stdin: if Francesco | |
2042 ;; Potorti accepts a patch, or otherwise implements stdin tagging, | |
2043 ;; then I will provide a `htmlfontify-tar-file' defun ) | |
2044 (defun hfy-parse-tags-buffer (srcdir buffer) | |
2045 "Parse a BUFFER containing etags formatted output, loading the | |
2046 `hfy-tags-cache' and `hfy-tags-sortl' entries for SRCDIR." | |
2047 (let ((cache-entry (assoc srcdir hfy-tags-cache)) | |
2048 (tlist-cache (assoc srcdir hfy-tags-sortl)) | |
2049 (trmap-cache (assoc srcdir hfy-tags-rmap )) | |
2050 (cache-hash nil) (trmap-hash nil) (tags-list nil) | |
2051 (hash-entry nil) (tag-string nil) (tag-line nil) | |
2052 (tag-point nil) (new-entry nil) (etags-file nil)) | |
2053 | |
2054 ;; (re)initialise the tag reverse map: | |
2055 (if trmap-cache (setq trmap-hash (cadr trmap-cache)) | |
2056 (setq trmap-hash (make-hash-table :test 'equal)) | |
2057 (setq hfy-tags-rmap (list (list srcdir trmap-hash) hfy-tags-rmap))) | |
2058 (clrhash trmap-hash) | |
2059 | |
2060 ;; (re)initialise the tag cache: | |
2061 (if cache-entry (setq cache-hash (cadr cache-entry)) | |
2062 (setq cache-hash (make-hash-table :test 'equal)) | |
2063 (setq hfy-tags-cache (list (list srcdir cache-hash) hfy-tags-cache))) | |
2064 (clrhash cache-hash) | |
2065 | |
2066 ;; cache the TAG => ((file line point) (file line point) ... ) entries: | |
106128
ed77a6edfaa1
* hfy-cmap.el (hfy-rgb-file): Use locate-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106126
diff
changeset
|
2067 (with-current-buffer buffer |
106126 | 2068 (goto-char (point-min)) |
2069 | |
2070 (while (and (looking-at "^\x0c") (= 0 (forward-line 1))) | |
2071 ;;(message "^L boundary") | |
2072 (if (and (looking-at "^\\(.+\\),\\([0-9]+\\)$") | |
2073 (= 0 (forward-line 1))) | |
2074 (progn | |
2075 (setq etags-file (match-string 1)) | |
2076 ;;(message "TAGS for file: %s" etags-file) | |
2077 (while (and (looking-at hfy-etag-regex) (= 0 (forward-line 1))) | |
2078 (setq tag-string (match-string 1)) | |
2079 (if (= 0 (length tag-string)) nil ;; noop | |
2080 (setq tag-line (round (string-to-number (match-string 2)))) | |
2081 (setq tag-point (round (string-to-number (match-string 3)))) | |
2082 (setq hash-entry (gethash tag-string cache-hash)) | |
2083 (setq new-entry (list etags-file tag-line tag-point)) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2084 (push new-entry hash-entry) |
106126 | 2085 ;;(message "HASH-ENTRY %s %S" tag-string new-entry) |
2086 (puthash tag-string hash-entry cache-hash)))) ))) | |
2087 | |
2088 ;; cache a list of tags in descending length order: | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2089 (maphash (lambda (K V) (push K tags-list)) cache-hash) |
106126 | 2090 (setq tags-list (sort tags-list (lambda (A B) (< (length B) (length A))))) |
2091 | |
2092 ;; put the tag list into the cache: | |
2093 (if tlist-cache (setcar (cdr tlist-cache) tags-list) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2094 (push (list srcdir tags-list) hfy-tags-sortl)) |
106126 | 2095 |
2096 ;; return the number of tags found: | |
2097 (length tags-list) )) | |
2098 | |
2099 (defun hfy-prepare-index-i (srcdir dstdir filename &optional stub map) | |
2100 "Prepare a tags index buffer for SRCDIR. | |
2101 `hfy-tags-cache' must already have an entry for SRCDIR for this to work. | |
2102 `hfy-page-header', `hfy-page-footer', `hfy-link-extn' and `hfy-extn' | |
2103 all play a part here.\n | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
2104 If STUB is set, prepare an (appropriately named) index buffer |
106126 | 2105 specifically for entries beginning with STUB.\n |
2106 If MAP is set, use that instead of `hfy-tags-cache'. | |
2107 FILENAME is the name of the file being indexed. | |
2108 DSTDIR is the output directory, where files will be written." | |
2109 ;;(message "hfy-write-index");;DBUG | |
2110 (let ((cache-entry (assoc srcdir (or map hfy-tags-cache))) | |
2111 (cache-hash nil) | |
2112 (tag-list nil) | |
2113 (index-file | |
2114 (concat filename (if stub (concat "." stub) "") hfy-extn)) | |
2115 (index-buf nil)) | |
2116 (if (not (and cache-entry | |
2117 (setq cache-hash (cadr cache-entry)) | |
2118 (setq index-buf (get-buffer-create index-file)))) | |
2119 nil ;; noop | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2120 (maphash (lambda (K V) (push K tag-list)) cache-hash) |
106126 | 2121 (setq tag-list (sort tag-list 'string<)) |
2122 (set-buffer index-buf) | |
2123 (erase-buffer) | |
2124 (insert (funcall hfy-page-header filename "<!-- CSS -->")) | |
2125 (insert "<table class=\"index\">\n") | |
2126 | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2127 (dolist (TAG tag-list) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2128 (let ((tag-started nil)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2129 (dolist (DEF (gethash TAG cache-hash)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2130 (if (and stub (not (string-match (concat "^" stub) TAG))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2131 nil ;; we have a stub and it didn't match: NOOP |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2132 (let ((file (car DEF)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2133 (line (cadr DEF))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2134 (insert |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2135 (format |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2136 (concat |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2137 " <tr> \n" |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2138 " <td>%s</td> \n" |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2139 " <td><a href=\"%s%s\">%s</a></td> \n" |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2140 " <td><a href=\"%s%s#%s.%d\">%d</a></td>\n" |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2141 " </tr> \n") |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2142 (if (string= TAG tag-started) " " |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2143 (format "<a name=\"%s\">%s</a>" TAG TAG)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2144 file (or hfy-link-extn hfy-extn) file |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2145 file (or hfy-link-extn hfy-extn) TAG line line)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2146 (setq tag-started TAG)))))) |
106126 | 2147 (insert "</table>\n") |
2148 (insert (funcall hfy-page-footer filename)) | |
2149 (and dstdir (cd dstdir)) | |
2150 (set-visited-file-name index-file) | |
2151 index-buf) )) | |
2152 | |
2153 (defun hfy-prepare-index (srcdir dstdir) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
2154 "Return a list of index buffer(s), as determined by `hfy-split-index'. |
106126 | 2155 SRCDIR and DSTDIR are the source and output directories respectively." |
2156 (if (not hfy-split-index) | |
2157 (list (hfy-prepare-index-i srcdir dstdir hfy-index-file nil)) | |
2158 (let ((stub-list nil) | |
2159 (cache-hash nil) | |
2160 (index-list nil) | |
2161 (cache-entry (assoc srcdir hfy-tags-cache))) | |
2162 (if (and cache-entry (setq cache-hash (cadr cache-entry))) | |
2163 (maphash | |
2164 (lambda (K V) | |
2165 (let ((stub (upcase (substring K 0 1)))) | |
2166 (if (member stub stub-list) | |
2167 nil ;; seen this already: NOOP | |
2168 (setq | |
2169 stub-list (cons stub stub-list) | |
2170 index-list (cons (hfy-prepare-index-i srcdir | |
2171 dstdir | |
2172 hfy-index-file | |
2173 stub) | |
2174 index-list)) ))) cache-hash) ) index-list))) | |
2175 | |
2176 (defun hfy-prepare-tag-map (srcdir dstdir) | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
2177 "Prepare the counterpart(s) to the index buffer(s) - a list of buffers |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
2178 with the same structure, but listing (and linking to) instances of tags |
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
2179 \(as opposed to their definitions).\n |
106126 | 2180 SRCDIR and DSTDIR are the source and output directories respectively. |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
2181 See also `hfy-prepare-index', `hfy-split-index'." |
106126 | 2182 (if (not hfy-split-index) |
2183 (list (hfy-prepare-index-i srcdir | |
2184 dstdir | |
2185 hfy-instance-file | |
2186 nil | |
2187 hfy-tags-rmap)) | |
2188 (let ((stub-list nil) | |
2189 (cache-hash nil) | |
2190 (index-list nil) | |
2191 (cache-entry (assoc srcdir hfy-tags-rmap))) | |
2192 | |
2193 (if (and cache-entry (setq cache-hash (cadr cache-entry))) | |
2194 (maphash | |
2195 (lambda (K V) | |
2196 (let ((stub (upcase (substring K 0 1)))) | |
2197 (if (member stub stub-list) | |
2198 nil ;; seen this already: NOOP | |
2199 (setq | |
2200 stub-list (cons stub stub-list) | |
2201 index-list (cons (hfy-prepare-index-i srcdir | |
2202 dstdir | |
2203 hfy-instance-file | |
2204 stub | |
2205 hfy-tags-rmap) | |
2206 index-list)) ))) cache-hash) ) index-list))) | |
2207 | |
2208 (defun hfy-subtract-maps (srcdir) | |
2209 "Internal function - strips definitions of tags from the instance map. | |
2210 SRCDIR is the directory being \"published\". | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
2211 See also `hfy-tags-cache', `hfy-tags-rmap'." |
106126 | 2212 (let ((new-list nil) |
2213 (old-list nil) | |
2214 (def-list nil) | |
2215 (exc-list nil) | |
2216 (fwd-map (cadr (assoc srcdir hfy-tags-cache))) | |
2217 (rev-map (cadr (assoc srcdir hfy-tags-rmap ))) | |
2218 (taglist (cadr (assoc srcdir hfy-tags-sortl)))) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2219 (dolist (TAG taglist) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2220 (setq def-list (gethash TAG fwd-map) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2221 old-list (gethash TAG rev-map) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2222 exc-list (mapcar (lambda (P) (list (car P) (cadr P))) def-list) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2223 new-list nil) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2224 (dolist (P old-list) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2225 (or (member (list (car P) (cadr P)) exc-list) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2226 (push P new-list))) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2227 (puthash TAG new-list rev-map)))) |
106126 | 2228 |
2229 (defun htmlfontify-run-etags (srcdir) | |
2230 "Load the etags cache for SRCDIR. | |
106795
8802f28da1a8
Fix typos and remove superfluous backslash-quoting in htmlfontify.el.
Juanma Barranquero <lekktu@gmail.com>
parents:
106505
diff
changeset
|
2231 See also `hfy-load-tags-cache'." |
106126 | 2232 (interactive "D source directory: ") |
2233 (setq srcdir (directory-file-name srcdir)) | |
2234 (hfy-load-tags-cache srcdir)) | |
2235 | |
2236 ;;(defun hfy-test-read-args (foo bar) | |
2237 ;; (interactive "D source directory: \nD target directory: ") | |
2238 ;; (message "foo: %S\nbar: %S" foo bar)) | |
2239 | |
2240 (defun hfy-save-kill-buffers (buffer-list &optional dstdir) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2241 (dolist (B buffer-list) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2242 (set-buffer B) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2243 (and dstdir (file-directory-p dstdir) (cd dstdir)) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2244 (save-buffer) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2245 (kill-buffer B))) |
106126 | 2246 |
107971 | 2247 ;;;###autoload |
106126 | 2248 (defun htmlfontify-copy-and-link-dir (srcdir dstdir &optional f-ext l-ext) |
2249 "Trawl SRCDIR and write fontified-and-hyperlinked output in DSTDIR. | |
2250 F-EXT and L-EXT specify values for `hfy-extn' and `hfy-link-extn'.\n | |
2251 You may also want to set `hfy-page-header' and `hfy-page-footer'." | |
2252 (interactive "D source directory: \nD output directory: ") | |
2253 ;;(message "htmlfontify-copy-and-link-dir") | |
2254 (setq srcdir (directory-file-name srcdir)) | |
2255 (setq dstdir (directory-file-name dstdir)) | |
2256 (let ((source-files "SETME: list of source files, relative to srcdir") | |
2257 (tr-cache (assoc srcdir hfy-tags-rmap)) | |
2258 (hfy-extn (or f-ext ".html")) | |
2259 (hfy-link-extn (or l-ext ".html"))) | |
2260 ;; oops, forgot to load etags for srcdir: | |
2261 (if tr-cache nil | |
2262 (message "autoload of tags cache") | |
2263 (hfy-load-tags-cache srcdir) | |
2264 (setq tr-cache (assoc srcdir hfy-tags-rmap))) | |
2265 ;; clear out the old cache: | |
2266 (clrhash (cadr tr-cache)) | |
2267 (hfy-make-directory dstdir) | |
2268 (setq source-files (hfy-list-files srcdir)) | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2269 (dolist (file source-files) |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2270 (hfy-copy-and-fontify-file srcdir dstdir file)) |
106126 | 2271 (hfy-subtract-maps srcdir) |
2272 (hfy-save-kill-buffers (hfy-prepare-index srcdir dstdir) dstdir) | |
2273 (hfy-save-kill-buffers (hfy-prepare-tag-map srcdir dstdir) dstdir) )) | |
2274 | |
2275 ;; name of the init file we want: | |
2276 (defun hfy-initfile () | |
2277 "Return the expected location of the htmlfontify specific init/custom file." | |
2278 (let* ((file (or (getenv "HFY_INITFILE") ".hfy.el"))) | |
2279 (expand-file-name file "~") )) | |
2280 | |
2281 | |
2282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2283 ;; incomplete as yet : transfer hook settings to hfy init file: | |
2284 ;; (defalias 'hfy-set-hooks 'custom-set-variables) | |
2285 | |
2286 ;; (defun hfy-pp-hook (H) | |
2287 ;; (and (string-match "-hook$" (symbol-name H)) | |
2288 ;; (boundp H) | |
2289 ;; (symbol-value H) | |
2290 ;; (insert (format "\n '(%S %S)" H (symbol-value H))) | |
2291 ;; ) | |
2292 ;; ) | |
2293 | |
2294 ;; (defun hfy-save-hooks () | |
2295 ;; (let ((custom-file (hfy-initfile))) | |
2296 ;; (custom-save-delete 'hfy-set-hooks) | |
2297 ;; (let ((standard-output (current-buffer))) | |
2298 ;; (princ "(hfy-set-hooks\n;;auto-generated, only one copy allowed\n") | |
2299 ;; (mapatoms 'hfy-pp-hook) | |
2300 ;; (insert "\n)") | |
2301 ;; ) | |
2302 ;; ) | |
2303 ;; ) | |
2304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2305 | |
2306 (defalias 'hfy-init-progn 'progn) | |
2307 | |
2308 (defun hfy-save-initvar (sym) | |
2309 (princ (format "(setq %s\n '" sym)) | |
2310 (pp (symbol-value sym)) | |
2311 (princ ")\n")) | |
2312 | |
2313 (defun htmlfontify-save-initfile () | |
2314 "Save the htmlfontify settings to the htmlfontify init file." | |
2315 (interactive) | |
2316 (let* ((start-pos nil) | |
2317 (custom-file (hfy-initfile)) | |
2318 (standard-output (find-file-noselect custom-file 'nowarn))) | |
2319 (save-excursion | |
2320 (custom-save-delete 'hfy-init-progn) | |
2321 (setq start-pos (point)) | |
2322 (princ "(hfy-init-progn\n;;auto-generated, only one copy allowed\n") | |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2323 ;; FIXME: This saving&restoring of global customization |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2324 ;; variables can interfere with other customization settings for |
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2325 ;; those vars (in .emacs or in Customize). |
106126 | 2326 (mapc 'hfy-save-initvar |
106271
8d51419ae1f3
Misc coding convention cleanups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106270
diff
changeset
|
2327 '(auto-mode-alist interpreter-mode-alist)) |
106126 | 2328 (princ ")\n") |
2329 (indent-region start-pos (point) nil)) | |
2330 (custom-save-all) )) | |
2331 | |
2332 (defun htmlfontify-load-initfile () | |
2333 "Load the htmlfontify specific init/custom file." | |
2334 (interactive) | |
2335 (let ((file (hfy-initfile))) | |
2336 (load file 'NOERROR nil nil) )) | |
2337 | |
108099
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2338 |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2339 ;;;### (autoloads (hfy-fallback-colour-values htmlfontify-load-rgb-file) |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2340 ;;;;;; "hfy-cmap" "hfy-cmap.el" "3de2db2d213813bb3afe170ffd66cdde") |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2341 ;;; Generated autoloads from hfy-cmap.el |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2342 |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2343 (autoload 'htmlfontify-load-rgb-file "hfy-cmap" "\ |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2344 Load an X11 style rgb.txt FILE. |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2345 Search `hfy-rgb-load-path' if FILE is not specified. |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2346 Loads the variable `hfy-rgb-txt-colour-map', which is used by |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2347 `hfy-fallback-colour-values'. |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2348 |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2349 \(fn &optional FILE)" t nil) |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2350 |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2351 (autoload 'hfy-fallback-colour-values "hfy-cmap" "\ |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2352 Use a fallback method for obtaining the rgb values for a color. |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2353 |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2354 \(fn COLOUR-STRING)" nil nil) |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2355 |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2356 ;;;*** |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2357 |
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2358 |
106126 | 2359 (provide 'htmlfontify) |
2360 | |
106352 | 2361 ;; arch-tag: 944e5e63-c81d-4baa-a82a-0275f9c30e61 |
108099
3040d386675c
Minor htmlfontify simplifications.
Glenn Morris <rgm@gnu.org>
parents:
107971
diff
changeset
|
2362 ;;; htmlfontify.el ends here |