User: viteno
Date: 05/11/02 08:02:18
Modified: packages/xemacs-packages/text-modes ChangeLog htmlize.el
Log:
Sync savehist and htmlize with upstream.
Revision Changes Path
1.206 +4 -0 XEmacs/packages/xemacs-packages/edit-utils/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/edit-utils/ChangeLog,v
retrieving revision 1.205
retrieving revision 1.206
diff -u -p -r1.205 -r1.206
--- ChangeLog 2005/10/16 17:19:17 1.205
+++ ChangeLog 2005/11/02 07:02:13 1.206
@@ -1,3 +1,7 @@
+2005-11-02 Norbert Koch <viteno(a)xemacs.org>
+
+ * savehist.el: Sync with upstream version 22.
+
2005-10-16 Norbert Koch <viteno(a)xemacs.org>
* Makefile (VERSION): XEmacs package 2.26 released.
1.3 +319 -153 XEmacs/packages/xemacs-packages/edit-utils/savehist.el
Index: savehist.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/edit-utils/savehist.el,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -p -r1.2 -r1.3
--- savehist.el 1999/11/27 20:49:59 1.2
+++ savehist.el 2005/11/02 07:02:14 1.3
@@ -1,57 +1,56 @@
-;;; savehist.el --- Save minibuffer history
+;;; savehist.el --- Save minibuffer history.
-;; Copyright (c) 1997 Free Software Foundation
+;; Copyright (C) 1997,2005 Free Software Foundation
;; Author: Hrvoje Niksic <hniksic(a)xemacs.org>
;; Keywords: minibuffer
-;; Version: 0.4
+;; Version: 22
-;; This file is part of XEmacs.
+;; This file is part of GNU Emacs.
-;; XEmacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
-;; XEmacs is distributed in the hope that it will be useful,
+;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with XEmacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
-;;; Synched up with: not in FSF
-
;;; Commentary:
;; Many editors (e.g. Vim) have the feature of saving minibuffer
;; history to an external file after exit. This package provides the
-;; same feature in Emacs. When Emacs is about the exit,
-;; `savehist-save' will dump the contents of various minibuffer
-;; histories (as determined by `savehist-history-variables') to a save
-;; file (`~/.emacs-history' by default). Although the package was
-;; designed for saving the minibuffer histories, any variables can be
-;; saved that way.
+;; same feature in Emacs. When set up, it saves recorded minibuffer
+;; histories to a file (`~/.emacs-history' by default). Additional
+;; variables may be specified by customizing
+;; `savehist-additional-variables'.
-;; To use savehist, put the following to `~/.emacs':
+;; To use savehist, turn on savehist-mode by putting the following in
+;; `~/.emacs':
;;
-;; (require 'savehist)
-;; (savehist-load)
-
-;; Be sure to have `savehist.el' in a directory that is in your
-;; load-path, and byte-compile it.
+;; (savehist-mode 1)
+;;
+;; or with customize: `M-x customize-option RET savehist-mode RET'.
+;;
+;; You can also explicitly save history with `M-x savehist-save' and
+;; load it by loading the `savehist-file' with `M-x load-file'.
-;; This code should work on XEmacs 19.14 and later, as well as GNU
-;; Emacs 19.34 and later. It requires the Customize library, however
-;; (shipped with XEmacs 19.15 and later, and with GNU Emacs 20.x).
+;; If you are using a version of Emacs that does not ship with this
+;; package, be sure to have `savehist.el' in a directory that is in
+;; your load-path, and to byte-compile it.
-
;;; Code:
(require 'custom)
+(eval-when-compile
+ (require 'cl))
;; User variables
@@ -59,147 +58,314 @@
"Save minibuffer history."
:group 'minibuffer)
+;;;###autoload
+(defcustom savehist-mode nil
+ "Mode for automatic saving of minibuffer history.
+Set this by calling the `savehist-mode' function or using the customize
+interface."
+ :type 'boolean
+ :set (lambda (symbol value) (savehist-mode (or value 0)))
+ :initialize 'custom-initialize-default
+ :require 'savehist
+ :group 'savehist)
-(defcustom savehist-history-variables
- '(
- ;; Catch-all minibuffer history
- minibuffer-history
- ;; File-oriented commands
- file-name-history
- ;; Regexp-related reads
- regexp-history
- ;; Searches in minibuffer (via `M-r' and such)
- minibuffer-history-search-history
- ;; Query replace
- query-replace-history
- ;; eval-expression (`M-:')
- read-expression-history
- ;; shell-command (`M-!')
- shell-command-history
- ;; compile
- compile-history
- ;; find-tag (`M-.')
- find-tag-history
- ;; grep
- grep-history
- ;; Viper stuff
- vip-ex-history vip-search-history
- vip-replace1-history vip-replace2-history
- vip-shell-history vip-search-history
-
- ;; XEmacs-specific:
- ;; Buffer-related commands
- buffer-history
- ;; Reads of variables and functions
- variable-history function-history
- ;; Extended commands
- read-command-history
-
- ;; Info, lookup, and bookmark historys
- Info-minibuffer-history
- Manual-page-minibuffer-history
-
- ;; GNU Emacs-specific:
- ;; Extended commands
- extended-command-history)
- "*List of symbols to be saved.
-Every symbol should refer to a variable. The variable will be saved
-only if it is bound and has a non-nil value. Thus it is safe to
-specify a superset of the variables a user is expected to want to
-save.
-
-Default value contains minibuffer history variables used by XEmacs, GNU
-Emacs and Viper (uh-oh)."
- :type '(repeat (symbol :tag "Variable"))
- :group 'savehist)
-
-(defcustom savehist-file "~/.emacs-history"
- "*File name to save minibuffer history to.
-The minibuffer history is a series of Lisp expressions, which should be
-loaded using `savehist-load' from your .emacs. See `savehist-load' for
-more details."
- :type 'file
+(defcustom savehist-save-minibuffer-history t
+ "*If non-nil, save all recorded minibuffer histories.
+If you want to save only specific histories, use `savehist-save-hook' to
+modify the value of `savehist-minibuffer-history-variables'."
+ :type 'boolean
:group 'savehist)
-(defcustom savehist-length 100
- "*Maximum length of a minibuffer list.
-If set to nil, the length is unlimited."
- :type '(choice integer
- (const :tag "Unlimited" nil))
+(defcustom savehist-additional-variables ()
+ "*List of additional variables to save.
+Each element is a symbol whose value will be persisted across Emacs
+sessions that use savehist. The contents of variables should be
+printable with the Lisp printer. You don't need to add minibuffer
+history variables to this list, all minibuffer histories will be
+saved automatically as long as `savehist-save-minibuffer-history' is
+non-nil.
+
+User options should be saved with the customize interface. This
+list is useful for saving automatically updated variables that are not
+minibuffer histories, such as `compile-command' or `kill-ring'."
+ :type '(repeat variable)
:group 'savehist)
-(defcustom savehist-modes 384
+(defcustom savehist-file
+ (cond
+ ;; Backward compatibility with previous versions of savehist.
+ ((file-exists-p "~/.emacs-history") "~/.emacs-history")
+ ((and (not (featurep 'xemacs)) (file-directory-p "~/.emacs.d/"))
+ "~/.emacs.d/history")
+ ((and (featurep 'xemacs) (file-directory-p "~/.xemacs/"))
+ "~/.xemacs/history")
+ ;; For users without `~/.emacs.d/' or `~/.xemacs/'.
+ (t "~/.emacs-history"))
+ "*File name where minibuffer history is saved to and loaded from.
+The minibuffer history is a series of Lisp expressions loaded
+automatically when `savehist-mode' is turned on. See `savehist-mode'
+for more details.
+
+If you want your minibuffer history shared between Emacs and XEmacs,
+customize this value and make sure that `savehist-coding-system' is
+set to a coding system that exists in both emacsen."
+ :type 'file
+ :group 'savehist)
+
+(defcustom savehist-file-modes #o600
"*Default permissions of the history file.
-This is decimal, not octal. The default is 384 (0600 in octal)."
+This is decimal, not octal. The default is 384 (0600 in octal).
+Set to nil to use the default permissions that Emacs uses, typically
+mandated by umask. The default is a bit more restrictive to protect
+the user's privacy."
:type 'integer
:group 'savehist)
+(defcustom savehist-autosave-interval (* 5 60)
+ "*The interval between autosaves of minibuffer history.
+If set to nil, disables timer-based autosaving."
+ :type 'integer
+ :group 'savehist)
+
+(defcustom savehist-save-hook nil
+ "Hook called by `savehist-save' before saving the variables.
+You can use this hook to influence choice and content of variables to
+save."
+ :type 'hook)
+
+;; This should be capable of representing characters used by Emacs.
+;; We prefer UTF-8 over ISO 2022 because it is well-known outside
+;; Mule. XEmacs prir to 21.5 had UTF-8 provided by an external
+;; package which may not be loaded, which is why we check for version.
+(defvar savehist-coding-system (if (and (featurep 'xemacs)
+ (< emacs-major-version 21) (< emacs-minor-version 5))
+ 'iso-2022-8 'utf-8)
+ "The coding system savehist uses for saving the minibuffer history.
+Changing this value while Emacs is running is supported, but considered
+unwise, unless you know what you are doing.")
+
+;; Internal variables.
+
+(defvar savehist-timer nil)
+
+(defvar savehist-last-checksum nil)
+
+(defvar savehist-minibuffer-history-variables nil
+ "List of minibuffer histories.
+The contents of this variable is built while Emacs is running, and saved
+along with minibuffer history. You can change its value off
+`savehist-save-hook' to influence which variables are saved.")
+
+;; Coding system without any conversion, used for calculating an
+;; internal checksum. Should be as fast as possible, ideally simply
+;; exposing the internal representation of buffer text.
+(defconst savehist-no-conversion (if (featurep 'xemacs) 'binary
'no-conversion))
+
+;; Whether the history has already been loaded. This prevents
+;; toggling savehist-mode from destroying existing minibuffer history.
+(defvar savehist-loaded nil)
+
+(when (featurep 'xemacs)
+ ;; Must declare this under XEmacs, which doesn't have built-in
+ ;; minibuffer history truncation.
+ (defvar history-length 100))
-;; Functions
+;; Functions.
;;;###autoload
-(defun savehist-load (&optional no-hook)
- "Load the minibuffer histories from `savehist-file'.
-Unless NO-HOOK is specified, the function will also add the save function
-to `kill-emacs-hook', thus ensuring that the minibuffer contents will be
-saved before leaving Emacs.
-
-This function should be normally used from your Emacs init file. Since it
-removes your current minibuffer histories, it is unwise to call it at any
-other time."
+(defun savehist-mode (arg)
+ "Toggle savehist-mode.
+Positive ARG turns on `savehist-mode'. When on, savehist-mode causes
+minibuffer history to be saved periodically and when exiting Emacs.
+When turned on for the first time in an Emacs session, it causes the
+previous minibuffer history to be loaded from `savehist-file'.
+
+This mode should normally be turned on from your Emacs init file.
+Calling it at any other time replaces your current minibuffer histories,
+which is probably undesirable."
(interactive "P")
- (unless no-hook
- (add-hook 'kill-emacs-hook 'savehist-save))
- (load savehist-file t))
-
-;;;###autoload
-(defun savehist-save ()
- "Save the histories from `savehist-history-variables' to
`savehist-file'.
-A variable will be saved if it is bound and non-nil."
- (interactive)
- (save-excursion
- ;; Is it wise to junk `find-file-hooks' just like that? How else
- ;; should I avoid font-lock et al.?
- (let ((find-file-hooks nil)
- (buffer-exists-p (get-file-buffer savehist-file)))
- (set-buffer (find-file-noselect savehist-file))
- (unwind-protect
+ (setq savehist-mode
+ (if (null arg)
+ (not savehist-mode)
+ (> (prefix-numeric-value arg) 0)))
+ (if (not savehist-mode)
+ (savehist-uninstall)
+ (when (and (not savehist-loaded)
+ (file-exists-p savehist-file))
+ (condition-case errvar
(progn
- (erase-buffer)
- (insert
- ";; -*- emacs-lisp -*-\n"
- ";; Minibuffer history file.\n\n"
- ";; This file is automatically generated by `savehist-save'"
- " or when\n"
- ";; exiting Emacs.\n"
- ";; Do not edit. Unless you really want to, that is.\n\n")
- (let ((print-length nil)
- (print-string-length nil)
- (print-level nil)
- (print-readably t))
- (dolist (sym savehist-history-variables)
- (when (and (boundp sym)
- (symbol-value sym))
- (prin1
- `(setq ,sym (quote ,(savehist-delimit (symbol-value sym)
- savehist-length)))
- (current-buffer))
- (insert ?\n))))
- (save-buffer)
- (set-file-modes savehist-file savehist-modes))
- (or buffer-exists-p
- (kill-buffer (current-buffer)))))))
-
-;; If ARG is a list with less than N elements, return it, else return
-;; its subsequence of N elements. If N is nil or ARG is not a list,
-;; always return ARG.
-(defun savehist-delimit (arg n)
- (if (and n
- (listp arg)
- (> (length arg) n))
- (subseq arg 0 n)
- arg))
+ ;; Don't set coding-system-for-read -- we rely on the
+ ;; coding cookie to convey that information. That way, if
+ ;; the user changes the value of savehist-coding-system,
+ ;; we can still correctly load the old file.
+ (load savehist-file nil (not (interactive-p)))
+ (setq savehist-loaded t))
+ (error
+ ;; Don't install the mode if reading failed. Doing so would
+ ;; effectively destroy the user's data at the next save.
+ (setq savehist-mode nil)
+ (savehist-uninstall)
+ (signal (car errvar) (cdr errvar)))))
+ (savehist-install))
+ ;; Return the new setting.
+ savehist-mode)
+(add-minor-mode 'savehist-mode "")
+
+(defun savehist-load ()
+ "Obsolete function provided for transition from old versions of savehist.
+Don't call this from new code, use (savehist-mode 1) instead.
+
+This function loads the variables stored in `savehist-file' and turns on
+savehist-mode. If savehist-file is in the old format that doesn't record
+the value of `savehist-minibuffer-history-variables', that value is
+deducted from the contents of the file."
+ (savehist-mode 1)
+ ;; Old versions of savehist distributed with XEmacs didn't save
+ ;; savehist-minibuffer-history-variables. If that variable is nil
+ ;; after loading the file, try to intuit the intended value.
+ (when (null savehist-minibuffer-history-variables)
+ (setq savehist-minibuffer-history-variables
+ (with-temp-buffer
+ (ignore-errors
+ (insert-file-contents savehist-file))
+ (let ((vars ()) form)
+ (while (setq form (condition-case nil
+ (read (current-buffer)) (error nil)))
+ ;; Each form read is of the form (setq VAR VALUE).
+ ;; Collect VAR, i.e. (nth form 1).
+ (push (nth 1 form) vars))
+ vars)))))
+(make-obsolete 'savehist-load 'savehist-mode)
+
+(defun savehist-install ()
+ "Hook savehist into Emacs.
+Normally invoked by calling `savehist-mode' to set the minor mode.
+Installs `savehist-autosave' in `kill-emacs-hook' and on a timer. To
+undo this, call `savehist-uninstall'."
+ (add-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook)
+ (add-hook 'kill-emacs-hook 'savehist-autosave)
+ ;; Install an invocation of savehist-autosave on a timer. This
+ ;; should not cause noticeable delays for users -- savehist-autosave
+ ;; executes in under 5 ms on my system.
+ (when (and savehist-autosave-interval
+ (null savehist-timer))
+ (setq savehist-timer
+ (if (featurep 'xemacs)
+ (start-itimer
+ "savehist" 'savehist-autosave savehist-autosave-interval
+ savehist-autosave-interval)
+ (run-with-timer savehist-autosave-interval
+ savehist-autosave-interval 'savehist-autosave)))))
+
+(defun savehist-uninstall ()
+ "Undo installing savehist.
+Normally invoked by calling `savehist-mode' to unset the minor mode."
+ (remove-hook 'minibuffer-setup-hook 'savehist-minibuffer-hook)
+ (remove-hook 'kill-emacs-hook 'savehist-autosave)
+ (when savehist-timer
+ (if (featurep 'xemacs)
+ (delete-itimer savehist-timer)
+ (cancel-timer savehist-timer))
+ (setq savehist-timer nil)))
+
+(defun savehist-save (&optional auto-save)
+ "Save the values of minibuffer history variables.
+Unbound symbols referenced in `savehist-additional-variables' are ignored.
+If AUTO-SAVE is non-nil, compare the saved contents to the one last saved,
+ and don't save the buffer if they are the same."
+ (interactive)
+ (with-temp-buffer
+ (insert
+ (format ";; -*- mode: emacs-lisp; coding: %s -*-\n"
savehist-coding-system)
+ ";; Minibuffer history file, automatically generated by
`savehist'.\n\n")
+ (run-hooks 'savehist-save-hook)
+ (let ((print-length nil)
+ (print-string-length nil)
+ (print-level nil)
+ (print-readably t)
+ (print-quoted t))
+ ;; Save the minibuffer histories, along with the value of
+ ;; savehist-minibuffer-history-variables itself.
+ (when savehist-save-minibuffer-history
+ (prin1 `(setq savehist-minibuffer-history-variables
+ ',savehist-minibuffer-history-variables)
+ (current-buffer))
+ (insert ?\n)
+ (dolist (symbol savehist-minibuffer-history-variables)
+ (when (boundp symbol)
+ (let ((value (savehist-trim-history (symbol-value symbol))))
+ (when value ; don't save empty histories
+ (prin1 `(setq ,symbol ',value) (current-buffer))
+ (insert ?\n))))))
+ ;; Save the additional variables.
+ (dolist (symbol savehist-additional-variables)
+ (when (boundp symbol)
+ (let ((value (symbol-value symbol)))
+ (when (savehist-printable value)
+ (prin1 `(setq ,symbol ',value) (current-buffer))
+ (insert ?\n))))))
+ ;; If autosaving, avoid writing if nothing has changed since the
+ ;; last write.
+ (let ((checksum (md5 (current-buffer) nil nil savehist-no-conversion)))
+ (unless (and auto-save (equal checksum savehist-last-checksum))
+ ;; Set file-precious-flag when saving the buffer because we
+ ;; don't want a half-finished write ruining the entire
+ ;; history. Remember that this is run from a timer and from
+ ;; kill-emacs-hook, and also that multiple Emacs instances
+ ;; could write to this file at once.
+ (let ((file-precious-flag t)
+ (coding-system-for-write savehist-coding-system))
+ (write-region (point-min) (point-max) savehist-file nil
+ (unless (interactive-p) 'quiet)))
+ (when savehist-file-modes
+ (set-file-modes savehist-file savehist-file-modes))
+ (setq savehist-last-checksum checksum)))))
+
+(defun savehist-autosave ()
+ "Save the minibuffer history if it has been modified since the last save.
+Does nothing if savehist-mode is off."
+ (when savehist-mode
+ (savehist-save t)))
+
+(defun savehist-trim-history (value)
+ ;; Retain only the first history-length items in VALUE. Only used
+ ;; under XEmacs, which doesn't (yet) implement automatic trimming of
+ ;; history lists to history-length items.
+ (if (and (featurep 'xemacs)
+ (natnump history-length)
+ (> (length value) history-length))
+ ;; Equivalent to `(subseq value 0 history-length)', but doesn't
+ ;; need cl-extra at run-time.
+ (loop repeat history-length collect (pop value))
+ value))
+
+(defun savehist-printable (value)
+ "Return non-nil if VALUE is printable."
+ (cond
+ ;; Quick response for oft-encountered types known to be printable.
+ ((stringp value))
+ ((numberp value))
+ ((symbolp value))
+ (t
+ ;; For others, check explicitly.
+ (with-temp-buffer
+ (condition-case nil
+ (let ((print-readably t) (print-level nil))
+ ;; Print the value into a buffer...
+ (prin1 value (current-buffer))
+ ;; ...and attempt to read it.
+ (read (point-min-marker))
+ ;; The attempt worked: the object is printable.
+ t)
+ ;; The attempt failed: the object is not printable.
+ (error nil))))))
+
+(defun savehist-minibuffer-hook ()
+ (add-to-list 'savehist-minibuffer-history-variables
+ minibuffer-history-variable))
(provide 'savehist)
+
+;; arch-tag: b3ce47f4-c5ad-4ebc-ad02-73aba705cf9f
;;; savehist.el ends here
1.158 +4 -0 XEmacs/packages/xemacs-packages/text-modes/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/text-modes/ChangeLog,v
retrieving revision 1.157
retrieving revision 1.158
diff -u -p -r1.157 -r1.158
--- ChangeLog 2005/09/21 07:15:44 1.157
+++ ChangeLog 2005/11/02 07:02:17 1.158
@@ -1,3 +1,7 @@
+2005-11-02 Norbert Koch <viteno(a)xemacs.org>
+
+ * htmlize.el: Sync with upstream version 1.28.
+
2005-09-21 Norbert Koch <viteno(a)xemacs.org>
* Makefile (VERSION): XEmacs package 1.89 released.
1.14 +154 -37 XEmacs/packages/xemacs-packages/text-modes/htmlize.el
Index: htmlize.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/text-modes/htmlize.el,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -p -r1.13 -r1.14
--- htmlize.el 2003/11/18 16:31:00 1.13
+++ htmlize.el 2005/11/02 07:02:17 1.14
@@ -1,6 +1,6 @@
;; htmlize.el -- Convert buffer text and decorations to HTML.
-;; Copyright (C) 1997,1998,1999,2000,2001,2002,2003 Hrvoje Niksic
+;; Copyright (C) 1997,1998,1999,2000,2001,2002,2003,2005 Hrvoje Niksic
;; Author: Hrvoje Niksic <hniksic(a)xemacs.org>
;; Keywords: hypermedia, extensions
@@ -70,8 +70,8 @@
;; Thanks go to the multitudes of people who have sent reports and
;; contributed comments, suggestions, and fixes. They include Ron
-;; Gut, Bob Weiner, Toni Drabik, Peter Breton, Thomas Vogels and many
-;; others.
+;; Gut, Bob Weiner, Toni Drabik, Peter Breton, Thomas Vogels, Juri
+;; Linkov, and many others.
;; User quotes: "You sir, are a sick, sick, _sick_ person. :)"
;; -- Bill Perry, author of Emacs/W3
@@ -93,7 +93,7 @@
;; `cl' is loaded.
(load "cl-extra")))
-(defconst htmlize-version "1.16")
+(defconst htmlize-version "1.28")
;; Incantations to make custom stuff work without customize, e.g. on
;; XEmacs 19.14 or GNU Emacs 19.34.
@@ -144,7 +144,7 @@ do your own hyperlinkification from html
:type 'boolean
:group 'htmlize)
-(defcustom htmlize-hyperlink-style "\
+(defcustom htmlize-hyperlink-style "
a {
color: inherit;
background-color: inherit;
@@ -159,6 +159,14 @@ do your own hyperlinkification from html
:type 'string
:group 'htmlize)
+(defcustom htmlize-replace-form-feeds t
+ "*Non-nil means replace form feed characters in source code with <hr />.
+If this is a string, it additionally specifies the replacement to use.
+If you need more elaborate processing, set this to nil and use
+htmlize-after-hook."
+ :type 'boolean
+ :group 'htmlize)
+
(defcustom htmlize-html-charset nil
"*The charset declared by the resulting HTML documents.
When non-nil, causes htmlize to insert the following in the HEAD section
@@ -401,7 +409,7 @@ output.")
(defun htmlize-protect-string (string)
"HTML-protect string, escaping HTML metacharacters and I18N chars."
;; Only protecting strings that actually contain unsafe or non-ASCII
- ;; chars removes a lot of unnecessary consing.
+ ;; chars removes a lot of unnecessary funcalls and consing.
(if (not (string-match "[^\r\n\t -%'-;=?-~]" string))
string
(mapconcat (lambda (char)
@@ -423,8 +431,8 @@ output.")
(setf (gethash char htmlize-extended-character-cache)
(format "&#%d;" char)))
((and (fboundp 'encode-char)
- ;; Have to check: encode-char fails for Arabic
- ;; and possibly other chars.
+ ;; Must check if encode-char works for CHAR;
+ ;; it fails for Arabic and possibly elsewhere.
(encode-char char 'ucs))
(setf (gethash char htmlize-extended-character-cache)
(format "&#%d;" (encode-char char 'ucs))))
@@ -435,20 +443,56 @@ output.")
(char-to-string char)))))
string "")))
+(defconst htmlize-ellipsis "...")
+(put-text-property 0 (length htmlize-ellipsis) 'htmlize-ellipsis t
htmlize-ellipsis)
+
(defun htmlize-buffer-substring-no-invisible (beg end)
;; Like buffer-substring-no-properties, but don't copy invisible
- ;; parts of the region.
+ ;; parts of the region. Where buffer-substring-no-properties
+ ;; mandates an ellipsis to be shown, htmlize-ellipsis is inserted.
(let ((pos beg)
- visible-list invisible next-change)
+ visible-list invisible show next-change)
;; Iterate over the changes in the `invisible' property and filter
;; out the portions where it's non-nil, i.e. where the text is
;; invisible.
(while (< pos end)
(setq invisible (get-char-property pos 'invisible)
next-change (htmlize-next-change pos 'invisible end))
- (unless invisible
- (push (buffer-substring-no-properties pos next-change)
- visible-list))
+ (if (not (listp buffer-invisibility-spec))
+ ;; If buffer-invisibility-spec is not a list, then all
+ ;; characters with non-nil `invisible' property are visible.
+ (setq show (not invisible))
+ ;; Otherwise, the value of a non-nil `invisible' property can be:
+ ;; 1. a symbol -- make the text invisible if it matches
+ ;; buffer-invisibility-spec.
+ ;; 2. a list of symbols -- make the text invisible if
+ ;; any symbol in the list matches
+ ;; buffer-invisibility-spec.
+ ;; If the match of buffer-invisibility-spec has a non-nil
+ ;; CDR, replace the invisible text with an ellipsis.
+ (let (match)
+ (if (symbolp invisible)
+ (setq match (member* invisible buffer-invisibility-spec
+ :key (lambda (i)
+ (if (symbolp i) i (car i)))))
+ (setq match (block nil
+ (dolist (elem invisible)
+ (let ((m (member*
+ elem buffer-invisibility-spec
+ :key (lambda (i)
+ (if (symbolp i) i (car i))))))
+ (when m (return m))))
+ nil)))
+ (setq show (cond ((null match) t)
+ ((and (cdr-safe (car match))
+ ;; Conflate successive ellipses.
+ (not (eq show htmlize-ellipsis)))
+ htmlize-ellipsis)
+ (t nil)))))
+ (cond ((eq show t)
+ (push (buffer-substring-no-properties pos next-change) visible-list))
+ ((stringp show)
+ (push show visible-list)))
(setq pos next-change))
(if (= (length visible-list) 1)
;; If VISIBLE-LIST consists of only one element, return it
@@ -457,6 +501,15 @@ output.")
(car visible-list)
(apply #'concat (nreverse visible-list)))))
+(defun htmlize-trim-ellipsis (text)
+ ;; Remove htmlize-ellipses ("...") from the beginning of TEXT if it
+ ;; starts with it. It checks for the special property of the
+ ;; ellipsis so it doesn't work on ordinary text that begins with
+ ;; "...".
+ (if (get-text-property 0 'htmlize-ellipsis text)
+ (substring text (length htmlize-ellipsis))
+ text))
+
(defconst htmlize-tab-spaces
;; A table of strings with spaces. (aref htmlize-tab-spaces 5) is
;; like (make-string 5 ?\ ), except it doesn't cons.
@@ -542,6 +595,16 @@ without modifying their meaning."
;; <
http://www.mail-archive.com/bbdb-info@xemacs.org/>
;; <hniksic(a)xemacs.org>
;; <xalan-dev-sc.10148567319.hacuhiucknfgmpfnjcpg-john=doe.com(a)xml.apache.org>
+
+(defun htmlize-defang-local-variables ()
+ ;; Juri Linkov reports that an HTML-ized "Local variables" can lead
+ ;; visiting the HTML to fail with "Local variables list is not
+ ;; properly terminated". He suggested changing the phrase to
+ ;; syntactically equivalent HTML that Emacs doesn't recognize.
+ (goto-char (point-min))
+ (while (search-forward "Local Variables:" nil t)
+ (replace-match "Local Variables:" nil t)))
+
;;; Color handling.
@@ -633,11 +696,25 @@ If no rgb.txt file is found, return nil.
;; return "unspecified-fg" or "unspecified-bg". If the face is
;; `default' and the color is unspecified, look up the color in
;; frame parameters.
- (let ((color (if fg (face-foreground face) (face-background face))))
+ (let* ((function (if fg #'face-foreground #'face-background))
+ color)
+ (if (>= emacs-major-version 22)
+ ;; For GNU Emacs 22+ set INHERIT to get the inherited values.
+ (setq color (funcall function face nil t))
+ (setq color (funcall function face))
+ ;; For GNU Emacs 21 (which has `face-attribute'): if the color
+ ;; is nil, recursively check for the face's parent.
+ (when (and (null color)
+ (fboundp 'face-attribute)
+ (face-attribute face :inherit)
+ (not (eq (face-attribute face :inherit) 'unspecified)))
+ (setq color (htmlize-face-color-internal
+ (face-attribute face :inherit) fg))))
(when (and (eq face 'default) (null color))
(setq color (cdr (assq (if fg 'foreground-color 'background-color)
(frame-parameters)))))
- (when (or (equal color "unspecified-fg")
+ (when (or (eq color 'unspecified)
+ (equal color "unspecified-fg")
(equal color "unspecified-bg"))
(setq color nil))
(when (and (eq face 'default)
@@ -680,7 +757,7 @@ If no rgb.txt file is found, return nil.
;; returns nil.
)
((string-match "\\`#" color)
- ;; The color is alredy in #rrggbb format.
+ ;; The color is already in #rrggbb format.
(setq rgb-string color))
((and htmlize-use-rgb-txt
htmlize-color-rgb-hash)
@@ -724,7 +801,7 @@ If no rgb.txt file is found, return nil.
italicp ; whether face is italic
underlinep ; whether face is underlined
overlinep ; whether face is overlined
- strikep ; whether face is striked through
+ strikep ; whether face is struck through
css-name ; CSS name of face
)
@@ -776,9 +853,12 @@ If no rgb.txt file is found, return nil.
(setf (htmlize-fstruct-underlinep fstruct)
(face-underline-p face))))
((fboundp 'face-attribute)
- ;; GNU Emacs 21.
+ ;; GNU Emacs 21 and further.
(dolist (attr '(:weight :slant :underline :overline :strike-through))
- (let ((value (face-attribute face attr)))
+ (let ((value (if (>= emacs-major-version 22)
+ ;; Use the INHERIT arg in GNU Emacs 22.
+ (face-attribute face attr nil t)
+ (face-attribute face attr))))
(when (and value (not (eq value 'unspecified)))
(htmlize-face-emacs21-attr fstruct attr value)))))
(t
@@ -849,8 +929,7 @@ If no rgb.txt file is found, return nil.
(defun htmlize-face-list-p (face-prop)
"Return non-nil if FACE-PROP is a list of faces, nil otherwise."
;; If not for attrlists, this would return (listp face-prop). This
- ;; way we have to be more careful because some an attrlist is also a
- ;; list!
+ ;; way we have to be more careful because attrlist is also a list!
(cond
((eq face-prop nil)
;; FACE-PROP being nil means empty list (no face), so return t.
@@ -900,6 +979,12 @@ If no rgb.txt file is found, return nil.
(push new-name css-names)))))
face-map))
+(defun htmlize-unstringify-face (face)
+ "If FACE is a string, return it interned, otherwise return it unchanged."
+ (if (stringp face)
+ (intern face)
+ face))
+
(defun htmlize-faces-in-buffer ()
"Return a list of faces used in the current buffer.
Under XEmacs, this returns the set of faces specified by the extents
@@ -931,16 +1016,20 @@ property and by buffer overlays that spe
next (or (next-single-property-change pos 'face) (point-max)))
;; FACE-PROP can be a face/attrlist or a list thereof.
(setq faces (if (htmlize-face-list-p face-prop)
- (union face-prop faces :test 'equal)
- (adjoin face-prop faces :test 'equal)))
+ (union (mapcar #'htmlize-unstringify-face face-prop)
+ faces :test 'equal)
+ (adjoin (htmlize-unstringify-face face-prop)
+ faces :test 'equal)))
(setq pos next)))
;; Faces used by overlays.
(dolist (overlay (overlays-in (point-min) (point-max)))
(let ((face-prop (overlay-get overlay 'face)))
;; FACE-PROP can be a face/attrlist or a list thereof.
(setq faces (if (htmlize-face-list-p face-prop)
- (union face-prop faces :test 'equal)
- (adjoin face-prop faces :test 'equal))))))
+ (union (mapcar #'htmlize-unstringify-face face-prop)
+ faces :test 'equal)
+ (adjoin (htmlize-unstringify-face face-prop)
+ faces :test 'equal))))))
faces))
;; htmlize-faces-at-point returns the faces in use at point. The
@@ -968,8 +1057,9 @@ property and by buffer overlays that spe
;; Faces from text properties.
(let ((face-prop (get-text-property (point) 'face)))
(setq all-faces (if (htmlize-face-list-p face-prop)
- (reverse face-prop)
- (list face-prop))))
+ (nreverse (mapcar #'htmlize-unstringify-face
+ face-prop))
+ (list (htmlize-unstringify-face face-prop)))))
;; Faces from overlays.
(let ((overlays
;; Collect overlays at point that specify `face'.
@@ -991,14 +1081,21 @@ property and by buffer overlays that spe
(dolist (overlay overlays)
(setq face-prop (overlay-get overlay 'face))
(setq list (if (htmlize-face-list-p face-prop)
- (nconc (reverse face-prop) list)
- (cons face-prop list))))
- (setq all-faces (nconc all-faces list)))))))
+ (nconc (nreverse (mapcar
+ #'htmlize-unstringify-face
+ face-prop))
+ list)
+ (cons (htmlize-unstringify-face face-prop) list))))
+ ;; Under "Merging Faces" the manual explicitly states
+ ;; that faces specified by overlays take precedence over
+ ;; faces specified by text properties.
+ (setq all-faces (nconc all-faces list)))
+ all-faces))))
;; htmlize supports generating HTML in two several fundamentally
;; different ways, one with the use of CSS and nested <span> tags, and
;; the other with the use of the old <font> tags. Rather than adding
-;; a bunch of if's to many places, we take a semi-OO approach.
+;; a bunch of ifs to many places, we take a semi-OO approach.
;; `htmlize-buffer-1' calls a number of "methods", which indirect to
;; the functions that depend on `htmlize-output-type'. The currently
;; used methods are `doctype', `insert-head', `body-tag', and
@@ -1108,19 +1205,19 @@ property and by buffer overlays that spe
;; To make generated HTML legal, htmlize.el used to specify the SGML
;; declaration of "HTML Pro" DTD here. HTML Pro aka Silmaril DTD
- ;; was a project whose goal was to produce a DTD that would
+ ;; was a project whose goal was to produce a GPL'ed DTD that would
;; encompass all the incompatible HTML extensions procured by
;; Netscape, MSIE, and other players in the field. Apparently the
;; project got abandoned, the last available version being "Draft 0
;; Revision 11" from January 1997, as documented at
- ;; <
http://validator.w3.org/sgml-lib/pro/html/dtds/htmlpro.html>.
+ ;; <
http://imbolc.ucc.ie/~pflynn/articles/htmlpro.html>.
- ;; Since by now (2001) HTML Pro is remembered by none but the most
+ ;; Since by now (2005) HTML Pro is remembered by none but the most
;; die-hard early-web-days nostalgics and used by not even them,
;; there is no use in specifying it. So we return the standard HTML
;; 4.0 declaration, which makes generated HTML technically illegal.
;; If you have a problem with that, use the `css' generation engine
- ;; which I believe creates fully conformant HTML.
+ ;; which I believe creates fully conforming HTML.
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">"
@@ -1222,7 +1319,7 @@ property and by buffer overlays that spe
;; Declare variables used in loop body outside the loop
;; because it's faster to establish `let' bindings only
;; once.
- next-change text face-list fstruct-list)
+ next-change text face-list fstruct-list trailing-ellipsis)
;; This loop traverses and reads the source buffer, appending
;; the resulting HTML to HTMLBUF with `princ'. This method is
;; fast because: 1) it doesn't require examining the text
@@ -1242,6 +1339,13 @@ property and by buffer overlays that spe
;; untabify it and escape the HTML metacharacters.
(setq text (htmlize-buffer-substring-no-invisible
(point) next-change))
+ (when trailing-ellipsis
+ (setq text (htmlize-trim-ellipsis text)))
+ ;; If TEXT ends up empty, don't change trailing-ellipsis.
+ (when (> (length text) 0)
+ (setq trailing-ellipsis
+ (get-text-property (1- (length text))
+ 'htmlize-ellipsis text)))
(setq text (htmlize-untabify text (current-column)))
(setq text (htmlize-protect-string text))
;; Don't bother writing anything if there's no text (this
@@ -1252,11 +1356,24 @@ property and by buffer overlays that spe
(funcall insert-text-method text fstruct-list htmlbuf))
(goto-char next-change)))
- ;; Insert the epilog.
+ ;; Insert the epilog and post-process the buffer.
(with-current-buffer htmlbuf
(insert "</pre>\n </body>\n</html>\n")
(when htmlize-generate-hyperlinks
(htmlize-make-hyperlinks))
+ (htmlize-defang-local-variables)
+ (when htmlize-replace-form-feeds
+ ;; Change each "^L\n" to "\n<hr/>".
+ (goto-char (point-min))
+ (let ((source
+ ;; ^L has already been escaped, so search for that.
+ (htmlize-protect-string "\^L\n"))
+ (replacement
+ (concat "\n" (if (stringp htmlize-replace-form-feeds)
+ htmlize-replace-form-feeds
+ "<hr />"))))
+ (while (search-forward source nil t)
+ (replace-match replacement t t))))
(goto-char (point-min))
(when htmlize-html-major-mode
;; What sucks about this is that the minor modes, most notably