syntax: select the appropriate mode according to file extension

* lib/zile/grammar/diff-bundle.lua: New file, with the syntax
grammar for diff and patch files.
* lib/zile/zile.mk (dist_pkgdata_DATA): Add diff-bundle.lua.
* lib/zz/default-color-bundle.lua: Set highlight styles for new
diff grammar.
* lib/zile/bundle.lua (load_file_associations): Load a map of
file extension to grammar basename using the fileTypes key in
each grammar file.
* lib/zile/term_redisplay.lua (draw_status_line): Display the
name of the loaded grammar for the current buffer in its mode-
line.
* NEWS: Update.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
refactor: centralise parser state in a table.

* lib/zile/syntax.lua (state.new): New function. Return a new
parser state...
(syntax_attrs): ...refactored from here.
(highlight): Change to accept a single state table parameter.
(parse): Likewise, but save long derefrence chains into locals
for better access speed.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
refactor: add parser state metamethods and simplify.

* lib/zile/syntax.lua (push_op): Moved from here...
(metatable.push_op): ...to here.  Adjust all callers.
(state.new): Set the metatable on the new parser state.
(highlight): Cache parser attrs and ops in locals for faster
access.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
zz: restore sandbox function labelling for undo, killring etc.

The maintenance of runtime labels that functions such as undo use
to determine whether they are being called consecutively was
accidentally removed with c908ad8.
This changeset restores the missing functionality, so undo and
other functions that rely on it work properly again.
* lib/zz/eval.lua (labelfn): New function, return a wrapper
function that when called manages labels correctly.
(Defun): Ensure new symbol value and __call metatable entries
call the label managing wrapper function.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
zz: fix undefined call of table.clone.

* lib/zz/commands/buffer.lua: Store std.table.clone in localvar.
(write_buffers_list): Call clone directly.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
zemacs: new `query-replace-regexp' function.

* lib/zemacs/zlisp/search.zl (do_query_replace): New function,
factored out of query-replace.
(query-replace): Simplify accordingly.  Improve docstring.
(query-replace-regexp): Same as `query-replace', but search
string is treated as a regular expression.
* lib/zz/commands/search.lua (do_query_replace, query_replace,
query_replace_regexp): Keep feature parity in Zz too.
* NEWS: Update.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
zlisp: add implementation of `progn` special form.

* lib/zemacs/specs/zlisp_lisp_spec.yaml (progn): Specify correct
behaviour.
* lib/zemacs/zlisp/lisp.zl (progn): Implementation to satisfy
specifications.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
zlisp: make 't => true and 'nil => false mapping explicit.

* lib/zemacs/eval.lua (marshaller): Insert false into Lua
argument list when evaluation returns 'nil.
Return Lua subr call result unmolested.
(call_command, eval_string, execute_function): Name the result
holding variable `value` rather than `ok` so as not to hint that
it is a boolean.
* lib/zemacs/zlisp/minibuf.zl (message): Convert Lua internal
values (false, true, Symbol table) back to Zlisp write syntax
representation ('nil, 't, symbol name) before display.
* lib/zemacs/specs/zlisp_lisp_spec.yaml (progn): Remove pending
call from newly passing examples.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
zlisp: return correct value from `goto-char`.

* lib/zemacs/specs/zlisp_move_spec.yaml (goto-char): Specify
return values.
* lib/zile/buffer.lua (goto_offset): Return actual position
moved to.  This is not what Emacs does, but is more useful as a
Zile API this way.
* lib/zemacs/zlisp/move.zl (goto-char): Ignore goto_offset
return value, and simply return the value of the position
parameter as Emacs does.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
specs: fix a comment typo.

* lib/zemacs/specs/zlisp_move_spec.yaml (forward-line): Fix
comment to refer to forward-line correctly.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
specs: add a checklist, apply it to zlisp_move_spec.yaml.

* lib/zemacs/specs/README: New file.  A checklist of what needs
to be specified for each ZLisp built-in command.
* lib/zemacs/specs/zlisp_move_spec.yaml (beginning-of-line)
(end-of-line, backward-char, forward-char): Adjust specifications
to satisfy checklist.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
zlisp: propagate error messages back up the call stack.

* lib/zemacs/specs/zlisp_lisp_spec.yaml (eval-expression):
Specify behaviour when called interactively with any input type.
(eval-buffer): Specify errors that are caught.
* lib/zemacs/callbacks.lua (get_and_run_command): Display error
messages that precolate up to here.
* lib/zemacs/eval.lua (execute_function): Return early with
diagnostics when called with a void or invalid function name.
Otherwise, be sure to propagote any error from subroutines.
(call_command): Propagate any error from execute_function.
(eval_command): Propagate any error from call_command.
(eval_string): Return early with diagnostics for evaluating a
void variable.
Propagate any error from eval_command.
* lib/zemacs/zlisp/lisp.zl (execute-extended-command): Propagate
any error from execute_function above.
(eval-expression): Remove FIXME. Transform boolean return values
correctly for display by caller.
* lib/zemacs/main.lua (main): Display reason for lisp file load
failure.
* lib/zemacs/zlisp/move.zl (backward-char, forward-char): Always
return `nil`, like Emacs.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
symbol: tostring returns symbol name, not value.

Previously, printing symbol lists for debugging purposes was
peculiarly unhelpful, just to save a little code when evaluating
a symbol from ZLisp.  We don't use the evaluation short-cut any
more, so let's print the symbol name from tostring so that
symbol lists work as expected.
* lib/zile/Symbol.lua (display_variable_value): Remove.
(metatable.__tostring): Return symbol name.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
lib: encapsulate zile/lib module functions properly.

* lib/zile/lib.lua (iscallable, recase, stack): Declare local.
(stack.new, stack:push, stack:pop, stack:top): Move definitions
into stack table.
Return exported function table.
Adjust all callers.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
MutableString: fix missing object method reference.

* lib/zile/MutableString.lua (_functions): Add missing reference
to remove method.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
MutableString: fix byte length calculation in remove method.

* lib/zile/MutableString.lua (remove): When removing a chunk, we
shift down the bytes between the end of the removed chunk and the
end of the buffer; most definitely not the same number of bytes
we happen to be overwriting!

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
Array: new class module.

* lib/zile/spec/Array_spec.yaml: New file. Specify behaviour of
a new Array class module.
* lib/zile/specs/specs.mk (specl_SPECS): Add it.
* lib/zile/Array.lua: New file. Object based alien arrays.
* lib/zile/zile.mk (dist_pkgdata_DATA): Add it.
* build-aux/config.ld.in (file): Add lib/zile/Array.lua.
* local.mk (dist_classes_DATA): Add generated Array LDocs.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
configury: fix a typo in local.mk.

* local.mk (doc/.ldocs): Move misplaced close paren to the
correct position.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
lib: Add Lua API for argument checking.

* lib/zile/lib.lua (argerror): New function. Equivalent to
luaL_argerror.
(argcheck): New function. Equivalent to luaL_argcheck.
(argcheck): New function. This is where the heavy lifting
happens, and mismatches between expected and actual argument
types are found and diagnosed.
(iscallable, recase, stack): Add LDocs.
* build-aux/config.ld.in (file): Add lib.lua.
* local.mk (dist_modules_DATA): Add generated zile.lib.html.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
Array: ensure cloning existing arrays works correctly.

* lib/zile/specs/Array_spec.yaml (__call): Redo the specifications
to ensure cloning an existing array copies elements correctly.
Use a more `alien.array` like API for instantiating new arrays.
(realloc): Add missing specifications.
* lib/zile/Array.lua (_init): Implement new API to meet new
specifications. Use lib.argcheck to check argument types.
(copy, setzero): New private helper functions.
(setlen): Rename from this...
(realloc): ...to this, for consistency with alien.array APIs.
Manage array.used field from here.  Use lib.argcheck.
(push): Simplify. Use lib.argscheck.
(pop, __index, __newindex): Simplify.
(__tostring): New function. Return a string that will recreate the
array if passed to Lua load().

Signed-off-by: Gary V. Vaughan <gary@gnu.org>