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