aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/hfy-cmap.el32
-rw-r--r--lisp/htmlfontify.el39
3 files changed, 42 insertions, 44 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ede4c72f6a4..c77d5c1ff4e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
12009-11-19 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * hfy-cmap.el (hfy-rgb-file): Use locate-file.
4 (htmlfontify-load-rgb-file): Remove unnused var `ff'.
5 Use with-current-buffer and string-to-number.
6 (hfy-fallback-colour-values): Use assoc-string.
7 * htmlfontify.el (hfy-face-to-css): Remove unused var `style'.
8 (hfy-face-at): Remove unused var `found-face'.
9 (hfy-compile-stylesheet): Remove unused var `css'.
10 (hfy-fontify-buffer): Remove unused vars `in-style', `invis-button',
11 and `orig-buffer'.
12 (hfy-buffer, hfy-copy-and-fontify-file, hfy-parse-tags-buffer):
13 Use with-current-buffer.
14 (hfy-text-p): Use expand-file-name and fewer setq.
15
12009-11-19 Vivek Dasmohapatra <vivek@etla.org> 162009-11-19 Vivek Dasmohapatra <vivek@etla.org>
2 17
3 * htmlfontify.el, hfy-cmap.el: New files. 18 * htmlfontify.el, hfy-cmap.el: New files.
diff --git a/lisp/hfy-cmap.el b/lisp/hfy-cmap.el
index 62d09899611..0327dec2a1c 100644
--- a/lisp/hfy-cmap.el
+++ b/lisp/hfy-cmap.el
@@ -798,12 +798,7 @@
798 798
799(defun hfy-rgb-file () 799(defun hfy-rgb-file ()
800 "Return a fully qualified path to the X11 style rgb.txt file." 800 "Return a fully qualified path to the X11 style rgb.txt file."
801 (catch 'rgb-file 801 (locate-file "rgb.txt" hfy-rgb-load-path))
802 (mapcar
803 (lambda (DIR)
804 (let ((rgb-file (concat DIR "/rgb.txt")))
805 (if (file-readable-p rgb-file)
806 (throw 'rgb-file rgb-file) nil)) ) hfy-rgb-load-path) nil))
807 802
808(defconst hfy-rgb-regex 803(defconst hfy-rgb-regex
809 "^\\s-*\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\(.+\\)\\s-*$") 804 "^\\s-*\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\(.+\\)\\s-*$")
@@ -818,36 +813,31 @@ Loads the variable `hfy-rgb-txt-colour-map', which is used by
818 (read-file-name "rgb.txt \(equivalent\) file: " "" nil t (hfy-rgb-file)))) 813 (read-file-name "rgb.txt \(equivalent\) file: " "" nil t (hfy-rgb-file))))
819 (let ((rgb-buffer nil) 814 (let ((rgb-buffer nil)
820 (end-of-rgb 0) 815 (end-of-rgb 0)
821 (rgb-txt nil) 816 (rgb-txt nil))
822 (ff 255.0))
823 (if (and (setq rgb-txt (or file (hfy-rgb-file))) 817 (if (and (setq rgb-txt (or file (hfy-rgb-file)))
824 (file-readable-p rgb-txt)) 818 (file-readable-p rgb-txt))
825 (save-excursion 819 (with-current-buffer
826 (setq rgb-buffer (find-file-noselect rgb-txt 'nowarn)) 820 (setq rgb-buffer (find-file-noselect rgb-txt 'nowarn))
827 (set-buffer rgb-buffer) 821 (goto-char (point-min))
828 (goto-char (point-min))
829 (htmlfontify-unload-rgb-file) 822 (htmlfontify-unload-rgb-file)
830 (while (/= end-of-rgb 1) 823 (while (/= end-of-rgb 1)
831 (if (looking-at hfy-rgb-regex) 824 (if (looking-at hfy-rgb-regex)
832 (setq hfy-rgb-txt-colour-map 825 (setq hfy-rgb-txt-colour-map
833 (cons (list (match-string 4) 826 (cons (list (match-string 4)
834 (string-to-int (match-string 1)) 827 (string-to-number (match-string 1))
835 (string-to-int (match-string 2)) 828 (string-to-number (match-string 2))
836 (string-to-int (match-string 3))) 829 (string-to-number (match-string 3)))
837 hfy-rgb-txt-colour-map)) ) 830 hfy-rgb-txt-colour-map)) )
838 (setq end-of-rgb (forward-line))) 831 (setq end-of-rgb (forward-line)))
839 (kill-buffer rgb-buffer)) 832 (kill-buffer rgb-buffer)))))
840 )
841 )
842 )
843 833
844(defun htmlfontify-unload-rgb-file () 834(defun htmlfontify-unload-rgb-file ()
845 (interactive) 835 (interactive)
846 (setq hfy-rgb-txt-colour-map nil)) 836 (setq hfy-rgb-txt-colour-map nil))
847 837
848(defun hfy-fallback-colour-values (colour-string) 838(defun hfy-fallback-colour-values (colour-string)
849 (cdr (assoc-ignore-case colour-string (or hfy-rgb-txt-colour-map 839 (cdr (assoc-string colour-string (or hfy-rgb-txt-colour-map
850 hfy-fallback-colour-map))) ) 840 hfy-fallback-colour-map))) )
851 841
852(provide 'hfy-cmap) 842(provide 'hfy-cmap)
853;;; hfy-cmap.el ends here 843;;; hfy-cmap.el ends here
diff --git a/lisp/htmlfontify.el b/lisp/htmlfontify.el
index 30695c44bc0..f60e7e87d47 100644
--- a/lisp/htmlfontify.el
+++ b/lisp/htmlfontify.el
@@ -813,6 +813,7 @@ regular specifiers."
813TAG is an Emacs font attribute key (eg :underline). 813TAG is an Emacs font attribute key (eg :underline).
814VAL is ignored." 814VAL is ignored."
815 (list 815 (list
816 ;; FIXME: Why not '("text-decoration" . "underline")? --Stef
816 (cond ((eq tag :underline ) (cons "text-decoration" "underline" )) 817 (cond ((eq tag :underline ) (cons "text-decoration" "underline" ))
817 ((eq tag :overline ) (cons "text-decoration" "overline" )) 818 ((eq tag :overline ) (cons "text-decoration" "overline" ))
818 ((eq tag :strike-through) (cons "text-decoration" "line-through"))))) 819 ((eq tag :strike-through) (cons "text-decoration" "line-through")))))
@@ -1085,7 +1086,6 @@ See also: `hfy-face-to-style'"
1085 ;;(message "hfy-face-to-css");;DBUG 1086 ;;(message "hfy-face-to-css");;DBUG
1086 (let ((css-list nil) 1087 (let ((css-list nil)
1087 (css-text nil) 1088 (css-text nil)
1088 (style nil)
1089 (seen nil)) 1089 (seen nil))
1090 ;;(message "(hfy-face-to-style %S)" fn) 1090 ;;(message "(hfy-face-to-style %S)" fn)
1091 (setq css-list (hfy-face-to-style fn)) 1091 (setq css-list (hfy-face-to-style fn))
@@ -1206,7 +1206,6 @@ return a defface style list of face properties instead of a face symbol."
1206 (face-name (hfy-p-to-face (text-properties-at p))) 1206 (face-name (hfy-p-to-face (text-properties-at p)))
1207 ;; (face-name (hfy-get-face-at p)) 1207 ;; (face-name (hfy-get-face-at p))
1208 (prop-seen nil) 1208 (prop-seen nil)
1209 (found-face nil)
1210 (extra-props nil) 1209 (extra-props nil)
1211 (text-props (text-properties-at p))) 1210 (text-props (text-properties-at p)))
1212 ;;(message "face-name: %S" face-name) 1211 ;;(message "face-name: %S" face-name)
@@ -1315,7 +1314,6 @@ return a defface style list of face properties instead of a face symbol."
1315 (t p))) 1314 (t p)))
1316 (if (memq p prop-seen) nil ;; noop 1315 (if (memq p prop-seen) nil ;; noop
1317 (setq prop-seen (cons p prop-seen) 1316 (setq prop-seen (cons p prop-seen)
1318 found-face t
1319 extra-props (cons p (cons v extra-props)))) )))))) 1317 extra-props (cons p (cons v extra-props)))) ))))))
1320 overlay-data) 1318 overlay-data)
1321 ;;(message "+ %d: %s; %S" p face-name extra-props) 1319 ;;(message "+ %d: %s; %S" p face-name extra-props)
@@ -1340,7 +1338,6 @@ The plists are returned in descending priority order."
1340 ;; Make the font stack stay: 1338 ;; Make the font stack stay:
1341 ;;(hfy-tmpfont-stack nil) 1339 ;;(hfy-tmpfont-stack nil)
1342 (fn nil) 1340 (fn nil)
1343 (css nil)
1344 (style nil)) 1341 (style nil))
1345 (save-excursion 1342 (save-excursion
1346 (goto-char pt) 1343 (goto-char pt)
@@ -1459,13 +1456,12 @@ Otherwise a plausible filename is constructed from `default-directory',
1459 (let* ((name (concat (buffer-name) hfy-extn)) 1456 (let* ((name (concat (buffer-name) hfy-extn))
1460 (src (buffer-file-name)) 1457 (src (buffer-file-name))
1461 (buf (get-buffer-create name))) 1458 (buf (get-buffer-create name)))
1462 (save-excursion 1459 (with-current-buffer buf
1463 (set-buffer buf) 1460 (setq buffer-file-name
1464 (if src (setq buffer-file-name (concat src hfy-extn)) 1461 (if src (concat src hfy-extn)
1465 (if (string-match "^.*/\\([^/]*\\)$" name) 1462 (expand-file-name (if (string-match "^.*/\\([^/]*\\)$" name)
1466 (setq buffer-file-name 1463 (match-string 1 name)
1467 (concat default-directory "/" (match-string 1 name))) 1464 name))))
1468 (setq buffer-file-name (concat default-directory "/" name) )))
1469 buf))) 1465 buf)))
1470 1466
1471(defun hfy-lookup (face style) 1467(defun hfy-lookup (face style)
@@ -1602,10 +1598,7 @@ Do not record undo information during evaluation of BODY."
1602SRCDIR, if set, is the directory being htmlfontified. 1598SRCDIR, if set, is the directory being htmlfontified.
1603FILE, if set, is the file name." 1599FILE, if set, is the file name."
1604 (if srcdir (setq srcdir (directory-file-name srcdir))) 1600 (if srcdir (setq srcdir (directory-file-name srcdir)))
1605 (let* ( (in-style nil) 1601 (let* ( (html-buffer (hfy-buffer))
1606 (invis-buttons nil)
1607 (orig-buffer (current-buffer))
1608 (html-buffer (hfy-buffer))
1609 (css-sheet nil) 1602 (css-sheet nil)
1610 (css-map nil) 1603 (css-map nil)
1611 (invis-ranges nil) 1604 (invis-ranges nil)
@@ -1848,9 +1841,8 @@ bombproof, but good enough in the context in which it is being used."
1848 1841
1849(defun hfy-text-p (srcdir file) 1842(defun hfy-text-p (srcdir file)
1850 "Is SRCDIR/FILE text? Uses `hfy-istext-command' to determine this." 1843 "Is SRCDIR/FILE text? Uses `hfy-istext-command' to determine this."
1851 (let (cmd rsp) 1844 (let* ((cmd (format hfy-istext-command (expand-file-name file srcdir)))
1852 (setq cmd (format hfy-istext-command (concat srcdir "/" file)) 1845 (rsp (shell-command-to-string cmd)))
1853 rsp (shell-command-to-string cmd))
1854 (if (string-match "text" rsp) t nil))) 1846 (if (string-match "text" rsp) t nil)))
1855 1847
1856;; open a file, check fontification, if fontified, write a fontified copy 1848;; open a file, check fontification, if fontified, write a fontified copy
@@ -1867,9 +1859,8 @@ adding an extension of `hfy-extn'. Fontification is actually done by
1867 (source nil) 1859 (source nil)
1868 (html nil)) 1860 (html nil))
1869 (cd srcdir) 1861 (cd srcdir)
1870 (save-excursion 1862 (with-current-buffer (setq source (find-file-noselect file))
1871 (setq source (find-file-noselect file)) 1863 ;; FIXME: Shouldn't this use expand-file-name? --Stef
1872 (set-buffer source)
1873 (setq target (concat dstdir "/" file)) 1864 (setq target (concat dstdir "/" file))
1874 (hfy-make-directory (hfy-dirname target)) 1865 (hfy-make-directory (hfy-dirname target))
1875 (if (not (hfy-opt 'skip-refontification)) (hfy-force-fontification)) 1866 (if (not (hfy-opt 'skip-refontification)) (hfy-force-fontification))
@@ -1942,6 +1933,8 @@ a source file, append a .X to `hfy-index-file', where X is the uppercased
1942first character of TAG.\n 1933first character of TAG.\n
1943See also: `hfy-relstub', `hfy-index-file'`'." 1934See also: `hfy-relstub', `hfy-index-file'`'."
1944 ;;(message "hfy-href-stub");;DBUG 1935 ;;(message "hfy-href-stub");;DBUG
1936 ;; FIXME: Why not use something like
1937 ;; (file-relative-name (if ...) (file-name-directory this-file)) ? --Stef
1945 (concat 1938 (concat
1946 (hfy-relstub this-file) 1939 (hfy-relstub this-file)
1947 (if (= 1 (length def-files)) (car def-files) 1940 (if (= 1 (length def-files)) (car def-files)
@@ -1965,6 +1958,7 @@ TAG-MAP is the entry in `hfy-tags-cache'."
1965(defun hfy-word-regex (string) 1958(defun hfy-word-regex (string)
1966 "Return a regex that matches STRING as the first `match-string', with non 1959 "Return a regex that matches STRING as the first `match-string', with non
1967word characters on either side." 1960word characters on either side."
1961 ;; FIXME: Should this use [^$[:alnum:]_] instead? --Stef
1968 (concat "[^$A-Za-z_0-9]\\(" (regexp-quote string) "\\)[^A-Za-z_0-9]")) 1962 (concat "[^$A-Za-z_0-9]\\(" (regexp-quote string) "\\)[^A-Za-z_0-9]"))
1969 1963
1970;; mark all tags for hyperlinking, except the tags at 1964;; mark all tags for hyperlinking, except the tags at
@@ -2092,8 +2086,7 @@ FILE is the specific file we are rendering."
2092 (clrhash cache-hash) 2086 (clrhash cache-hash)
2093 2087
2094 ;; cache the TAG => ((file line point) (file line point) ... ) entries: 2088 ;; cache the TAG => ((file line point) (file line point) ... ) entries:
2095 (save-excursion 2089 (with-current-buffer buffer
2096 (set-buffer buffer)
2097 (goto-char (point-min)) 2090 (goto-char (point-min))
2098 2091
2099 (while (and (looking-at "^\x0c") (= 0 (forward-line 1))) 2092 (while (and (looking-at "^\x0c") (= 0 (forward-line 1)))