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 }
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
696 --> </script>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
697 </head>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
698 <body onload=\"stripe('index'); return true;\">\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
699 file style))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
700
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
701 (defun hfy-default-footer (file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
702 "Default value for `hfy-page-footer'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
703 FILE is the name of the file being rendered, in case it is needed."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
704 "\n </body>\n</html>\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
705
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
706 (defun hfy-link-style-string (style-string)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
707 "Replace the end of a css style declaration STYLE-STRING with the contents
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
708 of the variable `hfy-src-doc-link-style', removing text matching the regex
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
709 `hfy-src-doc-link-unstyle' first, if necessary."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
710 ;;(message "hfy-colour-vals");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
711 (if (string-match hfy-src-doc-link-unstyle style-string)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
712 (setq style-string (replace-match "" 'fixed-case 'literal style-string)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
713 (if (and (not (string-match hfy-src-doc-link-style style-string))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
714 (string-match "} *$" style-string))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
715 (concat (replace-match hfy-src-doc-link-style
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
716 'fixed-case
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
717 'literal
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
718 style-string) " }") style-string))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
719
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
720 ;; utility functions - cast emacs style specification values into their
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
721 ;; css2 equivalents:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
722 (defun hfy-triplet (colour)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
723 "Takes a COLOUR name \(string\) and return a CSS rgb(R, G, B) triplet string.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
724 Uses the definition of \"white\" to map the numbers to the 0-255 range, so
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
725 if you\'ve redefined white, \(esp if you've redefined it to have a triplet
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
726 member lower than that of the colour you are processing, strange things
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
727 may happen\)."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
728 ;;(message "hfy-colour-vals");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
729 (let ((white (mapcar (lambda (I) (float (1+ I))) (hfy-colour-vals "white")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
730 (rgb16 (mapcar (lambda (I) (float (1+ I))) (hfy-colour-vals colour))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
731 (if rgb16
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
732 ;;(apply 'format "rgb(%d, %d, %d)"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
733 ;; Use #rrggbb instead, it is smaller
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
734 (apply 'format "#%02x%02x%02x"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
735 (mapcar (lambda (X)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
736 (* (/ (nth X rgb16)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
737 (nth X white)) 255)) '(0 1 2))))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
738
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
739 (defun hfy-family (family) (list (cons "font-family" family)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
740 (defun hfy-bgcol (colour) (list (cons "background" (hfy-triplet colour))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
741 (defun hfy-colour (colour) (list (cons "color" (hfy-triplet colour))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
742 (defun hfy-width (width) (list (cons "font-stretch" (symbol-name width))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
743
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
744 (defcustom hfy-font-zoom 1.05
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
745 "Font scaling from Emacs to HTML."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
746 :type 'float
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
747 :group 'htmlfontify)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
748
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
749 (defun hfy-size (height)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
750 "Derive a CSS font-size specifier from an Emacs font :height attribute HEIGHT.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
751 Does not cope with the case where height is a function to be applied to
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
752 the height of the underlying font."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
753 (list
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
754 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
755 ;;(t (cons "font-size" ": 1em"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
756 ((floatp height)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
757 (cons "font-size" (format "%d%%" (* (* hfy-font-zoom height) 100))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
758 ((integerp height)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
759 (cons "font-size" (format "%dpt" (/ (* hfy-font-zoom height) 10 )))) )) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
760
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
761 (defun hfy-slant (slant)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
762 "Derive a font-style css specifier from the Emacs :slant attribute SLANT:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
763 CSS does not define the reverse-* styles, so just maps those to the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
764 regular specifiers."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
765 (list (cons "font-style" (cond ((eq 'italic slant) "italic" )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
766 ((eq 'reverse-italic slant) "italic" )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
767 ((eq 'oblique slant) "oblique")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
768 ((eq 'reverse-oblique slant) "oblique")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
769 (t "normal" )))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
770
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
771 (defun hfy-weight (weight)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
772 "Derive a font-weight css specifier from an Emacs weight spec symbol WEIGHT."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
773 (list (cons "font-weight" (cond ((eq 'ultra-bold weight) "900")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
774 ((eq 'extra-bold weight) "800")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
775 ((eq 'bold weight) "700")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
776 ((eq 'semi-bold weight) "600")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
777 ((eq 'normal weight) "500")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
778 ((eq 'semi-light weight) "400")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
779 ((eq 'light weight) "300")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
780 ((eq 'extra-light weight) "200")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
781 ((eq 'ultra-light weight) "100")))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
782
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
783 (defun hfy-box-to-border-assoc (spec)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
784 (if spec
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
785 (let ((tag (car spec))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
786 (val (cadr spec)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
787 (cons (cond ((eq tag :color) (cons "colour" val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
788 ((eq tag :width) (cons "width" val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
789 ((eq tag :style) (cons "style" val)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
790 (hfy-box-to-border-assoc (cddr spec))))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
791
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
792 (defun hfy-box-to-style (spec)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
793 (let* ((css (hfy-box-to-border-assoc spec))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
794 (col (cdr (assoc "colour" css)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
795 (s (cdr (assoc "style" css))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
796 (list
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
797 (if col (cons "border-color" (cdr (assoc "colour" css))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
798 (cons "border-width" (format "%dpx" (or (cdr (assoc "width" css)) 1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
799 (cons "border-style" (cond ((eq s 'released-button) "outset")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
800 ((eq s 'pressed-button ) "inset" )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
801 (t "solid" ))))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
802
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
803 (defun hfy-box (box)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
804 "Derive CSS border-* attributes from the Emacs :box attribute BOX."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
805 (if box
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
806 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
807 ((integerp box) (list (cons "border-width" (format "%dpx" box))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
808 ((stringp box) (list (cons "border" (format "solid %s 1px" box))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
809 ((listp box) (hfy-box-to-style box) ))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
810
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
811 (defun hfy-decor (tag val)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
812 "Derive CSS text-decoration specifiers from various Emacs font attributes.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
813 TAG is an Emacs font attribute key (eg :underline).
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
814 VAL is ignored."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
815 (list
|
106128
|
816 ;; FIXME: Why not '("text-decoration" . "underline")? --Stef
|
106126
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
817 (cond ((eq tag :underline ) (cons "text-decoration" "underline" ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
818 ((eq tag :overline ) (cons "text-decoration" "overline" ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
819 ((eq tag :strike-through) (cons "text-decoration" "line-through")))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
820
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
821 (defun hfy-invisible (&optional val)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
822 "This text should be invisible.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
823 Do something in CSS to make that happen.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
824 VAL is ignored here."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
825 '(("display" . "none")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
826
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
827 (defun hfy-combined-face-spec (face)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
828 "Return a `defface' style alist of possible specifications for FACE.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
829 Entries resulting from customisation \(`custom-set-faces'\) will take
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
830 precedence."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
831 (let ((spec nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
832 (setq spec (append (or (get face 'saved-face) (list))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
833 (or (get face 'face-defface-spec) (list))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
834 (if (and hfy-display-class hfy-default-face-def (eq face 'default))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
835 (setq spec (append hfy-default-face-def spec))) spec))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
836
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
837 (defun hfy-face-attr-for-class (face &optional class)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
838 "Return the face attributes for FACE.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
839 If CLASS is set, it must be a `defface' alist key \[see below\],
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
840 in which case the first face specification returned by `hfy-combined-face-spec'
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
841 which *doesn\'t* clash with CLASS is returned.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
842 \(A specification with a class of t is considered to match any class you
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
843 specify - this matches Emacs\' behaviour when deciding on which face attributes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
844 to use, to the best of my understanding\).\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
845 If CLASS is nil, then you just get get whatever `face-attr-construct' returns,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
846 ie the current specification in effect for FACE.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
847 *NOTE* This function forces any face that is not \'default and which has
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
848 no :inherit property to inherit from \'default \( this is because \'default
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
849 is magical in that Emacs' fonts behave as if they inherit implicitly from
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
850 \'default, but no such behaviour exists in HTML/CSS \).\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
851 See `hfy-display-class' for details of valid values for CLASS."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
852 (let ((face-spec nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
853 (setq
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
854 face-spec
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
855 (if class
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
856 (let ((face-props (hfy-combined-face-spec face))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
857 (face-specn nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
858 (face-class nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
859 (face-attrs nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
860 (face-score -1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
861 (face-match nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
862 (while face-props
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
863 (setq face-specn (car face-props)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
864 face-class (car face-specn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
865 face-attrs (cdr face-specn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
866 face-props (cdr face-props))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
867 ;; if the current element CEL of CLASS is t we match
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
868 ;; if the current face-class is t, we match
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
869 ;; if the cdr of CEL has a non-nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
870 ;; intersection with the cdr of the first member of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
871 ;; the current face-class with the same car as CEL, we match
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
872 ;; if we actually clash, then we can't match
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
873 (let ((cbuf class)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
874 (cel nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
875 (key nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
876 (val nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
877 (x nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
878 (next nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
879 (score 0))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
880 (while (and cbuf (not next))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
881 (setq cel (car cbuf)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
882 cbuf (cdr cbuf)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
883 key (car cel)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
884 val (cdr cel)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
885 val (if (listp val) val (list val)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
886 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
887 ((or (eq cel t) (memq face-class '(t default)));;default match
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
888 (setq score 0) (ignore "t match"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
889 ((not (cdr (assq key face-class))) ;; neither good nor bad
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
890 nil (ignore "non match, non collision"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
891 ((setq x (hfy-interq val (cdr (assq key face-class))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
892 (setq score (+ score (length x)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
893 (ignore "intersection"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
894 (t ;; nope.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
895 (setq next t score -10) (ignore "collision")) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
896 (if (> score face-score)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
897 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
898 (setq face-match face-attrs
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
899 face-score score )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
900 (ignore "%d << %S/%S" score face-class class))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
901 (ignore "--- %d ---- (insufficient)" score)) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
902 ;; matched ? last attrs : nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
903 (if face-match
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
904 (if (listp (car face-match)) (car face-match) face-match) nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
905 ;; Unfortunately the default face returns a
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
906 ;; :background. Fortunately we can remove it, but how do we do
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
907 ;; that in a non-system specific way?
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
908 (let ((spec (face-attr-construct face))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
909 (new-spec nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
910 (if (not (memq :background spec))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
911 spec
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
912 (while spec
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
913 (let ((a (nth 0 spec))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
914 (b (nth 1 spec)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
915 (unless (and (eq a :background)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
916 (stringp b)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
917 (string= b "SystemWindow"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
918 (setq new-spec (cons a (cons b new-spec)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
919 (setq spec (cddr spec)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
920 new-spec)) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
921 (if (or (memq :inherit face-spec) (eq 'default face))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
922 face-spec
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
923 (nconc face-spec (list :inherit 'default))) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
924
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
925 ;; construct an assoc of (css-tag-name . css-tag-value) pairs
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
926 ;; from a face or assoc of face attributes:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
927
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
928 ;; Some tests etc:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
929 ;; (mumamo-message-with-face "testing face" 'highlight)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
930 ;; (mumamo-message-with-face "testing face" '(:foreground "red" :background "yellow"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
931 ;; (hfy-face-to-style-i '(:inherit default foreground-color "red"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
932 ;; default face=(:stipple nil :background "SystemWindow" :foreground
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
933 ;; "SystemWindowText" :inverse-video nil :box nil :strike-through
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
934 ;; nil :overline nil :underline nil :slant normal :weight normal
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
935 ;; :height 98 :width normal :family "outline-courier new")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
936 (defun hfy-face-to-style-i (fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
937 "The guts of `hfy-face-to-style': FN should be a `defface' font spec,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
938 as returned by `face-attr-construct' or `hfy-face-attr-for-class'. Note
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
939 that this function does not get font-sizes right if they are based on
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
940 inherited modifiers \(via the :inherit\) attribute, and any other
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
941 modifiers that are cumulative if they appear multiple times need to be
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
942 merged by the user - `hfy-flatten-style' should do this."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
943 ;;(message "hfy-face-to-style-i");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
944
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
945 ;; fn's value could be something like
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
946 ;; (:inherit
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
947 ;; ((foreground-color . "blue"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
948 ;; (foreground-color . "blue")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
949 ;; nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
950
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
951 (when fn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
952 (let ((key (car fn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
953 (val (cadr fn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
954 (next (cddr fn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
955 (that nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
956 (this nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
957 (parent nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
958 (if (eq key :inherit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
959 (let ((vs (if (listp val) val (list val))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
960 ;; (let ((x '(a b))) (setq x (append '(c d) x)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
961 ;; (let ((x '(a b))) (setq x (append '(c d) x)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
962 (dolist (v vs)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
963 (setq parent
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
964 (append
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
965 parent
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
966 (hfy-face-to-style-i
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
967 (hfy-face-attr-for-class v hfy-display-class)) ))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
968 (setq this
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
969 (if val (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
970 ((eq key :family ) (hfy-family val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
971 ((eq key :width ) (hfy-width val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
972 ((eq key :weight ) (hfy-weight val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
973 ((eq key :slant ) (hfy-slant val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
974 ((eq key :foreground ) (hfy-colour val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
975 ((eq key :background ) (hfy-bgcol val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
976 ((eq key :box ) (hfy-box val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
977 ((eq key :height ) (hfy-size val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
978 ((eq key :underline ) (hfy-decor key val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
979 ((eq key :overline ) (hfy-decor key val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
980 ((eq key :strike-through) (hfy-decor key val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
981 ((eq key :invisible ) (hfy-invisible val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
982 ((eq key :bold ) (hfy-weight 'bold))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
983 ((eq key :italic ) (hfy-slant 'italic))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
984 (setq that (hfy-face-to-style-i next))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
985 ;;(lwarn t :warning "%S => %S" fn (nconc this that parent))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
986 (nconc this that parent))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
987
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
988 (defun hfy-size-to-int (spec)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
989 "Convert SPEC, a css font-size specifier, back to an Emacs :height attribute
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
990 value. Used while merging multiple font-size attributes."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
991 ;;(message "hfy-size-to-int");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
992 (list
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
993 (if (string-match "\\([0-9]+\\)\\(%\\|pt\\)" spec)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
994 (cond ((string= "%" (match-string 2 spec))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
995 (/ (string-to-number (match-string 1 spec)) 100.0))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
996 ((string= "pt" (match-string 2 spec))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
997 (* (string-to-number (match-string 1 spec)) 10)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
998 (string-to-number spec))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
999
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1000 ;; size is different, in that in order to get it right at all,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1001 ;; we have to trawl the inheritance path, accumulating modifiers,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1002 ;; _until_ we get to an absolute (pt) specifier, then combine the lot
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1003 (defun hfy-flatten-style (style)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1004 "Take STYLE (see `hfy-face-to-style-i', `hfy-face-to-style') and merge
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1005 any multiple attributes appropriately. Currently only font-size is merged
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1006 down to a single occurrence - others may need special handling, but I
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1007 haven\'t encountered them yet. Returns a `hfy-style-assoc'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1008 ;;(message "(hfy-flatten-style %S)" style) ;;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1009 (let ((n 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1010 (m (list 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1011 (x nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1012 (r nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1013 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1014 (lambda (css)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1015 (if (string= (car css) "font-size")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1016 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1017 (when (not x) (setq m (nconc m (hfy-size-to-int (cdr css)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1018 (when (string-match "pt" (cdr css)) (setq x t)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1019 (setq r (nconc r (list css))) )) style)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1020 ;;(message "r: %S" r)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1021 (setq n (apply '* m))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1022 (nconc r (hfy-size (if x (round n) (* n 1.0)))) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1023
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1024 (defun hfy-face-to-style (fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1025 "Take FN, a font or `defface' style font specification,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1026 \(as returned by `face-attr-construct' or `hfy-face-attr-for-class'\)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1027 and return a `hfy-style-assoc'.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1028 See also: `hfy-face-to-style-i', `hfy-flatten-style'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1029 ;;(message "hfy-face-to-style");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1030 (let ((face-def (if (facep fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1031 (hfy-face-attr-for-class fn hfy-display-class) fn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1032 (final-style nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1033
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1034 (setq final-style (hfy-flatten-style (hfy-face-to-style-i face-def)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1035 ;;(message "%S" final-style)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1036 (if (not (assoc "text-decoration" final-style))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1037 (progn (setq final-style
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1038 ;; Fix-me: there is no need for this since
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1039 ;; text-decoration is not inherited.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1040 ;; but it's not wrong and if this ever changes it will
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1041 ;; be needed, so I think it's better to leave it in? -- v
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1042 (nconc final-style '(("text-decoration"."none"))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1043 final-style))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1044
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1045 ;; strip redundant bits from a name. Technically, this could result in
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1046 ;; a collision, but it is pretty unlikely - will fix later...
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1047 ;; also handle ephemeral fonts created by overlays, which don't actually
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1048 ;; have names:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1049 (defun hfy-face-or-def-to-name (fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1050 "Render a font symbol or `defface' font spec FN into a name \(string\)."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1051 ;;(message "generating name for %s" fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1052 (if (not (listp fn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1053 (format "%s" fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1054 (let* ((key (format "%s" fn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1055 (entry (assoc key hfy-tmpfont-stack))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1056 (base (cadr (memq :inherit fn)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1057 (tag (cdr entry)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1058 ;;(message "checking for key «%s» in font stack [%d]"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1059 ;; key (if entry 1 0))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1060 (if entry nil ;; noop
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1061 (setq tag (format "%04d" (length hfy-tmpfont-stack))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1062 entry (cons key tag)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1063 hfy-tmpfont-stack (cons entry hfy-tmpfont-stack)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1064 ;;(message " -> name: %s-%s" (or base 'default) tag)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1065 (format "%s-%s" (or base 'default) tag)) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1066
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1067 (defun hfy-css-name (fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1068 "Strip the boring bits from a font-name FN and return a CSS style name."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1069 ;;(message "hfy-css-name");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1070 (let ((face-name (hfy-face-or-def-to-name fn)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1071 (if (or (string-match "font-lock-\\(.*\\)" face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1072 (string-match "cperl-\\(.*\\)" face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1073 (string-match "^[Ii]nfo-\\(.*\\)" face-name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1074 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1075 (setq face-name (match-string 1 face-name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1076 (if (string-match "\\(.*\\)-face$" face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1077 (setq face-name (match-string 1 face-name))) face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1078 face-name)) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1079
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1080 ;; construct an assoc of (stripped-name . "{ css-stuff-here }") pairs
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1081 ;; from a face:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1082 (defun hfy-face-to-css (fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1083 "Take FN, a font or `defface' specification \(cf `face-attr-construct'\)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1084 and return a CSS style specification.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1085 See also: `hfy-face-to-style'"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1086 ;;(message "hfy-face-to-css");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1087 (let ((css-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1088 (css-text nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1089 (seen nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1090 ;;(message "(hfy-face-to-style %S)" fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1091 (setq css-list (hfy-face-to-style fn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1092 (setq css-text
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1093 (nconc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1094 (mapcar
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1095 (lambda (E)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1096 (if (car E)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1097 (if (not (member (car E) seen))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1098 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1099 (setq seen (cons (car E) seen))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1100 (format " %s: %s; " (car E) (cdr E)))))) css-list)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1101 (cons (hfy-css-name fn) (format "{%s}" (apply 'concat css-text)))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1102
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1103 ;; extract a face from a list of char properties, if there is one:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1104 (defun hfy-p-to-face (props)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1105 "Given PROPS, a list of text-properties, return the value of the face
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1106 property, or nil."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1107 (if props
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1108 (if (string= (car props) "face")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1109 (let ((propval (cadr props)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1110 (if (and (listp propval) (not (cdr propval)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1111 (car propval)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1112 propval))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1113 (hfy-p-to-face (cddr props)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1114 nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1115
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1116 (defun hfy-p-to-face-lennart (props)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1117 "Given PROPS, a list of text-properties, return the value of the face
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1118 property, or nil."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1119 (when props
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1120 (let ((face (plist-get props 'face))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1121 (font-lock-face (plist-get props 'font-lock-face))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1122 (button (plist-get props 'button))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1123 ;;(face-rec (memq 'face props))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1124 ;;(button-rec (memq 'button props)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1125 )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1126 (if button
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1127 (let* ((category (plist-get props 'category))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1128 (face (when category (plist-get (symbol-plist category) 'face))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1129 face)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1130 (if font-lock-face
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1131 font-lock-face
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1132 face)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1133
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1135 ;; (defun hfy-get-face-at (pos)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1136 ;; ;; (let ((face (get-char-property-and-overlay pos 'face)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1137 ;; ;; (when (and face (listp face)) (setq face (car face)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1138 ;; ;; (unless (listp face)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1139 ;; ;; face)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1140 ;; ;;(get-char-property pos 'face)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1141 ;; ;; Overlays are handled later
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1142 ;; (if (or (not show-trailing-whitespace)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1143 ;; (not (get-text-property pos 'hfy-show-trailing-whitespace)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1144 ;; (get-text-property pos 'face)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1145 ;; (list 'trailing-whitespace (get-text-property pos 'face)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1146 ;; )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1147
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1148 (defun hfy-prop-invisible-p (prop)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1149 "Is text property PROP an active invisibility property?"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1150 (or (and (eq buffer-invisibility-spec t) prop)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1151 (or (memq prop buffer-invisibility-spec)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1152 (assq prop buffer-invisibility-spec))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1153
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1154 (defun hfy-find-invisible-ranges ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1155 "Return a list of (start-point . end-point) cons cells of invisible regions."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1156 (let (invisible p i e s) ;; return-value pos invisible end start
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1157 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1158 (setq p (goto-char (point-min)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1159 (when (invisible-p p) (setq s p i t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1160 (while (< p (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1161 (if i ;; currently invisible
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1162 (when (not (invisible-p p)) ;; but became visible
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1163 (setq e p
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1164 i nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1165 invisible (cons (cons s e) invisible)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1166 ;; currently visible:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1167 (when (invisible-p p) ;; but have become invisible
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1168 (setq s p i t)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1169 (setq p (next-char-property-change p)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1170 ;; still invisible at buffer end?
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1171 (when i
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1172 (setq e (point-max)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1173 invisible (cons (cons s e) invisible))) ) invisible))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1174
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1175 (defun hfy-invisible-name (point map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1176 "Generate a CSS style name for an invisible section of the buffer.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1177 POINT is the point inside the invisible region.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1178 MAP is the invisibility map as returned by `hfy-find-invisible-ranges'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1179 ;;(message "(hfy-invisible-name %S %S)" point map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1180 (let (name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1181 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1182 (lambda (range)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1183 (when (and (>= point (car range))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1184 (< point (cdr range)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1185 (setq name (format "invisible-%S-%S" (car range) (cdr range))))) map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1186 name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1187
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1188 ;; Fix-me: This function needs some cleanup by someone who understand
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1189 ;; all the formats that face properties can have.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1190 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1191 ;; overlay handling should be fine. haven't tested multiple stacked overlapping
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1192 ;; overlays recently, but the common case of a text property face + an overlay
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1193 ;; 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
|
1194 ;; -- v
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1195 (defun hfy-face-at (p)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1196 "Find face in effect at point P.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1197 If overlays are to be considered \(see `hfy-optimisations'\) then this may
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1198 return a defface style list of face properties instead of a face symbol."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1199 ;;(message "hfy-face-at");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1200 ;; Fix-me: clean up, remove face-name etc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1201 ;; not sure why we'd want to remove face-name? -- v
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1202 (let ((overlay-data nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1203 (base-face nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1204 ;; restored hfy-p-to-face as it handles faces like (bold) as
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1205 ;; well as face like 'bold - hfy-get-face-at doesn't dtrt -- v
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1206 (face-name (hfy-p-to-face (text-properties-at p)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1207 ;; (face-name (hfy-get-face-at p))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1208 (prop-seen nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1209 (extra-props nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1210 (text-props (text-properties-at p)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1211 ;;(message "face-name: %S" face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1212 (when (and face-name (listp face-name) (facep (car face-name)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1213 ;;(message "face-name is a list %S" face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1214 ;;(setq text-props (cons 'face face-name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1215 (dolist (f face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1216 (if (listp f) ;; for things like (variable-pitch (:foreground "red"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1217 (setq extra-props (cons f extra-props))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1218 (setq extra-props (cons :inherit (cons f extra-props)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1219 (setq face-name nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1220 ;; text-properties-at => (face (:foreground "red" ...))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1221 ;; or => (face (compilation-info underline)) list of faces
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1222 ;; overlay-properties
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1223 ;; format= (evaporate t face ((foreground-color . "red")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1224
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1225 ;; SO: if we have turned overlays off,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1226 ;; or if there's no overlay data
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1227 ;; just bail out and return whatever face data we've accumulated so far
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1228 (if (or (not (hfy-opt 'keep-overlays))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1229 (not (setq overlay-data (hfy-overlay-props-at p))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1230 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1231 ;;(message "· %d: %s; %S; %s"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1232 ;; p face-name extra-props text-props)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1233 face-name) ;; no overlays or extra properties
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1234 ;; collect any face data and any overlay data for processing:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1235 (when text-props
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1236 (setq overlay-data (cons text-props overlay-data)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1237 (setq overlay-data (nreverse overlay-data))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1238 ;;(message "- %d: %s; %S; %s; %s"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1239 ;; p face-name extra-props text-props overlay-data)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1240 ;; remember the basic face name so we don't keep repeating its specs:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1241 (when face-name (setq base-face face-name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1242 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1243 (lambda (P)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1244 (let ((iprops (cadr (memq 'invisible P))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1245 ;;(message "(hfy-prop-invisible-p %S)" iprops)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1246 (when (hfy-prop-invisible-p iprops)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1247 (setq extra-props
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1248 (cons :invisible (cons t extra-props))) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1249 (let ((fprops (cadr (or (memq 'face P)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1250 (memq 'font-lock-face P)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1251 ;;(message "overlay face: %s" fprops)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1252 (if (not (listp fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1253 (let ((this-face (if (stringp fprops) (intern fprops) fprops)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1254 (when (not (eq this-face base-face))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1255 (setq extra-props
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1256 (cons :inherit
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1257 (cons this-face extra-props))) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1258 (while fprops
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1259 (if (facep (car fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1260 (let ((face (car fprops)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1261 (when (stringp face) (setq face (intern fprops)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1262 (setq extra-props
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1263 (cons :inherit
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1264 (cons face
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1265 extra-props)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1266 (setq fprops (cdr fprops)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1267 (let (p v)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1268 ;; Sigh.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1269 (if (listp (car fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1270 (if (nlistp (cdr (car fprops)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1271 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1272 ;; ((prop . val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1273 (setq p (caar fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1274 (setq v (cdar fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1275 (setq fprops (cdr fprops)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1276 ;; ((prop val))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1277 (setq p (caar fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1278 (setq v (cadar fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1279 (setq fprops (cdr fprops)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1280 (if (listp (cdr fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1281 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1282 ;; (:prop val :prop val ...)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1283 (setq p (car fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1284 (setq v (cadr fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1285 (setq fprops (cddr fprops)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1286 (if (and (listp fprops)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1287 (not (listp (cdr fprops))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1288 ;;(and (consp x) (cdr (last x)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1289 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1290 ;; (prop . val)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1291 (setq p (car fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1292 (setq v (cdr fprops))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1293 (setq fprops nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1294 (error "Eh... another format! fprops=%s" fprops) )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1295 (setq p (case p
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1296 ;; These are all the properties handled
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1297 ;; in `hfy-face-to-style-i'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1298 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1299 ;; Are these translations right?
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1300 ;; yes, they are -- v
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1301 ('family :family )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1302 ('width :width )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1303 ('height :height )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1304 ('weight :weight )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1305 ('slant :slant )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1306 ('underline :underline )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1307 ('overline :overline )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1308 ('strike-through :strike-through)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1309 ('box :box )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1310 ('foreground-color :foreground)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1311 ('background-color :background)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1312 ('bold :bold )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1313 ('italic :italic )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1314 (t p)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1315 (if (memq p prop-seen) nil ;; noop
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1316 (setq prop-seen (cons p prop-seen)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1317 extra-props (cons p (cons v extra-props)))) ))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1318 overlay-data)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1319 ;;(message "+ %d: %s; %S" p face-name extra-props)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1320 (if extra-props
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1321 (if (listp face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1322 (nconc extra-props face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1323 (nconc extra-props (face-attr-construct face-name)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1324 face-name)) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1325
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1326 (defun hfy-overlay-props-at (p)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1327 "Grab overlay properties at point P.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1328 The plists are returned in descending priority order."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1329 (sort (mapcar (lambda (O) (overlay-properties O)) (overlays-at p))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1330 (lambda (A B) (> (or (cadr (memq 'priority A)) 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1331 (or (cadr (memq 'priority B)) 0)) ) ) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1332
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1333 ;; construct an assoc of (face-name . (css-name . "{ css-style }")) elements:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1334 (defun hfy-compile-stylesheet ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1335 "Trawl the current buffer, construct and return a `hfy-sheet-assoc'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1336 ;;(message "hfy-compile-stylesheet");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1337 (let ((pt (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1338 ;; Make the font stack stay:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1339 ;;(hfy-tmpfont-stack nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1340 (fn nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1341 (style nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1342 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1343 (goto-char pt)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1344 (while (< pt (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1345 (if (and (setq fn (hfy-face-at pt)) (not (assoc fn style)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1346 (setq style (cons (cons fn (hfy-face-to-css fn)) style)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1347 (setq pt (next-char-property-change pt))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1348 (setq style (cons (cons 'default (hfy-face-to-css 'default)) style))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1349
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1350 (defun hfy-fontified-p ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1351 "`font-lock' doesn't like to say it\'s been fontified when in batch
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1352 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
|
1353 mode we check for non-default face properties. Otherwise we test
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1354 variable `font-lock-mode' and variable `font-lock-fontified' for truth."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1355 ;;(message "font-lock-fontified: %S" font-lock-fontified)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1356 ;;(message "noninteractive : %S" noninteractive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1357 ;;(message "font-lock-mode : %S" font-lock-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1358 (and font-lock-fontified
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1359 (if noninteractive
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1360 (let ((pt (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1361 (face-name nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1362 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1363 (goto-char pt)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1364 (while (and (< pt (point-max)) (not face-name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1365 (setq face-name (hfy-face-at pt))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1366 (setq pt (next-char-property-change pt)))) face-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1367 font-lock-mode)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1368
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1369 ;; remember, the map is in reverse point order:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1370 ;; I wrote this while suffering the effects of a cold, and maybe a
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1371 ;; mild fever - I think it's correct, but it might be a little warped
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1372 ;; as my minfd keeps ... where was I? Oh yes, the bunnies...
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1373 (defun hfy-merge-adjacent-spans (face-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1374 "Where FACE-MAP is a `hfy-facemap-assoc' for the current buffer,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1375 this function merges adjacent style blocks which are of the same value
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1376 and are separated by nothing more interesting than whitespace.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1377 <span class=\"foo\">narf</span> <span class=\"foo\">brain</span>\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1378 \(as interpreted from FACE-MAP\) would become:\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1379 <span class=\"foo\">narf brain</span>\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1380 Returns a modified copy of FACE-MAP."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1381 (let ((tmp-map face-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1382 (map-buf nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1383 (first-start nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1384 (first-stop nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1385 (last-start nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1386 (last-stop nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1387 (span-stop nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1388 (span-start nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1389 (reduced-map nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1390 ;;(setq reduced-map (cons (car tmp-map) reduced-map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1391 ;;(setq reduced-map (cons (cadr tmp-map) reduced-map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1392 (while tmp-map
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1393 (setq first-start (cadddr tmp-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1394 first-stop (caddr tmp-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1395 last-start (cadr tmp-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1396 last-stop (car tmp-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1397 map-buf tmp-map
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1398 span-start last-start
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1399 span-stop last-stop )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1400 (while (and (equal (cdr first-start)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1401 (cdr last-start))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1402 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1403 (goto-char (car first-stop))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1404 (not (re-search-forward "[^ \t\n\r]" (car last-start) t))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1405 (setq map-buf (cddr map-buf)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1406 span-start first-start
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1407 first-start (cadddr map-buf)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1408 first-stop (caddr map-buf)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1409 last-start (cadr map-buf)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1410 last-stop (car map-buf)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1411 (setq reduced-map (cons span-stop reduced-map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1412 (setq reduced-map (cons span-start reduced-map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1413 (setq tmp-map (memq last-start tmp-map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1414 (setq tmp-map (cdr tmp-map)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1415 (setq reduced-map (nreverse reduced-map))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1416
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1417 ;; remember to generate 'synthetic' </span> entries -
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1418 ;; emacs copes by just having a stack of styles in effect
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1419 ;; and only using the top one: html has a more simplistic approach -
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1420 ;; we have to explicitly end a style, there's no way of temporarily
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1421 ;; overriding it w. another one... (afaik)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1422 (defun hfy-compile-face-map ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1423 ;; no need for special <a> version.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1424 ;; IME hyperlinks don't get underlined, esp when you htmlfontify a whole
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1425 ;; source tree, so the <a> version is needed -- v
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1426 ;; Fix-me: save table for multi-buffer
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1427 "Compile and return a `hfy-facemap-assoc' for the current buffer."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1428 ;;(message "hfy-compile-face-map");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1429 (let ((pt (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1430 (pt-narrow 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1431 (fn nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1432 (map nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1433 (prev-tag nil)) ;; t if the last tag-point was a span-start
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1434 ;; nil if it was a span-stop
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1435 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1436 (goto-char pt)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1437 (while (< pt (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1438 (if (setq fn (hfy-face-at pt))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1439 (progn (if prev-tag (setq map (cons (cons pt-narrow 'end) map)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1440 (setq map (cons (cons pt-narrow fn) map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1441 (setq prev-tag t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1442 (if prev-tag (setq map (cons (cons pt-narrow 'end) map)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1443 (setq prev-tag nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1444 (setq pt (next-char-property-change pt))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1445 (setq pt-narrow (1+ (- pt (point-min)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1446 (if (and map (not (eq 'end (cdar map))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1447 (setq map (cons (cons (- (point-max) (point-min)) 'end) map))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1448 (if (hfy-opt 'merge-adjacent-tags) (hfy-merge-adjacent-spans map) map)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1449
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1450 (defun hfy-buffer ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1451 "Generate a buffer to hold the html output.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1452 The filename of this buffer is derived from the source \(current\) buffer\'s
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1453 variable `buffer-file-name', if it is set, plus `hfy-extn'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1454 Otherwise a plausible filename is constructed from `default-directory',
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1455 `buffer-name' and `hfy-extn'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1456 (let* ((name (concat (buffer-name) hfy-extn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1457 (src (buffer-file-name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1458 (buf (get-buffer-create name)))
|
106128
|
1459 (with-current-buffer buf
|
|
1460 (setq buffer-file-name
|
|
1461 (if src (concat src hfy-extn)
|
|
1462 (expand-file-name (if (string-match "^.*/\\([^/]*\\)$" name)
|
|
1463 (match-string 1 name)
|
|
1464 name))))
|
106126
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1465 buf)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1466
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1467 (defun hfy-lookup (face style)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1468 "Get a CSS style name for FACE from STYLE."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1469 (cadr (assoc face style)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1470
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1471 (defun hfy-link-style (style-string)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1472 "Copy, alter and return a STYLE-STRING to make it suitable for a hyperlink.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1473 Uses `hfy-link-style-fun' to do this."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1474 (if (functionp hfy-link-style-fun)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1475 (funcall hfy-link-style-fun style-string)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1476 style-string))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1477
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1478 (defun hfy-sprintf-stylesheet (css file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1479 "Return the inline CSS style sheet for FILE as a string."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1480 (let ((stylesheet nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1481 (setq stylesheet
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1482 (concat
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1483 hfy-meta-tags
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1484 "\n<style type=\"text/css\"><!-- \n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1485 ;; Fix-me: Add handling of page breaks here + scan for ^L
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1486 ;; where appropriate.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1487 (format "body %s\n" (cddr (assq 'default css)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1488 (apply 'concat
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1489 (mapcar
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1490 (lambda (style)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1491 (format
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1492 "span.%s %s\nspan.%s a %s\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1493 (cadr style) (cddr style)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1494 (cadr style) (hfy-link-style (cddr style)))) css))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1495 " --></style>\n"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1496 (funcall hfy-page-header file stylesheet)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1497
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1498 (defconst hfy-javascript "
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1499 <script type=\"text/javascript\">
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1500 // <![CDATA[
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1501 function toggle_invis( name )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1502 {
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1503 var filter =
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1504 { acceptNode:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1505 function( node )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1506 { var classname = node.id;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1507 if( classname )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1508 { var classbase = classname.substr( 0, name.length );
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1509 if( classbase == name ) { return NodeFilter.FILTER_ACCEPT; } }
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1510 return NodeFilter.FILTER_SKIP; } };
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1511 var walker = document.createTreeWalker( document.body ,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1512 NodeFilter.SHOW_ELEMENT ,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1513 filter ,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1514 false );
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1515 while( walker.nextNode() )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1516 {
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1517 var e = walker.currentNode;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1518 if( e.style.display == \"none\" ) { e.style.display = \"inline\"; }
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1519 else { e.style.display = \"none\"; }
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1520 }
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1521 }
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1522 // ]]>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1523 </script>\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1524
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1525 ;; tag all the dangerous characters we want to escape
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1526 ;; (ie any "<> chars we _didn't_ put there explicitly for css markup)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1527 (defun hfy-html-enkludge-buffer ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1528 "Mark dangerous [\"\<\>] characters with the \'hfy-quoteme property.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1529 See also `hfy-html-dekludge-buffer'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1530 ;;(message "hfy-html-enkludge-buffer");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1531 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1532 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1533 (while (re-search-forward hfy-html-quote-regex nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1534 (put-text-property (match-beginning 0) (point) 'hfy-quoteme t))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1535
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1536 ;; dangerous char -> &entity;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1537 (defun hfy-html-quote (char-string)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1538 "Map CHAR-STRING to an html safe string (entity) if need be."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1539 ;;(message "hfy-html-quote");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1540 (or (cadr (assoc char-string hfy-html-quote-map)) char-string) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1541
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1542 ;; actually entity-ise dangerous chars.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1543 ;; note that we can't do this until _after_ we have inserted the css
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1544 ;; markup, since we use a position-based map to insert this, and if we
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1545 ;; enter any other text before we do this, we'd have to track another
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1546 ;; map of offsets, which would be tedious...
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1547 (defun hfy-html-dekludge-buffer ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1548 "Transform all dangerous characters marked with the \'hfy-quoteme property
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1549 using `hfy-html-quote'\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1550 See also `hfy-html-enkludge-buffer'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1551 ;;(message "hfy-html-dekludge-buffer");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1552 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1553 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1554 (while (re-search-forward hfy-html-quote-regex nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1555 (if (get-text-property (match-beginning 0) 'hfy-quoteme)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1556 (replace-match (hfy-html-quote (match-string 1))) )) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1557
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1558 ;; Borrowed from font-lock.el
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1559 (defmacro hfy-save-buffer-state (varlist &rest body)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1560 "Bind variables according to VARLIST and eval BODY restoring buffer state.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1561 Do not record undo information during evaluation of BODY."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1562 (declare (indent 1) (debug let))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1563 (let ((modified (make-symbol "modified")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1564 `(let* ,(append varlist
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1565 `((,modified (buffer-modified-p))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1566 (buffer-undo-list t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1567 (inhibit-read-only t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1568 (inhibit-point-motion-hooks t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1569 (inhibit-modification-hooks t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1570 deactivate-mark
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1571 buffer-file-name
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1572 buffer-file-truename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1573 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1574 ,@body)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1575 (unless ,modified
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1576 (restore-buffer-modified-p nil)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1577
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1578 (defun hfy-mark-trailing-whitespace ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1579 "Tag trailing whitespace with a hfy property if it is currently highlighted."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1580 (when show-trailing-whitespace
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1581 (let ((inhibit-read-only t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1582 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1583 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1584 (hfy-save-buffer-state nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1585 (while (re-search-forward "[ \t]+$" nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1586 (put-text-property (match-beginning 0) (match-end 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1587 'hfy-show-trailing-whitespace t)))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1588
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1589 (defun hfy-unmark-trailing-whitespace ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1590 "Undo the effect of `hfy-mark-trailing-whitespace'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1591 (when show-trailing-whitespace
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1592 (hfy-save-buffer-state nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1593 (remove-text-properties (point-min) (point-max)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1594 '(hfy-show-trailing-whitespace)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1595
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1596 (defun hfy-fontify-buffer (&optional srcdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1597 "Implement the guts of `htmlfontify-buffer'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1598 SRCDIR, if set, is the directory being htmlfontified.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1599 FILE, if set, is the file name."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1600 (if srcdir (setq srcdir (directory-file-name srcdir)))
|
106128
|
1601 (let* ( (html-buffer (hfy-buffer))
|
106126
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1602 (css-sheet nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1603 (css-map nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1604 (invis-ranges nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1605 (rovl nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1606 (orig-ovls (overlays-in (point-min) (point-max)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1607 (rmin (when mark-active (region-beginning)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1608 (rmax (when mark-active (region-end ))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1609 (when (and mark-active
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1610 transient-mark-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1611 (unless (and (= rmin (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1612 (= rmax (point-max)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1613 (setq rovl (make-overlay rmin rmax))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1614 (overlay-put rovl 'priority 1000)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1615 (overlay-put rovl 'face 'region)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1616 ;; copy the buffer, including fontification, and switch to it:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1617 (hfy-mark-trailing-whitespace)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1618 (setq css-sheet (hfy-compile-stylesheet )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1619 css-map (hfy-compile-face-map )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1620 invis-ranges (hfy-find-invisible-ranges))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1621 (hfy-unmark-trailing-whitespace)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1622 (when rovl
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1623 (delete-overlay rovl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1624 (copy-to-buffer html-buffer (point-min) (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1625 (set-buffer html-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1626 ;; Apply overlay invisible spec
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1627 (setq orig-ovls
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1628 (sort orig-ovls
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1629 (lambda (A B)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1630 (> (or (cadr (memq 'priority (overlay-properties A))) 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1631 (or (cadr (memq 'priority (overlay-properties B))) 0)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1633 ;; at this point, html-buffer retains the fontification of the parent:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1634 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1635 ;; 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
|
1636 ;; that can make it look like we've rendered invalid xhtml when all that's
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1637 ;; happened is some tags are in the invisible portions of the buffer:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1638 (setq buffer-invisibility-spec nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1640 ;; #####################################################################
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1641 ;; if we are in etags mode, add properties to mark the anchors and links
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1642 (if (and srcdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1643 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1644 (hfy-mark-tag-names srcdir file) ;; mark anchors
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1645 (hfy-mark-tag-hrefs srcdir file))) ;; mark links
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1646 ;; #####################################################################
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1647 ;; mark the 'dangerous' characters
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1648 ;;(message "marking dangerous characters")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1649 (hfy-html-enkludge-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1650 ;; trawl the position-based face-map, inserting span tags as we go
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1651 ;; note that we cannot change any character positions before this point
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1652 ;; or we will invalidate the map:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1653 ;; NB: This also means we have to trawl the map in descending file-offset
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1654 ;; order, obviously.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1655 ;; ---------------------------------------------------------------------
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1656 ;; Remember, inserting pushes properties to the right, which we don't
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1657 ;; actually want to happen for link properties, so we have to flag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1658 ;; them and move them by hand - if you don't, you end up with
|
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</span><span class="bletch"></a>...
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1661 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1662 ;; instead of:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1663 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1664 ;; <span class="foo"><a href="bar">texta</a></span><span class="bletch">...
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1665 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1666 ;; If my analysis of the problem is correct, we can detect link-ness by
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1667 ;; either hfy-linkp or hfy-endl properties at the insertion point, but I
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1668 ;; think we only need to relocate the hfy-endl property, as the hfy-linkp
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1669 ;; property has already served its main purpose by this point.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1670 ;;(message "mapcar over the CSS-MAP")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1671 (message "invis-ranges:\n%S" invis-ranges)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1672 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1673 (lambda (point-face)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1674 (let ((pt (car point-face))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1675 (fn (cdr point-face))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1676 (move-link nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1677 (goto-char pt)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1678 (setq move-link
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1679 (or (get-text-property pt 'hfy-linkp)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1680 (get-text-property pt 'hfy-endl )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1681 (if (eq 'end fn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1682 (insert "</span>")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1683 (if (not (and srcdir file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1684 nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1685 (when move-link
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1686 (remove-text-properties (point) (1+ (point)) '(hfy-endl nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1687 (put-text-property pt (1+ pt) 'hfy-endl t) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1688 ;; if we have invisible blocks, we need to do some extra magic:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1689 (if invis-ranges
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1690 (let ((iname (hfy-invisible-name pt invis-ranges))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1691 (fname (hfy-lookup fn css-sheet )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1692 (when (assq pt invis-ranges)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1693 (insert
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1694 (format "<span onclick=\"toggle_invis('%s');\">" iname))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1695 (insert "…</span>"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1696 (insert
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1697 (format "<span class=\"%s\" id=\"%s-%d\">" fname iname pt)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1698 (insert (format "<span class=\"%s\">" (hfy-lookup fn css-sheet))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1699 (if (not move-link) nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1700 ;;(message "removing prop2 @ %d" (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1701 (if (remove-text-properties (point) (1+ (point)) '(hfy-endl nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1702 (put-text-property pt (1+ pt) 'hfy-endl t))) )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1703 css-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1704 ;; #####################################################################
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1705 ;; Invisibility
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1706 ;; Maybe just make the text invisible in XHTML?
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1707 ;; DONE -- big block of obsolete invisibility code elided here -- v
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1708 ;; #####################################################################
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1709 ;; (message "checking to see whether we should link...")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1710 (if (and srcdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1711 (let ((lp 'hfy-link)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1712 (pt nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1713 (pr nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1714 (rr nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1715 ;; (message " yes we should.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1716 ;; translate 'hfy-anchor properties to anchors
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1717 (setq pt (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1718 (while (setq pt (next-single-property-change pt 'hfy-anchor))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1719 (if (setq pr (get-text-property pt 'hfy-anchor))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1720 (progn (goto-char pt)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1721 (remove-text-properties pt (1+ pt) '(hfy-anchor nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1722 (insert (concat "<a name=\"" pr "\"></a>")))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1723 ;; translate alternate 'hfy-link and 'hfy-endl props to opening
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1724 ;; and closing links. (this should avoid those spurious closes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1725 ;; we sometimes get by generating only paired tags)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1726 (setq pt (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1727 (while (setq pt (next-single-property-change pt lp))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1728 (if (not (setq pr (get-text-property pt lp))) nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1729 (goto-char pt)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1730 (remove-text-properties pt (1+ pt) (list lp nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1731 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1732 ((eq lp 'hfy-link)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1733 (if (setq rr (get-text-property pt 'hfy-inst))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1734 (insert (format "<a name=\"%s\"></a>" rr)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1735 (insert (format "<a href=\"%s\">" pr))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1736 (setq lp 'hfy-endl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1737 ((eq lp 'hfy-endl)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1738 (insert "</a>") (setq lp 'hfy-link)) ))) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1739
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1740 ;; #####################################################################
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1741 ;; transform the dangerous chars. This changes character positions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1742 ;; since entities have > char length.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1743 ;; note that this deletes the dangerous characters, and therefore
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1744 ;; destroys any properties they may contain (such as 'hfy-endl),
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1745 ;; so we have to do this after we use said properties:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1746 ;; (message "munging dangerous characters")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1747 (hfy-html-dekludge-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1748 ;; insert the stylesheet at the top:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1749 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1750 ;;(message "inserting stylesheet")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1751 (insert (hfy-sprintf-stylesheet css-sheet file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1752 (insert hfy-javascript)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1753 (if (hfy-opt 'div-wrapper) (insert "<div class=\"default\">"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1754 (insert "\n<pre>")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1755 (goto-char (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1756 (insert "</pre>\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1757 (if (hfy-opt 'div-wrapper) (insert "</div>"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1758 ;;(message "inserting footer")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1759 (insert (funcall hfy-page-footer file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1760 ;; call any post html-generation hooks:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1761 (run-hooks 'hfy-post-html-hooks)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1762 ;; return the html buffer
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1763 (set-buffer-modified-p nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1764 html-buffer))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1765
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1766 (defun hfy-force-fontification ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1767 "Try to force font-locking even when it is optimised away."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1768 (mapc (lambda (fun) (funcall fun)) hfy-init-kludge-hooks)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1769 (eval-and-compile (require 'font-lock))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1770 (if (boundp 'font-lock-cache-position)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1771 (or font-lock-cache-position
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1772 (set 'font-lock-cache-position (make-marker))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1773 (if (not noninteractive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1774 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1775 (message "hfy interactive mode (%S %S)" window-system major-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1776 (when (and font-lock-defaults
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1777 font-lock-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1778 (font-lock-fontify-region (point-min) (point-max) nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1779 (message "hfy batch mode (%s:%S)"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1780 (or (buffer-file-name) (buffer-name)) major-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1781 (when font-lock-defaults
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1782 (font-lock-fontify-buffer)) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1783
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1784 (defun htmlfontify-buffer (&optional srcdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1785 "Create a new buffer, named for the current buffer + a .html extension,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1786 containing an inline css-stylesheet and formatted css-markup html
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1787 that reproduces the look of the current Emacs buffer as closely
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1788 as possible.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1789
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1790 Dangerous characters in the existing buffer are turned into html
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1791 entities, so you should even be able to do html-within-html
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1792 fontified display.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1793
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1794 You should, however, note that random control or eight-bit
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1795 characters such as ^L (\x0c) or ¤ (\xa4) won't get mapped yet.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1796
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1797 If the SRCDIR and FILE arguments are set, lookup etags derived
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1798 entries in the `hfy-tags-cache' and add html anchors and
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1799 hyperlinks as appropriate."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1800 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1801 ;; pick up the file name in case we didn't receive it
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1802 (if (not file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1803 (progn (setq file (or (buffer-file-name) (buffer-name)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1804 (if (string-match "/\\([^/]*\\)$" file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1805 (setq file (match-string 1 file)))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1806
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1807 (if (not (hfy-opt 'skip-refontification))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1808 (save-excursion ;; Keep region
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1809 (hfy-force-fontification)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1810 (if (interactive-p) ;; display the buffer in interactive mode:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1811 (switch-to-buffer (hfy-fontify-buffer srcdir file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1812 (hfy-fontify-buffer srcdir file)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1813
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1814 ;; recursive file listing
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1815 (defun hfy-list-files (directory)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1816 "Return a list of files under DIRECTORY.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1817 Strips any leading \"./\" from each filename."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1818 ;;(message "hfy-list-files");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1819 (cd directory)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1820 (mapcar (lambda (F) (if (string-match "^./\\(.*\\)" F) (match-string 1 F) F))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1821 (split-string (shell-command-to-string hfy-find-cmd))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1822
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1823 ;; strip the filename off, return a directiry name
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1824 ;; not a particularly thorough implementaion, but it will be
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1825 ;; fed pretty carefully, so it should be Ok:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1826 (defun hfy-dirname (file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1827 "Return everything preceding the last \"/\" from a relative filename FILE,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1828 on the assumption that this will produce a relative directory name. Hardly
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1829 bombproof, but good enough in the context in which it is being used."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1830 ;;(message "hfy-dirname");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1831 (let ((f (directory-file-name file)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1832 (and (string-match "^\\(.*\\)/" f) (match-string 1 f))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1833
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1834 ;; create a directory, cf mkdir -p
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1835 (defun hfy-make-directory (dir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1836 "Approx equivalent of mkdir -p DIR."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1837 ;;(message "hfy-make-directory");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1838 (if (file-exists-p dir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1839 (if (file-directory-p dir) t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1840 (make-directory dir t)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1841
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1842 (defun hfy-text-p (srcdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1843 "Is SRCDIR/FILE text? Uses `hfy-istext-command' to determine this."
|
106128
|
1844 (let* ((cmd (format hfy-istext-command (expand-file-name file srcdir)))
|
|
1845 (rsp (shell-command-to-string cmd)))
|
106126
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1846 (if (string-match "text" rsp) t nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1847
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1848 ;; open a file, check fontification, if fontified, write a fontified copy
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1849 ;; to the destination directory, otherwise just copy the file:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1850 (defun hfy-copy-and-fontify-file (srcdir dstdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1851 "Open FILE in SRCDIR - if fontified, write a fontified copy to DSTDIR
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1852 adding an extension of `hfy-extn'. Fontification is actually done by
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1853 `htmlfontify-buffer'. If the buffer is not fontified, just copy it."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1854 ;;(message "hfy-copy-and-fontify-file");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1855 (let (;;(fast-lock-minimum-size hfy-fast-lock-save)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1856 ;;(font-lock-support-mode 'fast-lock-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1857 ;;(window-system (or window-system 'htmlfontify))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1858 (target nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1859 (source nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1860 (html nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1861 (cd srcdir)
|
106128
|
1862 (with-current-buffer (setq source (find-file-noselect file))
|
|
1863 ;; FIXME: Shouldn't this use expand-file-name? --Stef
|
106126
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1864 (setq target (concat dstdir "/" file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1865 (hfy-make-directory (hfy-dirname target))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1866 (if (not (hfy-opt 'skip-refontification)) (hfy-force-fontification))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1867 (if (or (hfy-fontified-p) (hfy-text-p srcdir file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1868 (progn (setq html (hfy-fontify-buffer srcdir file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1869 (set-buffer html)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1870 (write-file (concat target hfy-extn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1871 (kill-buffer html))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1872 ;; #o0200 == 128, but emacs20 doesn't know that
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1873 (if (and (file-exists-p target) (not (file-writable-p target)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1874 (set-file-modes target (logior (file-modes target) 128)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1875 (copy-file (buffer-file-name source) target 'overwrite))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1876 (kill-buffer source)) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1877
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1878 ;; list of tags in file in srcdir
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1879 (defun hfy-tags-for-file (srcdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1880 "List of etags tags that have definitions in this FILE.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1881 Looks up the tags cache in `hfy-tags-cache' using SRCDIR as the key."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1882 ;;(message "hfy-tags-for-file");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1883 (let ((cache-entry (assoc srcdir hfy-tags-cache))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1884 (cache-hash nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1885 (tag-list nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1886 (if (setq cache-hash (cadr cache-entry))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1887 (maphash
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1888 (lambda (K V)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1889 (if (assoc file V)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1890 (setq tag-list (cons K tag-list)))) cache-hash))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1891 tag-list))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1892
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1893 ;; mark the tags native to this file for anchors
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1894 (defun hfy-mark-tag-names (srcdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1895 "Mark tags in FILE (lookup SRCDIR in `hfy-tags-cache') with the \'hfy-anchor
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1896 property, with a value of \"tag.line-number\"."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1897 ;;(message "(hfy-mark-tag-names %s %s)" srcdir file);;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1898 (let ((cache-entry (assoc srcdir hfy-tags-cache))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1899 (cache-hash nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1900 (if (setq cache-hash (cadr cache-entry))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1901 (mapcar
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1902 (lambda (TAG)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1903 (mapcar
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1904 (lambda (TLIST)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1905 (if (string= file (car TLIST))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1906 (let* ((line (cadr TLIST) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1907 (chr (caddr TLIST) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1908 (link (format "%s.%d" TAG line) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1909 (put-text-property (+ 1 chr)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1910 (+ 2 chr)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1911 'hfy-anchor link))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1912 (gethash TAG cache-hash)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1913 (hfy-tags-for-file srcdir file)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1914
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1915 (defun hfy-relstub (file &optional start)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1916 "Return a \"../\" stub of the appropriate length for the current source
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1917 tree depth \(as determined from FILE \(a filename\)\).
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1918 START is the offset at which to start looking for the / character in FILE."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1919 ;;(message "hfy-relstub");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1920 (let ((c ""))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1921 (while (setq start (string-match "/" file start))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1922 (setq start (1+ start)) (setq c (concat c "../"))) c))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1923
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1924 (defun hfy-href-stub (this-file def-files tag)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1925 "Return an href stub for a tag href i THIS-FILE:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1926 If DEF-FILES \(list of files containing definitions for the tag in question\)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1927 contains only one entry, the href should link straight to that file.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1928 Otherwise, the link should be to the index file.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1929 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
|
1930 this point.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1931 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
|
1932 a source file, append a .X to `hfy-index-file', where X is the uppercased
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1933 first character of TAG.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1934 See also: `hfy-relstub', `hfy-index-file'`'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1935 ;;(message "hfy-href-stub");;DBUG
|
106128
|
1936 ;; FIXME: Why not use something like
|
|
1937 ;; (file-relative-name (if ...) (file-name-directory this-file)) ? --Stef
|
106126
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1938 (concat
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1939 (hfy-relstub this-file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1940 (if (= 1 (length def-files)) (car def-files)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1941 (if (not hfy-split-index) hfy-index-file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1942 (concat hfy-index-file "." (upcase (substring tag 0 1)))))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1943
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1944 (defun hfy-href (this-file def-files tag tag-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1945 "Return a relative href to the tag in question, based on\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1946 THIS-FILE `hfy-link-extn' `hfy-extn' DEF-FILES TAG and TAG-MAP\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1947 THIS-FILE is the current source file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1948 DEF-FILES is a list of file containing possible link endpoints for TAG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1949 TAG is the TAG in question
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1950 TAG-MAP is the entry in `hfy-tags-cache'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1951 ;;(message "hfy-href");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1952 (concat
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1953 (hfy-href-stub this-file def-files tag)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1954 (or hfy-link-extn hfy-extn) "#" tag ;;(.src -> .html)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1955 (if (= 1 (length def-files))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1956 (concat "." (format "%d" (cadr (assoc (car def-files) tag-map)))))) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1957
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1958 (defun hfy-word-regex (string)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1959 "Return a regex that matches STRING as the first `match-string', with non
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1960 word characters on either side."
|
106128
|
1961 ;; FIXME: Should this use [^$[:alnum:]_] instead? --Stef
|
106126
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1962 (concat "[^$A-Za-z_0-9]\\(" (regexp-quote string) "\\)[^A-Za-z_0-9]"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1963
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1964 ;; mark all tags for hyperlinking, except the tags at
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1965 ;; their own points of definition, iyswim:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1966 (defun hfy-mark-tag-hrefs (srcdir file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1967 "Mark href start points with the \'hfy-link prop \(value: href string\)\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1968 Mark href end points with the \'hfy-endl prop \(value t\)\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1969 Avoid overlapping links, and mark links in descending length of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1970 tag name in order to prevent subtags from usurping supertags,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1971 \(eg \"term\" for \"terminal\").
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1972 SRCDIR is the directory being \"published\".
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1973 FILE is the specific file we are rendering."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1974 ;;(message "hfy-mark-tag-hrefs");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1975 (let ((cache-entry (assoc srcdir hfy-tags-cache))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1976 (list-cache (assoc srcdir hfy-tags-sortl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1977 (rmap-cache (assoc srcdir hfy-tags-rmap ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1978 (no-comment (hfy-opt 'zap-comment-links))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1979 (no-strings (hfy-opt 'zap-string-links ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1980 (cache-hash nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1981 (tags-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1982 (tags-rmap nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1983 (case-fold-search nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1984 ;; extract the tag mapping hashes (fwd and rev) and the tag list:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1985 (if (and (setq cache-hash (cadr cache-entry))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1986 (setq tags-rmap (cadr rmap-cache ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1987 (setq tags-list (cadr list-cache )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1988 (mapcar
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1989 (lambda (TAG)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1990 (let* ((start nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1991 (stop nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1992 (href nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1993 (name nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1994 (case-fold-search nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1995 (tmp-point nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1996 (maybe-start nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1997 (face-at nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1998 (rmap-entry nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1999 (rnew-elt nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2000 (rmap-line nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2001 (tag-regex (hfy-word-regex TAG))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2002 (tag-map (gethash TAG cache-hash))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2003 (tag-files (mapcar (lambda (X) (car X)) tag-map)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2004 ;; find instances of TAG and do what needs to be done:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2005 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2006 (while (search-forward TAG nil 'NOERROR)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2007 (setq tmp-point (point)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2008 maybe-start (- (match-beginning 0) 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2009 (goto-char maybe-start)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2010 (if (not (looking-at tag-regex))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2011 nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2012 (setq start (match-beginning 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2013 (setq stop (match-end 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2014 (setq face-at
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2015 (and (or no-comment no-strings) (hfy-face-at start)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2016 (if (listp face-at)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2017 (setq face-at (cadr (memq :inherit face-at))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2018 (if (or (text-property-any start (1+ stop) 'hfy-linkp t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2019 (and no-comment (eq 'font-lock-comment-face face-at))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2020 (and no-strings (eq 'font-lock-string-face face-at)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2021 nil ;; already a link, NOOP
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2022
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2023 ;; set a reverse map entry:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2024 (setq rmap-line (line-number-at-pos)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2025 rmap-entry (gethash TAG tags-rmap)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2026 rnew-elt (list file rmap-line start)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2027 rmap-entry (cons rnew-elt rmap-entry)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2028 name (format "%s.%d" TAG rmap-line))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2029 (put-text-property start (1+ start) 'hfy-inst name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2030 (puthash TAG rmap-entry tags-rmap)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2031
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2032 ;; mark the link. link to index if the tag has > 1 def
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2033 ;; add the line number to the #name if it does not:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2034 (setq href (hfy-href file tag-files TAG tag-map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2035 (put-text-property start (1+ start) 'hfy-link href)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2036 (put-text-property stop (1+ stop ) 'hfy-endl t )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2037 (put-text-property start (1+ stop ) 'hfy-linkp t )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2038 (goto-char tmp-point)) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2039 tags-list) )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2040
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2041 (defun hfy-shell ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2042 "Return `shell-file-name', or \"/bin/sh\" if it is a non-bourne shell."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2043 (if (string-match "\\<bash\\>\\|\\<sh\\>\\|\\<dash\\>" shell-file-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2044 shell-file-name
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2045 (or hfy-shell-file-name "/bin/sh")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2046
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2047 ;; cache the #(tag => file line point) entries for files under srcdir
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2048 ;; and cache the descending sorted list of tags in the relevant alist,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2049 ;; also keyed by srcdir:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2050 (defun hfy-load-tags-cache (srcdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2051 "Run `hfy-etags-cmd' on SRCDIR, then call `hfy-parse-tags-buffer'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2052 ;;(message "hfy-load-tags-cache");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2053 (let ((etags-buffer (get-buffer-create "*hfy-tags*"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2054 (etags-command (format hfy-etags-cmd hfy-etags-bin))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2055 (shell-file-name (hfy-shell)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2056 (cd srcdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2057 (shell-command etags-command etags-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2058 (hfy-parse-tags-buffer srcdir etags-buffer)) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2059
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2060 ;; break this out from `hfy-load-tags-cache' to make the tar file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2061 ;; functionality easier to implement.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2062 ;; ( tar file functionality not merged here because it requires a
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2063 ;; hacked copy of etags capable of tagging stdin: if Francesco
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2064 ;; Potorti accepts a patch, or otherwise implements stdin tagging,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2065 ;; then I will provide a `htmlfontify-tar-file' defun )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2066 (defun hfy-parse-tags-buffer (srcdir buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2067 "Parse a BUFFER containing etags formatted output, loading the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2068 `hfy-tags-cache' and `hfy-tags-sortl' entries for SRCDIR."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2069 (let ((cache-entry (assoc srcdir hfy-tags-cache))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2070 (tlist-cache (assoc srcdir hfy-tags-sortl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2071 (trmap-cache (assoc srcdir hfy-tags-rmap ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2072 (cache-hash nil) (trmap-hash nil) (tags-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2073 (hash-entry nil) (tag-string nil) (tag-line nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2074 (tag-point nil) (new-entry nil) (etags-file nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2075
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2076 ;; (re)initialise the tag reverse map:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2077 (if trmap-cache (setq trmap-hash (cadr trmap-cache))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2078 (setq trmap-hash (make-hash-table :test 'equal))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2079 (setq hfy-tags-rmap (list (list srcdir trmap-hash) hfy-tags-rmap)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2080 (clrhash trmap-hash)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2081
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2082 ;; (re)initialise the tag cache:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2083 (if cache-entry (setq cache-hash (cadr cache-entry))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2084 (setq cache-hash (make-hash-table :test 'equal))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2085 (setq hfy-tags-cache (list (list srcdir cache-hash) hfy-tags-cache)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2086 (clrhash cache-hash)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2087
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2088 ;; cache the TAG => ((file line point) (file line point) ... ) entries:
|
106128
|
2089 (with-current-buffer buffer
|
106126
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2090 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2091
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2092 (while (and (looking-at "^\x0c") (= 0 (forward-line 1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2093 ;;(message "^L boundary")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2094 (if (and (looking-at "^\\(.+\\),\\([0-9]+\\)$")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2095 (= 0 (forward-line 1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2096 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2097 (setq etags-file (match-string 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2098 ;;(message "TAGS for file: %s" etags-file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2099 (while (and (looking-at hfy-etag-regex) (= 0 (forward-line 1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2100 (setq tag-string (match-string 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2101 (if (= 0 (length tag-string)) nil ;; noop
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2102 (setq tag-line (round (string-to-number (match-string 2))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2103 (setq tag-point (round (string-to-number (match-string 3))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2104 (setq hash-entry (gethash tag-string cache-hash))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2105 (setq new-entry (list etags-file tag-line tag-point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2106 (setq hash-entry (cons new-entry hash-entry))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2107 ;;(message "HASH-ENTRY %s %S" tag-string new-entry)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2108 (puthash tag-string hash-entry cache-hash)))) )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2109
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2110 ;; cache a list of tags in descending length order:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2111 (maphash (lambda (K V) (setq tags-list (cons K tags-list))) cache-hash)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2112 (setq tags-list (sort tags-list (lambda (A B) (< (length B) (length A)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2113
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2114 ;; put the tag list into the cache:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2115 (if tlist-cache (setcar (cdr tlist-cache) tags-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2116 (setq hfy-tags-sortl (cons (list srcdir tags-list) hfy-tags-sortl)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2117
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2118 ;; return the number of tags found:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2119 (length tags-list) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2120
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2121 (defun hfy-prepare-index-i (srcdir dstdir filename &optional stub map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2122 "Prepare a tags index buffer for SRCDIR.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2123 `hfy-tags-cache' must already have an entry for SRCDIR for this to work.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2124 `hfy-page-header', `hfy-page-footer', `hfy-link-extn' and `hfy-extn'
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2125 all play a part here.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2126 If STUB is set, prepare an \(appropriately named\) index buffer
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2127 specifically for entries beginning with STUB.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2128 If MAP is set, use that instead of `hfy-tags-cache'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2129 FILENAME is the name of the file being indexed.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2130 DSTDIR is the output directory, where files will be written."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2131 ;;(message "hfy-write-index");;DBUG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2132 (let ((cache-entry (assoc srcdir (or map hfy-tags-cache)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2133 (cache-hash nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2134 (tag-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2135 (index-file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2136 (concat filename (if stub (concat "." stub) "") hfy-extn))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2137 (index-buf nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2138 (if (not (and cache-entry
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2139 (setq cache-hash (cadr cache-entry))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2140 (setq index-buf (get-buffer-create index-file))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2141 nil ;; noop
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2142 (maphash (lambda (K V) (setq tag-list (cons K tag-list))) cache-hash)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2143 (setq tag-list (sort tag-list 'string<))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2144 (set-buffer index-buf)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2145 (erase-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2146 (insert (funcall hfy-page-header filename "<!-- CSS -->"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2147 (insert "<table class=\"index\">\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2148
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2149 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2150 (lambda (TAG)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2151 (let ((tag-started nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2152 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2153 (lambda (DEF)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2154 (if (and stub (not (string-match (concat "^" stub) TAG)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2155 nil ;; we have a stub and it didn't match: NOOP
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2156 (let ((file (car DEF))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2157 (line (cadr DEF)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2158 (insert
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2159 (format
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2160 (concat
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2161 " <tr> \n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2162 " <td>%s</td> \n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2163 " <td><a href=\"%s%s\">%s</a></td> \n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2164 " <td><a href=\"%s%s#%s.%d\">%d</a></td>\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2165 " </tr> \n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2166 (if (string= TAG tag-started) " "
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2167 (format "<a name=\"%s\">%s</a>" TAG TAG))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2168 file (or hfy-link-extn hfy-extn) file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2169 file (or hfy-link-extn hfy-extn) TAG line line))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2170 (setq tag-started TAG))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2171 (gethash TAG cache-hash)))) tag-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2172 (insert "</table>\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2173 (insert (funcall hfy-page-footer filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2174 (and dstdir (cd dstdir))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2175 (set-visited-file-name index-file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2176 index-buf) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2177
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2178 (defun hfy-prepare-index (srcdir dstdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2179 "Return a list of index buffer\(s\), as determined by `hfy-split-index'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2180 SRCDIR and DSTDIR are the source and output directories respectively."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2181 (if (not hfy-split-index)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2182 (list (hfy-prepare-index-i srcdir dstdir hfy-index-file nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2183 (let ((stub-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2184 (cache-hash nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2185 (index-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2186 (cache-entry (assoc srcdir hfy-tags-cache)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2187 (if (and cache-entry (setq cache-hash (cadr cache-entry)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2188 (maphash
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2189 (lambda (K V)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2190 (let ((stub (upcase (substring K 0 1))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2191 (if (member stub stub-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2192 nil ;; seen this already: NOOP
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2193 (setq
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2194 stub-list (cons stub stub-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2195 index-list (cons (hfy-prepare-index-i srcdir
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2196 dstdir
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2197 hfy-index-file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2198 stub)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2199 index-list)) ))) cache-hash) ) index-list)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2200
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2201 (defun hfy-prepare-tag-map (srcdir dstdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2202 "Prepare the counterpart\(s\) to the index buffer\(s\) - a list of buffers
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2203 with the same structure, but listing \( and linking to \) instances of tags
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2204 \( as opposed to their definitions \).\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2205 SRCDIR and DSTDIR are the source and output directories respectively.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2206 See: `hfy-prepare-index'
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2207 `hfy-split-index'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2208 (if (not hfy-split-index)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2209 (list (hfy-prepare-index-i srcdir
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2210 dstdir
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2211 hfy-instance-file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2212 nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2213 hfy-tags-rmap))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2214 (let ((stub-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2215 (cache-hash nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2216 (index-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2217 (cache-entry (assoc srcdir hfy-tags-rmap)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2218
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2219 (if (and cache-entry (setq cache-hash (cadr cache-entry)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2220 (maphash
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2221 (lambda (K V)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2222 (let ((stub (upcase (substring K 0 1))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2223 (if (member stub stub-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2224 nil ;; seen this already: NOOP
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2225 (setq
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2226 stub-list (cons stub stub-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2227 index-list (cons (hfy-prepare-index-i srcdir
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2228 dstdir
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2229 hfy-instance-file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2230 stub
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2231 hfy-tags-rmap)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2232 index-list)) ))) cache-hash) ) index-list)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2233
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2234 (defun hfy-subtract-maps (srcdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2235 "Internal function - strips definitions of tags from the instance map.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2236 SRCDIR is the directory being \"published\".
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2237 See: `hfy-tags-cache' and `hfy-tags-rmap'"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2238 (let ((new-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2239 (old-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2240 (def-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2241 (exc-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2242 (fwd-map (cadr (assoc srcdir hfy-tags-cache)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2243 (rev-map (cadr (assoc srcdir hfy-tags-rmap )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2244 (taglist (cadr (assoc srcdir hfy-tags-sortl))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2245 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2246 (lambda (TAG)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2247 (setq def-list (gethash TAG fwd-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2248 old-list (gethash TAG rev-map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2249 new-list nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2250 exc-list nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2251 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2252 (lambda (P)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2253 (setq exc-list (cons (list (car P) (cadr P)) exc-list))) def-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2254 (mapc
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2255 (lambda (P)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2256 (or (member (list (car P) (cadr P)) exc-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2257 (setq new-list (cons P new-list)))) old-list)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2258 (puthash TAG new-list rev-map)) taglist) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2259
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2260 (defun htmlfontify-run-etags (srcdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2261 "Load the etags cache for SRCDIR.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2262 See `hfy-load-tags-cache'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2263 (interactive "D source directory: ")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2264 (setq srcdir (directory-file-name srcdir))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2265 (hfy-load-tags-cache srcdir))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2266
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2267 ;;(defun hfy-test-read-args (foo bar)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2268 ;; (interactive "D source directory: \nD target directory: ")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2269 ;; (message "foo: %S\nbar: %S" foo bar))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2270
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2271 (defun hfy-save-kill-buffers (buffer-list &optional dstdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2272 (mapc (lambda (B)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2273 (set-buffer B)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2274 (and dstdir (file-directory-p dstdir) (cd dstdir))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2275 (save-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2276 (kill-buffer B)) buffer-list) )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2277
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2278 (defun htmlfontify-copy-and-link-dir (srcdir dstdir &optional f-ext l-ext)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2279 "Trawl SRCDIR and write fontified-and-hyperlinked output in DSTDIR.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2280 F-EXT and L-EXT specify values for `hfy-extn' and `hfy-link-extn'.\n
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2281 You may also want to set `hfy-page-header' and `hfy-page-footer'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2282 (interactive "D source directory: \nD output directory: ")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2283 ;;(message "htmlfontify-copy-and-link-dir")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2284 (setq srcdir (directory-file-name srcdir))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2285 (setq dstdir (directory-file-name dstdir))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2286 (let ((source-files "SETME: list of source files, relative to srcdir")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2287 (tr-cache (assoc srcdir hfy-tags-rmap))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2288 (hfy-extn (or f-ext ".html"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2289 (hfy-link-extn (or l-ext ".html")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2290 ;; oops, forgot to load etags for srcdir:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2291 (if tr-cache nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2292 (message "autoload of tags cache")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2293 (hfy-load-tags-cache srcdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2294 (setq tr-cache (assoc srcdir hfy-tags-rmap)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2295 ;; clear out the old cache:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2296 (clrhash (cadr tr-cache))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2297 (hfy-make-directory dstdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2298 (setq source-files (hfy-list-files srcdir))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2299 (mapc (lambda (file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2300 (hfy-copy-and-fontify-file srcdir dstdir file)) source-files)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2301 (hfy-subtract-maps srcdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2302 (hfy-save-kill-buffers (hfy-prepare-index srcdir dstdir) dstdir)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2303 (hfy-save-kill-buffers (hfy-prepare-tag-map srcdir dstdir) dstdir) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2304
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2305 ;; name of the init file we want:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2306 (defun hfy-initfile ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2307 "Return the expected location of the htmlfontify specific init/custom file."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2308 (let* ((file (or (getenv "HFY_INITFILE") ".hfy.el")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2309 (expand-file-name file "~") ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2310
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2311
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2313 ;; incomplete as yet : transfer hook settings to hfy init file:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2314 ;; (defalias 'hfy-set-hooks 'custom-set-variables)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2315
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2316 ;; (defun hfy-pp-hook (H)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2317 ;; (and (string-match "-hook$" (symbol-name H))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2318 ;; (boundp H)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2319 ;; (symbol-value H)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2320 ;; (insert (format "\n '(%S %S)" H (symbol-value H)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2321 ;; )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2322 ;; )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2323
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2324 ;; (defun hfy-save-hooks ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2325 ;; (let ((custom-file (hfy-initfile)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2326 ;; (custom-save-delete 'hfy-set-hooks)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2327 ;; (let ((standard-output (current-buffer)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2328 ;; (princ "(hfy-set-hooks\n;;auto-generated, only one copy allowed\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2329 ;; (mapatoms 'hfy-pp-hook)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2330 ;; (insert "\n)")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2331 ;; )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2332 ;; )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2333 ;; )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2335
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2336 (defalias 'hfy-init-progn 'progn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2337
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2338 (defun hfy-save-initvar (sym)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2339 (princ (format "(setq %s\n '" sym))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2340 (pp (symbol-value sym))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2341 (princ ")\n"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2342
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2343 (defun htmlfontify-save-initfile ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2344 "Save the htmlfontify settings to the htmlfontify init file."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2345 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2346 (let* ((start-pos nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2347 (custom-file (hfy-initfile))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2348 (standard-output (find-file-noselect custom-file 'nowarn)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2349 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2350 (custom-save-delete 'hfy-init-progn)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2351 (setq start-pos (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2352 (princ "(hfy-init-progn\n;;auto-generated, only one copy allowed\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2353 (mapc 'hfy-save-initvar
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2354 (list 'auto-mode-alist 'interpreter-mode-alist))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2355 (princ ")\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2356 (indent-region start-pos (point) nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2357 (custom-save-all) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2358
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2359 (defun htmlfontify-load-initfile ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2360 "Load the htmlfontify specific init/custom file."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2361 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2362 (let ((file (hfy-initfile)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2363 (load file 'NOERROR nil nil) ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2364
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2365 (provide 'htmlfontify)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2366 ;;; htmlfontify.el ends here
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2367
|