From e6908d75832dc3cbc8573119a5b32d9a66c90a6f Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Fri, 19 Aug 2011 01:50:23 +0530 Subject: [PATCH 6/6] htmlfontify.el: Add htmlfontify-string & fix a bug in fontification * contrib/lisp/htmlfontify.el (htmlfontify-string): New defun. (hfy-compile-face-map): Make sure that the last char in the buffer is correctly fontified. --- contrib/lisp/htmlfontify.el | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/contrib/lisp/htmlfontify.el b/contrib/lisp/htmlfontify.el index 6a4d62f..5b86d98 100755 --- a/contrib/lisp/htmlfontify.el +++ b/contrib/lisp/htmlfontify.el @@ -1448,7 +1448,7 @@ Returns a modified copy of FACE-MAP." (setq pt (next-char-property-change pt)) (setq pt-narrow (+ offset pt))) (if (and map (not (eq 'end (cdar map)))) - (push (cons (- (point-max) (point-min)) 'end) map))) + (push (cons (1+ (- (point-max) (point-min))) 'end) map))) (if (hfy-opt 'merge-adjacent-tags) (hfy-merge-adjacent-spans map) map))) (defun hfy-buffer () @@ -1792,6 +1792,21 @@ FILE, if set, is the file name." (set-buffer-modified-p nil) html-buffer)) +(defun htmlfontify-string (string) + "Take a STRING and return a fontified version of it. +It is assumed that STRING has text properties that allow it to be +fontified. This is a simple convenience wrapper around +`htmlfontify-buffer'." + (let* ((hfy-optimisations-1 (copy-list hfy-optimisations)) + (hfy-optimisations (add-to-list 'hfy-optimisations-1 + 'skip-refontification))) + (with-temp-buffer + (insert string) + (htmlfontify-buffer) + (prog1 (buffer-string) + (setq buffer-modified-p nil) + (kill-buffer))))) + (defun hfy-force-fontification () "Try to force font-locking even when it is optimized away." (run-hooks 'hfy-init-kludge-hook) -- 1.7.2.3