Commit e78d6b941698

Vincent Demeester <vincent@sbr.pm>
2017-04-24 17:10:35
Add pandoc mode
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 35ba05d
.emacs.d/elpa/pandoc-mode-20161104.1521/dir
@@ -0,0 +1,18 @@
+This is the file .../info/dir, which contains the
+topmost node of the Info hierarchy, called (dir)Top.
+The first time you invoke Info you start off looking at this node.
+
+File: dir,	Node: Top	This is the top of the INFO tree
+
+  This (the Directory node) gives a menu of major topics.
+  Typing "q" exits, "?" lists all Info commands, "d" returns here,
+  "h" gives a primer for first-timers,
+  "mEmacs<Return>" visits the Emacs manual, etc.
+
+  In Emacs, you can click mouse button 2 on a menu item or cross reference
+  to select it.
+
+* Menu:
+
+Emacs
+* Pandoc mode: (pandoc-mode).      Minor mode for interacting with Pandoc.
.emacs.d/elpa/pandoc-mode-20161104.1521/pandoc-mode-autoloads.el
@@ -0,0 +1,33 @@
+;;; pandoc-mode-autoloads.el --- automatically extracted autoloads
+;;
+;;; Code:
+(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path))))
+
+;;;### (autoloads nil "pandoc-mode" "pandoc-mode.el" (22782 4330
+;;;;;;  710847 487000))
+;;; Generated autoloads from pandoc-mode.el
+
+(autoload 'pandoc-mode "pandoc-mode" "\
+Minor mode for interacting with Pandoc.
+
+\(fn &optional ARG)" t nil)
+
+(autoload 'conditionally-turn-on-pandoc "pandoc-mode" "\
+Turn on pandoc-mode if a pandoc settings file exists.
+This is for use in major mode hooks.
+
+\(fn)" nil nil)
+
+;;;***
+
+;;;### (autoloads nil nil ("pandoc-mode-pkg.el" "pandoc-mode-utils.el")
+;;;;;;  (22782 4330 757846 31000))
+
+;;;***
+
+;; Local Variables:
+;; version-control: never
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; End:
+;;; pandoc-mode-autoloads.el ends here
.emacs.d/elpa/pandoc-mode-20161104.1521/pandoc-mode-pkg.el
@@ -0,0 +1,8 @@
+(define-package "pandoc-mode" "20161104.1521" "Minor mode for interacting with Pandoc"
+  '((hydra "0.10.0")
+    (dash "2.10.0"))
+  :keywords
+  '("text" "pandoc"))
+;; Local Variables:
+;; no-byte-compile: t
+;; End:
.emacs.d/elpa/pandoc-mode-20161104.1521/pandoc-mode-utils.el
@@ -0,0 +1,1165 @@
+;;; pandoc-mode-utils.el --- Part of `pandoc-mode'  -*- lexical-binding: t -*-
+
+;; Copyright (c) 2009-2016 Joost Kremers
+
+;; Author: Joost Kremers <joostkremers@fastmail.fm>
+;; Maintainer: Joost Kremers <joostkremers@fastmail.fm>
+;; Created: 31 Oct 2009
+;; Version: 2.20
+;; Keywords: text, pandoc
+;; Package-Requires: ((hydra "0.10.0") (dash "2.10.0"))
+
+;; Redistribution and use in source and binary forms, with or without
+;; modification, are permitted provided that the following conditions
+;; are met:
+;;
+;; 1. Redistributions of source code must retain the above copyright
+;;    notice, this list of conditions and the following disclaimer.
+;; 2. Redistributions in binary form must reproduce the above copyright
+;;    notice, this list of conditions and the following disclaimer in the
+;;    documentation and/or other materials provided with the distribution.
+;; 3. The name of the author may not be used to endorse or promote products
+;;    derived from this software without specific prior written permission.
+;;
+;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+;; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+;; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE,
+;; DATA, OR PROFITS ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+;;; Commentary:
+
+;; This file is part of `pandoc-mode'.
+;;
+;; Pandoc-mode is a minor mode for interacting with Pandoc, a 'universal
+;; document converter': <http://johnmacfarlane.net/pandoc/>.
+;;
+;; See the pandoc-mode manual for usage and installation instructions.
+
+;;; Code:
+
+(require 'dash)
+(require 'cl-lib)
+
+(defgroup pandoc nil "Minor mode for interacting with pandoc." :group 'wp)
+
+(defcustom pandoc-binary "pandoc"
+  "The name of the pandoc binary.
+You can specify a full path here or a relative path (the
+default).  In the latter case, the value of `exec-path` is used
+to search the binary."
+  :group 'pandoc
+  :type 'file)
+
+(defcustom pandoc-use-async t
+  "If non-NIL, use an asynchronous process to run pandoc.
+Using an asynchronous subprocess avoids freezing Emacs, but can
+cause problems sometimes.  Setting this option to nil runs pandoc
+in a synchronous subprocess."
+  :group 'pandoc
+  :type 'boolean)
+
+(defcustom pandoc-process-connection-type (default-value process-connection-type)
+  "Control type of device used to communicate with the pandoc subprocess.
+This option only takes effect if `pandoc-use-async' is set to t.
+The variable `process-connection-type' is set to the value of
+this option before calling pandoc.  See the doc string of that
+variable for details."
+  :group 'pandoc
+  :type '(choice (const :tag "Use a pty" t)
+                 (const :tag "Use a pipe" nil)))
+
+(defcustom pandoc-async-success-hook nil
+  "List of functions to call when `pandoc' returns successfully.
+This hook is only run when `pandoc-use-async' is set to t."
+  :group 'pandoc
+  :type 'hook)
+
+(defcustom pandoc-data-dir "~/.emacs.d/pandoc-mode/"
+  "Default `pandoc-mode' data dir.
+This is where `pandoc-mode' looks for global settings files."
+  :group 'pandoc
+  :type 'directory)
+
+(defcustom pandoc-directives '(("include" . pandoc--process-include-directive)
+                               ("lisp" . pandoc--process-lisp-directive))
+  "List of directives to be processed before pandoc is called.
+The directive must be given without `@@'; the function should
+return a string that will replace the directive and its
+argument (if any).
+
+The directives are processed in the order in which they appear in
+this list.  If a directive produces output that contains another
+directive, the new directive will only be processed if it is of
+the same type (i.e., an @@include directive loading a text that
+also contains @@include directives) or if it is lower on the
+list, not if it appears higher on the list."
+  :group 'pandoc
+  :type '(alist :key-type (string :tag "Directive") :value-type function))
+
+(defcustom pandoc-directives-hook nil
+  "List of functions to call before the directives are processed."
+  :group 'pandoc
+  :type '(repeat function))
+
+(defcustom pandoc-extension-active-marker "X"
+  "Marker used to indicate an active extension."
+  :group 'pandoc
+  :type 'string)
+
+(defcustom pandoc-extension-inactive-marker " "
+  "Marker used to indicate an inactive extension."
+  :group 'pandoc
+  :type 'string)
+
+(defcustom pandoc-citation-jump-function 'pandoc-goto-citation-reference
+  "Action to take when locating a BibTeX reference from a citation key.
+Three actions have been predefined: Open the BibTeX file in Emacs
+and jump to the location of the key (the default option), open
+the BibTeX file in Ebib and show the key, or show the key's entry
+in a *Help* buffer.
+
+It is also possible to use a custom function.  This function must
+take two arguments:
+
+1) The string that matches the citation KEY at point
+2) A list of BIBLIOGRAPHY files
+
+It should direct the user to a bibliographic reference that
+matches KEY."
+  :group 'pandoc
+  :type '(choice (const :tag "Open BibTeX file" pandoc-goto-citation-reference)
+                 (const :tag "Open Ebib" pandoc-open-in-ebib)
+                 (const :tag "Show entry in *Help* buffer" pandoc-show-entry-as-help)
+                 (function :tag "Use a custom function")))
+
+(defcustom pandoc-major-modes
+  '((haskell-mode . "native")
+    (text-mode . "markdown")
+    (markdown-mode . "markdown")
+    (org-mode . "org")
+    (gfm-mode . "markdown_github")
+    (mediawiki-mode . "mediawiki")
+    (textile-mode . "textile")
+    (rst-mode . "rst")
+    (html-mode . "html")
+    (latex-mode . "latex")
+    (json-mode . "json"))
+  "List of major modes and their default pandoc input formats."
+  :group 'pandoc
+  :type '(repeat (cons (symbol :tag "Major mode") (string :tag "Input format"))))
+
+(defvar pandoc--input-formats
+  '(("commonmark"        "CommonMark"               "C")
+    ("docbook"           "DocBook XML"              "D")
+    ("docx"              "MS Word (docx)"           "d")
+    ("epub"              "EPUB E-Book"              "e")
+    ("haddock"           "Haddock Markup"           "k")
+    ("html"              "HTML"                     "h")
+    ("json"              "JSON"                     "j")
+    ("latex"             "LaTeX"                    "l")
+    ("markdown"          "Markdown"                 "m")
+    ("markdown_github"   "Markdown (Github)"        "G")
+    ("markdown_mmd"      "Markdown (MMD)"           "M")
+    ("markdown_phpextra" "Markdown (PHPExtra)"      "P")
+    ("markdown_strict"   "Markdown (Strict)"        "S")
+    ("mediawiki"         "MediaWiki"                "w")
+    ("native"            "Native Haskell"           "N")
+    ("odt"               "OpenOffice Text Document" "L")
+    ("opml"              "OPML"                     "O")
+    ("org"               "Orgmode"                  "o")
+    ("rst"               "reStructuredText"         "r")
+    ("t2t"               "Txt2Tags"                 "x")
+    ("textile"           "Textile"                  "T")
+    ("twiki"             "Twiki"                    "t"))
+  "List of pandoc input formats.")
+
+(defvar pandoc--input-formats-menu
+  (mapcar (lambda (f)
+            (cons (cadr f) (car f)))
+          pandoc--input-formats)
+  "List of items in pandoc-mode's input format menu.")
+
+(defvar pandoc--output-formats
+  ;; used shortcut keys:
+  ;; A B C D E   G H I J K L M N O P R S T   W   Z
+  ;; a   c d e f   h i j k l m n o p r s t u w y z
+  '(("asciidoc"          "AsciiDoc"                 "a")
+    ("beamer"            "Beamer Slide Show"        "B")
+    ("commonmark"        "CommonMark"               "C")
+    ("context"           "ConTeXt"                  "c")
+    ("docbook"           "DocBook XML"              "D")
+    ("docbook5"          "DocBook XML v. 5"         "K") ; not really an appropriate shortcut key
+    ("docx"              "MS Word (docx)"           "d")
+    ("dokuwiki"          "DokuWiki"                 "W")
+    ("dzslides"          "DZSlides Slide Show"      "z") ; not really an appropriate shortcut key
+    ("epub"              "EPUB E-Book"              "e")
+    ("epub3"             "EPUB3 E-Book"             "E")
+    ("fb2"               "FictionBook2"             "f")
+    ("haddock"           "Haddock"                  "k")
+    ("html"              "HTML"                     "h")
+    ("html5"             "HTML5"                    "H")
+    ("icml"              "InDesign ICML"            "I")
+    ("json"              "JSON"                     "j")
+    ("latex"             "LaTeX"                    "l")
+    ("man"               "Man Page"                 "n")
+    ("markdown"          "Markdown"                 "m")
+    ("markdown_github"   "Markdown (Github)"        "G")
+    ("markdown_mmd"      "Markdown (MMD)"           "M")
+    ("markdown_phpextra" "Markdown (PHPExtra)"      "P")
+    ("markdown_strict"   "Markdown (Strict)"        "S")
+    ("mediawiki"         "MediaWiki"                "w")
+    ("native"            "Native Haskell"           "N")
+    ("opendocument"      "OpenDocument XML"         "p")
+    ("odt"               "OpenOffice Text Document" "L")
+    ("opml"              "OPML"                     "O")
+    ("org"               "Org-mode"                 "o")
+    ("plain"             "Plain Text"               "t")
+    ("rst"               "reStructuredText"         "r")
+    ("revealjs"          "RevealJS Slide Show"      "J")
+    ("rtf"               "Rich Text Format"         "R")
+    ("s5"                "S5 HTML/JS Slide Show"    "s")
+    ("slideous"          "Slideous Slide Show"      "u")
+    ("slidy"             "Slidy Slide Show"         "y")
+    ("tei"               "TEI"                      "A") ; not an appropriate shortcut key
+    ("texinfo"           "TeXinfo"                  "i")
+    ("textile"           "Textile"                  "T")
+    ("zimwiki"           "ZimWiki"                  "Z"))
+  "List of Pandoc output formats, their descriptions and hydra shortcut keys.")
+
+(defcustom pandoc-output-format-extensions
+  '(("asciidoc"          ".txt")
+    ("beamer"            ".tex")
+    ("context"           ".tex")
+    ("docbook"           ".xml")
+    ("docbook5"          ".xml")
+    ("dokuwiki"          ".txt")
+    ("dzslides"          ".html")
+    ("epub"              ".epub")
+    ("epub3"             ".epub")
+    ("fb2"               ".fb2")
+    ("haddock"           ".hs")
+    ("html"              ".html")
+    ("html5"             ".html")
+    ("icml"              ".icml")
+    ("json"              ".json")
+    ("latex"             ".tex")
+    ("man"               "")
+    ("markdown"          ".md")
+    ("markdown_github"   ".md")
+    ("markdown_mmd"      ".md")
+    ("markdown_phpextra" ".md")
+    ("markdown_strict"   ".md")
+    ("mediawiki"         ".mw")
+    ("docx"              ".docx")
+    ("native"            ".hs")
+    ("opendocument"      ".odf")
+    ("odt"               ".odt")
+    ("opml"              ".opml")
+    ("org"               ".org")
+    ("plain"             ".txt")
+    ("rst"               ".rst")
+    ("revealjs"          ".html")
+    ("rtf"               ".rtf")
+    ("s5"                ".html")
+    ("slideous"          ".html")
+    ("slidy"             ".html")
+    ("texinfo"           ".texi")
+    ("textile"           ".textile"))
+  "List of Pandoc output formats and their associated file extensions.
+These extensions are used when pandoc-mode creates an output
+file.  The file extension should include a dot.  Note that it does
+not make sense to change the names of the output formats, since
+Pandoc only recognizes the ones listed here.  However, it is
+possible to customize the extensions."
+  :group 'pandoc
+  :type '(repeat :tag "Output Format" (list (string :tag "Format") (string :tag "Extension"))))
+
+(defvar pandoc--pdf-able-formats '("latex" "context" "html5")
+  "List of output formats that can be used to generate pdf output.")
+
+(defvar pandoc--extensions
+  '(("abbreviations"                       ("markdown_phpextra"))
+    ("all_symbols_escapable"               ("markdown" "markdown_mmd"))
+    ("angle_brackets_escapable"            ("markdown_github"))
+    ("ascii_identifiers"                   ("markdown_github"))
+    ("auto_identifiers"                    ("markdown" "markdown_github" "markdown_mmd" "latex" "rst" "mediawiki" "textile"))
+    ("autolink_bare_uris"                  ("markdown_github"))
+    ("backtick_code_blocks"                ("markdown" "markdown_github"))
+    ("blank_before_blockquote"             ("markdown"))
+    ("blank_before_header"                 ("markdown"))
+    ("bracketed_spans"                     ("markdown"))
+    ("citations"                           ("markdown"))
+    ("compact_definition_lists"            ())
+    ("definition_lists"                    ("markdown" "markdown_phpextra" "markdown_mmd"))
+    ("east_asian_line_breaks"              ())
+    ("emoji"                               ("markdown_github"))
+    ("escaped_line_breaks"                 ("markdown"))
+    ("example_lists"                       ("markdown"))
+    ("fancy_lists"                         ("markdown"))
+    ("fenced_code_attributes"              ("markdown" "markdown_github"))
+    ("fenced_code_blocks"                  ("markdown" "markdown_phpextra" "markdown_github"))
+    ("footnotes"                           ("markdown" "markdown_phpextra" "markdown_mmd"))
+    ("grid_tables"                         ("markdown"))
+    ("hard_line_breaks"                    ("markdown_github"))
+    ("header_attributes"                   ("markdown" "markdown_phpextra"))
+    ("ignore_line_breaks"                  ())
+    ("implicit_figures"                    ("markdown"))
+    ("implicit_header_references"          ("markdown" "markdown_mmd"))
+    ("inline_code_attributes"              ("markdown"))
+    ("inline_notes"                        ("markdown"))
+    ("intraword_underscores"               ("markdown" "markdown_phpextra" "markdown_github" "markdown_mmd"))
+    ("latex_macros"                        ("markdown"))
+    ("line_blocks"                         ("markdown"))
+    ("link_attributes"                     ("markdown" "markdown_phpextra")) ; TODO check
+    ("lists_without_preceding_blankline"   ("markdown_github"))
+    ("markdown_attribute"                  ("markdown_phpextra" "markdown_mmd"))
+    ("markdown_in_html_blocks"             ("markdown"))
+    ("mmd_header_identifiers"              ("markdown_mmd"))
+    ("mmd_link_attributes"                 ("markdown_mmd"))
+    ("mmd_title_block"                     ("markdown_mmd"))
+    ("multiline_tables"                    ("markdown"))
+    ("native_divs"                         ("markdown"))
+    ("native_spans"                        ("markdown"))
+    ("pandoc_title_block"                  ("markdown"))
+    ("pipe_tables"                         ("markdown" "markdown_phpextra" "markdown_github" "markdown_mmd"))
+    ("raw_html"                            ("markdown" "markdown_phpextra" "markdown_github" "markdown_mmd" "markdown_strict"))
+    ("raw_tex"                             ("markdown" "markdown_mmd"))
+    ("shortcut_reference_links"            ("markdown" "markdown_strict" "markdown_github" "markdown_phpextra" "markdown_mmd"))
+    ("simple_tables"                       ("markdown"))
+    ("startnum"                            ("markdown"))
+    ("strikeout"                           ("markdown" "markdown_github"))
+    ("subscript"                           ("markdown"))
+    ("superscript"                         ("markdown"))
+    ("table_captions"                      ("markdown"))
+    ("tex_math_dollars"                    ("markdown" "html"))
+    ("tex_math_double_backslash"           ("markdown_mmd" "html"))
+    ("tex_math_single_backslash"           ("markdown_github" "html"))
+    ("yaml_metadata_block"                 ("markdown")))
+  "List of Markdown extensions supported by Pandoc.")
+
+(defvar pandoc--cli-options nil
+  "List of Pandoc command line options that do not need special treatment.
+This includes all command line options except the list and alist
+options, because they need to be handled separately in
+`pandoc--format-all-options'.")
+
+(defvar pandoc--filepath-options
+  '(data-dir
+    extract-media)
+  "List of options that have a file path as value.
+These file paths are expanded before they are sent to Pandoc.
+For relative paths, the file's working directory is used as base
+directory.  Two options are preset, others are added by
+`define-pandoc-file-option'.")
+
+(defvar pandoc--switches '(("Use File Scope" . file-scope))
+  "List of binary options.
+These are set by `define-pandoc-switch'.")
+
+(defvar pandoc--list-options nil
+  "List of options that have a list as value.
+These are set by `define-pandoc-list-option'.")
+
+(defvar pandoc--alist-options nil
+  "List of options that have an alist as value.
+These are set by `define-pandoc-alist-option'.")
+
+(defvar pandoc--options
+  `((read)
+    (read-lhs)
+    (read-extensions ,@(mapcar 'list (sort (mapcar #'car pandoc--extensions) #'string<)))
+    (write . "native")
+    (write-lhs)
+    (write-extensions ,@(mapcar 'list (sort (mapcar #'car pandoc--extensions) #'string<)))
+    (output)
+    (data-dir)
+    (extract-media)
+    (file-scope)
+    (output-dir)
+    (master-file))                      ; the last two are not actually pandoc options
+  "Pandoc option alist.
+List of options and their default values.  For each buffer in
+which pandoc-mode is activated, a buffer-local copy of this list
+is made that stores the local values of the options.  The
+`define-pandoc-*-option' functions add their options to this list
+with the default value NIL.")
+
+(defvar-local pandoc--local-settings nil "A buffer-local variable holding a file's pandoc options.")
+
+(defvar-local pandoc--settings-modified-flag nil "T if the current settings were modified and not saved.")
+
+(defvar pandoc--output-buffer (get-buffer-create " *Pandoc output*"))
+(defvar pandoc--log-buffer (get-buffer-create " *Pandoc log*"))
+
+(defvar pandoc--options-menu nil
+  "Auxiliary variable for creating the options menu.")
+
+(defvar pandoc--files-menu nil
+  "Auxiliary variable for creating the file menu.")
+
+(defun pandoc--read-file-name (prompt dir relative)
+  "Read a file name using PROMPT.
+DIR is the directory used for completing file names.  If RELATIVE
+is non-nil, return the file path as a relative path starting from
+DIR, otherwise return the full path."
+  ;; we inhibit inserting the default directory, though not all completion
+  ;; systems honor this.
+  (let* ((insert-default-directory (not relative))
+         (file (read-file-name prompt dir)))
+    (if relative
+        (file-relative-name file dir)
+      file)))
+
+(defun pandoc--expand-absolute-path (filename)
+  "Expand FILENAME if it is an absolute path.
+If FILENAME is a relative path, return it unchanged."
+  (if (file-name-absolute-p filename)
+      (expand-file-name filename)
+    filename))
+
+(defun pandoc--log (type format-string &rest args)
+  "Write a message to the *Pandoc log* buffer.
+If TYPE is `message', also display the message in the echo area.
+Any other value just logs the message, adding an empty line after
+it.  The arguments FORMAT-STRING and ARGS function as with
+`message'."
+  (with-current-buffer (get-buffer-create pandoc--log-buffer)
+    (goto-char (point-max))
+    (insert (apply #'format format-string args) "\n\n"))
+  (when (eq type 'message)
+    (apply #'message format-string args)))
+
+(defun pandoc--pp-switch (switch)
+  "Return a pretty-printed representation of SWITCH."
+  (if (pandoc--get switch)
+      "yes"
+    "no"))
+
+(defun pandoc--pp-option (option)
+  "Return a pretty-printed representation of OPTION."
+  (or (pandoc--get option)
+      ""))
+
+(defun pandoc--get (option &optional buffer)
+  "Return the value of OPTION.
+Optional argument BUFFER is the buffer from which the value is to
+be retrieved."
+  (or buffer (setq buffer (current-buffer)))
+  (let ((var (intern (concat "pandoc/" (symbol-name option)))))
+    (if (local-variable-p var buffer)
+        (buffer-local-value var buffer)
+      (cdr (assq option (buffer-local-value 'pandoc--local-settings buffer))))))
+
+(defun pandoc--set (option value)
+  "Set the local value of OPTION to VALUE."
+  (when (assq option pandoc--options) ; check if the option is licit
+    (unless (assq option pandoc--local-settings) ; add the option if it's not there
+      (push (list option) pandoc--local-settings)
+      ;; in case of extensions, also add the list of extensions themselves.
+      (if (memq option '(read-extensions write-extensions))
+          (setcdr (assq option pandoc--local-settings) (mapcar #'list (sort (mapcar #'car pandoc--extensions) #'string<)))))
+    (cond
+     ((memq option pandoc--alist-options)
+      (pandoc--set-alist-option option value))
+     ((memq option pandoc--list-options)
+      (pandoc--set-list-option option value))
+     ((eq option 'read-extensions)
+      (pandoc--set-extension (car value) 'read (cdr value)))
+     ((eq option 'write-extensions)
+      (pandoc--set-extension (car value) 'write (cdr value)))
+     (t (setcdr (assq option pandoc--local-settings) value)))
+    (setq pandoc--settings-modified-flag t)))
+
+(defun pandoc--set-alist-option (option new-elem)
+  "Set an alist OPTION.
+NEW-ELEM is a cons (<name> . <value>), which is added to the alist
+for OPTION in `pandoc--local-settings'.  If an element with <name>
+already exists, it is replaced, or removed if <value> is NIL.
+
+If NEW-ELEM is nil, OPTION is unset entirely."
+  (let* ((value (cdr new-elem))
+         (items (pandoc--get option))
+         (item (assoc (car new-elem) items)))
+    (cond
+     ((null new-elem)
+      (setq items nil))
+     ((and item value) ; if <name> exists and we have a new value
+      (setcdr item value)) ; replace the existing value
+     ((and item (not value)) ; if <name> exists but we have no new value
+      (setq items (delq item items))) ; remove <name>
+     ((and (not item) value) ; if <name> does not exist
+      (setq items (cons new-elem items)))) ; add it
+    (setcdr (assoc option pandoc--local-settings) items)))
+
+(defun pandoc--set-list-option (option value)
+  "Add VALUE to list option OPTION.
+If VALUE is nil, OPTION is unset entirely."
+  (let* ((values (pandoc--get option)))
+    (setcdr (assoc option pandoc--local-settings)
+            (if value
+                (cons value values)
+              nil)))) ; if VALUE was nil, we unset the option
+
+(defun pandoc--remove-from-list-option (option value)
+  "Remove VALUE from the list of OPTION."
+  (let* ((values (pandoc--get option))
+         (new-values (remove value values)))
+    (setcdr (assoc option pandoc--local-settings) new-values)))
+
+(defun pandoc--toggle (switch)
+  "Toggle the value of SWITCH."
+  (pandoc--set switch (not (pandoc--get switch))))
+
+;; Note: the extensions appear to be binary options, but they are not:
+;; they're really (balanced) ternary options. They can be on or off, but
+;; that doesn't tell us whether they're on or off because the user set them
+;; that way or because that's the default setting for the relevant format.
+;;
+;; What we do is we create an alist of the extensions, where each extension
+;; can have one of three values: nil, meaning default, the symbol -,
+;; meaning switched off by the user, or the symbol +, meaning switched on
+;; by the user.
+
+(defun pandoc--extension-in-format-p (extension format &optional rw)
+  "Check if EXTENSION is a default extension for FORMAT.
+RW must be either 'read or 'write, indicating whether FORMAT is
+being considered as an input or an output format."
+  (let ((formats (cadr (assoc extension pandoc--extensions))))
+    (or (member format formats)
+        (member format (cadr (assoc rw formats))))))
+
+(defun pandoc--extension-active-p (extension rw)
+  "Return T if EXTENSION is active in the current buffer.
+RW is either `read' or `write', indicating whether to test for the
+input or the output format.
+
+An extension is active either if it's part of the in/output
+format and hasn't been deactivated by the user, or if the user
+has activated it."
+  (let ((value (pandoc--get-extension extension rw)))
+    (or (eq value '+)
+        (and (not value)
+             (pandoc--extension-in-format-p extension (pandoc--get rw) rw)))))
+
+(defun pandoc--set-extension (extension rw value)
+  "Set the value of EXTENSION for RW to VALUE.
+RW is either 'read or 'write, indicating whether the read or
+write extension is to be set."
+  (setcdr (assoc extension (if (eq rw 'read)
+                               (pandoc--get 'read-extensions)
+                             (pandoc--get 'write-extensions)))
+          value))
+
+(defun pandoc--get-extension (extension rw)
+  "Return the value of EXTENSION for RW.
+RW is either 'read or 'write, indicating whether the read or
+write extension is to be queried."
+  (cdr (assoc extension (if (eq rw 'read)
+                            (pandoc--get 'read-extensions)
+                          (pandoc--get 'write-extensions)))))
+
+;; hydra variables
+(defvar pandoc--reader-hydra-list nil)
+(defvar pandoc--writer-hydra-list nil)
+(defvar pandoc--specific-hydra-list nil)
+(defvar pandoc--html-hydra-list nil)
+(defvar pandoc--tex-hydra-list nil)
+(defvar pandoc--epub-hydra-list nil)
+(defvar pandoc--citations-hydra-list nil)
+(defvar pandoc--math-hydra-list nil)
+
+;; menu variables
+(defvar pandoc--reader-menu-list nil)
+(defvar pandoc--writer-menu-list nil)
+(defvar pandoc--specific-menu-list nil)
+(defvar pandoc--html-menu-list nil)
+(defvar pandoc--tex-menu-list nil)
+(defvar pandoc--epub-menu-list nil)
+(defvar pandoc--citations-menu-list nil)
+(defvar pandoc--math-menu-list nil)
+
+(defmacro define-pandoc-switch (option hydra description)
+  "Create a binary option.
+OPTION must be a symbol and must be identical to the long form of
+the pandoc option (without dashes).
+
+HYDRA is a list describing how the option must be added to one of
+the hydras.  The first element is a symbol naming the hydra (and
+menu) to which the option must be added, The second element is a
+string of one character, the key by which the option will be
+available in the hydra, and the third is a format string
+describing the width of the option (which must be the same for
+all options in a single hydra).
+
+DESCRIPTION is the description of the option as it will appear in
+the menu."
+  (declare (indent defun))
+  `(progn
+     (push ,(vector description `(pandoc--toggle (quote ,option))
+                    :active t
+                    :style 'toggle
+                    :selected `(pandoc--get (quote ,option)))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-menu-list")))
+     (push (cons ,description (quote ,option)) pandoc--switches)
+     (push (quote ,option) pandoc--cli-options)
+     (push (list (quote ,option)) pandoc--options)
+     (push (quote ,(list (concat "_" (cadr hydra) "_: " (format (cl-caddr hydra) description) (format " [%%s(pandoc--pp-switch '%s)]" option))
+                         (cadr hydra)
+                         `(pandoc--toggle (quote ,option))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-hydra-list")))))
+
+(defmacro define-pandoc-file-option (option hydra prompt &optional default)
+  "Define OPTION as a file option.
+The option is added to `pandoc--options', `pandoc--cli-options',
+and to `pandoc--filepath-options'.  Furthermore, a menu entry is
+created and a function to set/unset the option.
+
+The function to set the option can be called with the prefix
+argument `\\[universal-argument] -' (or `\\[negative-argument]')
+to unset the option.  It can also be called with the prefix
+argument \\[universal-argument], in which case the file's full
+path is stored.
+
+HYDRA is a list describing how the option must be added to one of
+the hydras.  The first element is a symbol naming the hydra (and
+menu) to which the option must be added, The second element is a
+string of one character, the key by which the option will be
+available in the hydra, and the third is a format string
+describing the width of the option (which must be the same for
+all options in a single hydra).
+
+OPTION must be a symbol and must be identical to the long form of
+the pandoc option (without dashes).  PROMPT is a string that is
+used to prompt for setting and unsetting the option.  It must be
+formulated in such a way that the strings \"No \", \"Set \" and
+\"Default \" can be added before it.  DEFAULT must be either NIL
+or T and indicates whether the option can have a default value."
+  (declare (indent defun))
+  `(progn
+     (push (quote ,option) pandoc--filepath-options)
+     (push (quote ,option) pandoc--cli-options)
+     (push (list (quote ,option)) pandoc--options)
+     (push (list ,@(delq nil ; if DEFAULT is nil, we need to remove it from the list.
+                         (list prompt
+                               (vector (concat "No " prompt) `(pandoc--set (quote ,option) nil)
+                                       :active t
+                                       :style 'radio
+                                       :selected `(null (pandoc--get (quote ,option))))
+                               (when default
+                                 (vector (concat "Default " prompt) `(pandoc--set (quote ,option) t)
+                                         :active t
+                                         :style 'radio
+                                         :selected `(eq (pandoc--get (quote ,option)) t)))
+                               (vector (concat "Set " prompt "...") (intern (concat "pandoc-set-"
+                                                                                    (symbol-name option)))
+                                       :active t
+                                       :style 'radio
+                                       :selected `(stringp (pandoc--get (quote ,option)))))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-menu-list")))
+
+     (push (quote ,(list (concat "_" (cadr hydra) "_: " (format (cl-caddr hydra) prompt) (format " [%%s(pandoc--pp-option '%s)]" option))
+                         (cadr hydra)
+                         (intern (concat "pandoc-set-" (symbol-name option)))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-hydra-list")))
+
+     (fset (quote ,(intern (concat "pandoc-set-" (symbol-name option))))
+           (lambda (prefix)
+             (interactive "P")
+             (pandoc--set (quote ,option)
+                          (cond
+                           ((eq prefix '-) nil) ; C-u - or M--
+                           ((listp prefix) ; no prefix or C-u
+                            (pandoc--read-file-name (concat ,prompt ": ") default-directory (not prefix)))
+                           (t ,default))))))) ; any other prefix
+
+(defmacro define-pandoc-number-option (option hydra prompt)
+  "Define OPTION as a numeric option.
+The option is added to `pandoc--options' and to
+`pandoc--cli-options'.  Furthermore, a menu entry is created and
+a function to set/unset the option.
+
+The function to set the option can be called with the prefix
+argument `\\[universal-argument] -' (or `\\[negative-argument]')
+to unset the option.  If no prefix argument is given, the user is
+prompted for a value.
+
+HYDRA is a list describing how the option must be added to one of
+the hydras.  The first element is a symbol naming the hydra (and
+menu) to which the option must be added, The second element is a
+string of one character, the key by which the option will be
+available in the hydra, and the third is a format string
+describing the width of the option (which must be the same for
+all options in a single hydra).
+
+OPTION must be a symbol and must be identical to the long form of
+the pandoc option (without dashes).  PROMPT is a string that is
+used to prompt for setting and unsetting the option.  It must be
+formulated in such a way that the strings \"Default \" and \"Set
+\" can be added before it."
+  (declare (indent defun))
+  `(progn
+     (push (list (quote ,option)) pandoc--options)
+     (push (quote ,option) pandoc--cli-options)
+     (push (list ,prompt
+                 ,(vector (concat "Default " prompt) `(pandoc--set (quote ,option) nil)
+                          :active t
+                          :style 'radio
+                          :selected `(null (pandoc--get (quote ,option))))
+                 ,(vector (concat "Set " prompt "...") (intern (concat "pandoc-set-" (symbol-name option)))
+                          :active t
+                          :style 'radio
+                          :selected `(pandoc--get (quote ,option))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-menu-list")))
+
+     (push (quote ,(list (concat "_" (cadr hydra) "_: " (format (cl-caddr hydra) prompt) (format " [%%s(pandoc--pp-option '%s)]" option))
+                         (cadr hydra)
+                         (intern (concat "pandoc-set-" (symbol-name option)))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-hydra-list")))
+
+     (fset (quote ,(intern (concat "pandoc-set-" (symbol-name option))))
+           (lambda (prefix)
+             (interactive "P")
+             (pandoc--set (quote ,option)
+                          (if (eq prefix '-)
+                              nil
+                            (string-to-number (read-string ,(concat prompt ": ")))))))))
+
+(defmacro define-pandoc-string-option (option hydra prompt &optional default)
+  "Define OPTION as a string option.
+The option is added to `pandoc--options' and to
+`pandoc--cli-options'.  Furthermore, a menu entry is created and a
+function to set the option.
+
+The function to set the option can be called with the prefix
+argument `\\[universal-argument] -' (or `\\[negative-argument]')
+to unset the option.  A default value (if any) can be set by
+calling the function with any other prefix argument.  If no
+prefix argument is given, the user is prompted for a value.
+
+HYDRA is a list describing how the option must be added to one of
+the hydras.  The first element is a symbol naming the hydra (and
+menu) to which the option must be added, The second element is a
+string of one character, the key by which the option will be
+available in the hydra, and the third is a format string
+describing the width of the option (which must be the same for
+all options in a single hydra).
+
+OPTION must be a symbol and must be identical to the long form of
+the pandoc option (without dashes).  PROMPT is a string that is
+used to prompt for setting and unsetting the option.  It must be
+formulated in such a way that the strings \"No \", \"Set \" and
+\"Default \" can be added before it.  DEFAULT must be either NIL
+or T and indicates whether the option can have a default value."
+  `(progn
+     (push (list (quote ,option)) pandoc--options)
+     (push (quote ,option) pandoc--cli-options)
+     (push (list ,@(delq nil ; if DEFAULT is nil, we need to remove it from the list.
+                         (list prompt
+                               (vector (concat "No " prompt) `(pandoc--set (quote ,option) nil)
+                                       :active t
+                                       :style 'radio
+                                       :selected `(null (pandoc--get (quote ,option))))
+                               (when default
+                                 (vector (concat "Default " prompt) `(pandoc--set (quote ,option) t)
+                                         :active t
+                                         :style 'radio
+                                         :selected `(eq (pandoc--get (quote ,option)) t)))
+                               (vector (concat "Set " prompt "...") (intern (concat "pandoc-set-" (symbol-name option)))
+                                       :active t
+                                       :style 'radio
+                                       :selected `(stringp (pandoc--get (quote ,option)))))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-menu-list")))
+
+     (push (quote ,(list (concat "_" (cadr hydra) "_: " (format (cl-caddr hydra) prompt) (format " [%%s(pandoc--pp-option '%s)]" option))
+                         (cadr hydra)
+                         (intern (concat "pandoc-set-" (symbol-name option)))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-hydra-list")))
+
+     (fset (quote ,(intern (concat "pandoc-set-" (symbol-name option))))
+           (lambda (prefix)
+             (interactive "P")
+             (pandoc--set (quote ,option)
+                          (cond
+                           ((eq prefix '-) nil)
+                           ((null prefix) (read-string ,(concat prompt ": ")))
+                           (t ,default)))))))
+
+(defmacro define-pandoc-list-option (option hydra type description prompt)
+  "Define OPTION as a list option.
+The option is added to `pandoc--options' and `pandoc--list-options'.
+
+Furthermore, a menu entry is created and a function to set the
+option.  This function can also be called with the prefix
+argument `\\[universal-argument] -' (or `\\[negative-argument]') to remove an item from the list,
+or with the prefix argument `\\[universal-argument] \\[universal-argument]' to clear the entire list.
+If the list is a list of files, the function can also be called
+with the prefix argument `\\[universal-argument]' to store the full path.
+
+HYDRA is a list describing how the option must be added to one of
+the hydras.  The first element is a symbol naming the hydra (and
+menu) to which the option must be added, The second element is a
+string of one character, the key by which the option will be
+available in the hydra, and the third is a format string
+describing the width of the option (which must be the same for
+all options in a single hydra).
+
+OPTION must be a symbol and must be identical to the long form of
+the pandoc option (without dashes).  TYPE specifies the kind of
+data that is stored in the list.  Currently, possible values are
+`string' and `file'.  DESCRIPTION is the description for the
+option's submenu.  PROMPT is a string that is used to prompt for
+setting and unsetting the option.  It must be formulated in such a
+way that the strings \"Add \", \"Remove \" can be added before
+it."
+
+  `(progn
+     (push (list (quote ,option)) pandoc--options)
+     (push (quote ,option) pandoc--list-options)
+     (put (quote ,option) (quote pandoc-list-type) (quote ,type))
+     (push (list ,description
+                 ,(vector (concat "Add " prompt) (intern (concat "pandoc-set-" (symbol-name option)))
+                          :active t)
+                 ,(vector (concat "Remove " prompt) (list (intern (concat "pandoc-set-" (symbol-name option))) `(quote -))
+                          :active `(pandoc--get (quote ,option))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-menu-list")))
+
+     (push (quote ,(list (concat "_" (cadr hydra) "_: " (format (cl-caddr hydra) description) (format " [%%s(pandoc--pp-option '%s)]" option))
+                         (cadr hydra)
+                         (intern (concat "pandoc-set-" (symbol-name option)))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-hydra-list")))
+
+     (fset (quote ,(intern (concat "pandoc-set-" (symbol-name option))))
+           (lambda (prefix)
+             (interactive "P")
+             (cond
+              ((and (listp prefix)
+                    (eq (car prefix) 16)) ; C-u C-u
+               (pandoc--set (quote ,option) nil)
+               (message ,(concat description " removed.")))
+              ((listp prefix) ; C-u or no prefix arg
+               (let ((value ,(cond
+                              ((eq type 'string)
+                               `(read-string "Add value: " nil nil (pandoc--get (quote ,option))))
+                              ((eq type 'file)
+                               `(pandoc--read-file-name "Add file: " default-directory (not prefix))))))
+                 (pandoc--set (quote ,option) value)
+                 (message ,(concat prompt " \"%s\" added.") value)))
+              ((eq prefix '-)
+               (let ((value (completing-read "Remove item: " (pandoc--get (quote ,option)) nil t)))
+                 (pandoc--remove-from-list-option (quote ,option) value)
+                 (message ,(concat prompt " \"%s\" removed.") value))))))))
+
+(defmacro define-pandoc-alist-option (option hydra description prompt)
+  "Define OPTION as an alist option.
+The option is added to `pandoc--options' and `pandoc--alist-options'.
+Furthermore, a menu entry is created and a function to set the
+option.  This function can also be called with the prefix
+argument `\\[universal-argument] -' (or `\\[negative-argument]') to remove an item from the list,
+or with the prefix argument `\\[universal-argument] \\[universal-argument]' to clear the entire list.
+
+HYDRA is a list describing how the option must be added to one of
+the hydras.  The first element is a symbol naming the hydra (and
+menu) to which the option must be added, The second element is a
+string of one character, the key by which the option will be
+available in the hydra, and the third is a format string
+describing the width of the option (which must be the same for
+all options in a single hydra).
+
+OPTION must be a symbol and must be identical to the long form of
+the pandoc option (without dashes).  DESCRIPTION is the
+description for the option's submenu.  PROMPT is a string that is
+used to prompt for setting and unsetting the option.  It must be
+formulated in such a way that the strings \"Set/Change \" and
+\"Unset \" can be added before it."
+
+  `(progn
+     (push (list (quote ,option)) pandoc--options)
+     (push (quote ,option) pandoc--alist-options)
+     (push (list ,description
+                 ,(vector (concat "Set/Change " prompt) (intern (concat "pandoc-set-" (symbol-name option)))
+                          :active t)
+                 ,(vector (concat "Unset " prompt) (list (intern (concat "pandoc-set-" (symbol-name option))) `(quote -))
+                          :active t))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-menu-list")))
+
+     (push (quote ,(list (concat "_" (cadr hydra) "_: " (format (cl-caddr hydra) description) (format " [%%s(pandoc--pp-option '%s)]" option))
+                         (cadr hydra)
+                         (intern (concat "pandoc-set-" (symbol-name option)))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-hydra-list")))
+
+     (fset (quote ,(intern (concat "pandoc-set-" (symbol-name option))))
+           (lambda (prefix)
+             (interactive "P")
+             (if (and (listp prefix)
+                      (eq (car prefix) 16)) ; C-u C-u
+                 (progn
+                   (pandoc--set (quote ,option) nil)
+                   (message ,(concat description " removed")))
+               ;; for prefix argument - or no prefix argument
+               (let ((var (completing-read (concat ,prompt ": ") (pandoc--get (quote ,option)))))
+                 (when (and var (not (string= "" var)))
+                   (let ((value (if (eq prefix '-)
+                                    nil
+                                  (read-string "Value: " nil nil (cdr (assq var (pandoc--get (quote ,option))))))))
+                     (when (string= value "") ;; strings may be empty (which corresponds to boolean True in Pandoc)
+                       (setq value t))
+                     (pandoc--set (quote ,option) (cons var value))
+                     (message ,(concat prompt " `%s' \"%s\".") var (if value
+                                                                       (format "added with value `%s'" value)
+                                                                     "removed"))))))))))
+
+(defmacro define-pandoc-choice-option (option hydra prompt choices &optional output-formats)
+  "Define OPTION as a choice option.
+The option is added to `pandoc--options' and `pandoc--cli-options'.
+Furthermore, a menu entry is created and a function to set the
+option.
+
+HYDRA is a list describing how the option must be added to one of
+the hydras.  The first element is a symbol naming the hydra (and
+menu) to which the option must be added, The second element is a
+string of one character, the key by which the option will be
+available in the hydra, and the third is a format string
+describing the width of the option (which must be the same for
+all options in a single hydra).
+
+OPTION must be a symbol and must be identical to the long form of
+the pandoc option (without dashes).  PROMPT is a string that is
+used to prompt for setting and unsetting the option and is also
+used in the menu.  CHOICES is the list of choices, which must be
+strings.  The first of these is the default value, i.e., the one
+that Pandoc uses if the option is unspecified.  OUTPUT-FORMATS is
+a list of output formats for which OPTION should be active in the
+menu."
+  `(progn
+     (push (list (quote ,option)) pandoc--options)
+     (push (quote ,option) pandoc--cli-options)
+     (push (list ,prompt
+                 :active ,(if output-formats
+                              `(quote (member (pandoc--get 'write) (quote ,output-formats)))
+                            t)
+                 ,(vector (car choices) `(pandoc--set (quote ,option) ,(car choices))
+                          :style 'radio
+                          :selected `(null (pandoc--get (quote ,option))))
+                 ,@(mapcar (lambda (choice)
+                             (vector choice `(pandoc--set (quote ,option) ,choice)
+                                     :style 'radio
+                                     :selected `(string= (pandoc--get (quote ,option)) ,choice)))
+                           (cdr choices)))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-menu-list")))
+
+     (push (quote ,(list (concat "_" (cadr hydra) "_: " (format (cl-caddr hydra) prompt) (format " [%%s(pandoc--pp-option '%s)]" option))
+                         (cadr hydra)
+                         (intern (concat "pandoc-set-" (symbol-name option)))))
+           ,(intern (concat "pandoc--" (symbol-name (car hydra)) "-hydra-list")))
+
+     (fset (quote ,(intern (concat "pandoc-set-" (symbol-name option))))
+           (lambda (prefix)
+             (interactive "P")
+             (pandoc--set (quote ,option)
+                          (if (eq prefix '-)
+                              nil
+                            (let ((value (completing-read ,(format "Set %s: " prompt) (quote ,choices) nil t)))
+                              (if (or (not value)
+                                      (member value '("" (car ,choices))))
+                                  nil
+                                value))))))))
+
+(defun pandoc--trim-right-padding (strings)
+  "Trim right padding in STRINGS.
+STRINGS is a list of strings ending in one or more spaces.  The
+right padding of each string is trimmed to the longest string."
+  (let ((n (-min (--map (let ((idx (string-match-p " *\\'" it)))
+                          (length (substring it idx)))
+                        strings))))
+    (--map (substring it 0 (if (> n 0) (- n))) strings)))
+
+(defun pandoc--tabulate (strings &optional colwidth width fmt-str colsep trim)
+  "Tabulate STRINGS.
+STRINGS is a list of strings.  The return value is a string
+containing STRINGS tabulated top-to-bottom, left-to-right.
+COLWIDTH is the width of the columns of the table, which defaults
+to the width of the largest string in STRINGS.  Each string is
+right-padded with spaces to make it the length of COLWIDTH.  WIDTH
+is the width of the table, which defaults to the width of the
+current frame.  The number of rows and columns is calculated on
+the basis of COLWIDTH and WIDTH.
+
+FMT-STR is a format string that is used to format STRINGS.  It
+defaults to \"%-<n>s\", where <n> is colwidth.  FMT-STR must
+contain a \"%s\" specifier for the strings to be tabulated.  Note
+that if FMT-STR is provided, COLWIDTH is only used to calculate
+the number of rows and columns, not for padding the strings.  The
+calling function must then ensure that the strings are of
+equal length.
+
+COLSEP is the string placed between two columns.  It defaults to
+two spaces.  The length of this string is taken into account when
+calculating the number of columns.
+
+If TRIM is t, each row is trimmed to its widest member."
+
+  (or colwidth (setq colwidth (-max (--map (length it) strings))))
+  (or width (setq width (frame-width)))
+  (or fmt-str (setq fmt-str (format "%%-%ds" colwidth)))
+  (or colsep (setq colsep "  "))
+  (let* ((n-cols (/ width (+ (length colsep) colwidth)))
+         (n-rows (if (= n-cols 0) ; happens when `width' is too small to hold `strings'.
+                     (length strings)
+                   (ceiling (/ (length strings) (float n-cols)))))
+         (cols (-partition-all n-rows (--map (format fmt-str it) strings))))
+    (if trim
+        (setq cols (-map #'pandoc--trim-right-padding cols)))
+    (let ((rows (apply #'-zip-fill "" cols)))
+      (if (atom (cdar rows)) ; -zip-fill returns cons cells if it zips two lists
+          (setq rows (mapc (lambda (c)
+                             (setcdr c (list (cdr c))))
+                           rows)))
+      (mapconcat (lambda (line)
+                   (mapconcat #'identity line colsep))
+                 rows
+                 "\n"))))
+
+(defun pandoc--tabulate-extensions (rw)
+  "Tabulate extension strings as a new string.
+RW can be `read' or `write', indicating which extensions to
+insert."
+  (let* ((extensions (--map (car it) pandoc--extensions))
+         (colwidth (-max (-map #'length extensions)))
+         (fmt-str (format "%%2d %%%%s(pandoc--extension-active-marker \"%%s\" '%%s) %%-%ds" colwidth))
+         (strings (--map (format fmt-str
+                                 (1+ (-elem-index it extensions))
+                                 it
+                                 rw
+                                 (replace-regexp-in-string "_" " " it))
+                         extensions)))
+    (pandoc--tabulate strings (+ 5 colwidth) nil "%s" nil 'trim)))
+
+(defun pandoc--tabulate-input-formats ()
+  "Tabulate input formats for `pandoc-input-format-hydra'."
+  (let ((strings (--map (concat "_" (cl-caddr it) "_: " (cadr it)) pandoc--input-formats)))
+    (pandoc--tabulate strings nil 70 nil nil 'trim)))
+
+(defun pandoc--tabulate-output-formats ()
+  "Tabulate output formats for `pandoc-output-format-hydra'."
+  (let ((strings (--map (concat "_" (cl-caddr it) "_: " (cadr it)) pandoc--output-formats)))
+    (pandoc--tabulate strings nil 150 nil nil 'trim)))
+
+(defmacro define-pandoc-hydra (name body docstring hexpr &rest extra-heads)
+  "Define a pandoc-mode hydra.
+NAME, BODY and DOCSTRING are as in `defhydra'.  HEXPR is an
+expression that is evaluated and should yield a list of hydra
+heads.  EXTRA-HEADS are additional heads, which are not
+evaluated."
+  (let ((heads (eval hexpr)))
+    `(defhydra ,name ,body
+       ,docstring
+       ,@heads
+       ,@extra-heads)))
+
+;;; Defining the options
+;; Note that the options are added to the menus and hydras in reverse order.
+
+;;; Reader options
+(define-pandoc-choice-option track-changes           (reader "T" "%-23s")      "Track Changes" ("accept" "reject" "all") ("docx"))
+(define-pandoc-number-option tab-stop                (reader "t" "%-23s")      "Tab Stop Width")
+(define-pandoc-switch        preserve-tabs           (reader "p" "%-23s")      "Preserve Tabs")
+(define-pandoc-switch        normalize               (reader "n" "%-23s")      "Normalize Document")
+(define-pandoc-alist-option  metadata                (reader "m" "%-23s")      "Metadata" "Metadata item")
+(define-pandoc-list-option   filter                  (reader "f" "%-23s") file "Filters" "Filter")
+(define-pandoc-string-option default-image-extension (reader "i" "%-23s")      "Default Image Extension")
+(define-pandoc-string-option indented-code-classes   (reader "c" "%-23s")      "Indented Code Classes")
+(define-pandoc-number-option base-header-level       (reader "h" "%-23s")      "Base Header Level")
+(define-pandoc-switch        old-dashes              (reader "o" "%-23s")      "Use Old-style Dashes")
+(define-pandoc-switch        smart                   (reader "s" "%-23s")      "Smart")
+(define-pandoc-switch        parse-raw               (reader "r" "%-23s")      "Parse Raw")
+;; extract-media
+
+;; TODO for data-dir, output-dir and extract-media, a macro define-pandoc-dir-option might be useful.
+
+
+;;; General writer options
+(define-pandoc-switch        verbose             (writer "V" "%-19s") "Verbose output") ; Pandoc's README places this in the general options
+(define-pandoc-file-option   include-after-body  (writer "A" "%-19s") "Include After Body")
+(define-pandoc-file-option   include-before-body (writer "B" "%-19s") "Include Before Body")
+(define-pandoc-file-option   include-in-header   (writer "H" "%-19s") "Include Header")
+(define-pandoc-string-option highlight-style     (writer "S" "%-19s") "Highlighting Style")
+(define-pandoc-switch        no-highlight        (writer "h" "%-19s") "No Highlighting")
+(define-pandoc-number-option toc-depth           (writer "D" "%-19s") "TOC Depth")
+(define-pandoc-switch        table-of-contents   (writer "T" "%-19s") "Table of Contents")
+(define-pandoc-number-option columns             (writer "c" "%-19s") "Column Width")
+(define-pandoc-switch        no-wrap             (writer "W" "%-19s") "No Wrap")
+(define-pandoc-choice-option wrap                (writer "w" "%-19s") "Wrap"                ("auto" "none" "preserve"))
+(define-pandoc-number-option dpi                 (writer "d" "%-19s") "DPI")
+(define-pandoc-alist-option  variable            (writer "v" "%-19s") "Variables"           "Variable")
+(define-pandoc-file-option   template            (writer "t" "%-19s") "Template File")
+(define-pandoc-switch        standalone          (writer "s" "%-19s") "Standalone")
+;; print-default-template ; not actually included
+
+
+;;; Options affecting specific writers
+
+;; general
+(define-pandoc-file-option   reference-docx     (specific "d" "%-21s") "Reference docx File")
+(define-pandoc-file-option   reference-odt      (specific "o" "%-21s") "Reference ODT File")
+(define-pandoc-number-option slide-level        (specific "h" "%-21s") "Slide Level Header")
+(define-pandoc-switch        incremental        (specific "i" "%-21s") "Incremental")
+(define-pandoc-switch        number-sections    (specific "n" "%-21s") "Number Sections")
+(define-pandoc-switch        atx-headers        (specific "a" "%-21s") "Use ATX-style Headers")
+(define-pandoc-switch        reference-links    (specific "r" "%-21s") "Reference Links")
+(define-pandoc-choice-option reference-location (specific "l" "%-21s") "Reference Location" ("block" "section" "document") ("markdown" "markdown_github" "markdown_mmd" "markdown_phpextra" "markdown_strict"))
+(define-pandoc-choice-option top-level-division (specific "t" "%-21s") "Top Level Division" ("section" "part" "chapter")   ("latex" "context" "docbook" "docbook5" "tei"))
+
+;; html-based
+(define-pandoc-list-option   css               (html "c" "%-31s") file "CSS Style Sheet" "CSS")
+(define-pandoc-string-option title-prefix      (html "t" "%-31s")      "Title prefix")
+(define-pandoc-string-option id-prefix         (html "i" "%-31s")      "ID prefix")
+(define-pandoc-choice-option email-obfuscation (html "e" "%-31s")      "Email Obfuscation" ("none" "javascript" "references") ("html" "html5" "s5" "slidy" "slideous" "dzslides" "revealjs"))
+(define-pandoc-switch        section-divs      (html "d" "%-31s")      "Wrap Sections in <div> Tags")
+(define-pandoc-string-option number-offset     (html "o" "%-31s")      "Number Offsets")
+(define-pandoc-switch        ascii             (html "a" "%-31s")      "Use Only ASCII in HTML")
+(define-pandoc-switch        html-q-tags       (html "Q" "%-31s")      "Use <q> Tags for Quotes in HTML")
+(define-pandoc-switch        self-contained    (html "s" "%-31s")      "Self-contained Document")
+
+;; TeX-based (LaTeX, ConTeXt)
+(define-pandoc-list-option   latex-engine-opt (tex "o" "%-30s") string "LaTeX Options" "LaTeX Option")
+(define-pandoc-choice-option latex-engine     (tex "e" "%-30s")        "LaTeX Engine" ("pdflatex" "xelatex" "lualatex") ("latex" "beamer" "context"))
+(define-pandoc-switch        listings         (tex "L" "%-30s")        "Use LaTeX listings Package")
+(define-pandoc-switch        no-tex-ligatures (tex "l" "%-30s")        "Do Not Use TeX Ligatures")
+(define-pandoc-switch        chapters         (tex "c" "%-30s")        "Top-level Headers Are Chapters")
+
+;; epub
+(define-pandoc-number-option epub-chapter-level (epub "c" "%-18s")      "EPub Chapter Level")
+(define-pandoc-list-option   epub-embed-font    (epub "f" "%-18s") file "EPUB Fonts"         "EPUB Embedded Font")
+(define-pandoc-file-option   epub-metadata      (epub "m" "%-18s")      "EPUB Metadata File")
+(define-pandoc-file-option   epub-cover-image   (epub "C" "%-18s")      "EPUB Cover Image")
+(define-pandoc-file-option   epub-stylesheet    (epub "s" "%-18s")      "EPUB Style Sheet" 'default)
+
+
+;;; Citation rendering
+(define-pandoc-switch      biblatex               (citations "l" "%-27s")      "Use BibLaTeX")
+(define-pandoc-switch      natbib                 (citations "n" "%-27s")      "Use NatBib")
+(define-pandoc-file-option citation-abbreviations (citations "a" "%-27s")      "Citation Abbreviations File")
+(define-pandoc-file-option csl                    (citations "c" "%-27s")      "CSL File")
+(define-pandoc-list-option bibliography           (citations "B" "%-27s") file "Bibliography Files"          "Bibliography File")
+
+
+;;; Math rendering in HTML
+(define-pandoc-string-option katex-stylesheet (math "K" "%-18s") "KaTeX Stylesheet"   'default)
+(define-pandoc-string-option katex            (math "k" "%-18s") "KaTeX URL"          'default)
+(define-pandoc-string-option webtex           (math "w" "%-18s") "WebTeX URL"         'default)
+(define-pandoc-string-option mimetex          (math "m" "%-18s") "MimeTeX CGI Script" 'default)
+(define-pandoc-switch        gladtex          (math "g" "%-18s") "gladTeX")
+(define-pandoc-string-option mathjax          (math "J" "%-18s") "MathJax URL"        'default)
+(define-pandoc-string-option jsmath           (math "j" "%-18s") "jsMath URL"         'default)
+(define-pandoc-string-option mathml           (math "m" "%-18s") "MathML URL"         'default)
+(define-pandoc-string-option latexmathml      (math "L" "%-18s") "LaTeXMathML URL"    'default)
+
+(provide 'pandoc-mode-utils)
+
+;;; pandoc-mode-utils.el ends here
.emacs.d/elpa/pandoc-mode-20161104.1521/pandoc-mode-utils.elc
Binary file
.emacs.d/elpa/pandoc-mode-20161104.1521/pandoc-mode.el
@@ -0,0 +1,1506 @@
+;;; pandoc-mode.el --- Minor mode for interacting with Pandoc  -*- lexical-binding: t -*-
+
+;; Copyright (c) 2009-2016 Joost Kremers
+
+;; Author: Joost Kremers <joostkremers@fastmail.fm>
+;; Maintainer: Joost Kremers <joostkremers@fastmail.fm>
+;; Created: 31 Oct 2009
+;; Version: 2.20
+;; Keywords: text, pandoc
+;; Package-Requires: ((hydra "0.10.0") (dash "2.10.0"))
+
+;; Redistribution and use in source and binary forms, with or without
+;; modification, are permitted provided that the following conditions
+;; are met:
+;;
+;; 1. Redistributions of source code must retain the above copyright
+;;    notice, this list of conditions and the following disclaimer.
+;; 2. Redistributions in binary form must reproduce the above copyright
+;;    notice, this list of conditions and the following disclaimer in the
+;;    documentation and/or other materials provided with the distribution.
+;; 3. The name of the author may not be used to endorse or promote products
+;;    derived from this software without specific prior written permission.
+;;
+;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+;; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+;; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE,
+;; DATA, OR PROFITS ; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+;;; Commentary:
+
+;; Pandoc-mode is a minor mode for interacting with Pandoc, a 'universal
+;; document converter': <http://johnmacfarlane.net/pandoc/>.
+;;
+;; See the pandoc-mode manual for usage and installation instructions.
+
+;;; Code:
+
+(require 'easymenu)
+(require 'hydra)
+(require 'dash)
+(require 'pandoc-mode-utils)
+(require 'cl-lib)
+(require 'thingatpt)
+
+(defvar-local pandoc--@-counter 0 "Counter for (@)-lists.")
+
+(defvar pandoc--window-config nil
+  "Stores the window configuration before calling pandoc--select-@.")
+
+(defvar pandoc--pre-select-buffer nil
+  "Buffer from which pandoc--@-select is called.")
+
+(defvar pandoc--@-buffer nil
+  "Buffer for selecting an (@)-element.")
+
+(defvar pandoc--@-overlay nil
+  "Overlay for pandoc--@-buffer.")
+
+(defun pandoc--@-counter-inc ()
+  "Increment pandoc--@-counter and return the new value."
+  (when (= pandoc--@-counter 0) ; hasn't been updated in this buffer yet.
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "(@\\([0-9]+?\\))" (point-max) t)
+        (let ((label (string-to-number (match-string 1))))
+          (when (> label pandoc--@-counter)
+            (setq pandoc--@-counter label))))))
+  (setq pandoc--@-counter (1+ pandoc--@-counter)))
+
+(defvar pandoc-@-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "q" #'pandoc-quit-@-select)
+    (define-key map "j" #'pandoc-next-@)
+    (define-key map "n" #'pandoc-next-@)
+    (define-key map [down] #'pandoc-next-@)
+    (define-key map "k" #'pandoc-prev-@)
+    (define-key map "p" #'pandoc-prev-@)
+    (define-key map [up] #'pandoc-prev-@)
+    (define-key map [return] #'pandoc-select-current-@)
+    (define-key map [home] #'pandoc-goto-first-@)
+    (define-key map [prior] #'pandoc-goto-first-@)
+    (define-key map [end] #'pandoc-goto-last-@)
+    (define-key map [next] #'pandoc-goto-first-@)
+    map)
+  "Keymap for pandoc-@-mode.")
+
+(defun pandoc-quit-@-select ()
+  "Leave pandoc--@-select-buffer without selecting an (@)-label."
+  (interactive)
+  (remove-overlays)
+  (set-window-configuration pandoc--window-config)
+  (switch-to-buffer pandoc--pre-select-buffer))
+
+(defun pandoc-next-@ ()
+  "Highlight next (@)-definition."
+  (interactive)
+  (if (= (count-lines (point) (point-max)) 2)
+      (beep)
+    (forward-line 2)
+    (move-overlay pandoc--@-overlay (point) (point-at-eol))))
+
+(defun pandoc-prev-@ ()
+  "Highlight previous (@)-definition."
+  (interactive)
+  (if (= (point) (point-min))
+      (beep)
+    (forward-line -2)
+    (move-overlay pandoc--@-overlay (point) (point-at-eol))))
+
+(defun pandoc-goto-first-@ ()
+  "Highlight the first (@)-definition."
+  (interactive)
+  (goto-char (point-min))
+  (move-overlay pandoc--@-overlay (point) (point-at-eol)))
+
+(defun pandoc-goto-last-@ ()
+  "Highlight the last (@)-definition."
+  (interactive)
+  (goto-char (point-max))
+  (forward-line -2)
+  (move-overlay pandoc--@-overlay (point) (point-at-eol)))
+
+(defun pandoc-select-current-@ ()
+  "Leave pandoc--@-select-buffer and insert selected (@)-label at point."
+  (interactive)
+  (looking-at " \\((@.*?)\\)")
+  (let ((label (match-string 1)))
+    (remove-overlays)
+    (set-window-configuration pandoc--window-config)
+    (switch-to-buffer pandoc--pre-select-buffer)
+    (insert label)))
+
+(define-derived-mode pandoc-@-mode
+  fundamental-mode "Pandoc-select"
+  "Major mode for the Pandoc-select buffer."
+  (setq buffer-read-only t)
+  (setq truncate-lines t))
+
+(defvar pandoc-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-c/" #'pandoc-main-hydra/body)
+    map)
+  "Keymap for pandoc-mode.")
+
+;;;###autoload
+(define-minor-mode pandoc-mode
+  "Minor mode for interacting with Pandoc."
+  :init-value nil :lighter (:eval (concat " Pandoc/" (pandoc--get 'write))) :global nil
+  (cond
+   (pandoc-mode    ; pandoc-mode is turned on
+    (setq pandoc--local-settings (copy-tree pandoc--options))
+    (pandoc--set 'read (cdr (assq major-mode pandoc-major-modes)))
+    (setq pandoc--settings-modified-flag nil)
+    (or (buffer-live-p pandoc--output-buffer)
+        (setq pandoc--output-buffer (get-buffer-create " *Pandoc output*")))
+    (pandoc-faces-load))
+   ((not pandoc-mode)    ; pandoc-mode is turned off
+    (setq pandoc--local-settings nil
+          pandoc--settings-modified-flag nil)
+    (pandoc-faces-unload))))
+
+;;;###autoload
+(defun conditionally-turn-on-pandoc ()
+  "Turn on pandoc-mode if a pandoc settings file exists.
+This is for use in major mode hooks."
+  (when (and (buffer-file-name)
+             (file-exists-p (pandoc--create-settings-filename 'local (buffer-file-name) "default")))
+    (pandoc-mode 1)))
+
+(defun pandoc-toggle-extension (extension rw)
+  "Toggle the value of EXTENSION.
+RW is either `read' or `write', indicating whether the extension
+should be toggled for the input or the output format."
+  (interactive (list (completing-read "Extension: " pandoc--extensions nil t)
+                     (intern (completing-read "Read/write: " '("read" "write") nil t))))
+  (let* ((current-value (pandoc--get-extension extension rw))
+         (new-value (cond
+                     ((memq current-value '(+ -)) ; if the value is set explicitly
+                      nil)  ; we can simply return it to the default
+                     ((pandoc--extension-in-format-p extension (pandoc--get rw) rw) ; if the extension is part of the current format
+                      '-)  ; we explicitly unset it
+                     (t '+)))) ; otherwise we explicitly set it
+    (pandoc--set-extension extension rw new-value)))
+
+(defun pandoc-toggle-read-extension-by-number (n)
+  "Toggle a `read' extension.
+N is the index of the extension in `pandoc--extensions'."
+  (interactive "P")
+  (let* ((ext (caar (nthcdr (1- n) pandoc--extensions))))
+    (pandoc-toggle-extension ext 'read)))
+
+(defun pandoc-toggle-write-extension-by-number (n)
+  "Toggle a `write' extension.
+N is the index of the extension in `pandoc--extensions'."
+  (interactive "P")
+  (let* ((ext (caar (nthcdr (1- n) pandoc--extensions))))
+    (pandoc-toggle-extension ext 'write)))
+
+(defun pandoc--create-settings-filename (type filename output-format)
+  "Create a settings filename.
+TYPE is the type of settings file, either 'local or 'project.
+FILENAME is name of the file for which the settings file is to be
+created, OUTPUT-FORMAT the output format of the settings file,
+which is recorded in its name.  The return value is an absolute
+filename."
+  (setq filename (expand-file-name filename))
+  (cond
+   ((eq type 'local)
+    (concat (file-name-directory filename) "." (file-name-nondirectory filename) "." output-format ".pandoc"))
+   ((eq type 'project)
+    (concat (file-name-directory filename) "Project." output-format ".pandoc"))))
+
+(defun pandoc--create-global-settings-filename (format)
+  "Create a global settings filename.
+FORMAT is the output format to use."
+  (concat (file-name-as-directory pandoc-data-dir) format ".pandoc"))
+
+(defun pandoc--format-all-options (input-file &optional pdf)
+  "Create a list of strings with pandoc options for the current buffer.
+INPUT-FILE is the name of the input file.  If PDF is non-nil, an
+output file is always set, which gets the suffix `.pdf'.  If the
+output format is \"odt\", \"epub\" or \"docx\" but no output file
+is specified, one will be created."
+  (let ((read (format "--read=%s%s%s" (pandoc--get 'read) (if (pandoc--get 'read-lhs) "+lhs" "")
+                      (pandoc--format-extensions (pandoc--get 'read-extensions))))
+        (write (if pdf
+                   (if (member (pandoc--get 'write) pandoc--pdf-able-formats)
+                       (format "--write=%s" (pandoc--get 'write))
+                     "--write=latex")
+                 (format "--write=%s%s%s" (pandoc--get 'write) (if (pandoc--get 'write-lhs) "+lhs" "")
+                         (pandoc--format-extensions (pandoc--get 'write-extensions)))))
+        (output (pandoc--format-output-option input-file pdf))
+        (list-options (mapcar (lambda (option)
+                                (pandoc--format-list-options option (pandoc--get option)))
+                              pandoc--list-options))
+        (alist-options (mapcar (lambda (option)
+                                 (pandoc--format-alist-options option (pandoc--get option)))
+                               pandoc--alist-options))
+        (cli-options (pandoc--format-cli-options)))
+    ;; Note: list-options and alist-options are both lists of lists, so we need to flatten them first.
+    (delq nil (append (list read write output) cli-options (apply #'append list-options) (apply #'append alist-options)))))
+
+(defun pandoc--format-extensions (extensions)
+  "Create a string of extensions to be added to the Pandoc command line.
+EXTENSIONS is an alist of (<extension> . <value>) pairs."
+  (mapconcat (lambda (elt)
+               (if (cdr elt)
+                   (format "%s%s" (cdr elt) (car elt))
+                 ""))
+             extensions
+             ""))
+
+(defun pandoc--format-output-option (input-file pdf)
+  "Create the output option for calling Pandoc.
+INPUT-FILE is the name of the input file.  PDF is t if the output
+file is a pdf file.  Return a string that can be added to the
+call to Pandoc."
+  (cond
+   ((or (eq (pandoc--get 'output) t) ; if the user set the output file to T
+        (and (null (pandoc--get 'output)) ; or if the user set no output file but either
+             (or pdf                    ; (i) we're converting to pdf, or
+                 (member (pandoc--get 'write) ; (ii) the output format is odt, epub or docx
+                         '("odt" "epub" "docx")))))
+    (format "--output=%s/%s%s"          ; we create an output file name.
+            (expand-file-name (or (pandoc--get 'output-dir)
+                                  (file-name-directory input-file)))
+            (file-name-sans-extension (file-name-nondirectory input-file))
+            (if pdf
+                ".pdf"
+              (cadr (assoc (pandoc--get 'write) pandoc-output-format-extensions)))))
+   ((stringp (pandoc--get 'output)) ; if the user set an output file,
+    (format "--output=%s/%s"      ; we combine it with the output directory
+            (expand-file-name (or (pandoc--get 'output-dir)
+                                  (file-name-directory input-file)))
+            (if pdf                  ; and check if we're converting to pdf
+                (concat (file-name-sans-extension (pandoc--get 'output)) ".pdf")
+              (pandoc--get 'output))))
+   (t nil)))
+
+(defun pandoc--format-list-options (option values)
+  "Create a list of cli options for OPTION from the values in VALUES."
+  (mapcar (lambda (value)
+            (format "--%s=%s" option (if (eq (get option 'pandoc-list-type) 'file)
+                                         (pandoc--expand-absolute-path value)
+                                       value)))
+          values))
+
+(defun pandoc--format-alist-options (option alist)
+  "Create a list of cli options for OPTION from the key-value pairs in ALIST."
+  (mapcar (lambda (kv)
+            (let ((key (car kv))
+                  (value (cdr kv)))
+              ;; if key or value contains a colon, we use the short form
+              ;; of the option, because it uses = to separate the two.
+              (if (or (string-match-p ":" key)
+                      (string-match-p ":" value))
+                  ;; the only two alist options are `variable' and
+                  ;; `metadata', whose short forms are `V' and `M',
+                  ;; respectively, so we can just capitalise their first
+                  ;; letters.
+                  (format "-%c %s%s" (upcase (aref (symbol-name option) 0))
+                          key
+                          (if (eq value t)
+                              ""
+                            (format "=%s" value)))
+                (format "--%s=%s%s" option key
+                        (if (eq value t)
+                            ""
+                          (format ":%s" value))))))
+          alist))
+
+(defun pandoc--format-cli-options ()
+  "Create a list of options in `pandoc--cli-options'."
+  (mapcar (lambda (option)
+            (let ((value (pandoc--get option)))
+              (when (and value
+                         (memq option pandoc--filepath-options))
+                (setq value (pandoc--expand-absolute-path value)))
+              (cond
+               ((eq value t) (format "--%s" option))
+               ((or (numberp value)
+                    (stringp value)) (format "--%s=%s" option value))
+               (t nil))))
+          pandoc--cli-options))
+
+(defun pandoc-process-directives (output-format)
+  "Processes pandoc-mode @@-directives in the current buffer.
+OUTPUT-FORMAT is passed unchanged to the functions associated
+with the @@-directives."
+  (interactive (list (pandoc--get 'write)))
+  (mapc #'funcall pandoc-directives-hook)
+  (let ((case-fold-search nil)
+        (directives-regexp (concat "\\([\\]?\\)@@" (regexp-opt (mapcar #'car pandoc-directives) t))))
+    (goto-char (point-min))
+    (while (re-search-forward directives-regexp nil t)
+      (if (string= (match-string 1) "\\")
+          (delete-region (match-beginning 1) (match-end 1))
+        (let ((@@-beg (match-beginning 0))
+              (@@-end (match-end 0))
+              (directive-fn (cdr (assoc (match-string 2) pandoc-directives))))
+          (cond
+           ((eq (char-after) ?{) ; if there is an argument.
+            ;; note: point is on the left brace, and scan-lists
+            ;; returns the position *after* the right brace. we need
+            ;; to adjust both values to get the actual argument.
+            (let* ((arg-beg (1+ (point)))
+                   (arg-end (1- (scan-lists (point) 1 0)))
+                   (text (buffer-substring-no-properties arg-beg arg-end)))
+              (goto-char @@-beg)
+              (delete-region @@-beg (1+ arg-end))
+              (insert (funcall directive-fn output-format text)))
+            (goto-char @@-beg))
+           ;; check if the next character is not a letter or number.
+           ;; if it is, we're actually on a different directive.
+           ((looking-at "[a-zA-Z0-9]") t)
+           ;; otherwise there is no argument.
+           (t (goto-char @@-beg)
+              (delete-region @@-beg @@-end) ; else there is no argument
+              (insert (funcall directive-fn output-format))
+              (goto-char @@-beg))))))))
+
+(defun pandoc--process-lisp-directive (_ lisp)
+  "Process @@lisp directives.
+The first argument is the output argument and is ignored.  LISP
+is the argument of the @@lisp directive."
+  (format "%s" (eval (car (read-from-string lisp)))))
+
+(defun pandoc--process-include-directive (_ include-file)
+  "Process @@include directives.
+The first argument is the output argument and is ignored.
+INCLUDE-FILE is the argument of the @@include directive."
+  (with-temp-buffer
+    (insert-file-contents include-file)
+    (buffer-string)))
+
+;; `pandoc-call-external' sets up a process sentinel that needs to refer to
+;; `pandoc-binary' to provide an informative message. We want to allow a
+;; buffer-local value of `pandoc-binary', but the process sentinel doesn't
+;; have the necessary context. With `lexical-binding' set to t, we could
+;; make the sentinel a closure, but this only works for Emacs >= 24.1. An
+;; alternative way is to use a global variable, which, however, means that
+;; we can only have one pandoc subprocess at a time. Hopefully that won't
+;; be a problem.
+
+(defvar pandoc--local-binary "pandoc"
+  "Temporary store for the buffer-local value of `pandoc-binary'.")
+
+(defun pandoc--call-external (output-format &optional pdf region)
+  "Call pandoc on the current buffer.
+This function creates a temporary buffer and sets up the required
+local options.  The contents of the current buffer is copied into
+the temporary buffer, the @@-directives are processed, after
+which pandoc is called.
+
+OUTPUT-FORMAT is the format to use.  If t, the current buffer's
+output format is used.  If PDF is non-nil, a pdf file is created.
+REGION is a cons cell specifying the beginning and end of the
+region to be sent to pandoc.
+
+If the current buffer's \"master file\" option is set, that file
+is processed instead.  The output format is taken from the current
+buffer, however, unless one is provided specifically.  REGION is
+also ignored in this case."
+  (let* ((orig-buffer (current-buffer))
+         (buffer (if (pandoc--get 'master-file)
+                     (find-file-noselect (pandoc--get 'master-file))
+                   (current-buffer)))
+         (filename (buffer-file-name buffer))
+         (display-name (buffer-name)))
+    ;; If the buffer is visiting a file, we want to display the file name in
+    ;; messages. If the buffer is not visiting a file, we create a file name in
+    ;; case we need one, but we display the buffer name in messages.
+    (if filename
+        (setq display-name (file-name-nondirectory filename))
+      (setq filename (concat "./" (cl-remove-if-not (lambda (c)
+                                                      (string-match-p "[[:alpha:][:digit:]+_.-]" (char-to-string c)))
+                                                    (buffer-name)))))
+    ;; if there's a master file, ignore the region
+    (if (pandoc--get 'master-file)
+        (setq region nil))
+    ;; keep track of the buffer-local value of `pandoc-binary', if there is one
+    (setq pandoc--local-binary (buffer-local-value 'pandoc-binary buffer))
+    (with-current-buffer buffer
+      ;; we use with-current-buffer so that we can work on the master file
+      ;; if there is one. we then change to a temp buffer, so we can
+      ;; process @@-directives without having to undo them and set the
+      ;; options independently of the original buffer.
+      (with-temp-buffer
+        (cond
+         ;; if an output format was provided, try and load a settings file for it
+         ((stringp output-format)
+          (unless (and filename
+                       (pandoc--load-settings-for-file (expand-file-name filename) output-format t))
+            ;; if no settings file was found, unset all options except input and output format
+            (setq pandoc--local-settings (copy-tree pandoc--options))
+            (pandoc--set 'write output-format)
+            (pandoc--set 'read (pandoc--get 'read buffer))))
+         ;; if no output format was provided, we use BUFFER's options,
+         ;; except the output format, which we take from ORIG-BUFFER:
+         ((eq output-format t)
+          (setq pandoc--local-settings (buffer-local-value 'pandoc--local-settings buffer))
+          (pandoc--set 'write (pandoc--get 'write orig-buffer))))
+        ;; copy any local `pandoc/' variables from `orig-buffer' or
+        ;; `buffer' (the values in `orig-buffer' take precedence):
+        (mapc (lambda (option)
+                (let ((var (intern (concat "pandoc/" (symbol-name (car option))))))
+                  (if (local-variable-p var orig-buffer)
+                      (set (make-local-variable var) (buffer-local-value var orig-buffer))
+                    (if (local-variable-p var buffer)
+                        (set (make-local-variable var) (buffer-local-value var buffer))))))
+              pandoc--options)
+        (let ((option-list (pandoc--format-all-options filename pdf)))
+          (insert-buffer-substring-no-properties buffer (car region) (cdr region))
+          (message "Running %s on %s" (file-name-nondirectory pandoc--local-binary) display-name)
+          (pandoc-process-directives (pandoc--get 'write))
+          (with-current-buffer (get-buffer-create pandoc--output-buffer)
+            (erase-buffer))
+          (pandoc--log 'log "%s\n%s" (make-string 50 ?=) (current-time-string))
+          (pandoc--log 'log "Calling %s with:\n\n%s %s" (file-name-nondirectory pandoc--local-binary) pandoc--local-binary (mapconcat #'identity option-list " "))
+	  (let ((coding-system-for-read 'utf-8)
+                (coding-system-for-write 'utf-8)
+                (log-success (lambda (file binary)
+                               (pandoc--log 'message "%s: %s finished successfully"
+                                      (file-name-nondirectory file)
+                                      (file-name-nondirectory binary))))
+                (log-failure (lambda (file binary)
+                               (pandoc--log 'message "%s: Error in %s process"
+                                      (file-name-nondirectory file)
+                                      (file-name-nondirectory binary)))))
+            (cond
+             (pandoc-use-async
+              (let* ((process-connection-type pandoc-process-connection-type)
+                     (process (apply #'start-process "pandoc-process" pandoc--output-buffer pandoc--local-binary option-list)))
+                (set-process-sentinel process (lambda (_ e)
+                                                (cond
+                                                 ((string-equal e "finished\n")
+                                                  (funcall log-success display-name pandoc--local-binary)
+                                                  (run-hooks 'pandoc-async-success-hook))
+                                                 (t (funcall log-failure display-name pandoc--local-binary)
+                                                    (display-buffer pandoc--output-buffer)))))
+                (process-send-region process (point-min) (point-max))
+                (process-send-eof process)))
+             ((not pandoc-use-async)
+              (if (= 0 (apply #'call-process-region (point-min) (point-max) pandoc--local-binary nil pandoc--output-buffer t option-list))
+                  (funcall log-success display-name pandoc--local-binary)
+                (funcall log-failure display-name pandoc--local-binary)
+                (display-buffer pandoc--output-buffer))))))))))
+
+(defun pandoc-run-pandoc (prefix)
+  "Run pandoc on the current document.
+If called with a PREFIX argument, the user is asked for an output
+format.  Otherwise, the output format currently set in the buffer
+is used.
+
+If the region is active, pandoc is run on the region instead of
+the buffer."
+  (interactive "P")
+  (pandoc--call-external (if prefix
+                       (completing-read "Output format to use: " pandoc--output-formats nil t)
+                     t)
+                   nil
+                   (if (use-region-p)
+                       (cons (region-beginning) (region-end)))))
+
+(defvar-local pandoc--output-format-for-pdf nil
+  "Output format used to for pdf conversion.
+  Set the first time the user converts to pdf.  Unset when the
+user changes output format.")
+
+(defun pandoc-convert-to-pdf (prefix)
+  "Convert the current document to pdf.
+If the output format of the current buffer can be used to create
+a pdf (latex, context, or html5), the buffer's options are used.
+If not, the user is asked to supply a format.  If a settings file
+for the user-supplied format exists, the settings from this file
+are used for conversion.  If no such settings file exists, only
+the input and output format are set, all other options are unset.
+This user-supplied output format is persistent: the next pdf
+conversion uses the same format.
+
+If called with a PREFIX argument \\[universal-argument], always ask the user for a
+pdf-able format.
+
+Note that if the user changes the output format for the buffer,
+the format for pdf conversion is unset.
+
+If the region is active, pandoc is run on the region instead of
+the buffer (except when a master file is set, in which case
+pandoc is always run on the master file)."
+  ;; TODO When the region is active, it might be nice to run pandoc on the
+  ;; region but use the master file's settings.
+  (interactive "P")
+  (cond
+   ((member (pandoc--get 'write) pandoc--pdf-able-formats)
+    (setq pandoc--output-format-for-pdf t))
+   ((or (not pandoc--output-format-for-pdf)
+        (and (listp prefix) (eq (car prefix) 4)))
+    (setq pandoc--output-format-for-pdf (completing-read "Specify output format for pdf creation: " pandoc--pdf-able-formats nil t nil nil (car pandoc--pdf-able-formats)))))
+  (pandoc--call-external pandoc--output-format-for-pdf t (when (use-region-p) (cons (region-beginning) (region-end)))))
+
+(defun pandoc-set-default-format ()
+  "Set the current output format as default.
+This is done by creating a symbolic link to the relevant settings
+files.  (Therefore, this function is not available on Windows.)"
+  (interactive)
+  (if (eq system-type 'windows-nt)
+      (message "This option is not available on MS Windows")
+    (let ((current-settings-file
+           (file-name-nondirectory (pandoc--create-settings-filename 'local (buffer-file-name)
+                                                               (pandoc--get 'write))))
+          (current-project-file
+           (file-name-nondirectory (pandoc--create-settings-filename 'project (buffer-file-name)
+                                                               (pandoc--get 'write)))))
+      (when (not (file-exists-p current-settings-file))
+        (pandoc--save-settings 'local (pandoc--get 'write)))
+      (make-symbolic-link current-settings-file
+                          (pandoc--create-settings-filename 'local (buffer-file-name) "default") t)
+      (when (file-exists-p current-project-file)
+        (make-symbolic-link current-project-file
+                            (pandoc--create-settings-filename 'project (buffer-file-name) "default") t))
+      (message "`%s' set as default output format." (pandoc--get 'write)))))
+
+(defun pandoc-save-settings-file ()
+  "Save the settings of the current buffer.
+This function just calls pandoc--save-settings with the
+appropriate output format."
+  (interactive)
+  (pandoc--save-settings 'local (pandoc--get 'write)))
+
+(defun pandoc-save-project-file ()
+  "Save the current settings as a project file."
+  (interactive)
+  (pandoc--save-settings 'project (pandoc--get 'write)))
+
+(defun pandoc-save-global-settings-file ()
+  "Save the current settings to a global settings file."
+  (interactive)
+  (unless (file-directory-p pandoc-data-dir)
+    (make-directory pandoc-data-dir))
+  (pandoc--save-settings 'global (pandoc--get 'write)))
+
+(defun pandoc--save-settings (type format &optional no-confirm)
+  "Save the settings of the current buffer.
+TYPE must be a quoted symbol and specifies the type of settings
+file.  It can be `local', `project', or `global'.  FORMAT is the
+output format for which the settings are to be saved.  If
+NO-CONFIRM is non-nil, any existing settings file is overwritten
+without asking."
+  (let* ((filename (buffer-file-name))
+         (settings pandoc--local-settings)
+         (settings-file (if (eq type 'global)
+                            (pandoc--create-global-settings-filename format)
+                          (pandoc--create-settings-filename type filename format))))
+    (if (and (not no-confirm)
+             (file-exists-p settings-file)
+             (not (y-or-n-p (format "%s file `%s' already exists.  Overwrite? "
+                                    (capitalize (symbol-name type))
+                                    (file-name-nondirectory settings-file)))))
+        (message "%s file not written." (capitalize (symbol-name type)))
+      (with-temp-buffer
+        (let ((print-length nil)
+              (print-level nil)
+              (print-circle nil))
+          (insert ";; -*- mode: emacs-lisp -*-\n\n"
+                  (format ";; pandoc-mode %s settings file%s\n"
+                          type
+                          (if (eq type 'local)
+                              (concat " for " (file-name-nondirectory filename))
+                            ""))
+                  (format ";; saved on %s\n\n" (format-time-string "%Y.%m.%d %H:%M")))
+          (pp settings (current-buffer)))
+        (let ((make-backup-files nil))
+          (write-region (point-min) (point-max) settings-file))
+        (message "%s settings file written to `%s'." (capitalize (symbol-name type)) (file-name-nondirectory settings-file)))
+      (setq pandoc--settings-modified-flag nil))))
+
+(defun pandoc-revert-settings ()
+  "Revert settings for the current buffer.
+The settings file is reread from disk, so that any changes made
+to the settings that have not been saved are reverted."
+  (interactive)
+  (let ((format (pandoc--get 'write)))
+    (setq pandoc--local-settings (copy-tree pandoc--options))
+    (pandoc--load-settings-profile format 'no-confirm)))
+
+(defun pandoc-load-default-settings ()
+  "Load the default settings of the file in the current buffer.
+This function is for use in `pandoc-mode-hook'."
+  (pandoc--load-settings-profile "default"))
+
+(defun pandoc--load-settings-profile (format &optional no-confirm)
+  "Load the options for FORMAT from the corresponding settings file.
+If NO-CONFIRM is t, no confirmation is asked if the current
+settings have not been saved."
+  (pandoc--load-settings-for-file (when (buffer-file-name)
+                              (expand-file-name (buffer-file-name)))
+                            format
+                            no-confirm))
+
+(defun pandoc--load-settings-for-file (file format &optional no-confirm)
+  "Load the settings file of FILE for FORMAT.
+Search for a local, a project and a global settings file, in that
+order, and load the first one that exists and is readable.
+
+If NO-CONFIRM is t, no confirmation is asked if the current
+settings have not been saved.  FILE must be an absolute path
+name.  If FILE is nil, a global settings file is read, if any.
+The settings are stored in the current buffer's
+`pandoc--local-settings'.  Return nil if no settings or project
+file is found for FILE, otherwise non-nil."
+  (when (and (not no-confirm)
+             pandoc--settings-modified-flag
+             (y-or-n-p (format "Current settings for format \"%s\" modified.  Save first? " (pandoc--get 'write))))
+    (pandoc--save-settings 'local (pandoc--get 'write) t))
+  (let (settings)
+    ;; first try to read local settings
+    (when file
+      (setq settings (cons 'local (pandoc--read-settings-from-file (pandoc--create-settings-filename 'local file format)))))
+    ;; if it fails, try project settings
+    (when (and file (not (cdr settings)))
+      (setq settings (cons 'project (pandoc--read-settings-from-file (pandoc--create-settings-filename 'project file format)))))
+    ;; if that fails too, or if there is no file, try reading global settings
+    (unless (cdr settings)
+      (setq settings (cons 'global (pandoc--read-settings-from-file (pandoc--create-global-settings-filename format)))))
+    ;; now set them
+    (when (cdr settings)
+      (setq pandoc--local-settings (cdr settings))
+      (message "%s settings file loaded for format \"%s\"." (capitalize (symbol-name (car settings))) format))))
+
+(defun pandoc--read-settings-from-file (file)
+  "Read the settings in FILE and return them.
+If FILE does not exist or cannot be read, return nil."
+  (if (file-readable-p file)
+      (with-temp-buffer
+        (insert-file-contents file)
+        (goto-char (point-min))
+        (if (looking-at "#") ; We're probably dealing with an old settings file.
+            (pandoc--read-old-settings-from-buffer)
+          (let ((flist (when (search-forward "(" nil t)
+                         (forward-char -1)
+                         (read (current-buffer)))))
+            (if (listp flist)
+                flist))))))
+
+(defun pandoc--read-old-settings-from-buffer ()
+  "Read old-style settings from the current buffer.
+`pandoc--settings-modified-flag' is set, so that the user will be
+asked to save the settings on exit.  Return an alist with the
+options and their values."
+  (goto-char (point-min))
+  (let (options)                        ; we collect the options in a list
+    (while (re-search-forward "^\\([a-z-]*\\)::\\(.*?\\)$" nil t)
+      (let ((option (intern (match-string 1)))
+            (value (match-string 2)))
+        ;; If the option is a variable or extension, we read its name and
+        ;; value and add them to the alist as a dotted list.
+        (push (if (memq option '(variable read-extensions write-extensions))
+                  (progn
+                    (string-match "^\\(.*?\\):\\(.*?\\)$" value)
+                    (cons option (cons (match-string 1 value)
+                                       (if (eq option 'variable)
+                                           (match-string 2 value)
+                                         (intern (match-string 2 value))))))
+                (cons option (cond
+                              ((string-match "^[0-9]$" value) (string-to-number value))
+                              ((string= "t" value) t)
+                              ((string= "nil" value) nil)
+                              (t value))))
+              options)))
+    ;; `options' isn't in the proper format for pandoc--local-settings yet:
+    ;; there may be multiple variables and extensions in it. Since we're in
+    ;; a temp buffer, we can simply use pandoc--set to set all options and
+    ;; then return the local value of `pandoc--local-settings'.
+    (setq pandoc--local-settings (copy-tree pandoc--options))
+    (mapc (lambda (option)
+            (pandoc--set (car option) (cdr option)))
+          options)
+    pandoc--local-settings))
+
+(defun pandoc-view-output ()
+  "Displays the *Pandoc output* buffer."
+  (interactive)
+  (display-buffer pandoc--output-buffer))
+
+(defun pandoc-view-settings ()
+  "Displays the settings file in a *Help* buffer."
+  (interactive)
+  ;; remove all options that do not have a value.
+  (let* ((remove-defaults (lambda (alist)
+                            (delq nil (mapcar (lambda (option)
+                                                (if (cdr option)
+                                                    option))
+                                              alist))))
+         (settings (copy-tree pandoc--local-settings))
+         (read-extensions (assq 'read-extensions settings))
+         (write-extensions (assq 'write-extensions settings)))
+    (when read-extensions
+      (setcdr read-extensions (funcall remove-defaults (cdr read-extensions))))
+    (when write-extensions
+      (setcdr write-extensions (funcall remove-defaults (cdr write-extensions))))
+    (setq settings (funcall remove-defaults settings))
+    (with-help-window " *Pandoc Help*"
+      (let ((print-length nil)
+            (print-level nil)
+            (print-circle nil))
+        (pp settings)))))
+
+(defun pandoc-view-log ()
+  "Display the log buffer in a temporary window."
+  (interactive)
+  (display-buffer pandoc--log-buffer))
+
+(defun pandoc-insert-@ ()
+  "Insert a new labeled (@) list marker at point."
+  (interactive)
+  (let ((label (pandoc--@-counter-inc)))
+    (insert (format "(@%s)" label))))
+
+(defun pandoc--collect-@-definitions ()
+  "Collect (@)-definitions and return them as a list."
+  (save-excursion
+    (goto-char (point-min))
+    (let (definitions)
+      (while (re-search-forward "^[[:space:]]*\\((@.*?).*\\)$" nil t)
+        (push (match-string-no-properties 1) definitions))
+      (nreverse definitions))))
+
+(defun pandoc-select-@ ()
+  "Show a list of (@)-definitions and allow the user to choose one."
+  (interactive)
+  (let ((definitions (pandoc--collect-@-definitions)))
+    (setq pandoc--window-config (current-window-configuration))
+    (setq pandoc--pre-select-buffer (current-buffer))
+    (setq pandoc--@-buffer (get-buffer-create " *Pandoc select*"))
+    (set-buffer pandoc--@-buffer)
+    (pandoc-@-mode)
+    (let ((buffer-read-only nil))
+      (erase-buffer)
+      (mapc (lambda (definition)
+              (insert (concat " " definition "\n\n")))
+            definitions)
+      (goto-char (point-min))
+      (setq pandoc--@-overlay (make-overlay (point-min) (point-at-eol)))
+      (overlay-put pandoc--@-overlay 'face 'highlight))
+    (select-window (display-buffer pandoc--@-buffer))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Functions to set specific options. ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun pandoc-set-write (format)
+  "Set the output format to FORMAT.
+If a settings and/or project file exists for FORMAT, they are
+loaded.  If none exists, all options are unset (except the input
+format)."
+  (interactive (list (completing-read "Set output format to: " pandoc--output-formats nil t)))
+  (when (and pandoc--settings-modified-flag
+             (y-or-n-p (format "Current settings for output format \"%s\" changed.  Save? " (pandoc--get 'write))))
+    (pandoc--save-settings 'local (pandoc--get 'write) t))
+  (unless (pandoc--load-settings-profile format t)
+    (setq pandoc--local-settings (copy-tree pandoc--options))
+    (pandoc--set 'write format)
+    (pandoc--set 'read (cdr (assq major-mode pandoc-major-modes))))
+  (setq pandoc--settings-modified-flag nil)
+  (setq pandoc--output-format-for-pdf nil)
+  (message "Output format set to `%s'" format))
+
+(defun pandoc-set-read (format)
+  "Set the input format to FORMAT."
+  (interactive (list (completing-read "Set input format to: " pandoc--input-formats nil t)))
+  (pandoc--set 'read format)
+  (message "Input format set to `%s'" format))
+
+(defun pandoc-set-output (prefix)
+  "Set the output file.
+If called with the PREFIX argument `\\[universal-argument] -' (or
+`\\[negative-argument]', the output file is unset.  If called
+with any other prefix argument, the output file is created on the
+basis of the input file and the output format."
+  (interactive "P")
+  (pandoc--set 'output
+         (cond
+          ((eq prefix '-) nil)
+          ((null prefix) (file-name-nondirectory (read-file-name "Output file: ")))
+          (t t))))
+
+(defun pandoc-set-data-dir (prefix)
+  "Set the option `Data Directory'.
+If called with the PREFIX argument `\\[universal-argument] -' (or
+`\\[negative-argument]'), the data directory is set to NIL, which
+means use $HOME/.pandoc."
+  (interactive "P")
+  (pandoc--set 'data-dir
+         (if (eq prefix '-)
+             nil
+           (read-directory-name "Data directory: " nil nil t))))
+
+(defun pandoc-set-output-dir (prefix)
+  "Set the option `Output Directory'.
+If called with the PREFIX argument `\\[universal-argument] -' (or
+`\\[negative-argument]'), the output directory is set to NIL,
+which means use the directory of the input file."
+  (interactive "P")
+  (pandoc--set 'output-dir
+         (if (eq prefix '-)
+             nil
+           (read-directory-name "Output directory: " nil nil t))))
+
+(defun pandoc-set-extract-media (prefix)
+  "Set the option `Extract media'.
+If called with the PREFIX argument `\\[universal-argument] -' (or
+`\\[negative-argument]'), no media files are extracted."
+  (interactive "P")
+  (pandoc--set 'extract-media
+         (if (eq prefix '-)
+             nil
+           (read-directory-name "Extract media files to directory: " nil nil t))))
+
+(defun pandoc-set-file-scope (prefix)
+  "Set the option `File scope'.
+If called with the PREFIX argument `\\[universal-argument] -' (or
+`\\[negative-argument]'), document scope is used."
+  (interactive "P")
+  (pandoc--set 'file-scope (if (eq prefix '-) nil t)))
+
+(defun pandoc-set-master-file (prefix)
+  "Set the master file.
+If called with the PREFIX argument `\\[universal-argument] -' (or
+`\\[negative-argument]'), the master file is set to nil, which
+means the current file is the master file."
+  (interactive "P")
+  (pandoc--set 'master-file (cond
+                       ((eq prefix '-) nil)
+                       (t (pandoc--read-file-name "Master file: " default-directory (not prefix))))))
+
+(defun pandoc-set-this-file-as-master ()
+  "Set the current file as master file.
+This option creates a Project settings file in the current
+directory to ensure that all files use the current file as master
+file."
+  (interactive)
+  (pandoc--set 'master-file (buffer-file-name))
+  (pandoc--save-settings 'project (pandoc--get 'write)))
+
+(defun pandoc-toggle-interactive (prefix)
+  "Toggle one of pandoc's binary options.
+If called with the PREFIX argument `\\[universal-argument] -' (or
+`\\[negative-argument]'), the options is unset.  If called with
+any other prefix argument, the option is set.  Without any prefix
+argument, the option is toggled."
+  (interactive "P")
+  (let* ((completion-ignore-case t)
+         (option (cdr (assoc (completing-read (format "%s option: " (cond
+                                                                     ((eq prefix '-) "Unset")
+                                                                     ((null prefix) "Toggle")
+                                                                     (t "Set")))
+                                              pandoc--switches nil t) pandoc--switches))))
+    (pandoc--set option (cond
+                   ((eq prefix '-) nil)
+                   ((null prefix) (not (pandoc--get option)))
+                   (t t)))
+    (message "Option `%s' %s." (car (rassq option pandoc--switches)) (if (pandoc--get option)
+                                                                   "set"
+                                                                 "unset"))))
+
+(easy-menu-define pandoc-mode-menu pandoc-mode-map "Pandoc menu"
+  `("Pandoc"
+    ["Run Pandoc" pandoc-run-pandoc :active t]
+    ["Create PDF" pandoc-convert-to-pdf :active t]
+    ["View Output Buffer" pandoc-view-output :active t]
+    ["View Log Buffer" pandoc-view-log :active t]
+    ("Settings Files"
+     ["Save File Settings" pandoc-save-settings-file :active t]
+     ["Save Project File" pandoc-save-project-file :active t]
+     ["Save Global Settings File" pandoc-save-global-settings-file :active t]
+     ["Revert Settings" pandoc-revert-settings :active t]
+     ["Set As Default Format" pandoc-set-default-format :active (not (eq system-type 'windows-nt))])
+    ("Example Lists"
+     ["Insert New Example" pandoc-insert-@ :active t]
+     ["Select And Insert Example Label" pandoc-select-@ :active t])
+    "--"
+    ["View Current Settings" pandoc-view-settings :active t]
+
+    ,(append (cons "Input Format"
+                   (mapcar (lambda (option)
+                             (vector (car option)
+                                     `(pandoc--set 'read ,(cdr option))
+                                     :active t
+                                     :style 'radio
+                                     :selected `(string= (pandoc--get 'read)
+                                                         ,(cdr option))))
+                           pandoc--input-formats-menu))
+             (list ["Literal Haskell" (pandoc--toggle 'read-lhs)
+                    :active (member (pandoc--get 'read) '("markdown" "rst" "latex"))
+                    :style toggle :selected (pandoc--get 'read-lhs)])
+             (list (append (list "Extensions" :visible `(string-match "markdown" (pandoc--get 'read)))
+                           (mapcar (lambda (ext)
+                                     (vector (car ext)
+                                             `(pandoc-toggle-extension ,(car ext) 'read)
+                                             :active t
+                                             :style 'toggle
+                                             :selected `(pandoc--extension-active-p ,(car ext) 'read)))
+                                   pandoc--extensions))))
+
+    ,(append (cons "Output Format"
+                   (mapcar (lambda (option)
+                             (vector (cadr option)
+                                     `(pandoc-set-write ,(car option))
+                                     :active t
+                                     :style 'radio
+                                     :selected `(string= (pandoc--get 'write)
+                                                         ,(car option))))
+                           pandoc--output-formats))
+             (list ["Literal Haskell" (pandoc--toggle 'write-lhs)
+                    :active (member (pandoc--get 'write)
+                                    '("markdown" "rst" "latex" "beamer" "html" "html5"))
+                    :style toggle :selected (pandoc--get 'write-lhs)])
+             (list (append (list "Extensions" :visible `(string-match "markdown" (pandoc--get 'write)))
+                           (mapcar (lambda (ext)
+                                     (vector (car ext)
+                                             `(pandoc-toggle-extension ,(car ext) 'write)
+                                             :active t
+                                             :style 'toggle
+                                             :selected `(pandoc--extension-active-p ,(car ext) 'write)))
+                                   pandoc--extensions))))
+
+    ("Files"
+     ("Output File"
+      ["Output To Stdout" (pandoc--set 'output nil) :active t
+       :style radio :selected (null (pandoc--get 'output))]
+      ["Create Output Filename" (pandoc--set 'output t) :active t
+       :style radio :selected (eq (pandoc--get 'output) t)]
+      ["Set Output File..." pandoc-set-output :active t
+       :style radio :selected (stringp (pandoc--get 'output))])
+     ("Output Directory"
+      ["Use Input Directory" (pandoc--set 'output-dir nil) :active t
+       :style radio :selected (null (pandoc--get 'output-dir))]
+      ["Set Output Directory" pandoc-set-output-dir :active t
+       :style radio :selected (pandoc--get 'output-dir)])
+     ("Data Directory"
+      ["Use Default Data Directory" (pandoc--set 'data-dir nil) :active t
+       :style radio :selected (null (pandoc--get 'data-dir))]
+      ["Set Data Directory" pandoc-set-data-dir :active t
+       :style radio :selected (pandoc--get 'data-dir)])
+     ,@pandoc--files-menu
+     ("Extract Media"
+      ["Do Not Extract Media Files" (pandoc--set 'extract-media nil) :active t
+       :style radio :selected (null (pandoc--get 'extract-media))]
+      ["Extract Media Files" pandoc-set-extract-media :active t
+       :style radio :selected (pandoc--get 'extract-media)])
+     ("Scope"
+      ["Document Scope" (pandoc--set 'file-scope nil) :active t
+       :style radio :selected (null (pandoc--get 'file-scope))]
+      ["File Scope" pandoc-set-file-scope :active t
+       :style radio :selected (pandoc--get 'file-scope)])
+     ("Master File"
+      ["No Master File" (pandoc-set-master-file '-) :active t :style radio :selected (null (pandoc--get 'master-file))]
+      ["Use This File As Master File" pandoc-set-this-file-as-master :active t :style radio :selected (equal (pandoc--get 'master-file) (buffer-file-name))]
+      ["Set Master File" pandoc-set-master-file :active t :style radio :selected (and (pandoc--get 'master-file) (not (equal (pandoc--get 'master-file) (buffer-file-name))))]))
+
+    ("Reader Options"
+     ,@pandoc--reader-menu-list)
+    ("General Writer Options"
+     ,@pandoc--writer-menu-list)
+    ("Options For Specific Writers"
+     ,@pandoc--specific-menu-list
+     "--"
+     ("HTML-Based Formats"
+      ,@pandoc--html-menu-list)
+     ("TeX-Based Formats"
+      ,@pandoc--tex-menu-list)
+     ("EPUB"
+      ,@pandoc--epub-menu-list))
+    ("Citations"
+     ,@pandoc--citations-menu-list)
+    ("Math Rendering"
+     ,@pandoc--math-menu-list)))
+
+;; ("Options"
+;;  ,@pandoc--options-menu)
+;; ("Switches"
+;;  ;; put the binary options into the menu
+;;  ,@(mapcar (lambda (option)
+;;              (vector (car option) `(pandoc--toggle (quote ,(cdr option)))
+;;                      :active t
+;;                      :style 'toggle
+;;                      :selected `(pandoc--get (quote ,(cdr option)))))
+;;            pandoc--switches))
+
+(easy-menu-add pandoc-mode-menu pandoc-mode-map)
+
+;; hydras
+
+(defhydra pandoc-main-hydra (:foreign-keys warn :exit t :hint nil)
+  "
+Main menu
+
+_r_: Run Pandoc               _I_: Input format
+_p_: Convert to pdf           _O_: Output format
+_V_: View output buffer       _s_: Settings files
+_S_: View current settings    _e_: Example lists
+_L_: View log buffer
+_o_: Options
+
+"
+  ("r" pandoc-run-pandoc)
+  ("p" pandoc-convert-to-pdf)
+  ("V" pandoc-view-output)
+  ("S" pandoc-view-settings)
+  ("L" pandoc-view-log)
+  ("I" pandoc-input-format-hydra/body)
+  ("O" pandoc-output-format-hydra/body)
+  ("s" pandoc-settings-file-hydra/body)
+  ("e" pandoc-@-hydra/body)
+  ("o" pandoc-options-hydra/body)
+  ("q" nil "Quit"))
+
+(define-pandoc-hydra pandoc-input-format-hydra (:foreign-keys warn :exit t :hint nil)
+  (concat "Input format: %s(pandoc--get 'read)\n\n"
+          (pandoc--tabulate-input-formats)
+          "\n"
+          (make-string 50 ?-)
+          "\n"
+          "_X_: Extensions\n\n")
+  (--map (list (cl-caddr it) (list 'pandoc-set-read (car it)))
+         pandoc--input-formats)
+  ("X" pandoc-read-exts-hydra/body)
+  ("q" nil "Quit")
+  ("b" pandoc-main-hydra/body "Back"))
+
+(define-pandoc-hydra pandoc-output-format-hydra (:foreign-keys warn :hint nil)
+  (concat "Output format: %s(pandoc--get 'write)\n\n"
+          (pandoc--tabulate-output-formats)
+          "\n"
+          (make-string 50 ?-)
+          "\n"
+          "_X_: Extensions\n\n")
+  (--map (list (cl-caddr it) (list 'pandoc-set-write (car it)))
+         pandoc--output-formats)
+  ("X" pandoc-write-exts-hydra/body :exit t)
+  ("q" nil "Quit")
+  ("b" pandoc-main-hydra/body "Back" :exit t))
+
+(defhydra pandoc-settings-file-hydra (:foreign-keys warn :hint nil)
+  "
+Settings files
+
+_s_: Save file settings
+_p_: Save project file
+_g_: Save global settings file
+_d_: Set current format as default
+_r_: Revert settings
+
+"
+  ("s" pandoc-save-settings-file)
+  ("p" pandoc-save-project-file)
+  ("g" pandoc-save-global-settings-file)
+  ("d" pandoc-set-default-format)
+  ("r" pandoc-revert-settings)
+  ("q" nil "Quit")
+  ("b" pandoc-main-hydra/body "Back" :exit t))
+
+(defhydra pandoc-@-hydra (:foreign-keys warn :exit t :hint nil)
+  "
+Example lists
+
+_i_: Insert new example
+_s_: Select and insert example label
+
+"
+  ("i" pandoc-insert-@)
+  ("s" pandoc-select-@)
+  ("q" nil "Quit")
+  ("b" pandoc-main-hydra/body "Back"))
+
+(defun pandoc--extension-active-marker (extension rw)
+  "Return a marker indicating whether EXTENSION is active.
+RW is either `read' or `write', indicating whether to take the
+input or the output format."
+  (if (pandoc--extension-active-p extension rw)
+      pandoc-extension-active-marker
+    pandoc-extension-inactive-marker))
+
+(defhydra pandoc-read-exts-hydra (:foreign-keys warn :hint nil)
+  (concat "\n" (pandoc--tabulate-extensions 'read) "\n\n<number> [_t_]: Toggle extension, [_q_]: Quit, [_b_]: Back")
+  ("t" pandoc-toggle-read-extension-by-number)
+  ("q" nil)
+  ("b" pandoc-input-format-hydra/body :exit t))
+
+(defhydra pandoc-write-exts-hydra (:foreign-keys warn :hint nil)
+  (concat "\n" (pandoc--tabulate-extensions 'write) "\n\n<number> [_t_]: Toggle extension, [_q_]: Quit, [_b_]: Back")
+  ("t" pandoc-toggle-write-extension-by-number)
+  ("q" nil)
+  ("b" pandoc-output-format-hydra/body :exit t))
+
+(defhydra pandoc-options-hydra (:foreign-keys warn :exit t :hint nil)
+  "
+Options menu
+
+_f_: Files
+_r_: Reader options
+_w_: General writer options
+_s_: Options for specific writers
+_c_: Citations
+_m_: Math rendering
+
+"
+  ("f" pandoc-file-hydra/body)
+  ("r" pandoc-reader-options-hydra/body)
+  ("w" pandoc-writer-options-hydra/body)
+  ("s" pandoc-specific-options-hydra/body)
+  ("c" pandoc-citations-hydra/body)
+  ("m" pandoc-math-hydra/body)
+  ("q" nil "Quit")
+  ("b" pandoc-main-hydra/body "Back"))
+
+(defhydra pandoc-file-hydra (:foreign-keys warn :hint nil)
+  "
+File options
+
+_o_: Output file           [%s(pandoc--pp-option 'output)]
+_O_: Output directory      [%s(pandoc--pp-option 'output-dir)]
+_d_: Data directory        [%s(pandoc--pp-option 'data-dir)]
+_e_: Extract media files   [%s(pandoc--pp-option 'extract-media)]
+_f_: File Scope            [%s(pandoc--pp-option 'file-scope)]
+_m_: Master file           [%s(pandoc--pp-option 'master-file)]
+_M_: Use current file as master file
+
+"
+  ("o" pandoc-set-output)
+  ("O" pandoc-set-output-dir)
+  ("d" pandoc-set-data-dir)
+  ("e" pandoc-set-extract-media)
+  ("f" pandoc-set-file-scope)
+  ("m" pandoc-set-master-file)
+  ("M" pandoc-set-this-file-as-master)
+  ("q" nil "Quit")
+  ("b" pandoc-options-hydra/body "Back" :exit t))
+
+(define-pandoc-hydra pandoc-reader-options-hydra (:foreign-keys warn :hint nil)
+  (concat "Reader options"
+          "\n\n"
+          (mapconcat #'car pandoc--reader-hydra-list "\n")
+          "\n\n")
+  (mapcar #'cdr pandoc--reader-hydra-list)
+  ("q" nil "Quit")
+  ("b" pandoc-options-hydra/body "Back" :exit t))
+
+(define-pandoc-hydra pandoc-writer-options-hydra (:foreign-keys warn :hint nil)
+  (concat "General writer options"
+          "\n\n"
+          (mapconcat #'car pandoc--writer-hydra-list "\n")
+          "\n\n")
+  (mapcar #'cdr pandoc--writer-hydra-list)
+  ("q" nil "Quit")
+  ("b" pandoc-options-hydra/body "Back" :exit t))
+
+(define-pandoc-hydra pandoc-specific-options-hydra (:foreign-keys warn :hint nil)
+  (concat "Specific writer options"
+          "\n\n"
+          (mapconcat #'car pandoc--specific-hydra-list "\n")
+          "\n"
+          (make-string 50 ?-)
+          "\n"
+          "_H_: HTML-based writers\n"
+          "_T_: TeX-based writers\n"
+          "_E_: Epub"
+          "\n\n")
+  (mapcar #'cdr pandoc--specific-hydra-list)
+  ("H" pandoc-html-options-hydra/body :exit t)
+  ("T" pandoc-tex-options-hydra/body :exit t)
+  ("E" pandoc-epub-options-hydra/body :exit t)
+  ("q" nil "Quit")
+  ("b" pandoc-options-hydra/body "Back" :exit t))
+
+(define-pandoc-hydra pandoc-html-options-hydra (:foreign-keys warn :hint nil)
+  (concat "HTML-based writer options"
+          "\n\n"
+          (mapconcat #'car pandoc--html-hydra-list "\n")
+          "\n\n")
+  (mapcar #'cdr pandoc--html-hydra-list)
+  ("q" nil "Quit")
+  ("b" pandoc-specific-options-hydra/body "Back" :exit t))
+
+(define-pandoc-hydra pandoc-tex-options-hydra (:foreign-keys warn :hint nil)
+  (concat "TeX-based writer options"
+          "\n\n"
+          (mapconcat #'car pandoc--tex-hydra-list "\n")
+          "\n\n")
+  (mapcar #'cdr pandoc--tex-hydra-list)
+  ("q" nil "Quit")
+  ("b" pandoc-specific-options-hydra/body "Back" :exit t))
+
+(define-pandoc-hydra pandoc-epub-options-hydra (:foreign-keys warn :hint nil)
+  (concat "Epub writer options"
+          "\n\n"
+          (mapconcat #'car pandoc--epub-hydra-list "\n")
+          "\n\n")
+  (mapcar #'cdr pandoc--epub-hydra-list)
+  ("q" nil "Quit")
+  ("b" pandoc-specific-options-hydra/body "Back" :exit t))
+
+(define-pandoc-hydra pandoc-citations-hydra (:foreign-keys warn :hint nil)
+  (concat "Citations menu"
+          "\n\n"
+          (mapconcat #'car pandoc--citations-hydra-list "\n")
+          "\n\n")
+  (mapcar #'cdr pandoc--citations-hydra-list)
+  ("q" nil "Quit")
+  ("b" pandoc-options-hydra/body "Back" :exit t))
+
+(define-pandoc-hydra pandoc-math-hydra (:foreign-keys warn :hint nil)
+  (concat "Math rendering"
+          "\n\n"
+          (mapconcat #'car pandoc--math-hydra-list "\n")
+          "\n\n")
+  (mapcar #'cdr pandoc--math-hydra-list)
+  ("q" nil "Quit")
+  ("b" pandoc-options-hydra/body "Back" :exit t))
+
+
+;;; Faces:
+;;; Regexp based on github.com/vim-pandoc/vim-pandoc-syntax.
+;;; Overall structure modeled after face handling in markdown-mode.el:
+;;; http://jblevins.org/git/markdown-mode.git
+
+(defvar pandoc-citation-key-face 'pandoc-citation-key-face
+  "Face name to use for citations.")
+
+(defvar pandoc-citation-marker-face 'pandoc-citation-marker-face
+  "Face name to use for '@' citation identifier.")
+
+(defvar pandoc-citation-extra-face 'pandoc-citation-extra-face
+  "Face name to use for page numbers and other notation.")
+
+(defvar pandoc-citation-brackets-face 'pandoc-citation-brackets-face
+  "Face name to use for page numbers and other notation.")
+
+(defvar pandoc-strikethrough-text-face 'pandoc-strikethrough-text-face
+  "Face name to use for strikethrough text.")
+
+(defvar pandoc-strikethrough-tilde-face 'pandoc-strikethrough-tilde-face
+  "Face name to use for strikethrough delimiters.")
+
+(defvar pandoc-directive-@@-face 'pandoc-directive-@@-face
+  "Face name to use for '@@' in @@directives.")
+
+(defvar pandoc-directive-type-face 'pandoc-directive-type-face
+  "Face name to use for name of @@directives.")
+
+(defvar pandoc-directive-braces-face 'pandoc-directive-braces-face
+  "Face name to use for braces in @@directives.")
+
+(defvar pandoc-directive-contents-face 'pandoc-directive-contents-face
+  "Face name to use for contents of @@directives.")
+
+(defface pandoc-citation-key-face
+  '((t (:inherit font-lock-function-name-face)))
+  "Base face for pandoc citations."
+  :group 'pandoc)
+
+(defface pandoc-citation-marker-face
+  '((t (:inherit font-lock-variable-name-face)))
+  "Base face for pandoc citation marker '@'."
+  :group 'pandoc)
+
+(defface pandoc-citation-extra-face
+  '((t (:inherit font-lock-variable-name-face)))
+  "Base face for page numbers and other pandoc citation notation."
+  :group 'pandoc)
+
+(defface pandoc-citation-brackets-face
+  '((t (:inherit font-lock-function-name-face)))
+  "Base face for pandoc citation brackets."
+  :group 'pandoc)
+
+(defface pandoc-strikethrough-text-face
+  '((t (:strike-through t)))
+  "Base face for pandoc strikethrough text."
+  :group 'pandoc)
+
+(defface pandoc-strikethrough-tilde-face
+  '((t (:inherit font-lock-warning-face)))
+  "Base face for pandoc strikethrough delimiters."
+  :group 'pandoc)
+
+(defface pandoc-directive-@@-face
+  '((t (:inherit font-lock-type-face)))
+  "Base face for pandoc-mode @@directive syntax."
+  :group 'pandoc)
+
+(defface pandoc-directive-type-face
+  '((t (:inherit font-lock-preprocessor-face)))
+  "Base face for pandoc-mode @@directive type (include or lisp)."
+  :group 'pandoc)
+
+(defface pandoc-directive-braces-face
+  '((t (:inherit font-lock-variable-name-face)))
+  "Base face for pandoc-mode @@directive braces."
+  :group 'pandoc)
+
+(defface pandoc-directive-contents-face
+  '((t (:inherit font-lock-constant-face)))
+  "Base face for pandoc-mode @@directive type (include or lisp)."
+  :group 'pandoc)
+
+(defconst pandoc-regex-parenthetical-citation-single
+  "\\(\\[\\)\\(-?@\\)\\([-a-zA-Z0-9_+:]+\\)\\(\\]\\)"
+  "Regular expression for parenthetical citations with only one key.")
+
+(defconst pandoc-regex-parenthetical-citation-multiple
+  "\\(\\[\\)\\(.*?\\)\\(-?@\\)\\([-a-zA-Z0-9_+:]+\\)\\(.*?\\)\\(\\]\\)"
+  "Regular expression for parenthetical citations with page numbers or multiple keys.")
+
+(defconst pandoc-regex-in-text-citation
+  "\\[\\{0\\}\\(-?@\\)\\([-a-zA-Z0-9_+:]+\\)\\s-\\(\\[\\)\\(.*?\\)\\(\\]\\)"
+  "Regular expression for stand-alone citation with anchor.")
+
+(defconst pandoc-regex-in-text-citation-2
+  "\\(?:[^[:alnum:]]\\|^\\)\\(-?@\\)\\([-a-zA-Z0-9_+:]+\\)"
+  "Regular expression for stand-alone citation with no anchor.")
+
+(defconst pandoc-regex-strikethrough
+  "\\(~\\{2\\}\\)\\([^~].*?\\)\\(~\\{2\\}\\)"
+  "Regular expression for pandoc markdown's strikethrough syntax.")
+
+(defconst pandoc-regex-@@-directive
+  "\\(@@\\)\\(include\\|lisp\\)\\({\\)\\(.*?\\)\\(}\\)"
+  "Regular expression for pandoc-mode's @@directives.")
+
+(defvar pandoc-faces-keywords
+  (list
+   (cons pandoc-regex-@@-directive
+   	 '((1 pandoc-directive-@@-face)
+	   (2 pandoc-directive-type-face)
+	   (3 pandoc-directive-braces-face)
+   	   (4 pandoc-directive-contents-face)
+	   (5 pandoc-directive-braces-face)))
+   (cons pandoc-regex-parenthetical-citation-single
+   	 '((1 pandoc-citation-brackets-face t)
+   	   (2 pandoc-citation-marker-face)
+   	   (3 pandoc-citation-key-face)
+   	   (4 pandoc-citation-brackets-face t)))
+   (cons pandoc-regex-in-text-citation-2
+   	 '((1 pandoc-citation-marker-face)
+   	   (2 pandoc-citation-key-face)))
+   (cons pandoc-regex-parenthetical-citation-multiple
+         '((1 pandoc-citation-brackets-face t)
+           (2 pandoc-citation-extra-face)
+           (3 pandoc-citation-marker-face)
+           (4 pandoc-citation-key-face)
+           (5 pandoc-citation-extra-face append)
+           (6 pandoc-citation-brackets-face t)))
+   (cons pandoc-regex-in-text-citation
+	 '((1 pandoc-citation-marker-face)
+	   (2 pandoc-citation-key-face)
+	   (3 pandoc-citation-brackets-face)
+	   (4 pandoc-citation-extra-face)
+	   (5 pandoc-citation-brackets-face)))
+   (cons pandoc-regex-strikethrough
+   	 '((1 pandoc-strikethrough-tilde-face)
+   	   (2 pandoc-strikethrough-text-face )
+   	   (3 pandoc-strikethrough-tilde-face))))
+  "Keywords for pandoc faces.")
+
+(defun pandoc-faces-load ()
+  "Load pandoc-faces."
+  (font-lock-add-keywords nil pandoc-faces-keywords)
+  (if (fboundp 'font-lock-flush)
+      (font-lock-flush)
+    (with-no-warnings
+      (font-lock-fontify-buffer))))
+
+(defun pandoc-faces-unload ()
+  "Unload pandoc-faces."
+  (font-lock-remove-keywords nil pandoc-faces-keywords)
+  (if (fboundp 'font-lock-flush)
+      (font-lock-flush)
+    (with-no-warnings
+      (font-lock-fontify-buffer))))
+
+;;; Citation jumping:
+;;; Jump to citation in a bibliography file.
+
+(defun pandoc-jump-to-reference ()
+  "Display the BibTeX reference for the citation key at point.
+Extract the key at point and pass it to the function in
+`pandoc-citation-jump-function', together with a list of the
+current buffer's BibTeX files."
+  (interactive)
+  (let ((biblist (pandoc--get 'bibliography)))
+    (if biblist
+        (cond
+         ((thing-at-point-looking-at pandoc-regex-in-text-citation)
+          (funcall pandoc-citation-jump-function (match-string-no-properties 4) biblist))
+         ((thing-at-point-looking-at pandoc-regex-in-text-citation-2)
+          (funcall pandoc-citation-jump-function (match-string-no-properties 2) biblist))
+         ((thing-at-point-looking-at pandoc-regex-parenthetical-citation-single)
+          (funcall pandoc-citation-jump-function (match-string-no-properties 3) biblist))
+         ((thing-at-point-looking-at pandoc-regex-parenthetical-citation-multiple)
+          (funcall pandoc-citation-jump-function (match-string-no-properties 4) biblist))
+         (t (error "No citation at point")))
+      (error "No bibliography selected"))))
+
+(defun pandoc-goto-citation-reference (key biblist)
+  "Open the BibTeX file containing the entry for KEY.
+BIBLIST is a list of BibTeX files in which to search for KEY.
+The first file in which KEY is found is opened in a new
+window (using `find-file-other-window').
+
+This function is the default value of `pandoc-citation-jump-function'."
+  (let* ((key-regexp (concat "@[a-zA-Z]*[[:space:]]*[{(][[:space:]]*" key))
+         (bibfile (cl-loop for file in biblist
+                           if (with-temp-buffer
+                                (insert-file-contents file)
+                                (re-search-forward key-regexp nil t))
+                           return file)))
+    (if (not bibfile)
+        (error "Key '%s' not found" key)
+      (find-file-other-window bibfile)
+      (goto-char (point-min))
+      (re-search-forward key-regexp nil t)
+      (beginning-of-line))))
+
+(defun pandoc-open-in-ebib (key biblist)
+  "Open BibTeX item KEY in Ebib.
+BIBLIST is a list of BibTeX files in which to search for KEY.
+
+This function is for use in `pandoc-citation-jump-function'."
+  (let ((bibfile (cl-loop for file in biblist
+                          if (with-temp-buffer
+                               (insert-file-contents file)
+                               (re-search-forward (concat "@[a-zA-Z]*[[:space:]]*[{(][[:space:]]*" key) nil t))
+                          return file)))
+    (if bibfile
+        (ebib bibfile key)
+      (error "Key '%s' not found" key))))
+
+(defun pandoc-show-entry-as-help (key biblist)
+  "Show the BibTeX item KEY in a *Help* buffer.
+BIBLIST is a list of BibTeX files in which to search for KEY.
+
+This function is for use in `pandoc-citation-jump-function'."
+  (let ((entry (cl-loop for file in biblist
+                        thereis (with-temp-buffer
+                                  (insert-file-contents file)
+                                  (when (re-search-forward (concat "@[a-zA-Z]*[[:space:]]*\\([{(]\\)[[:space:]]*" key) nil t)
+                                    (beginning-of-line)
+                                    (let ((beg (point)))
+                                      (goto-char (match-beginning 1))
+                                      (forward-list)
+                                      (buffer-substring beg (point))))))))
+    (if entry
+        (with-help-window (help-buffer)
+          (princ entry))
+      (error "Key `%s' not found" key))))
+
+(provide 'pandoc-mode)
+
+;;; pandoc-mode.el ends here
.emacs.d/elpa/pandoc-mode-20161104.1521/pandoc-mode.elc
Binary file
.emacs.d/elpa/pandoc-mode-20161104.1521/pandoc-mode.info
@@ -0,0 +1,842 @@
+This is pandoc-mode.info, produced by makeinfo version 6.1 from
+pandoc-mode.texi.
+
+INFO-DIR-SECTION Emacs START-INFO-DIR-ENTRY * Pandoc-mode:
+(pandoc-mode).  Minor mode for interacting with Pandoc.
+END-INFO-DIR-ENTRY
+
+INFO-DIR-SECTION Emacs START-INFO-DIR-ENTRY * Pandoc-mode:
+(pandoc-mode).  Minor mode for interacting with Pandoc.
+END-INFO-DIR-ENTRY
+
+INFO-DIR-SECTION Emacs START-INFO-DIR-ENTRY * Pandoc-mode:
+(pandoc-mode).  Minor mode for interacting with Pandoc.
+END-INFO-DIR-ENTRY
+
+
+File: pandoc-mode.info,  Node: Top,  Next: Introduction,  Up: (dir)
+
+Emacs pandoc-mode
+*****************
+
+* Menu:
+
+* Introduction::
+* Installation::
+* Usage::
+* Font lock::
+* Settings Files::
+* File-local variables::
+* Managing numbered examples::
+* Using @@-directives::
+* Disabling the hydra menu::
+
+
+File: pandoc-mode.info,  Node: Introduction,  Next: Installation,  Prev: Top,  Up: Top
+
+1 Introduction
+**************
+
+‘pandoc-mode’ is an Emacs mode for interacting with Pandoc
+(http://pandoc.org/).  Pandoc is a program (plus libraries) created by
+John MacFarlane that can convert a text written in one markup language
+into another markup language.  ‘pandoc-mode’ is implemented as a minor
+mode that can be activated alongside the major mode for any of Pandoc’s
+supported input formats.  It provides facilities to set the various
+options that Pandoc accepts and to run Pandoc on the input file.  It is
+possible to create different output profiles for a single input file, so
+that you can, for example, write your text in Markdown and then
+translate it to HTML for online reading, PDF for offline reading and
+Texinfo for reading in Emacs, all with just a few keystrokes.
+
+The current version of ‘pandoc-mode’ is 2.20 and is compatible with
+Pandoc version 1.18.
+
+
+File: pandoc-mode.info,  Node: Installation,  Next: Usage,  Prev: Introduction,  Up: Top
+
+2 Installation
+**************
+
+The easiest way to install ‘pandoc-mode’ is to use the Melpa
+(http://melpa.org/) package repository.  Alternatively, you can install
+it manually: download ‘pandoc-mode.el’ and ‘pandoc-mode-utils.el’, put
+them into Emacs’ loadpath (byte-compiling is recommended) and add the
+line ‘(load "pandoc-mode")’ to your init file.
+
+Either installation method allows Emacs to load ‘pandoc-mode’, but they
+do not activate it.  In order to activate ‘pandoc-mode’ in a buffer, you
+need to type ‘M-x pandoc-mode’.  To start ‘pandoc-mode’ automatically
+when you load e.g., a Markdown file, you can add a hook to your init
+file:
+
+(add-hook 'markdown-mode-hook 'pandoc-mode)
+
+However, if you do not want to start ‘pandoc-mode’ every time you work
+on a Markdown document, you can use a different function in
+‘markdown-mode-hook’: instead of using ‘pandoc-mode’, you can use
+‘conditionally-turn-on-pandoc’.  This function checks if a default
+settings file exists for the file you’re opening and only turns on
+‘pandoc-mode’ if it finds one.  (For more info on the settings file, see
+the section *note ’Settings Files’: #settings-files.)
+
+Additionally, if you want to automatically load the default
+‘pandoc-mode’ settings file for the file you’re opening, you can add the
+following to your init file:
+
+(add-hook 'pandoc-mode-hook 'pandoc-load-default-settings)
+
+The function ‘pandoc-load-default-settings’ checks if a default settings
+file exists for the file being loaded and reads its settings if it finds
+one.
+* Menu:
+
+* OS X::
+
+
+File: pandoc-mode.info,  Node: OS X,  Up: Installation
+
+2.1 OS X
+========
+
+‘pandoc-mode’ expects that the ‘pandoc’ binary can be found in your
+system’s ‘$PATH’ and that the contents of ‘$PATH’ is available to Emacs.
+Especially on OS X, this may not always be the case.  To remedy this,
+you can set the user option ‘pandoc-binary’ to the full path of ‘pandoc’
+on your system.  A more elegant solution is to install the
+exec-path-from-shell (https://github.com/purcell/exec-path-from-shell)
+package.  This package makes sure that the contents of your system’s
+‘$PATH’ variable is visible to Emacs, allowing Emacs to find ‘pandoc’.
+
+
+File: pandoc-mode.info,  Node: Usage,  Next: Font lock,  Prev: Installation,  Up: Top
+
+3 Usage
+*******
+
+‘pandoc-mode’ uses the hydra (https://github.com/abo-abo/hydra) package
+to create a keyboard-driven menu interface to all options and settings.
+The main menu is called by pressing ‘C-c /’.  After that, everything
+should be self-explanatory.  From the main menu, you can run ‘pandoc’ on
+the buffer, view the output buffer and the current settings, set the
+input and output formats, and you can go to the options menu.
+
+Note that if ‘menu-bar-mode’ is active, ‘pandoc-mode’ also provides a
+menu in the menu bar.  It has the same structure as the hydra menu and
+it has the advantage that options that do not apply to the current file
+(due to its input or output format), are generally greyed out.  On the
+other hand, the hydra menu shows the value of the options and allows you
+to change more than one option without having to keep reopening the
+menu.  The menu bar menu disappears when you select an option, the hydra
+menu (generally) does not.  Instead, it can be dismissed with ‘q’.
+Below, I talk about the hydra menu specifically, but most of what is
+said applies to the menu bar menu as well.
+
+In the options menu, you can set options for running ‘pandoc’ on your
+input file.  All Pandoc options can be set from the menu (except for one
+or two that do not make sense, e.g., ‘--print-default-template’).  Note
+that when you set options, they only apply to the current file _and_ the
+current output format.  When you open another file, or when you change
+the output format, all settings are reset to their default values.
+(There are ways to make settings more permanent, of course, as discussed
+below.)
+* Menu:
+
+* Input and output formats::
+* The options menu::
+* Template variables and metadata::
+* Running Pandoc::
+* Setting an output file::
+* Creating a pdf::
+* Connection Type::
+* Citation Jumping::
+
+
+File: pandoc-mode.info,  Node: Input and output formats,  Next: The options menu,  Up: Usage
+
+3.1 Input and output formats
+============================
+
+The most important settings are the input and output formats.  The input
+format is set automatically by Emacs on the basis of the major mode of
+the input file, but you can change it if you need to.  The output format
+defaults to "Native Haskell", so most likely you will want to set it to
+something else before you run Pandoc.  The input and output format menus
+also provide access to a submenu with the Markdown extensions that
+Pandoc supports.
+
+As already stated, you may wish to use different output formats for a
+single input file.  Most likely, the options that you want to pass to
+Pandoc will be different for each output format.  To make this easier,
+‘pandoc-mode’ has the ability to save the settings for a specific output
+format.  The main menu has an option “Settings files” (‘C-c / s’), which
+takes you to a submenu where you can save the current settings.  Emacs
+saves these settings to a hidden file in the same directory as the file
+you’re editing, under a name composed of the input file, appended with
+the name of the output format and the string ‘.pandoc’.  So if your
+input file is called ‘mytext.md’, the ‘html’ settings file will be
+called ‘.mytext.md.html.pandoc’.  (See the section *note ’Settings
+Files’: #settings-files. for details.)
+
+A single document can have a separate settings file for each output
+format that Pandoc supports.  These can simply be created by setting all
+options the way you want them for the first output format, save them,
+then choose another output format, set the required options, save again,
+etc.  Because the name of a settings file contains the output format for
+which it was created, the different settings files won’t interfere with
+each other.  When you switch the output format (with ‘C-c / O’), Emacs
+checks if a corresponding settings file exists and loads it if one is
+found.
+
+On systems that have symbolic links, it is also possible to specify a
+default output format (‘C-c / s d’).  This is done by creating a
+symbolic link to the settings file of the current output format (a
+settings file is created if one doesn’t exist yet) with the output
+format replaced by the string ‘"default"’.  The file it points to is
+read by the function ‘pandoc-load-default-settings’, making it possible
+to automatically load a specific settings file when ‘pandoc-mode’ is
+invoked, as described above.
+
+Note that the current output format is always visible in the mode line:
+the "lighter" for ‘pandoc-mode’ in the mode line has the form
+‘Pandoc/<format>’, where ‘<format>’ is the current output format.
+
+The major modes for which ‘pandoc-mode’ selects an input format
+automatically can be customised (user option ‘pandoc-major-modes’).  You
+can add major modes or remove those that you don’t use.  Similarly, you
+can customise the file extensions for each output format
+(‘pandoc-output-format-extensions’).
+
+
+File: pandoc-mode.info,  Node: The options menu,  Next: Template variables and metadata,  Prev: Input and output formats,  Up: Usage
+
+3.2 The options menu
+====================
+
+The options menu has a number of submenus, each related to a specific
+type of options: file options, reader options, writer options (general
+and specific), citations and math rendering.  The file options menu
+contains options for the output file, output directory, data directory,
+the directory to extract media files to, and the master file.  Only two
+of these (the data directory and the extract media directory) correspond
+directly to a Pandoc option.  The output file and output directory
+options are combined to form Pandoc’s ‘--output’ option, while the
+master file option is only used by ‘pandoc-mode’.  These options are
+discussed in the sections *note ’Setting an output file’:
+#setting-an-output-file. and *note ’Master file’: #master-file,
+respectively.
+
+Note that the subdivision in the options menu is based on the
+subdivision in the Pandoc README and the user guide on Pandoc.org
+(http://pandoc.org/README.html), which should make it easier to find the
+relevant options in the menus.
+
+One nice thing about the hydra menus is that the value of an option is
+displayed beside it.  Pandoc’s options come in several different kinds.
+Switches, (boolean options that do not take a value), are toggled when
+you select them, and their value is displayed as either “yes” or “no”.
+If you select another kind of option, you are asked to provide a value
+in the minibuffer.  For template variables and metadata items, you are
+asked both a variable / metadata name and a value.
+
+Unsetting an option can usually be done by prefixing the relevant key
+with a dash ‘-’.  This is actually the negative prefix argument, which
+can be typed without the meta (alt) key when inside a hydra menu.  So
+for example, if you’re in the files menu (‘C-c / o f’), you can set an
+output file with ‘o’, and to unset the output file, you can type ‘- o’.
+
+Many Pandoc options have file names as values.  These are normally
+prompted for and stored as _relative_ paths.  File name completion is
+available, starting from the current directory.  For some options, such
+as ‘--css’, relative paths make more sense because an absolute file
+would almost certainly be incorrect once the output html file is moved
+to the web server.  Other options, such as ‘--template’, look in
+Pandoc’s data directory and therefore also do not require an absolute
+path.  Lastly, auxiliary files, such as ‘--include-in-header’, will
+usually be stored in the same directory as the source file or in a
+subdirectory, in which case a relative path is unproblematic.
+
+However, if for some reason you need to store an absolute path for an
+option, you can do so by using the prefix argument ‘C-u’.  So for
+example in the general writer options menu, accessible through ‘C-/ o
+w’, pressing ‘C-u H’ asks for a file to include in the header and stores
+it as an absolute path.  Note that absolute paths are not expanded,
+i.e., they may contain abbreviations such as ‘~’ for one’s home
+directory.  This makes it easier to share settings files between
+computers with different OSes (for example, Linux expands ‘~’ to
+‘/home/<user>’, while on OS X it becomes ‘/Users/<user>’).
+
+File options may have a default value (although currently, this is only
+the case for ‘--epub-stylesheet’).  Such options can be specified on the
+‘pandoc’ command line without naming a file.  To select such a default
+value for a file option, use a numeric prefix argument, which in the
+hydra menu is obtained by pressing a number without the meta key.  That
+is, to select the default EPUB style sheet, go to the EPUB options menu
+(‘C-/ o s E’) and press ‘1 s’.
+
+Options that are not files or numbers are “string options”, which
+include options that specify a URL. These may also have a default value,
+which can be set in the same way as with file options.  Note, though,
+that this does not apply to options that only have a limited set of
+possible values (e.g., ‘--email-obfuscation’, ‘--latex-engine’).  These
+can be set or unset, you cannot explicitly request their default value.
+(‘pandoc’ uses their default values even if they are not specified on
+the command line, unlike string options.)
+
+To get an overview of all the settings for the current file and output
+format, you can use the option “View current settings” in the main menu
+(‘C-c / S’).  This displays all settings in a ‘*Help*’ buffer in a
+Lisp-like format.  For example, the settings for TeXinfo output of this
+manual look like this:
+
+((standalone . t)
+ (read . "markdown")
+ (write . "texinfo")
+ (output . t)
+ (include-before-body . "~/src/pandoc-mode/manual/texi-before-body"))
+
+
+File: pandoc-mode.info,  Node: Template variables and metadata,  Next: Running Pandoc,  Prev: The options menu,  Up: Usage
+
+3.3 Template variables and metadata
+===================================
+
+‘pandoc-mode’ allows you to set or change template variables through the
+menu.  The variables are in the general writer options menu, the
+metadata in the reader options menu.  Emacs will ask you for the name of
+a variable or metadata item and for a value for it.  If you provide a
+name that already exists (TAB completion works), the new value replaces
+the old one.
+
+Deleting a template variable or metadata item can be done by prefixing
+the menu key with ‘-’.  Emacs will ask you for the variable name (TAB
+completion works here, too) and removes it from the list.
+
+
+File: pandoc-mode.info,  Node: Running Pandoc,  Next: Setting an output file,  Prev: Template variables and metadata,  Up: Usage
+
+3.4 Running Pandoc
+==================
+
+The first item in the menu is "Run Pandoc" (accessible with ‘C-c / r’),
+which, as the name suggests, runs Pandoc on the document, passing all
+options you have set.  By default, Pandoc sends the output to stdout
+(except when the output format is "odt", "epub" or "docx", in which case
+output is always sent to a file.).  Emacs captures this output and
+redirects it to the buffer ‘*Pandoc output*’.  The output buffer is not
+normally shown, but you can make it visible through the menu or by
+typing ‘C-c / V’.  Error messages from Pandoc are also displayed in this
+buffer.
+
+When you run Pandoc, ‘pandoc-mode’ also generates a few messages, which
+are logged in a buffer calles ‘*Pandoc log*’.  You will rarely need to
+see this, since ‘pandoc-mode’ displays a message telling you whether
+Pandoc finished successfully or not.  In the latter case, the output
+buffer is displayed, so you can see the error that Pandoc reported.
+
+Note that when you run Pandoc, Pandoc doesn’t read the file on disk.
+Rather, Emacs feeds it the contents of the buffer through ‘stdin’.  This
+means that you don’t actually have to save your file before running
+Pandoc.  Whatever is in your buffer, saved or not, is passed to Pandoc.
+Alternatively, if the region is active, only the region is sent to
+Pandoc.
+
+If you call this command with a prefix argument ‘C-u’ (so the key
+sequence becomes ‘C-/ C-u r’: ‘C-/’ to open the menu and ‘C-u r’ to run
+Pandoc), Emacs asks you for an output format to use.  If there is a
+settings file for the format you specify, the settings in it will be
+passed to Pandoc instead of the settings in the current buffer.  If
+there is no settings file, Pandoc will be called with just the output
+format and no other options.
+
+Note that specifying an output format this way does not change the
+output format or any of the settings in the buffer, it just changes the
+output profile used for calling Pandoc.  This can be useful if you use
+different output formats but don’t want to keep switching between
+profiles when creating the different output files.
+
+
+File: pandoc-mode.info,  Node: Setting an output file,  Next: Creating a pdf,  Prev: Running Pandoc,  Up: Usage
+
+3.5 Setting an output file
+==========================
+
+If you want to save the output to a file rather than have it appear in
+the output buffer, you can set an explicit output file.  Note that
+setting an output _file_ is not the same thing as setting an output
+_format_ (though normally the output file has a suffix that indicates
+the format of the file).
+
+In ‘pandoc-mode’, the output file setting has three options: the default
+is to send output to stdout, in which case it is redirected to the
+buffer ‘*Pandoc output*’.  This option can be selected by typing ‘- o’
+in the file options menu.  Alternatively, you can let Emacs create an
+output filename for you.  In this case the output file will have the
+same base name as the input file but with the proper suffix for the
+output format.  To select this option, prefix the output file key ‘o’
+with ‘C-u’ in the file options menu.  The third option is to specify an
+explicit output file.  This can (obviously) be done by hitting just ‘o’.
+
+Note that Pandoc does not allow output to be sent to stdout if the
+output format is an OpenOffice.org Document (ODT), EPUB or MS Word
+(docx) file.  Therefore, Emacs will always create an output filename in
+those cases, unless of course you’ve explicitly set an output file
+yourself.
+
+The output file you set is always just the base filename, it does not
+specify a directory.  Which directory the output file is written to
+depends on the setting "Output Directory" (which is not actually a
+Pandoc option).  Emacs creates an output destination out of the settings
+for the output directory and output file.  If you don’t specify any
+output directory, the output file will be written to the same directory
+that the input file is in.
+
+
+File: pandoc-mode.info,  Node: Creating a pdf,  Next: Connection Type,  Prev: Setting an output file,  Up: Usage
+
+3.6 Creating a pdf
+==================
+
+The second item in the main menu is "Create PDF" (invoked with ‘C-c /
+p’).  This option calls Pandoc with a PDF file as output file.  In order
+for Pandoc to create a PDF, the output format must be ‘latex’, ‘context’
+or ‘html5’ (in which case ‘wkhtmltopdf’ is used to create the PDF file).
+If the current buffer’s output format is one of these, ‘C-c / p’ creates
+the PDF using that format.
+
+If the current output format is set to something else, Emacs asks you
+which output format to use.  If there is a settings file for the output
+format you specify, it is used to create the PDF. (The current buffer’s
+settings aren’t changed, however.)  If there is no settings file, Pandoc
+is called with only the input and output formats and the output file.
+
+The format you choose is remembered (at least until you close the buffer
+or change the output format), so that the next time you convert the
+buffer to PDF, you are not asked for the format again.  If you wish to
+use a different format for PDF creation, use a prefix argument ‘C-u’.
+(That is, the key sequence to type is ‘C-c / C-u p’.)
+
+This setup means that you do not need to switch the output format to
+‘latex’, ‘context’ or ‘html5’ in order to create a PDF, which can be
+practical if you’re also converting to another format.  However, if you
+wish to change settings for PDF output, you *do* need to switch to the
+relevant output format.
+
+
+File: pandoc-mode.info,  Node: Connection Type,  Next: Citation Jumping,  Prev: Creating a pdf,  Up: Usage
+
+3.7 Connection Type
+===================
+
+By default, Emacs starts ‘pandoc’ as an asynchronous process using a
+tty.  If this causes problems for some reason, you can try using a pipe
+instead by customising ‘pandoc-process-connection-type’.  Alternatively,
+you can use a synchronous process by unsetting the user option
+‘pandoc-use-async’.
+
+
+File: pandoc-mode.info,  Node: Citation Jumping,  Prev: Connection Type,  Up: Usage
+
+3.8 Citation Jumping
+====================
+
+‘pandoc-mode’ provides the function ‘pandoc-jump-to-reference’ that
+locates a reference within external bibliography files indicated by the
+‘bibliography’ user option.  Note that entries to the ‘bibliography’
+user option list must have an absolute path for this option to work
+properly (i.e.  ‘"./Bibliography.bib"’ rather than
+‘"Bibliography.bib"’).  This feature is not bound to any key by default,
+but may of course be bound to a key combination as follows:
+
+(define-key markdown-mode-map (kbd "C-c j") 'pandoc-jump-to-reference)
+
+The jump behaviour can be customised by changing the option
+‘pandoc-citation-jump-function’.  Its default value is
+‘pandoc-goto-citation-reference’, which opens the relevant BibTeX file
+in a new window and moves point to the entry.  Two alternative functions
+have been defined: ‘pandoc-open-in-ebib’, which opens the relevant entry
+in Ebib, and ‘pandoc-show-entry-as-help’, which shows the entry in a
+‘*Help*’ buffer, but does not open the corresponding BibTeX file.
+
+Alternatively, you may also define your own function, which should take
+two arguments: the key of the entry to be displayed and a list of BibTeX
+files.
+
+
+File: pandoc-mode.info,  Node: Font lock,  Next: Settings Files,  Prev: Usage,  Up: Top
+
+4 Font lock
+***********
+
+‘pandoc-mode’ adds font lock keywords for citations and numbered example
+lists.  The relevant faces can be customised in the customisation group
+‘pandoc’.
+
+
+File: pandoc-mode.info,  Node: Settings Files,  Next: File-local variables,  Prev: Font lock,  Up: Top
+
+5 Settings Files
+****************
+
+Apart from settings files for individual files (which are called _local
+settings files_), ‘pandoc-mode’ supports two other types of settings
+files: project files and global files.  Project files are settings files
+that apply to all input files in a given directory (except those files
+for which a local settings file exists).  Global settings files, as the
+name implies, apply globally, to files for which no local or project
+file is found.  Both types of files are specific to a particular output
+format, just like local settings files.  Project files live in the
+directory they apply to and are called ‘Project.<format>.pandoc’.
+Global files live in the directory specified by the variable
+‘pandoc-data-dir’, which defaults to ‘~/.emacs.d/pandoc-mode/’, but this
+can of course be changed in the customisation group ‘pandoc’.
+
+Whenever ‘pandoc-mode’ loads settings for an input file, it first checks
+if there is a local settings file.  If none is found, it looks for a
+project file, and if that isn’t found, it tries to load a global
+settings file.  In this way, local settings override project settings
+and project settings override global settings.  Note, however, that if a
+local settings file exists, _all_ settings are read from this file.  Any
+project file or global file for the relevant output format is ignored.
+
+You can create a project or global settings file through the menu in the
+submenu "Settings Files".  This simply saves all settings for the
+current buffer to a project or global settings file.  (Any local
+settings file for the file in the current buffer will be kept.  You’ll
+need to delete it manually if you no longer need it.)
+
+The name of a global settings file has the form ‘<format>.pandoc’, where
+‘<format>’ obviously specifies the output format.  ‘<format>’ can also
+be the string ‘"default“’, however, in which case it specifies a default
+settings file, which is loaded by ‘pandoc-load-default-settings’ when no
+default local or project settings file is found.  In this way, you can
+override the default output format used for new files.
+
+Note that starting with version 2.5, ‘pandoc-mode’ settings files are
+written in a Lisp format (as demonstrated above).  Old-style settings
+files continue to be read, so there is no need to change anything, but
+if you change any settings and save them, the file is converted.
+
+
+File: pandoc-mode.info,  Node: File-local variables,  Next: Managing numbered examples,  Prev: Settings Files,  Up: Top
+
+6 File-local variables
+**********************
+
+‘pandoc-mode’ also allows options to be set as file-local variables,
+which gives you the ability to keep the settings for a file in the file
+itself.  To specify an option in this way, use the long form of the
+option as a variable name, prefixed with ‘pandoc/’ (note the slash; use
+‘pandoc/read’ and ‘pandoc/write’ for the input and output formats, and
+‘pandoc/table-of-contents’ for the TOC).
+
+For example, in order to set a bibliography file, add the following line
+to the local variable block:
+
+pandoc/bibliography: "~/path/to/mybib.bib"
+
+The easiest way to add a file-local variable is to use the command ‘M-x
+add-file-local-variable’.  This will put the variable at the end of the
+file and add the correct comment syntax.  Note that the values are Lisp
+expressions, which means that strings need to be surrounded with double
+quotes.  Symbols do not need to be quoted, however.
+
+Settings specified as file-local variables are kept separate from other
+settings: they cannot be set through the menu, they are _never_ saved to
+a settings file, and they are not shown when you call
+‘pandoc-view-settings’ (‘C-c / S’).  A source file can both have a
+settings file and specify settings in file-local variables.  If this
+happens, the latter override the former
+
+Note that it is also possible to specify the customisation option
+‘pandoc-binary’ as a file-local variable.  It does not require the
+‘pandoc/’ prefix, but since its value is a string, it must be enclosed
+in quotes:
+
+pandoc-binary: "/path/to/alternate/pandoc“
+
+
+File: pandoc-mode.info,  Node: Managing numbered examples,  Next: Using @@-directives,  Prev: File-local variables,  Up: Top
+
+7 Managing numbered examples
+****************************
+
+Pandoc provides a method for creating examples that are numbered
+sequentially throughout the document (see Numbered example lists
+(http://pandoc.org/README.html#numbered-example-lists) in the Pandoc
+documentation).  ‘pandoc-mode’ makes it easier to manage such lists.
+First, by going to "Example Lists | Insert New Example" (‘C-c / e i’),
+you can insert a new example list item with a numeric label: the first
+example you insert will be numbered ‘(@1)’, the second ‘(@2)’, and so
+on.  Before inserting the first example item, Emacs will search the
+document for any existing definitions and number the new items
+sequentially, so that the numeric label will always be unique.
+
+Pandoc allows you to refer to such labeled example items in the text by
+writing ‘(@1)’ and ‘pandoc-mode’ provides a facility to make this
+easier.  If you select the menu item "Example Lists | Select And Insert
+Example Label" (‘C-c / e s’) Emacs displays a list of all the
+‘(@)’-definitions in your document.  You can select one with the up or
+down keys (you can also use ‘j’ and ‘k’ or ‘n’ and ‘p’) and then hit
+‘return’ to insert the label into your document.  If you change your
+mind, you can leave the selection buffer with ‘q’ without inserting
+anything into your document.
+
+
+File: pandoc-mode.info,  Node: Using @@-directives,  Next: Disabling the hydra menu,  Prev: Managing numbered examples,  Up: Top
+
+8 Using @@-directives
+*********************
+
+‘pandoc-mode’ includes a facility to make specific, automatic changes to
+the text before sending it to Pandoc.  This is done with so-called
+‘@@’-directives, which trigger an Elisp function and are then replaced
+with the output of that function.  A ‘@@’-directive takes the form
+‘@@directive’, where ‘directive’ can be any user-defined string (see
+*note How to define directive strings: #defining--directives.).  Before
+Pandoc is called, Emacs searches the text for these directives and
+replaces them with the output of the functions they call.
+
+So suppose you define (e.g., in ‘~/.emacs.d/init’) a function
+‘my-pandoc-current-date’:
+
+(defun my-pandoc-current-date (_)
+  (format-time-string "%d %b %Y"))
+
+Now you can define a directive ‘@@date’ that calls this function.  The
+effect is that every time you write ‘@@date’ in your document, it is
+replaced with the current date.
+
+Note that the function that the directive calls must have one argument,
+which is used to pass the output format to the function (as a string).
+This way you can have your directives do different things depending on
+the output format.  This argument can be called anything you like.  In
+the above example, it is called ‘_’ (i.e., just an underscore), to
+indicate that the variable is not actually used in the function.  If you
+do use it, you should probably choose a more meaningful name.
+
+‘@@’-directives can also take the form ‘@@directive{...}’.  Here, the
+text between curly braces is an argument, which is passed to the
+function called by the directive as the second argument.  Note that
+there should be _no_ space between the directive and the left brace.  If
+there is, Emacs won’t see the argument and will treat it as normal text.
+
+It is possible to define a directive that can take an optional argument.
+This is simply done by defining the argument that the directive’s
+function takes as optional.  Suppose you define ‘my-pandoc-current-date’
+as follows:
+
+(defun my-pandoc-current-date (_ &optional text)
+  (format "%s%s" (if text (concat text ", ") "")
+                 (format-time-string "%d %b %Y")))
+
+This way, you could write ‘@@date’ to get just the date, and
+‘@@date{Cologne}’ to get "Cologne, 03 Nov 2016".
+
+Two directives have been predefined: ‘@@lisp’ and ‘@@include’.  Both of
+these take an argument.  ‘@@lisp’ can be used to include Elisp code in
+the document which is then executed and replaced by the result (which
+should be a string).  For example, another way to put the current date
+in your document, without defining a special function for it, is to
+write the following:
+
+@@lisp{(format-time-string "%d %b %Y")}
+
+Emacs takes the Elisp code between the curly braces, executes it, and
+replaces the directive with the result of the code.  Note that the code
+can be anything, and there is no check to see if it is “safe”.
+
+‘@@include’ can be used to include another file into the current
+document (which must of course have the same input format):
+
+@@include{copyright.text}
+
+This directive reads the file ‘copyright.text’ and replaces the
+‘@@include’ directive with its contents.
+
+Processing ‘@@’-directives works everywhere in the document, including
+in code and code blocks, and also in the %-header block.  So by putting
+the above ‘@@lisp’ directive in the third line of the %-header block,
+the meta data for your documents will always show the date on which the
+file was created by Pandoc.
+
+If it should ever happen that you need to write a literal ‘"@@lisp"’ in
+your document, you can simply put a backslash \ before the first ‘@’:
+‘\@@lisp’.  Emacs removes the backslash (which is necessary in case the
+string ‘\@@lisp’ is contained in a code block) and then continues
+searching for the next directive.
+
+After Emacs has processed a directive and inserted the text it produced
+in the buffer, processing of directives is resumed from the _start_ of
+the inserted text.  That means that if an ‘@@include’ directive produces
+another ‘@@include’ directive, the newly inserted ‘@@include’ directive
+gets processed as well.
+* Menu:
+
+* Master file::
+* Defining @@-directives::
+* Directive hooks::
+
+
+File: pandoc-mode.info,  Node: Master file,  Next: Defining @@-directives,  Up: Using @@-directives
+
+8.1 Master file
+===============
+
+If you have a master file with one or more ‘@@include’ directives and
+you’re editing one of the included files, running Pandoc from that
+buffer will not produce the desired result, because it runs Pandoc on
+the included file.  To make working with included files easier, you can
+specify a master file for them, with the command
+‘pandoc-set-master-file’ (through the menu with ‘C-c / o f m’).  When
+this option is set, Pandoc is run on the master file rather than on the
+file in the current buffer.
+
+The settings used in this case are always the settings for the master
+file, not the settings for the included file.  The only exception is the
+output format, which is taken from the buffer from which you run Pandoc.
+This makes it possible to change the output format while in a buffer
+visiting an included file and have ‘pandoc-mode’ do the right thing.
+
+One thing to keep in mind is that the master file setting is dependent
+on the output format.  When you set a master file, it is only set for
+the output format that is active.  This means that you need to set the
+output format _before_ you set the master file.
+
+Note that the master file menu also has an option “Use this file as
+master file” (‘C-c / o f M’).  When you select this option, the current
+file is set as master file and a project settings file is created for
+the current output format.  This is a quick way to set the master file
+for all files in a directory, since the project settings will apply to
+all files in the directory.
+
+
+File: pandoc-mode.info,  Node: Defining @@-directives,  Next: Directive hooks,  Prev: Master file,  Up: Using @@-directives
+
+8.2 Defining @@-directives
+==========================
+
+Defining ‘@@’-directives yourself is done in two steps.  First, you need
+to define the function that the directive will call.  This function must
+take at least one argument to pass the output format and may take at
+most one additional argument.  It should return a string, which is
+inserted into the buffer.  The second step is to go to the customisation
+buffer with ‘M-x customize-group’ ‘RET’ ‘pandoc’ ‘RET’.  One of the
+options there is ‘pandoc-directives’.  This variable contains a list of
+directives and the functions that they are linked with.  You can add a
+directive by providing a name (without ‘@@’) and the function to call.
+Note that directive names may only consists of letters (‘a-z’, ‘A-Z’) or
+numbers (‘0-9’).  Other characters are not allowed.  Directive names are
+case sensitive, so ‘@@Date’ is not the same as ‘@@date’.
+
+Passing more than one argument to an ‘@@’-directive is not supported.
+However, if you really want to, you could use ‘split-string’ to split
+the argument of the ‘@@’-directive and "fake" multiple arguments that
+way.
+
+A final note: the function that processes the ‘@@’-directives is called
+‘pandoc-process-directives’ and can be called interactively.  This may
+be useful if a directive is not producing the output that you expect.
+By running ‘pandoc-process-directives’ interactively, you can see what
+exactly your directives produce before the resulting text is sent to
+pandoc.  The changes can of course be undone with ‘M-x undo’ (usually
+bound to ‘C-/’).
+
+
+File: pandoc-mode.info,  Node: Directive hooks,  Prev: Defining @@-directives,  Up: Using @@-directives
+
+8.3 Directive hooks
+===================
+
+There is another customisable variable related to ‘@@’-directives:
+‘pandoc-directives-hook’.  This is a list of functions that are executed
+_before_ the directives are processed.  These functions are not supposed
+to change anything in the buffer, they are intended for setting up
+things that the directive functions might need.
+
+
+File: pandoc-mode.info,  Node: Disabling the hydra menu,  Prev: Using @@-directives,  Up: Top
+
+9 Disabling the hydra menu
+**************************
+
+The hydra package provides a nice way to control ‘pandoc-mode’ and to
+set all the options that Pandoc provides.  However, if for some reason
+you prefer to use normal key bindings, you can disable the hydra menu by
+rebinding ‘C-c /’.  To restore the original key bindings, put the
+following in your init file:
+
+(with-eval-after-load 'pandoc-mode
+  (define-key 'pandoc-mode-map "C-c / r" #'pandoc-run-pandoc)
+  (define-key 'pandoc-mode-map "C-c / p" #'pandoc-convert-to-pdf)
+  (define-key 'pandoc-mode-map "C-c / s" #'pandoc-save-settings-file)
+  (define-key 'pandoc-mode-map "C-c / w" #'pandoc-set-write)
+  (define-key 'pandoc-mode-map "C-c / f" #'pandoc-set-master-file)
+  (define-key 'pandoc-mode-map "C-c / m" #'pandoc-set-metadata)
+  (define-key 'pandoc-mode-map "C-c / v" #'pandoc-set-variable)
+  (define-key 'pandoc-mode-map "C-c / V" #'pandoc-view-output)
+  (define-key 'pandoc-mode-map "C-c / S" #'pandoc-view-settings)
+  (define-key 'pandoc-mode-map "C-c / c" #'pandoc-insert-@)
+  (define-key 'pandoc-mode-map "C-c / C" #'pandoc-select-@))
+
+It’s also possible to bind other commands to keys.  The switches (i.e.,
+the options that can only be on or off) can be toggled with the command
+‘pandoc-toggle-interactive’.  All other options (except ‘--read’) have
+dedicated functions to set them, called ‘pandoc-set-<option>’, where
+‘<option>’ corresponds to the long form of the option without the double
+dashes (use ‘write’ rather than ‘to’, and ‘table-of-contents’ rather
+than ‘toc’).
+
+
+
+Tag Table:
+Node: Top488
+Node: Introduction792
+Ref: #introduction913
+Node: Installation1770
+Ref: #installation1893
+Node: OS X3473
+Ref: #os-x3550
+Node: Usage4141
+Ref: #usage4247
+Node: Input and output formats6084
+Ref: #input-and-output-formats6239
+Node: The options menu9175
+Ref: #the-options-menu9354
+Node: Template variables and metadata14049
+Ref: #template-variables-and-metadata14248
+Node: Running Pandoc14823
+Ref: #running-pandoc14994
+Node: Setting an output file17095
+Ref: #setting-an-output-file17265
+Node: Creating a pdf18959
+Ref: #creating-a-pdf19114
+Node: Connection Type20557
+Ref: #connection-type20708
+Node: Citation Jumping21018
+Ref: #citation-jumping21148
+Node: Font lock22347
+Ref: #font-lock22463
+Node: Settings Files22627
+Ref: #settings-files22768
+Node: File-local variables25169
+Ref: #file-local-variables25339
+Node: Managing numbered examples26899
+Ref: #managing-numbered-examples27086
+Node: Using @@-directives28396
+Ref: #using--directives28573
+Node: Master file32796
+Ref: #master-file32932
+Node: Defining @@-directives34454
+Ref: #defining--directives34636
+Node: Directive hooks36214
+Ref: #directive-hooks36362
+Node: Disabling the hydra menu36699
+Ref: #disabling-the-hydra-menu36851
+
+End Tag Table
+
+
+Local Variables:
+coding: utf-8
+End: