-;; Compatibility functions for versions of emacs before emacs 23.
-;;
-;; Both functions here were copied from emacs 23 with the following copyright:
-;;
-;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1999, 2000, 2001, 2002, 2003,
-;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-;;
-;; and under the GPL version 3 (or later) exactly as notmuch itself.
-(compile-on-emacs-prior-to-23
- (defun apply-partially (fun &rest args)
- "Return a function that is a partial application of FUN to ARGS.
-ARGS is a list of the first N arguments to pass to FUN.
-The result is a new function which does the same as FUN, except that
-the first N arguments are fixed at the values with which this function
-was called."
- (lexical-let ((fun fun) (args1 args))
- (lambda (&rest args2) (apply fun (append args1 args2))))))
-
-(compile-on-emacs-prior-to-23
- (defun mouse-event-p (object)
- "Return non-nil if OBJECT is a mouse click event."
- (memq (event-basic-type object) '(mouse-1 mouse-2 mouse-3 mouse-movement))))
-
-;; This variable is used only buffer local, but it needs to be
-;; declared globally first to avoid compiler warnings.
-(defvar notmuch-show-process-crypto nil)
-(make-variable-buffer-local 'notmuch-show-process-crypto)
-
-;; Incremental JSON parsing
-
-;; These two variables are internal variables to the parsing
-;; routines. They are always used buffer local but need to be declared
-;; globally to avoid compiler warnings.
-
-(defvar notmuch-json-parser nil
- "Internal incremental JSON parser object: local to the buffer being parsed.")
-
-(defvar notmuch-json-state nil
- "State of the internal JSON parser: local to the buffer being parsed.")
-
-(defun notmuch-json-create-parser (buffer)
- "Return a streaming JSON parser that consumes input from BUFFER.
-
-This parser is designed to read streaming JSON whose structure is
-known to the caller. Like a typical JSON parsing interface, it
-provides a function to read a complete JSON value from the input.
-However, it extends this with an additional function that
-requires the next value in the input to be a compound value and
-descends into it, allowing its elements to be read one at a time
-or further descended into. Both functions can return 'retry to
-indicate that not enough input is available.
-
-The parser always consumes input from BUFFER's point. Hence, the
-caller is allowed to delete and data before point and may
-resynchronize after an error by moving point."
-
- (list buffer
- ;; Terminator stack: a stack of characters that indicate the
- ;; end of the compound values enclosing point
- '()
- ;; Next: One of
- ;; * 'expect-value if the next token must be a value, but a
- ;; value has not yet been reached
- ;; * 'value if point is at the beginning of a value
- ;; * 'expect-comma if the next token must be a comma
- 'expect-value
- ;; Allow terminator: non-nil if the next token may be a
- ;; terminator
- nil
- ;; Partial parse position: If state is 'value, a marker for
- ;; the position of the partial parser or nil if no partial
- ;; parsing has happened yet
- nil
- ;; Partial parse state: If state is 'value, the current
- ;; `parse-partial-sexp' state
- nil))
-
-(defmacro notmuch-json-buffer (jp) `(first ,jp))
-(defmacro notmuch-json-term-stack (jp) `(second ,jp))
-(defmacro notmuch-json-next (jp) `(third ,jp))
-(defmacro notmuch-json-allow-term (jp) `(fourth ,jp))
-(defmacro notmuch-json-partial-pos (jp) `(fifth ,jp))
-(defmacro notmuch-json-partial-state (jp) `(sixth ,jp))
-
-(defvar notmuch-json-syntax-table
- (let ((table (make-syntax-table)))
- ;; The standard syntax table is what we need except that "." needs
- ;; to have word syntax instead of punctuation syntax.
- (modify-syntax-entry ?. "w" table)
- table)
- "Syntax table used for incremental JSON parsing.")
-
-(defun notmuch-json-scan-to-value (jp)
- ;; Helper function that consumes separators, terminators, and
- ;; whitespace from point. Returns nil if it successfully reached
- ;; the beginning of a value, 'end if it consumed a terminator, or
- ;; 'retry if not enough input was available to reach a value. Upon
- ;; nil return, (notmuch-json-next jp) is always 'value.
-
- (if (eq (notmuch-json-next jp) 'value)
- ;; We're already at a value
- nil
- ;; Drive the state toward 'expect-value
- (skip-chars-forward " \t\r\n")
- (or (when (eobp) 'retry)
- ;; Test for the terminator for the current compound
- (when (and (notmuch-json-allow-term jp)
- (eq (char-after) (car (notmuch-json-term-stack jp))))
- ;; Consume it and expect a comma or terminator next
- (forward-char)
- (setf (notmuch-json-term-stack jp) (cdr (notmuch-json-term-stack jp))
- (notmuch-json-next jp) 'expect-comma
- (notmuch-json-allow-term jp) t)
- 'end)
- ;; Test for a separator
- (when (eq (notmuch-json-next jp) 'expect-comma)
- (when (/= (char-after) ?,)
- (signal 'json-readtable-error (list "expected ','")))
- ;; Consume it, switch to 'expect-value, and disallow a
- ;; terminator
- (forward-char)
- (skip-chars-forward " \t\r\n")
- (setf (notmuch-json-next jp) 'expect-value
- (notmuch-json-allow-term jp) nil)
- ;; We moved point, so test for eobp again and fall through
- ;; to the next test if there's more input
- (when (eobp) 'retry))
- ;; Next must be 'expect-value and we know this isn't
- ;; whitespace, EOB, or a terminator, so point must be on a
- ;; value