+2009-11-19 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * hfy-cmap.el (hfy-rgb-file): Use locate-file.
+ (htmlfontify-load-rgb-file): Remove unnused var `ff'.
+ Use with-current-buffer and string-to-number.
+ (hfy-fallback-colour-values): Use assoc-string.
+ * htmlfontify.el (hfy-face-to-css): Remove unused var `style'.
+ (hfy-face-at): Remove unused var `found-face'.
+ (hfy-compile-stylesheet): Remove unused var `css'.
+ (hfy-fontify-buffer): Remove unused vars `in-style', `invis-button',
+ and `orig-buffer'.
+ (hfy-buffer, hfy-copy-and-fontify-file, hfy-parse-tags-buffer):
+ Use with-current-buffer.
+ (hfy-text-p): Use expand-file-name and fewer setq.
+
2009-11-19 Vivek Dasmohapatra <vivek@etla.org>
* htmlfontify.el, hfy-cmap.el: New files.
(defun hfy-rgb-file ()
"Return a fully qualified path to the X11 style rgb.txt file."
- (catch 'rgb-file
- (mapcar
- (lambda (DIR)
- (let ((rgb-file (concat DIR "/rgb.txt")))
- (if (file-readable-p rgb-file)
- (throw 'rgb-file rgb-file) nil)) ) hfy-rgb-load-path) nil))
+ (locate-file "rgb.txt" hfy-rgb-load-path))
(defconst hfy-rgb-regex
"^\\s-*\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\(.+\\)\\s-*$")
(read-file-name "rgb.txt \(equivalent\) file: " "" nil t (hfy-rgb-file))))
(let ((rgb-buffer nil)
(end-of-rgb 0)
- (rgb-txt nil)
- (ff 255.0))
+ (rgb-txt nil))
(if (and (setq rgb-txt (or file (hfy-rgb-file)))
(file-readable-p rgb-txt))
- (save-excursion
- (setq rgb-buffer (find-file-noselect rgb-txt 'nowarn))
- (set-buffer rgb-buffer)
- (goto-char (point-min))
+ (with-current-buffer
+ (setq rgb-buffer (find-file-noselect rgb-txt 'nowarn))
+ (goto-char (point-min))
(htmlfontify-unload-rgb-file)
(while (/= end-of-rgb 1)
(if (looking-at hfy-rgb-regex)
(setq hfy-rgb-txt-colour-map
(cons (list (match-string 4)
- (string-to-int (match-string 1))
- (string-to-int (match-string 2))
- (string-to-int (match-string 3)))
+ (string-to-number (match-string 1))
+ (string-to-number (match-string 2))
+ (string-to-number (match-string 3)))
hfy-rgb-txt-colour-map)) )
(setq end-of-rgb (forward-line)))
- (kill-buffer rgb-buffer))
- )
- )
- )
+ (kill-buffer rgb-buffer)))))
(defun htmlfontify-unload-rgb-file ()
(interactive)
(setq hfy-rgb-txt-colour-map nil))
(defun hfy-fallback-colour-values (colour-string)
- (cdr (assoc-ignore-case colour-string (or hfy-rgb-txt-colour-map
- hfy-fallback-colour-map))) )
+ (cdr (assoc-string colour-string (or hfy-rgb-txt-colour-map
+ hfy-fallback-colour-map))) )
(provide 'hfy-cmap)
;;; hfy-cmap.el ends here
TAG is an Emacs font attribute key (eg :underline).
VAL is ignored."
(list
+ ;; FIXME: Why not '("text-decoration" . "underline")? --Stef
(cond ((eq tag :underline ) (cons "text-decoration" "underline" ))
((eq tag :overline ) (cons "text-decoration" "overline" ))
((eq tag :strike-through) (cons "text-decoration" "line-through")))))
;;(message "hfy-face-to-css");;DBUG
(let ((css-list nil)
(css-text nil)
- (style nil)
(seen nil))
;;(message "(hfy-face-to-style %S)" fn)
(setq css-list (hfy-face-to-style fn))
(face-name (hfy-p-to-face (text-properties-at p)))
;; (face-name (hfy-get-face-at p))
(prop-seen nil)
- (found-face nil)
(extra-props nil)
(text-props (text-properties-at p)))
;;(message "face-name: %S" face-name)
(t p)))
(if (memq p prop-seen) nil ;; noop
(setq prop-seen (cons p prop-seen)
- found-face t
extra-props (cons p (cons v extra-props)))) ))))))
overlay-data)
;;(message "+ %d: %s; %S" p face-name extra-props)
;; Make the font stack stay:
;;(hfy-tmpfont-stack nil)
(fn nil)
- (css nil)
(style nil))
(save-excursion
(goto-char pt)
(let* ((name (concat (buffer-name) hfy-extn))
(src (buffer-file-name))
(buf (get-buffer-create name)))
- (save-excursion
- (set-buffer buf)
- (if src (setq buffer-file-name (concat src hfy-extn))
- (if (string-match "^.*/\\([^/]*\\)$" name)
- (setq buffer-file-name
- (concat default-directory "/" (match-string 1 name)))
- (setq buffer-file-name (concat default-directory "/" name) )))
+ (with-current-buffer buf
+ (setq buffer-file-name
+ (if src (concat src hfy-extn)
+ (expand-file-name (if (string-match "^.*/\\([^/]*\\)$" name)
+ (match-string 1 name)
+ name))))
buf)))
(defun hfy-lookup (face style)
SRCDIR, if set, is the directory being htmlfontified.
FILE, if set, is the file name."
(if srcdir (setq srcdir (directory-file-name srcdir)))
- (let* ( (in-style nil)
- (invis-buttons nil)
- (orig-buffer (current-buffer))
- (html-buffer (hfy-buffer))
+ (let* ( (html-buffer (hfy-buffer))
(css-sheet nil)
(css-map nil)
(invis-ranges nil)
(defun hfy-text-p (srcdir file)
"Is SRCDIR/FILE text? Uses `hfy-istext-command' to determine this."
- (let (cmd rsp)
- (setq cmd (format hfy-istext-command (concat srcdir "/" file))
- rsp (shell-command-to-string cmd))
+ (let* ((cmd (format hfy-istext-command (expand-file-name file srcdir)))
+ (rsp (shell-command-to-string cmd)))
(if (string-match "text" rsp) t nil)))
;; open a file, check fontification, if fontified, write a fontified copy
(source nil)
(html nil))
(cd srcdir)
- (save-excursion
- (setq source (find-file-noselect file))
- (set-buffer source)
+ (with-current-buffer (setq source (find-file-noselect file))
+ ;; FIXME: Shouldn't this use expand-file-name? --Stef
(setq target (concat dstdir "/" file))
(hfy-make-directory (hfy-dirname target))
(if (not (hfy-opt 'skip-refontification)) (hfy-force-fontification))
first character of TAG.\n
See also: `hfy-relstub', `hfy-index-file'`'."
;;(message "hfy-href-stub");;DBUG
+ ;; FIXME: Why not use something like
+ ;; (file-relative-name (if ...) (file-name-directory this-file)) ? --Stef
(concat
(hfy-relstub this-file)
(if (= 1 (length def-files)) (car def-files)
(defun hfy-word-regex (string)
"Return a regex that matches STRING as the first `match-string', with non
word characters on either side."
+ ;; FIXME: Should this use [^$[:alnum:]_] instead? --Stef
(concat "[^$A-Za-z_0-9]\\(" (regexp-quote string) "\\)[^A-Za-z_0-9]"))
;; mark all tags for hyperlinking, except the tags at
(clrhash cache-hash)
;; cache the TAG => ((file line point) (file line point) ... ) entries:
- (save-excursion
- (set-buffer buffer)
+ (with-current-buffer buffer
(goto-char (point-min))
(while (and (looking-at "^\x0c") (= 0 (forward-line 1)))