Peter Szilagyi avatar Peter Szilagyi committed 1b8002c

org-mode release upgrade (7.6 => 7.9.2) attempting to fix tramp incompatibility

Comments (0)

Files changed (162)

elisp/contrib/org/Makefile

+# Makefile - for the org-mode distribution
+# GNU make is required
+#
+# This file is not part of GNU Emacs
+
+# set up environment
+ include mk/default.mk	# defaults, customizable via "local.mk"
+-include local.mk	# optional local customization, use default.mk as template
+
+# default target is "all" unless overridden in local.mk
+all::
+
+# Describe valid make targets for org-mode.
+.PHONY:	targets help helpall
+targets:	help
+help helpall::
+	$(info )
+	$(info Getting Help)
+	$(info ============)
+	$(info )
+	$(info make help           - show brief help)
+	$(info make targets        - ditto)
+	$(info make helpall        - show extended help)
+	$(info )
+	$(info Build and Check)
+	$(info ===============)
+	$(info make                - build Org ELisp and all documentation)
+	$(info make all            - ditto)
+	$(info make compile        - build Org ELisp files)
+	$(info make single         - build Org ELisp files, single Emacs per source)
+	$(info make autoloads      - create org-install.el to load Org in-place)
+	$(info make test           - build Org ELisp files and run test suite)
+helpall::
+	$(info make test-dirty     - check without building first)
+	$(info make compile-dirty  - build only stale Org ELisp files)
+	$(info )
+	$(info Compatibility)
+	$(info =============)
+	$(info make oldorg         - what the old make did: compile autoloads info)
+	$(info )
+	$(info Cleaning)
+	$(info ========)
+	$(info make clean          - remove built Org ELisp files and documentation)
+	$(info make cleanall       - remove everything that can be built and all remnants)
+	$(info make clean-install  - remove previous Org installation)
+	$(info )
+	$(info Configuration Check)
+	$(info ===================)
+help helpall::
+	$(info make config         - check main configuration)
+helpall::
+	$(info make config-version - check Org version)
+	$(info make config-test    - check test configuration)
+	$(info make config-exe     - check executables configuration)
+	$(info make config-cmd     - check command configuration)
+	$(info make config-all     - check all configuration)
+	$(info )
+	$(info Documentation)
+	$(info =============)
+help helpall::
+	$(info make doc            - build all documentation)
+helpall::
+	$(info make docs           - ditto)
+help helpall::
+	$(info make info           - build Info documentation)
+helpall::
+	$(info make html           - build HTML documentation)
+	$(info make pdf            - build PDF documentation)
+	$(info make card           - build reference cards)
+	$(info make refcard        - ditto)
+help helpall::
+	$(info )
+	$(info Installation)
+	$(info ============)
+	$(info make install        - build and install Org)
+helpall::
+	$(info make install-etc    - build and install files in /etc)
+	$(info make install-lisp   - build and install Org Elisp files)
+	$(info make install-info   - build and install Info documentation)
+	$(info )
+	$(info Convenience)
+	$(info ===========)
+	$(info make up0            - pull from upstream)
+	$(info make up1            - pull from upstream, build and check)
+	$(info make up2            - pull from upstream, build, check and install)
+	$(info make update         - pull from upstream and build)
+	$(info make update2        - pull from upstream, build and install)
+	$(info make uncompiled     - combine cleanlisp and autoloads)
+	$(info make local.mk       - create new local.mk as template for adaptation)
+help helpall::
+	$(info )
+	$(info Full documentation on Worg)
+	$(info ==========================)
+	$(info http://orgmode.org/worg/dev/org-build-system.html)
+	@echo ""
+
+ include mk/targets.mk	# toplevel make machinery

elisp/contrib/org/README

+The is a distribution of Org, a plain text notes and project planning
+tool for Emacs.
+
+The version of this release is: 7.9.1
+
+The homepage of Org is at http://orgmode.org
+
+This distribution contains:
+
+README
+    This file.
+
+COPYING
+    The GNU General Public License.
+
+Makefile
+    The makefile to compile and install Org.  For installation
+    instructions, see the manual or the more detailed procedure
+    on Worg: http://orgmode.org/worg/dev/org-build-system.html
+
+mk/
+    Files needed for building Org.
+
+lisp/
+    Directory with all the Emacs Lisp files that make up Org.
+
+doc/
+    The documentation files.  org.texi is the source of the
+    documentation, org.html and org.pdf are formatted versions of it.
+
+contrib/
+    A directory with third-party additions for Org.  Some really cool
+    stuff is in there.
+
+etc/
+    Files needed for the ODT exporter.
+
+testing/
+    Testing suite for Org.
+
+request-assign-future.txt
+    The form that contributors have to sign and get processed with
+    the FSF before contributed changes can be integrated into the Org
+    core.  All files in this distribution except the contrib/ directory
+    have copyright assigned to the FSF.

elisp/contrib/org/contrib/README

+This directory contains add-ons to Org-mode.
+
+These contributions are not part of GNU Emacs or of the official Org-mode
+package.  But the git repository for Org-mode is glad to provide useful way
+to distribute and develop them as long as they are distributed under a free
+software license.
+
+Please put your contribution in one of these directories:
+
+LISP (emacs-lisp code)
+======================
+htmlize.el               --- Convert buffer text and decorations to HTML
+org2rem.el               --- Convert org appointments into reminders
+org-annotate-file.el     --- Annotate a file with org syntax
+org-bibtex-extras.el     --- Extras for working with org-bibtex entries
+org-bookmark.el          --- Links to bookmarks
+org-checklist.el         --- org functions for checklist handling
+org-choose.el            --- Use TODO keywords to mark decision states
+org-collector.el         --- Collect properties into tables
+org-contacts             --- Contacts management
+org-contribdir.el        --- Dummy file to mark the org contrib Lisp directory
+org-depend.el            --- TODO dependencies for Org-mode
+org-drill.el             --- Self-testing with org-learn
+org-element.el           --- Parser and applications for Org syntax
+org-elisp-symbol.el      --- Org links to emacs-lisp symbols
+org-eval.el              --- The <lisp> tag, adapted from Muse
+org-eval-light.el        --- Evaluate in-buffer code on demand
+org-exp-bibtex.el        --- Export citations to LaTeX and HTML
+org-expiry.el 	         --- Expiry mechanism for Org entries
+org-export.el            --- Generic Export Engine For Org
+org-export-generic.el    --- Export framework for configurable backends
+org-git-link.el          --- Provide org links to specific file version
+org-interactive-query.el --- Interactive modification of tags query
+org-invoice.el           --- Help manage client invoices in OrgMode
+org-jira.el              --- Add a jira:ticket protocol to Org
+org-learn.el             --- SuperMemo's incremental learning algorithm
+org-mac-iCal.el          --- Imports events from iCal.app to the Emacs diary
+org-mac-link-grabber.el  --- Grab links and URLs from various Mac applications
+org-mairix.el 	         --- Hook mairix search into Org for different MUAs
+org-man.el 	         --- Support for links to manpages in Org-mode
+org-mime.el              --- org html export for text/html MIME emails
+org-mtags.el 	         --- Support for some Muse-like tags in Org-mode
+org-notify.el            --- Notifications for Org-mode
+org-notmuch.el           --- Support for links to notmuch messages
+org-panel.el 	         --- Simple routines for us with bad memory
+org-registry.el          --- A registry for Org links
+org-screen.el            --- Visit screen sessions through Org-mode links
+org-secretary.el         --- Team management with org-mode
+org-static-mathjax.el    --- Muse-like tags in Org-mode
+org-sudoku.el            --- Create and solve SUDOKU puzzles in Org tables
+orgtbl-sqlinsert.el      --- Convert Org-mode tables to SQL insertions
+org-toc.el 	         --- Table of contents for Org-mode buffer
+org-track.el             --- Keep up with Org development
+org-velocity.el          --- something like Notational Velocity for Org
+org-wikinodes.el         --- CamelCase wiki-like links for Org
+
+
+EXPORT ENGINE AND BACKENDS (emacs-lisp code)
+============================================
+
+org-export.el            --- the new export engine
+org-e-latex.el           --- LaTeX export backend
+org-e-ascii.el           --- ASCII export backend
+org-e-beamer.el          --- Beamer export backend
+org-e-groff.el           --- Groff export backend
+org-e-html.el            --- HTML export backend
+org-e-man.el             --- man pages export backend
+org-e-odt.el             --- ODT export backend
+org-e-texinfo.el         --- TeXinfo export backend
+org-md.el                --- MarkDown export backend
+
+
+BABEL
+=====
+library-of-babel.org     --- Documentation for the library of babel
+langs/ob-fomus.el        --- Org-babel functions for fomus evaluation
+langs/ob-oz.el           --- Org-babel functions for Oz evaluation
+
+
+ODT (OpenDocumentText)
+======================
+README.org               --- Legacy documentation for Org ODT exporter
+
+
+SCRIPTS (shell, bash, etc.)
+===========================
+
+dir2org.zsh          --- Org compatible fs structure output
+ditaa.jar            --- ASCII to PNG converter by Stathis Sideris, GPL
+org2hpda             --- Generate hipster pda style printouts from Org-mode
+org-docco.org        --- docco side-by-side annotated code export to HTML
+StartOzServer.oz     --- implements the Oz-side of the Org-babel Oz interface
+staticmathjax        --- XULRunner application to process MathJax statically
+
+This directory also contains supporting files for the following
+packages: ob-oz.el, org-docco.org, and org-static-mathjax.el.

elisp/contrib/org/contrib/babel/langs/ob-oz.el

+;;; ob-oz.el --- org-babel functions for Oz evaluation
+
+;; Copyright (C) 2009-2012 Torsten Anders and Eric Schulte 
+
+;; Author: Torsten Anders and Eric Schulte 
+;; Keywords: literate programming, reproducible research
+;; Homepage: http://orgmode.org
+;; Version: 0.02
+
+;;; License:
+
+;; This program 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 3, or (at your option)
+;; any later version.
+;;
+;; This program 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 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.
+
+;;; Commentary:
+
+;; Org-Babel support for evaluating Oz source code. 
+;;
+;; Oz code is always send to the Oz Programming Environment (OPI), the
+;; Emacs mode and compiler interface for Oz programs. Therefore, only
+;; session mode is supported. In practice, non-session code blocks are
+;; handled equally well by the session mode. However, only a single
+;; session is supported. Consequently, the :session header argument is
+;; ignored.
+;;
+;; The Org-babel header argument :results is interpreted as
+;; follows. :results output requires the respective code block to be
+;; an Oz statement and :results value requires an Oz
+;; expression. Currently, results are only supported for expressions
+;; (i.e. the result of :results output is always nil).
+;;
+;; Expression evaluation happens synchronously. Therefore there is an
+;; additional header argument :wait-time <number>, which specifies the
+;; maximum time to wait for the result of a given expression. nil
+;; means to wait as long as it takes to get a result (potentially wait
+;; forever).
+;;
+;; NOTE: Currently the copyright of this file may not be in a state to
+;;       permit inclusion as core software into Emacs or Org-mode.
+
+;;; Requirements:
+
+;; - Mozart Programming System, the implementation of the Oz
+;;   programming language (http://www.mozart-oz.org/), which includes
+;;   the major mode mozart for editing Oz programs.
+;;
+;; - StartOzServer.oz which is located in the contrib/scripts
+;;   directory of the Org-mode repository
+
+;;; TODO:
+
+;; - Decide: set communication to \\switch -threadedqueries?
+;;
+;; - Only start Oz compiler when required, e.g., load Org-babel only when needed?
+;;
+;; - Avoid synchronous evaluation to avoid blocking Emacs (complex
+;;   Strasheela programs can take long to find a result..). In order
+;;   to cleanly map code blocks to their associated results (which can
+;;   arrive then in any order) I could use IDs
+;;   (e.g. integers). However, how do I do concurrency in Emacs Lisp,
+;;   and how can I define org-babel-execute:oz concurrently.
+;; 
+;; - Expressions are rarely used in Oz at the top-level, and using
+;;   them in documentation and Literate Programs will cause
+;;   confusion. Idea: hide expression from reader and instead show
+;;   them statement (e.g., MIDI output statement) and then include
+;;   result in Org file. Implementation: for expressions (:results
+;;   value) support an additional header argument that takes arbitrary
+;;   Oz code. This code is not seen by the reader, but will be used
+;;   for the actual expression at the end.  Alternative: feed all
+;;   relevant code as statement (:results output), then add expression
+;;   as extra code block which outputs, e.g., file name (so the file
+;;   name must be accessible by global var), but the code of this
+;;   extra codeblock is not seen.  Hm, in that case it might be even
+;;   more easy to manually add this link to the Org file.
+;;
+
+
+(require 'ob)
+;;; major mode for editing Oz programs
+(require 'mozart)
+
+;;
+;; Interface to communicate with Oz.
+;; (1) For statements without any results: oz-send-string 
+;; (2) For expressions with a single result: oz-send-string-expression
+;;     (defined in org-babel-oz-ResultsValue.el)
+;; 
+
+;; oz-send-string-expression implements an additional very direct
+;; communication between Org-babel and the Oz compiler. Communication
+;; with the Oz server works already without this code via the function
+;; oz-send-string from mozart.el.in, but this function does not get
+;; back any results from Oz to Emacs. The following code creates a
+;; socket for sending code to the OPI compiler and results are
+;; returned by the same socket. On the Oz side, a socket is opened and
+;; conected to the compiler of the OPI (via oz-send-string). On the
+;; Emacs side, a connection to this socket is created for feeding code
+;; and receiving results. This additional communication channel to the
+;; OPI compiler ensures that results are returned cleanly (e.g., only
+;; the result of the sent code is returned, no parsing or any
+;; processing of *Oz Emulator* is required).
+;;
+;; There is no buffer, nor sentinel involved. Oz code is send
+;; directly, and results from Oz are send back, but Emacs Lisp
+;; requires a filter function for processing results.
+
+(defvar org-babel-oz-server-dir
+  (file-name-as-directory
+   (expand-file-name
+    "contrib/scripts"
+    (file-name-as-directory
+     (expand-file-name
+      "../../.."
+      (file-name-directory (or load-file-name buffer-file-name))))))
+  "Path to the contrib/scripts directory in which
+StartOzServer.oz is located.")
+
+(defvar org-babel-oz-port 6001		
+  "Port for communicating with Oz compiler.")
+(defvar org-babel-oz-OPI-socket nil
+  "Socket for communicating with OPI.")
+
+(defvar org-babel-oz-collected-result nil
+  "Aux var to hand result from org-babel-oz-filter to oz-send-string-expression.")
+(defun org-babel-oz-filter (proc string)
+  "Processes output from socket org-babel-oz-OPI-socket."
+;;   (setq org-babel-oz-collected-results (cons string org-babel-oz-collected-results))
+  (setq org-babel-oz-collected-result string)
+  )
+
+
+(defun org-babel-oz-create-socket ()
+  (message "Create OPI socket for evaluating expressions")
+  ;; Start Oz directly 
+  (run-oz)
+  ;; Create socket on Oz side (after Oz was started).
+  (oz-send-string (concat "\\insert '" org-babel-oz-server-dir "StartOzServer.oz'"))
+  ;; Wait until socket is created before connecting to it.
+  ;; Quick hack: wait 3 sec
+  ;; 
+  ;; extending time to 30 secs does not help when starting Emacs for
+  ;; the first time (and computer does nothing else)
+  (sit-for 3)
+  ;; connect to OPI socket
+  (setq org-babel-oz-OPI-socket  
+	;; Creates a socket. I/O interface of Emacs sockets as for processes.
+	(open-network-stream "*Org-babel-OPI-socket*" nil "localhost" org-babel-oz-port))
+  ;; install filter
+  (set-process-filter org-babel-oz-OPI-socket #'org-babel-oz-filter)
+)
+
+;; communication with org-babel-oz-OPI-socket is asynchronous, but
+;; oz-send-string-expression turns is into synchronous...
+(defun oz-send-string-expression (string &optional wait-time)
+  "Similar to oz-send-string, oz-send-string-expression sends a string to the OPI compiler. However, string must be expression and this function returns the result of the expression (as string). oz-send-string-expression is synchronous, wait-time allows to specify a maximum wait time. After wait-time is over with no result, the function returns nil."
+  (if (not org-babel-oz-OPI-socket) 
+      (org-babel-oz-create-socket))
+  (let ((polling-delay 0.1)
+	result)
+    (process-send-string org-babel-oz-OPI-socket string)
+    ;; wait for result
+    (if wait-time
+	(let ((waited 0))
+	  (unwind-protect
+	      (progn
+		(while 
+		    ;; stop loop if org-babel-oz-collected-result \= nil or waiting time is over
+		    (not (or (not (equal org-babel-oz-collected-result nil))
+			     (> waited wait-time)))
+		  (progn 
+		    (sit-for polling-delay)
+;; 		    (message "org-babel-oz: next polling iteration")
+		    (setq waited (+ waited polling-delay))))
+;; 		(message "org-babel-oz: waiting over, got result or waiting timed out")
+;; 		(message (format "wait-time: %s, waited: %s" wait-time waited))
+		(setq result org-babel-oz-collected-result)
+		(setq org-babel-oz-collected-result nil))))
+      (unwind-protect
+	  (progn
+	    (while (equal org-babel-oz-collected-result nil)
+	      (sit-for polling-delay))
+	    (setq result org-babel-oz-collected-result)
+	    (setq org-babel-oz-collected-result nil))))
+    result))
+
+(defun org-babel-expand-body:oz (body params)
+  (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
+    (if vars
+	;; prepend code to define all arguments passed to the code block
+	(let ((var-string (mapcar (lambda (pair)
+				    (format "%s=%s"
+					    (car pair)
+					    (org-babel-oz-var-to-oz (cdr pair))))
+				  vars)))
+	  ;; only add var declarations if any variables are there
+	  (mapconcat #'identity
+		     (append (list "local") var-string (list "in" body "end"))
+		     "\n"))
+      body)))
+
+(defun org-babel-execute:oz (body params)
+  "Execute a block of Oz code with org-babel.  This function is
+called by `org-babel-execute-src-block' via multiple-value-bind."
+  (let* ((result-params (cdr (assoc :result-params params)))
+	 (full-body (org-babel-expand-body:oz body params))
+	 (wait-time (plist-get params :wait-time)))
+    ;; actually execute the source-code block
+    (org-babel-reassemble-table
+     (cond
+      ((member "output" result-params)
+       (message "Org-babel: executing Oz statement")
+       (oz-send-string full-body))
+      ((member "value" result-params)
+       (message "Org-babel: executing Oz expression")
+       (oz-send-string-expression full-body (or wait-time 1)))
+      (t (error "either 'output' or 'results' must be members of :results.")))
+     (org-babel-pick-name (cdr (assoc :colname-names params))
+			  (cdr (assoc :colnames params)))
+     (org-babel-pick-name (cdr (assoc :roname-names params))
+			  (cdr (assoc :rownames params))))))
+
+;; This function should be used to assign any variables in params in
+;; the context of the session environment.
+(defun org-babel-prep-session:oz (session params)
+  "Prepare SESSION according to the header arguments specified in PARAMS."
+  (error "org-babel-prep-session:oz unimplemented"))
+;; TODO: testing... (copied from org-babel-haskell.el)
+;; (defun org-babel-prep-session:oz (session params)
+;;   "Prepare SESSION according to the header arguments specified in PARAMS."
+;;   (save-window-excursion
+;;     (org-babel-oz-initiate-session session)
+;;     (let* ((vars (org-babel-ref-variables params))
+;;            (var-lines (mapconcat ;; define any variables
+;;                        (lambda (pair)
+;;                          (format "%s=%s"
+;;                                  (car pair)
+;;                                  (org-babel-ruby-var-to-ruby (cdr pair))))
+;;                        vars "\n"))
+;;            (vars-file (concat (make-temp-file "org-babel-oz-vars") ".oz")))
+;;       (when vars
+;;         (with-temp-buffer
+;;           (insert var-lines) (write-file vars-file)
+;;           (oz-mode) 
+;; ;; 	  (inferior-oz-load-file) ; ??
+;; 	  ))
+;;       (current-buffer))))
+;;
+
+
+;; TODO: testing... (simplified version of def in org-babel-prep-session:ocaml)
+;;
+;; BUG: does not work yet. Error: ad-Orig-error: buffer none doesn't exist or has no process 
+;; UNUSED DEF
+(defun org-babel-oz-initiate-session (&optional session params)
+  "If there is not a current inferior-process-buffer in SESSION
+then create.  Return the initialized session."
+  (unless (string= session "none")
+    ;; TODO: make it possible to have multiple sessions
+    (save-window-excursion
+      ;; (run-oz)
+      (get-buffer oz-compiler-buffer))))
+
+(defun org-babel-oz-var-to-oz (var)
+  "Convert an elisp var into a string of Oz source code
+specifying a var of the same value."
+  (if (listp var)
+;;       (concat "[" (mapconcat #'org-babel-oz-var-to-oz var ", ") "]")
+      (eval var) 
+    (format "%s" var) ; don't preserve string quotes. 
+;;     (format "%s" var)
+    ))
+
+;; TODO: 
+(defun org-babel-oz-table-or-string (results)
+  "If the results look like a table, then convert them into an
+Emacs-lisp table, otherwise return the results as a string."
+  (error "org-babel-oz-table-or-string unimplemented"))
+
+
+(provide 'ob-oz)
+;;; org-babel-oz.el ends here

elisp/contrib/org/contrib/babel/library-of-babel.org

+#+title:    The Library of Babel
+#+author:     Org-mode People
+#+STARTUP:  hideblocks
+
+* Introduction
+
+The Library of Babel is an extensible collection of ready-made and
+easily-shortcut-callable source-code blocks for handling common tasks.
+Org-babel comes pre-populated with the source-code blocks located in
+this file.  It is possible to add source-code blocks from any org-mode
+file to the library by calling =(org-babel-lob-ingest
+"path/to/file.org")=.
+
+This file is included in worg mainly less for viewing through the web
+interface, and more for contribution through the worg git repository.
+If you have code snippets that you think others may find useful please
+add them to this file and [[file:~/src/worg/worg-git.org::contribute-to-worg][contribute them]] to worg.
+
+The raw Org-mode text of this file can be downloaded at
+[[repofile:contrib/babel/library-of-babel.org][library-of-babel.org]]
+
+* Simple
+
+A collection of simple utility functions:
+
+#+name: echo
+#+begin_src emacs-lisp :var input="echo'd"
+  input
+#+end_src
+
+* File I/O
+
+** Reading and writing files
+
+Read the contents of the file at =file=.  The =:results vector= and
+=:results scalar= header arguments can be used to read the contents of
+file as either a table or a string.
+
+#+name: read
+#+begin_src emacs-lisp :var file="" :var format=""
+  (if (string= format "csv")
+      (with-temp-buffer
+        (org-table-import (expand-file-name file) nil)
+        (org-table-to-lisp))
+    (with-temp-buffer
+      (insert-file-contents (expand-file-name file))
+      (buffer-string)))
+#+end_src
+
+Write =data= to a file at =file=.  If =data= is a list, then write it
+as a table in traditional Org-mode table syntax.
+
+#+name: write
+#+begin_src emacs-lisp :var data="" :var file="" :var ext='()
+  (flet ((echo (r) (if (stringp r) r (format "%S" r))))
+    (with-temp-file file
+      (case (and (listp data)
+                 (or ext (intern (file-name-extension file))))
+        ('tsv (insert (orgtbl-to-tsv data '(:fmt echo))))
+        ('csv (insert (orgtbl-to-csv data '(:fmt echo))))
+        (t    (org-babel-insert-result data)))))
+  nil
+#+end_src
+
+** Remote files
+
+*** json
+
+Read local or remote file in [[http://www.json.org/][json]] format into emacs-lisp objects.
+
+#+name: json
+#+begin_src emacs-lisp :var file='() :var url='()
+  (require 'json)
+  (cond
+   (file
+    (with-temp-filebuffer file
+      (goto-char (point-min))
+      (json-read)))
+   (url
+    (require 'w3m)
+    (with-temp-buffer
+      (w3m-retrieve url)
+      (goto-char (point-min))
+      (json-read))))
+#+end_src
+
+*** Google docs
+
+The following code blocks make use of the [[http://code.google.com/p/googlecl/][googlecl]] Google command line
+tool.  This tool provides functionality for accessing Google services
+from the command line, and the following code blocks use /googlecl/
+for reading from and writing to Google docs with Org-mode code blocks.
+
+**** Read a document from Google docs
+
+The =google= command seems to be throwing "Moved Temporarily" errors
+when trying to download textual documents, but this is working fine
+for spreadsheets.
+
+#+name: gdoc-read
+#+begin_src emacs-lisp :var title="example" :var format="csv"
+  (let* ((file (concat title "." format))
+         (cmd (format "google docs get --format %S --title %S" format title)))
+    (message cmd) (message (shell-command-to-string cmd))
+    (prog1 (if (string= format "csv")
+               (with-temp-buffer
+                 (org-table-import (shell-quote-argument file) '(4))
+                 (org-table-to-lisp))
+             (with-temp-buffer
+               (insert-file-contents (shell-quote-argument file))
+               (buffer-string)))
+      (delete-file file)))
+#+end_src
+
+For example, a line like the following can be used to read the
+contents of a spreadsheet named =num-cells= into a table.
+: #+call: gdoc-read(title="num-cells"")
+
+A line like the following can be used to read the contents of a
+document as a string.
+
+: #+call: gdoc-read(title="loremi", :format "txt")
+
+**** Write a document to a Google docs
+
+Write =data= to a google document named =title=.  If =data= is tabular
+it will be saved to a spreadsheet, otherwise it will be saved as a
+normal document.
+
+#+name: gdoc-write
+#+begin_src emacs-lisp :var title="babel-upload" :var data=fibs(n=10) :results silent
+  (let* ((format (if (listp data) "csv" "txt"))
+         (tmp-file (make-temp-file "org-babel-google-doc" nil (concat "." format)))
+         (cmd (format "google docs upload --title %S %S" title tmp-file)))
+    (with-temp-file tmp-file
+      (insert
+       (if (listp data)
+           (orgtbl-to-csv
+            data '(:fmt (lambda (el) (if (stringp el) el (format "%S" el)))))
+         (if (stringp data) data (format "%S" data)))))
+    (message cmd)
+    (prog1 (shell-command-to-string cmd) (delete-file tmp-file)))
+#+end_src
+
+example usage
+: #+name: fibs
+: #+begin_src emacs-lisp :var n=8
+:   (flet ((fib (m) (if (< m 2) 1 (+ (fib (- m 1)) (fib (- m 2))))))
+:     (mapcar (lambda (el) (list el (fib el))) (number-sequence 0 (- n 1))))
+: #+end_src
+:
+: #+call: gdoc-write(title="fibs", data=fibs(n=10))
+
+* Plotting code
+
+** R
+
+Plot column 2 (y axis) against column 1 (x axis). Columns 3 and
+beyond, if present, are ignored.
+
+#+name: R-plot
+#+begin_src R :var data=R-plot-example-data
+plot(data)
+#+end_src
+
+#+tblname: R-plot-example-data
+| 1 |  2 |
+| 2 |  4 |
+| 3 |  9 |
+| 4 | 16 |
+| 5 | 25 |
+
+#+call: R-plot(data=R-plot-example-data)
+
+#+resname: R-plot(data=R-plot-example-data)
+: nil
+
+** Gnuplot
+
+* Org reference
+
+** Headline references
+
+#+name: headline
+#+begin_src emacs-lisp :var headline=top :var file='()
+  (save-excursion
+    (when file (get-file-buffer file))
+    (org-open-link-from-string (org-make-link-string headline))
+    (save-restriction
+      (org-narrow-to-subtree)
+      (buffer-string)))
+#+end_src
+
+#+call: headline(headline="headline references")
+
+* Tables
+
+** LaTeX Table Export
+
+*** booktabs
+
+This source block can be used to wrap a table in the latex =booktabs=
+environment. The source block adds a =toprule= and =bottomrule= (so
+don't use =hline= at the top or bottom of the table).  The =hline=
+after the header is replaced with a =midrule=.
+
+Note that this function bypasses the Org-mode LaTeX exporter and calls
+=orgtbl-to-generic= to create the output table.  This means that the
+entries in the table are not translated from Org-mode to LaTeX.
+
+It takes the following arguments -- all but the first two are
+optional.
+
+| arg   | description                                |
+|-------+--------------------------------------------|
+| table | a reference to the table                   |
+| align | alignment string                           |
+| env   | optional environment, default to "tabular" |
+| width | optional width specification string        |
+
+#+name: booktabs
+#+begin_src emacs-lisp :var table='((:head) hline (:body)) :var align='() :var env="tabular" :var width='() :noweb yes :results latex
+  (flet ((to-tab (tab)
+                 (orgtbl-to-generic
+                  (mapcar (lambda (lis)
+                            (if (listp lis)
+                                (mapcar (lambda (el)
+                                          (if (stringp el)
+                                              el
+                                            (format "%S" el))) lis)
+                              lis)) tab)
+                  (list :lend " \\\\" :sep " & " :hline "\\hline"))))
+    (org-fill-template
+     "
+  \\begin{%env}%width%align
+  \\toprule
+  %table
+  \\bottomrule
+  \\end{%env}\n"
+     (list
+      (cons "env"       (or env "table"))
+      (cons "width"     (if width (format "{%s}" width) ""))
+      (cons "align"     (if align (format "{%s}" align) ""))
+      (cons "table"
+            ;; only use \midrule if it looks like there are column headers
+            (if (equal 'hline (second table))
+                (concat (to-tab (list (first table)))
+                        "\n\\midrule\n"
+                        (to-tab (cddr table)))
+              (to-tab table))))))
+#+end_src
+
+*** longtable
+
+This block can be used to wrap a table in the latex =longtable=
+environment, it takes the following arguments -- all but the first two
+are optional.
+
+| arg       | description                                                 |
+|-----------+-------------------------------------------------------------|
+| table     | a reference to the table                                    |
+| align     | optional alignment string                                   |
+| width     | optional width specification string                         |
+| hline     | the string to use as hline separator, defaults to "\\hline" |
+| head      | optional "head" string                                      |
+| firsthead | optional "firsthead" string                                 |
+| foot      | optional "foot" string                                      |
+| lastfoot  | optional "lastfoot" string                                  |
+
+#+name: longtable
+#+begin_src emacs-lisp :var table='((:table)) :var align='() :var width='() :var hline="\\hline" :var firsthead='() :var head='() :var foot='() :var lastfoot='() :noweb yes :results latex
+  (org-fill-template
+   "
+  \\begin{longtable}%width%align
+  %firsthead
+  %head
+  %foot
+  %lastfoot
+
+  %table
+  \\end{longtable}\n"
+   (list
+    (cons "width"     (if width (format "{%s}" width) ""))
+    (cons "align"     (if align (format "{%s}" align) ""))
+    (cons "firsthead" (if firsthead (concat firsthead "\n\\endfirsthead\n") ""))
+    (cons "head"      (if head (concat head "\n\\endhead\n") ""))
+    (cons "foot"      (if foot (concat foot "\n\\endfoot\n") ""))
+    (cons "lastfoot"  (if lastfoot (concat lastfoot "\n\\endlastfoot\n") ""))
+    (cons "table" (orgtbl-to-generic
+                   (mapcar (lambda (lis)
+                             (if (listp lis)
+                                 (mapcar (lambda (el)
+                                           (if (stringp el)
+                                               el
+                                             (format "%S" el))) lis)
+                               lis)) table)
+                   (list :lend " \\\\" :sep " & " :hline hline)))))
+#+end_src
+
+*** booktabs-notes
+
+This source block builds on [[booktabs]].  It accepts two additional
+arguments, both of which are optional.
+
+#+tblname: arguments
+| arg    | description                                          |
+|--------+------------------------------------------------------|
+| notes  | an org-mode table with footnotes                     |
+| lspace | if non-nil, insert =addlinespace= after =bottomrule= |
+
+An example footnote to the =arguments= table specifies the column
+span. Note the use of LaTeX, rather than Org-mode, markup.
+
+#+tblname: arguments-notes
+| \multicolumn{2}{l}{This is a footnote to the \emph{arguments} table.} |
+
+#+name: booktabs-notes
+#+begin_src emacs-lisp :var table='((:head) hline (:body)) :var notes='() :var align='() :var env="tabular" :var width='() :var lspace='() :noweb yes :results latex
+  (flet ((to-tab (tab)
+                 (orgtbl-to-generic
+                  (mapcar (lambda (lis)
+                            (if (listp lis)
+                                (mapcar (lambda (el)
+                                          (if (stringp el)
+                                              el
+                                            (format "%S" el))) lis)
+                              lis)) tab)
+                  (list :lend " \\\\" :sep " & " :hline "\\hline"))))
+    (org-fill-template
+     "
+    \\begin{%env}%width%align
+    \\toprule
+    %table
+    \\bottomrule%spacer
+    %notes
+    \\end{%env}\n"
+     (list
+      (cons "env"       (or env "table"))
+      (cons "width"     (if width (format "{%s}" width) ""))
+      (cons "align"     (if align (format "{%s}" align) ""))
+      (cons "spacer"    (if lspace "\\addlinespace" ""))
+      (cons "table"
+            ;; only use \midrule if it looks like there are column headers
+            (if (equal 'hline (second table))
+                (concat (to-tab (list (first table)))
+                        "\n\\midrule\n"
+                        (to-tab (cddr table)))
+              (to-tab table)))
+      (cons "notes" (if notes (to-tab notes) ""))
+      )))
+#+end_src
+
+** Elegant lisp for transposing a matrix
+
+#+tblname: transpose-example
+| 1 | 2 | 3 |
+| 4 | 5 | 6 |
+
+#+name: transpose
+#+begin_src emacs-lisp :var table=transpose-example
+  (apply #'mapcar* #'list table)
+#+end_src
+
+#+resname:
+| 1 | 4 |
+| 2 | 5 |
+| 3 | 6 |
+
+** Convert every element of a table to a string
+
+#+tblname: hetero-table
+| 1 | 2 | 3 |
+| a | b | c |
+
+#+name: all-to-string
+#+begin_src emacs-lisp :var tbl='()
+  (defun all-to-string (tbl)
+    (if (listp tbl)
+        (mapcar #'all-to-string tbl)
+      (if (stringp tbl)
+          tbl
+        (format "%s" tbl))))
+  (all-to-string tbl)
+#+end_src
+
+#+begin_src emacs-lisp :var tbl=hetero-table
+  (mapcar (lambda (row) (mapcar (lambda (cell) (stringp cell)) row)) tbl)
+#+end_src
+
+#+name:
+| nil | nil | nil |
+| t   | t   | t   |
+
+#+begin_src emacs-lisp :var tbl=all-to-string(hetero-table)
+  (mapcar (lambda (row) (mapcar (lambda (cell) (stringp cell)) row)) tbl)
+#+end_src
+
+#+name:
+| t | t | t |
+| t | t | t |
+
+* Misc
+
+** File-specific Version Control logging
+   :PROPERTIES:
+   :AUTHOR: Luke Crook
+   :END:
+
+This function will attempt to retrieve the entire commit log for the
+file associated with the current buffer and insert this log into the
+export. The function uses the Emacs VC commands to interface to the
+local version control system, but has only been tested to work with
+Git. 'limit' is currently unsupported.
+
+#+name: vc-log
+#+headers: :var limit=-1
+#+headers: :var buf=(buffer-name (current-buffer))
+#+begin_src emacs-lisp
+  ;; Most of this code is copied from vc.el vc-print-log
+  (require 'vc)
+  (when (vc-find-backend-function
+         (vc-backend (buffer-file-name (get-buffer buf))) 'print-log)
+    (let ((limit -1)
+          (vc-fileset nil)
+          (backend nil)
+          (files nil))
+      (with-current-buffer (get-buffer buf)
+        (setq vc-fileset (vc-deduce-fileset t)) ; FIXME: Why t? --Stef
+        (setq backend (car vc-fileset))
+        (setq files (cadr vc-fileset)))
+      (with-temp-buffer
+        (let ((status (vc-call-backend
+                       backend 'print-log files (current-buffer))))
+          (when (and (processp status)   ; Make sure status is a process
+                     (= 0 (process-exit-status status))) ; which has not terminated
+            (while (not (eq 'exit (process-status status)))
+              (sit-for 1 t)))
+          (buffer-string)))))
+#+end_src
+
+** Trivial python code blocks
+
+#+name: python-identity
+#+begin_src python :var a=1
+a
+#+end_src
+
+#+name: python-add
+#+begin_src python :var a=1 :var b=2
+a + b
+#+end_src
+
+** Arithmetic
+
+#+name: lob-add
+#+begin_src emacs-lisp :var a=0 :var b=0
+  (+ a b)
+#+end_src
+
+#+name: lob-minus
+#+begin_src emacs-lisp :var a=0 :var b=0
+  (- a b)
+#+end_src
+
+#+name: lob-times
+#+begin_src emacs-lisp :var a=0 :var b=0
+  (* a b)
+#+end_src
+
+#+name: lob-div
+#+begin_src emacs-lisp :var a=0 :var b=0
+  (/ a b)
+#+end_src
+
+* GANTT Charts
+
+The =elispgantt= source block was sent to the mailing list by Eric
+Fraga.  It was modified slightly by Tom Dye.
+
+#+name: elispgantt
+#+begin_src emacs-lisp :var table=gantttest
+  (let ((dates "")
+        (entries (nthcdr 2 table))
+        (milestones "")
+        (nmilestones 0)
+        (ntasks 0)
+        (projecttime 0)
+        (tasks "")
+        (xlength 1))
+    (message "Initial: %s\n" table)
+    (message "Entries: %s\n" entries)
+    (while entries
+      (let ((entry (first entries)))
+        (if (listp entry)
+            (let ((id (first entry))
+                  (type (nth 1 entry))
+                  (label (nth 2 entry))
+                  (task (nth 3 entry))
+                  (dependencies (nth 4 entry))
+                  (start (nth 5 entry))
+                  (duration (nth 6 entry))
+                  (end (nth 7 entry))
+                  (alignment (nth 8 entry)))
+              (if (> start projecttime) (setq projecttime start))
+              (if (string= type "task")
+                  (let ((end (+ start duration))
+                        (textposition (+ start (/ duration 2)))
+                        (flush ""))
+                    (if (string= alignment "left")
+                        (progn
+                          (setq textposition start)
+                          (setq flush "[left]"))
+                      (if (string= alignment "right")
+                          (progn
+                            (setq textposition end)
+                            (setq flush "[right]"))))
+                    (setq tasks
+                          (format "%s  \\gantttask{%s}{%s}{%d}{%d}{%d}{%s}\n"
+                                  tasks label task start end textposition flush))
+                    (setq ntasks (+ 1 ntasks))
+                    (if (> end projecttime)
+                        (setq projecttime end)))
+                (if (string= type "milestone")
+                    (progn
+                      (setq milestones
+                            (format
+                             "%s  \\ganttmilestone{$\\begin{array}{c}\\mbox{%s}\\\\ \\mbox{%s}\\end{array}$}{%d}\n"
+                             milestones label task start))
+                      (setq nmilestones (+ 1 nmilestones)))
+                  (if (string= type "date")
+                      (setq dates (format "%s  \\ganttdateline{%s}{%d}\n"
+                                          dates label start))
+                    (message "Ignoring entry with type %s\n" type)))))
+          (message "Ignoring non-list entry %s\n" entry)) ; end if list entry
+        (setq entries (cdr entries))))  ; end while entries left
+    (format "\\pgfdeclarelayer{background}
+  \\pgfdeclarelayer{foreground}
+  \\pgfsetlayers{background,foreground}
+  \\renewcommand{\\ganttprojecttime}{%d}
+  \\renewcommand{\\ganttntasks}{%d}
+  \\noindent
+  \\begin{tikzpicture}[y=-0.75cm,x=0.75\\textwidth]
+    \\begin{pgfonlayer}{background}
+      \\draw[very thin, red!10!white] (0,1+\\ganttntasks) grid [ystep=0.75cm,xstep=1/\\ganttprojecttime] (1,0);
+      \\draw[\\ganttdatelinecolour] (0,0) -- (1,0);
+      \\draw[\\ganttdatelinecolour] (0,1+\\ganttntasks) -- (1,1+\\ganttntasks);
+    \\end{pgfonlayer}
+  %s
+  %s
+  %s
+  \\end{tikzpicture}" projecttime ntasks tasks milestones dates))
+#+end_src
+
+* Available languages
+  :PROPERTIES:
+  :AUTHOR:   Bastien
+  :END:
+
+** From Org's core
+
+| Language   | Identifier | Language       | Identifier |
+|------------+------------+----------------+------------|
+| Asymptote  | asymptote  | Awk            | awk        |
+| Emacs Calc | calc       | C              | C          |
+| C++        | C++        | Clojure        | clojure    |
+| CSS        | css        | ditaa          | ditaa      |
+| Graphviz   | dot        | Emacs Lisp     | emacs-lisp |
+| gnuplot    | gnuplot    | Haskell        | haskell    |
+| Javascript | js         | LaTeX          | latex      |
+| Ledger     | ledger     | Lisp           | lisp       |
+| Lilypond   | lilypond   | MATLAB         | matlab     |
+| Mscgen     | mscgen     | Objective Caml | ocaml      |
+| Octave     | octave     | Org-mode       | org        |
+|            |            | Perl           | perl       |
+| Plantuml   | plantuml   | Python         | python     |
+| R          | R          | Ruby           | ruby       |
+| Sass       | sass       | Scheme         | scheme     |
+| GNU Screen | screen     | shell          | sh         |
+| SQL        | sql        | SQLite         | sqlite     |
+
+** From Org's contrib/babel/langs
+
+- ob-oz.el, by Torsten Anders and Eric Schulte
+- ob-fomus.el, by Torsten Anders

elisp/contrib/org/contrib/lisp/htmlize.el

+;; htmlize.el -- Convert buffer text and decorations to HTML.
+
+;; Copyright (C) 1997-2012 Hrvoje Niksic
+
+;; Author: Hrvoje Niksic <hniksic@xemacs.org>
+;; Keywords: hypermedia, extensions
+
+;; This program 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.
+
+;; This program 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 this program; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; This package converts the buffer text and the associated
+;; decorations to HTML.  Mail to <hniksic@xemacs.org> to discuss
+;; features and additions.  All suggestions are more than welcome.
+
+;; To use this, just switch to the buffer you want HTML-ized and type
+;; `M-x htmlize-buffer'.  You will be switched to a new buffer that
+;; contains the resulting HTML code.  You can edit and inspect this
+;; buffer, or you can just save it with C-x C-w.  `M-x htmlize-file'
+;; will find a file, fontify it, and save the HTML version in
+;; FILE.html, without any additional intervention.  `M-x
+;; htmlize-many-files' allows you to htmlize any number of files in
+;; the same manner.  `M-x htmlize-many-files-dired' does the same for
+;; files marked in a dired buffer.
+
+;; htmlize supports three types of HTML output, selected by setting
+;; `htmlize-output-type': `css', `inline-css', and `font'.  In `css'
+;; mode, htmlize uses cascading style sheets to specify colors; it
+;; generates classes that correspond to Emacs faces and uses <span
+;; class=FACE>...</span> to color parts of text.  In this mode, the
+;; produced HTML is valid under the 4.01 strict DTD, as confirmed by
+;; the W3C validator.  `inline-css' is like `css', except the CSS is
+;; put directly in the STYLE attribute of the SPAN element, making it
+;; possible to paste the generated HTML to other documents.  In `font'
+;; mode, htmlize uses <font color="...">...</font> to colorize HTML,
+;; which is not standard-compliant, but works better in older
+;; browsers.  `css' mode is the default.
+
+;; You can also use htmlize from your Emacs Lisp code.  When called
+;; non-interactively, `htmlize-buffer' and `htmlize-region' will
+;; return the resulting HTML buffer, but will not change current
+;; buffer or move the point.
+
+;; I tried to make the package elisp-compatible with multiple Emacsen,
+;; specifically aiming for XEmacs 19.14+ and GNU Emacs 19.34+.  Please
+;; let me know if it doesn't work on some of those, and I'll try to
+;; fix it.  I relied heavily on the presence of CL extensions,
+;; especially for cross-emacs compatibility; please don't try to
+;; remove that particular dependency.  When byte-compiling under GNU
+;; Emacs, you're likely to get some warnings; just ignore them.
+
+;; The latest version should be available at:
+;;
+;;        <http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el>
+;;
+;; You can find a sample of htmlize's output (possibly generated with
+;; an older version) at:
+;;
+;;        <http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el.html>
+
+;; 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, Juri
+;; Linkov, Maciek Pasternacki, and many others.
+
+;; User quotes: "You sir, are a sick, sick, _sick_ person. :)"
+;;                  -- Bill Perry, author of Emacs/W3
+
+
+;;; Code:
+
+(require 'cl)
+(eval-when-compile
+  (if (string-match "XEmacs" emacs-version)
+      (byte-compiler-options
+	(warnings (- unresolved))))
+  (defvar font-lock-auto-fontify)
+  (defvar font-lock-support-mode)
+  (defvar global-font-lock-mode)
+  (when (and (eq emacs-major-version 19)
+	     (not (string-match "XEmacs" emacs-version)))
+    ;; Older versions of GNU Emacs fail to autoload cl-extra even when
+    ;; `cl' is loaded.
+    (load "cl-extra")))
+
+(defconst htmlize-version "1.36")
+
+;; Incantations to make custom stuff work without customize, e.g. on
+;; XEmacs 19.14 or GNU Emacs 19.34.
+(eval-and-compile
+  (condition-case ()
+      (require 'custom)
+    (error nil))
+  (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
+      nil				; we've got what we needed
+    ;; No custom or obsolete custom, define surrogates.  Define all
+    ;; three macros, so we don't hose another library that expects
+    ;; e.g. `defface' to work after (fboundp 'defcustom) succeeds.
+    (defmacro defgroup (&rest ignored) nil)
+    (defmacro defcustom (var value doc &rest ignored)
+      `(defvar ,var ,value ,doc))
+    (defmacro defface (face value doc &rest stuff)
+      `(make-face ,face))))
+
+(defgroup htmlize nil
+  "Convert buffer text and faces to HTML."
+  :group 'hypermedia)
+
+(defcustom htmlize-head-tags ""
+  "*Additional tags to insert within HEAD of the generated document."
+  :type 'string
+  :group 'htmlize)
+
+(defcustom htmlize-output-type 'css
+  "*Output type of generated HTML, one of `css', `inline-css', or `font'.
+When set to `css' (the default), htmlize will generate a style sheet
+with description of faces, and use it in the HTML document, specifying
+the faces in the actual text with <span class=\"FACE\">.
+
+When set to `inline-css', the style will be generated as above, but
+placed directly in the STYLE attribute of the span ELEMENT: <span
+style=\"STYLE\">.  This makes it easier to paste the resulting HTML to
+other documents.
+
+When set to `font', the properties will be set using layout tags
+<font>, <b>, <i>, <u>, and <strike>.
+
+`css' output is normally preferred, but `font' is still useful for
+supporting old, pre-CSS browsers, and both `inline-css' and `font' for
+easier embedding of colorized text in foreign HTML documents (no style
+sheet to carry around)."
+  :type '(choice (const css) (const inline-css) (const font))
+  :group 'htmlize)
+
+(defcustom htmlize-generate-hyperlinks t
+  "*Non-nil means generate the hyperlinks for URLs and mail addresses.
+This is on by default; set it to nil if you don't want htmlize to
+insert hyperlinks in the resulting HTML.  (In which case you can still
+do your own hyperlinkification from htmlize-after-hook.)"
+  :type 'boolean
+  :group 'htmlize)
+
+(defcustom htmlize-hyperlink-style "
+      a {
+        color: inherit;
+        background-color: inherit;
+        font: inherit;
+        text-decoration: inherit;
+      }
+      a:hover {
+        text-decoration: underline;
+      }
+"
+  "*The CSS style used for hyperlinks when in CSS mode."
+  :type 'string
+  :group 'htmlize)
+
+(defcustom htmlize-replace-form-feeds t
+  "*Non-nil means replace form feeds in source code with HTML separators.
+Form feeds are the ^L characters at line beginnings that are sometimes
+used to separate sections of source code.  If this variable is set to
+`t', form feed characters are replaced with the <hr> separator.  If this
+is a string, it specifies the replacement to use.  Note that <pre> is
+temporarily closed before the separator is inserted, so the default
+replacement is effectively \"</pre><hr /><pre>\".  If you specify
+another replacement, don't forget to close and reopen the <pre> if you
+want the output to remain valid HTML.
+
+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
+of the generated HTML:
+
+  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=CHARSET\">
+
+where CHARSET is the value you've set for htmlize-html-charset.  Valid
+charsets are defined by MIME and include strings like \"iso-8859-1\",
+\"iso-8859-15\", \"utf-8\", etc.
+
+If you are using non-Latin-1 charsets, you might need to set this for
+your documents to render correctly.  Also, the W3C validator requires
+submitted HTML documents to declare a charset.  So if you care about
+validation, you can use this to prevent the validator from bitching.
+
+Needless to say, if you set this, you should actually make sure that
+the buffer is in the encoding you're claiming it is in.  (Under Mule
+that is done by ensuring the correct \"file coding system\" for the
+buffer.)  If you don't understand what that means, this option is
+probably not for you."
+  :type '(choice (const :tag "Unset" nil)
+		 string)
+  :group 'htmlize)
+
+(defcustom htmlize-convert-nonascii-to-entities (featurep 'mule)
+  "*Whether non-ASCII characters should be converted to HTML entities.
+
+When this is non-nil, characters with codes in the 128-255 range will be
+considered Latin 1 and rewritten as \"&#CODE;\".  Characters with codes
+above 255 will be converted to \"&#UCS;\", where UCS denotes the Unicode
+code point of the character.  If the code point cannot be determined,
+the character will be copied unchanged, as would be the case if the
+option were nil.
+
+When the option is nil, the non-ASCII characters are copied to HTML
+without modification.  In that case, the web server and/or the browser
+must be set to understand the encoding that was used when saving the
+buffer.  (You might also want to specify it by setting
+`htmlize-html-charset'.)
+
+Note that in an HTML entity \"&#CODE;\", CODE is always a UCS code point,
+which has nothing to do with the charset the page is in.  For example,
+\"&#169;\" *always* refers to the copyright symbol, regardless of charset
+specified by the META tag or the charset sent by the HTTP server.  In
+other words, \"&#169;\" is exactly equivalent to \"&copy;\".
+
+By default, entity conversion is turned on for Mule-enabled Emacsen and
+turned off otherwise.  This is because Mule knows the charset of
+non-ASCII characters in the buffer.  A non-Mule Emacs cannot tell
+whether a character with code 0xA9 represents Latin 1 copyright symbol,
+Latin 2 \"S with caron\", or something else altogether.  Setting this to
+t without Mule means asserting that 128-255 characters always mean Latin
+1.
+
+For most people htmlize will work fine with this option left at the
+default setting; don't change it unless you know what you're doing."
+  :type 'sexp
+  :group 'htmlize)
+
+(defcustom htmlize-ignore-face-size 'absolute
+  "*Whether face size should be ignored when generating HTML.
+If this is nil, face sizes are used.  If set to t, sizes are ignored
+If set to `absolute', only absolute size specifications are ignored.
+Please note that font sizes only work with CSS-based output types."
+  :type '(choice (const :tag "Don't ignore" nil)
+		 (const :tag "Ignore all" t)
+		 (const :tag "Ignore absolute" absolute))
+  :group 'htmlize)
+
+(defcustom htmlize-css-name-prefix ""
+  "*The prefix used for CSS names.
+The CSS names that htmlize generates from face names are often too
+generic for CSS files; for example, `font-lock-type-face' is transformed
+to `type'.  Use this variable to add a prefix to the generated names.
+The string \"htmlize-\" is an example of a reasonable prefix."
+  :type 'string
+  :group 'htmlize)
+
+(defcustom htmlize-use-rgb-txt t
+  "*Whether `rgb.txt' should be used to convert color names to RGB.
+
+This conversion means determining, for instance, that the color
+\"IndianRed\" corresponds to the (205, 92, 92) RGB triple.  `rgb.txt'
+is the X color database that maps hundreds of color names to such RGB
+triples.  When this variable is non-nil, `htmlize' uses `rgb.txt' to
+look up color names.
+
+If this variable is nil, htmlize queries Emacs for RGB components of
+colors using `color-instance-rgb-components' and `x-color-values'.
+This can yield incorrect results on non-true-color displays.
+
+If the `rgb.txt' file is not found (which will be the case if you're
+running Emacs on non-X11 systems), this option is ignored."
+  :type 'boolean
+  :group 'htmlize)
+
+(defcustom htmlize-html-major-mode nil
+  "The mode the newly created HTML buffer will be put in.
+Set this to nil if you prefer the default (fundamental) mode."
+  :type '(radio (const :tag "No mode (fundamental)" nil)
+		 (function-item html-mode)
+		 (function :tag "User-defined major mode"))
+  :group 'htmlize)
+
+(defvar htmlize-before-hook nil
+  "Hook run before htmlizing a buffer.
+The hook functions are run in the source buffer (not the resulting HTML
+buffer).")
+
+(defvar htmlize-after-hook nil
+  "Hook run after htmlizing a buffer.
+Unlike `htmlize-before-hook', these functions are run in the generated
+HTML buffer.  You may use them to modify the outlook of the final HTML
+output.")
+
+(defvar htmlize-file-hook nil
+  "Hook run by `htmlize-file' after htmlizing a file, but before saving it.")
+
+(defvar htmlize-buffer-places)
+
+;;; Some cross-Emacs compatibility.
+
+;; I try to conditionalize on features rather than Emacs version, but
+;; in some cases checking against the version *is* necessary.
+(defconst htmlize-running-xemacs (string-match "XEmacs" emacs-version))
+
+(eval-and-compile
+  ;; save-current-buffer, with-current-buffer, and with-temp-buffer
+  ;; are not available in 19.34 and in older XEmacsen.  Strictly
+  ;; speaking, we should stick to our own namespace and define and use
+  ;; htmlize-save-current-buffer, etc.  But non-standard special forms
+  ;; are a pain because they're not properly fontified or indented and
+  ;; because they look weird and ugly.  So I'll just go ahead and
+  ;; define the real ones if they're not available.  If someone
+  ;; convinces me that this breaks something, I'll switch to the
+  ;; "htmlize-" namespace.
+  (unless (fboundp 'save-current-buffer)
+    (defmacro save-current-buffer (&rest forms)
+      `(let ((__scb_current (current-buffer)))
+	 (unwind-protect
+	     (progn ,@forms)
+	   (set-buffer __scb_current)))))
+  (unless (fboundp 'with-current-buffer)
+    (defmacro with-current-buffer (buffer &rest forms)
+      `(save-current-buffer (set-buffer ,buffer) ,@forms)))
+  (unless (fboundp 'with-temp-buffer)
+    (defmacro with-temp-buffer (&rest forms)
+      (let ((temp-buffer (gensym "tb-")))
+	`(let ((,temp-buffer
+		(get-buffer-create (generate-new-buffer-name " *temp*"))))
+	   (unwind-protect
+	       (with-current-buffer ,temp-buffer
+		 ,@forms)
+	     (and (buffer-live-p ,temp-buffer)
+		  (kill-buffer ,temp-buffer))))))))
+
+;; We need a function that efficiently finds the next change of a
+;; property (usually `face'), preferably regardless of whether the
+;; change occurred because of a text property or an extent/overlay.
+;; As it turns out, it is not easy to do that compatibly.
+;;
+;; Under XEmacs, `next-single-property-change' does that.  Under GNU
+;; Emacs beginning with version 21, `next-single-char-property-change'
+;; is available and does the same.  GNU Emacs 20 had
+;; `next-char-property-change', which we can use.  GNU Emacs 19 didn't
+;; provide any means for simultaneously examining overlays and text
+;; properties, so when using Emacs 19.34, we punt and fall back to
+;; `next-single-property-change', thus ignoring overlays altogether.
+
+(cond
+ (htmlize-running-xemacs
+  ;; XEmacs: good.
+  (defun htmlize-next-change (pos prop &optional limit)
+    (next-single-property-change pos prop nil (or limit (point-max)))))
+ ((fboundp 'next-single-char-property-change)
+  ;; GNU Emacs 21: good.
+  (defun htmlize-next-change (pos prop &optional limit)
+    (next-single-char-property-change pos prop nil limit)))
+ ((fboundp 'next-char-property-change)
+  ;; GNU Emacs 20: bad, but fixable.
+  (defun htmlize-next-change (pos prop &optional limit)
+    (let ((done nil)
+	  (current-value (get-char-property pos prop))
+	  newpos next-value)
+      ;; Loop over positions returned by next-char-property-change
+      ;; until the value of PROP changes or we've hit EOB.
+      (while (not done)
+	(setq newpos (next-char-property-change pos limit)
+	      next-value (get-char-property newpos prop))
+	(cond ((eq newpos pos)
+	       ;; Possibly at EOB?  Whatever, just don't infloop.
+	       (setq done t))
+	      ((eq next-value current-value)
+	       ;; PROP hasn't changed -- keep looping.
+	       )
+	      (t
+	       (setq done t)))
+	(setq pos newpos))
+      pos)))
+ (t
+  ;; GNU Emacs 19.34: hopeless, cannot properly support overlays.
+  (defun htmlize-next-change (pos prop &optional limit)
+    (unless limit
+      (setq limit (point-max)))
+    (let ((res (next-single-property-change pos prop)))
+      (if (or (null res)
+	      (> res limit))
+	  limit
+	res)))))
+
+;;; Transformation of buffer text: HTML escapes, untabification, etc.
+
+(defvar htmlize-basic-character-table
+  ;; Map characters in the 0-127 range to either one-character strings
+  ;; or to numeric entities.
+  (let ((table (make-vector 128 ?\0)))
+    ;; Map characters in the 32-126 range to themselves, others to
+    ;; &#CODE entities;
+    (dotimes (i 128)
+      (setf (aref table i) (if (and (>= i 32) (<= i 126))
+			       (char-to-string i)
+			     (format "&#%d;" i))))
+    ;; Set exceptions manually.
+    (setf
+     ;; Don't escape newline, carriage return, and TAB.
+     (aref table ?\n) "\n"
+     (aref table ?\r) "\r"
+     (aref table ?\t) "\t"
+     ;; Escape &, <, and >.
+     (aref table ?&) "&amp;"
+     (aref table ?<) "&lt;"
+     (aref table ?>) "&gt;"
+     ;; Not escaping '"' buys us a measurable speedup.  It's only
+     ;; necessary to quote it for strings used in attribute values,
+     ;; which htmlize doesn't do.
+     ;(aref table ?\") "&quot;"
+     )
+    table))
+
+;; A cache of HTML representation of non-ASCII characters.  Depending
+;; on availability of `encode-char' and the setting of
+;; `htmlize-convert-nonascii-to-entities', this maps non-ASCII
+;; characters to either "&#<code>;" or "<char>" (mapconcat's mapper
+;; must always return strings).  It's only filled as characters are
+;; encountered, so that in a buffer with e.g. French text, it will
+;; only ever contain French accented characters as keys.  It's cleared
+;; on each entry to htmlize-buffer-1 to allow modifications of
+;; `htmlize-convert-nonascii-to-entities' to take effect.
+(defvar htmlize-extended-character-cache (make-hash-table :test 'eq))
+
+(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 funcalls and consing.
+  (if (not (string-match "[^\r\n\t -%'-;=?-~]" string))
+      string
+    (mapconcat (lambda (char)
+		 (cond
+		  ((< char 128)
+		   ;; ASCII: use htmlize-basic-character-table.
+		   (aref htmlize-basic-character-table char))
+		  ((gethash char htmlize-extended-character-cache)
+		   ;; We've already seen this char; return the cached
+		   ;; string.
+		   )
+		  ((not htmlize-convert-nonascii-to-entities)
+		   ;; If conversion to entities is not desired, always
+		   ;; copy the char literally.
+		   (setf (gethash char htmlize-extended-character-cache)
+			 (char-to-string char)))
+		  ((< char 256)
+		   ;; Latin 1: no need to call encode-char.
+		   (setf (gethash char htmlize-extended-character-cache)
+			 (format "&#%d;" char)))
+		  ((and (fboundp 'encode-char)
+			;; 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))))
+		  (t
+		   ;; encode-char doesn't work for this char.  Copy it
+		   ;; unchanged and hope for the best.
+		   (setf (gethash char htmlize-extended-character-cache)
+			 (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.  Where buffer-substring-no-properties
+  ;; mandates an ellipsis to be shown, htmlize-ellipsis is inserted.
+  (let ((pos beg)
+	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))
+      (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
+	;; without concatenation.  This avoids additional consing in
+	;; regions without any invisible text.
+	(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.
+  (let ((v (make-vector 32 nil)))
+    (dotimes (i (length v))
+      (setf (aref v i) (make-string i ?\ )))
+    v))
+
+(defun htmlize-untabify (text start-column)
+  "Untabify TEXT, assuming it starts at START-COLUMN."
+  (let ((column start-column)
+	(last-match 0)
+	(chunk-start 0)
+	chunks match-pos tab-size)
+    (while (string-match "[\t\n]" text last-match)
+      (setq match-pos (match-beginning 0))
+      (cond ((eq (aref text match-pos) ?\t)
+	     ;; Encountered a tab: create a chunk of text followed by
+	     ;; the expanded tab.
+	     (push (substring text chunk-start match-pos) chunks)
+	     ;; Increase COLUMN by the length of the text we've
+	     ;; skipped since last tab or newline.  (Encountering
+	     ;; newline resets it.)
+	     (incf column (- match-pos last-match))
+	     ;; Calculate tab size based on tab-width and COLUMN.
+	     (setq tab-size (- tab-width (% column tab-width)))
+	     ;; Expand the tab.
+	     (push (aref htmlize-tab-spaces tab-size) chunks)
+	     (incf column tab-size)
+	     (setq chunk-start (1+ match-pos)))
+	    (t
+	     ;; Reset COLUMN at beginning of line.
+	     (setq column 0)))
+      (setq last-match (1+ match-pos)))
+    ;; If no chunks have been allocated, it means there have been no
+    ;; tabs to expand.  Return TEXT unmodified.
+    (if (null chunks)
+	text
+      (when (< chunk-start (length text))
+	;; Push the remaining chunk.
+	(push (substring text chunk-start) chunks))
+      ;; Generate the output from the available chunks.
+      (apply #'concat (nreverse chunks)))))
+
+(defun htmlize-despam-address (string)
+  "Replace every occurrence of '@' in STRING with &#64;.
+`htmlize-make-hyperlinks' uses this to spam-protect mailto links
+without modifying their meaning."
+  ;; Suggested by Ville Skytta.
+  (while (string-match "@" string)
+    (setq string (replace-match "&#64;" nil t string)))
+  string)
+
+(defun htmlize-make-hyperlinks ()
+  "Make hyperlinks in HTML."
+  ;; Function originally submitted by Ville Skytta.  Rewritten by
+  ;; Hrvoje Niksic, then modified by Ville Skytta and Hrvoje Niksic.
+  (goto-char (point-min))
+  (while (re-search-forward
+	  "&lt;\\(\\(mailto:\\)?\\([-=+_.a-zA-Z0-9]+@[-_.a-zA-Z0-9]+\\)\\)&gt;"
+	  nil t)
+    (let ((address (match-string 3))
+	  (link-text (match-string 1)))
+      (delete-region (match-beginning 0) (match-end 0))
+      (insert "&lt;<a href=\"mailto:"
+	      (htmlize-despam-address address)
+	      "\">"
+	      (htmlize-despam-address link-text)
+	      "</a>&gt;")))
+  (goto-char (point-min))
+  (while (re-search-forward "&lt;\\(\\(URL:\\)?\\([a-zA-Z]+://[^;]+\\)\\)&gt;"
+			    nil t)
+    (let ((url (match-string 3))
+	  (link-text (match-string 1)))
+      (delete-region (match-beginning 0) (match-end 0))
+      (insert "&lt;<a href=\"" url "\">" link-text "</a>&gt;"))))
+
+;; Tests for htmlize-make-hyperlinks:
+
+;; <mailto:hniksic@xemacs.org>
+;; <http://fly.srk.fer.hr>
+;; <URL:http://www.xemacs.org>
+;; <http://www.mail-archive.com/bbdb-info@xemacs.org/>
+;; <hniksic@xemacs.org>
+;; <xalan-dev-sc.10148567319.hacuhiucknfgmpfnjcpg-john=doe.com@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&#58;" nil t)))
+
+
+;;; Color handling.
+
+(if (fboundp 'locate-file)
+    (defalias 'htmlize-locate-file 'locate-file)
+  (defun htmlize-locate-file (file path)
+    (dolist (dir path nil)
+      (when (file-exists-p (expand-file-name file dir))
+	(return (expand-file-name file dir))))))
+
+(defvar htmlize-x-library-search-path
+  '("/usr/X11R6/lib/X11/"
+    "/usr/X11R5/lib/X11/"
+    "/usr/lib/X11R6/X11/"
+    "/usr/lib/X11R5/X11/"
+    "/usr/local/X11R6/lib/X11/"
+    "/usr/local/X11R5/lib/X11/"
+    "/usr/local/lib/X11R6/X11/"
+    "/usr/local/lib/X11R5/X11/"
+    "/usr/X11/lib/X11/"
+    "/usr/lib/X11/"
+    "/usr/local/lib/X11/"
+    "/usr/X386/lib/X11/"
+    "/usr/x386/lib/X11/"
+    "/usr/XFree86/lib/X11/"
+    "/usr/unsupported/lib/X11/"
+    "/usr/athena/lib/X11/"
+    "/usr/local/x11r5/lib/X11/"
+    "/usr/lpp/Xamples/lib/X11/"
+    "/usr/openwin/lib/X11/"
+    "/usr/openwin/share/lib/X11/"))
+
+(defun htmlize-get-color-rgb-hash (&optional rgb-file)
+  "Return a hash table mapping X color names to RGB values.
+The keys in the hash table are X11 color names, and the values are the
+#rrggbb RGB specifications, extracted from `rgb.txt'.
+
+If RGB-FILE is nil, the function will try hard to find a suitable file
+in the system directories.
+
+If no rgb.txt file is found, return nil."
+  (let ((rgb-file (or rgb-file (htmlize-locate-file
+				"rgb.txt"
+				htmlize-x-library-search-path)))
+	(hash nil))
+    (when rgb-file
+      (with-temp-buffer
+	(insert-file-contents rgb-file)
+	(setq hash (make-hash-table :test 'equal))
+	(while (not (eobp))
+	  (cond ((looking-at "^\\s-*\\([!#]\\|$\\)")
+		 ;; Skip comments and empty lines.
+		 )
+		((looking-at
+		  "[ \t]*\\([0-9]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\(.*\\)")
+		 (setf (gethash (downcase (match-string 4)) hash)
+		       (format "#%02x%02x%02x"
+			       (string-to-number (match-string 1))
+			       (string-to-number (match-string 2))
+			       (string-to-number (match-string 3)))))
+		(t
+		 (error
+		  "Unrecognized line in %s: %s"
+		  rgb-file
+		  (buffer-substring (point) (progn (end-of-line) (point))))))
+	  (forward-line 1))))
+    hash))
+
+;; Compile the RGB map when loaded.  On systems where rgb.txt is