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