1. | Reporting bugs in nxml-mode for emacs | ||||
It would really help if you could be more explicit. Ideally, I would like a small example describing
| |||||
2. | How to find the nxml-mode key bindings? | ||||
[ C-h k C-h m ] C-h m runs the command describe-mode which is an interactive compiled Lisp function in `help'. (describe-mode) Display documentation of current major mode and minor modes. The major mode description comes first, followed by the minor modes, each on a separate page. For this to work correctly for a minor mode, the mode's indicator variable (listed in `minor-mode-alist') must also be a function whose documentation describes the minor mode. Alan Salewski adds C-h b runs the command describe-bindings which is an interactive compiled Lisp function in `help'. (describe-bindings &optional PREFIX BUFFER) Show a list of all defined keys, and their definitions. We put that list in a buffer, and display the buffer. The optional argument PREFIX, if non-nil, should be a key sequence; then we display only bindings that start with that prefix. The optional argument BUFFER specifies which buffer's bindings to display (default, the current buffer). | |||||
3. | nxml-mode slow on validation | ||||
Can you explain a little more? When are you seeing pauses? You should be able to just keep right on typing and ignore the fact that it's doing constant validation, since the validation gets suspended as soon as you start typing. It shouldn't be getting in your way. Customization might help:
| |||||
4. | Error count in nxml-mode | ||||
> when you start off with plain It should only be slow if you have thousands of distinct errors; if you have a huge chunk of plain text that you intend to add markup to, that should only be one or two errors. To see how many errors there are, do
| |||||
5. | High error count | ||||
> I read a text file of 1736 lines into emacs, did M-x nxml-mode, and it The problem is that it was treating the whole thing as part of the prolog. So long as you put a start-tag at the beginning of the document, you won't get the slownewss. Anyway, I've fixed it to use a different algorithm for deciding where the prolog ends and the instance begins in an ill-formed document. | |||||
6. | mode hook | ||||
You can use nxml-mode-hook for that. It's run every time nxml-mode is enabled, including for new files, so you just have to check whether you've got a new file. Try something like this: (add-hook 'nxml-mode-hook (lambda () (when (not (and (buffer-file-name) (file-exists-p (buffer-file-name)))) (message "A new nXML file"))) t) | |||||
7. | Empty vs no namespace | ||||
There is an example of this in the <card> example in the tutorial: relaxng.org <nsName/> matches any name in the namespace specified by the inherited attribute ns. In your case this attribute has the value "http://relaxng.org/ns/structure/1.0". <nsName ns=""> Same semantics as before, but here the ns attribute is specified locally so this matches any name not being in a namespace. In the case of attributes this means any attribute without a prefix. So what <attribute><anyName><except><nsName/><nsName ns="""/></except></anyName></attribute> really means in your case is "any attribute with a prefix where the prefix is not declared to the RELAX NG namespace uri". | |||||
8. | ANY DTD entry into Relax-ng | ||||
The fault is with Trang, and yet it's hard to see how it could do any better without taking an entirely different approach. The semantics of ANY in a DTD are essentially (#PCDATA|FOO|BAR|BAZ|...)*, where FOO, BAR, BAZ, ... are the declared elements in the DTD. It does not mean that "any XML" is permissible here, but that's how Trang translates it. Consequently, the declaration of the element named "x" as having an "id" attribute of type ID conflicts with the implicit declaration of "x" (as part of the element wildcard) as having an "id" attribute (as part of the attribute wildcard) of type text. Normally, this wouldn't matter, but the semantics of type ID are global, and RNG requires that ID-declared attributes be consistent throughout the document. Here is an RNC schema that should do what you want:
x = element x { attlist.x & not-x* & x* & text}
attlist.x &= attribute id { xsd:ID }?
start = x
not-x = element (* - x) { attribute * {text}* & not-x* & x* & text }
| |||||
9. | Change key binding | ||||
There is an explanation in the node "Local Keymaps" in the Emacs manual (do `g RET Local Keymaps RET' after entering the Emacs manual). Add this to your .emacs:
(add-hook
'nxml-mode-hook
(lambda ()
(define-key nxml-mode-map "\C-c\C-c" 'nxml-complete)))
Steinar Bang comments on this, Personally I've stopped adding anonymous functions to hooks, because it's easier to call remove-hook on named functions. Ie. I would have done the above as
(defun nxml-custom-keybindings ()
(define-key nxml-mode-map "\C-c\C-c" 'nxml-complete))
(add-hook 'nxml-mode-hook 'nxml-custom-keybindings)
| |||||
10. | repeated error message | ||||
Try doing M-x set-variable RET debug-on-error RET t RET M-x set-variable RET debug-on-signal RET t RET This should give a backtrace the next time the error happens, which may show where the real problem lies. Perhaps turning off syntax highlighting will work around this problem temporarily. Try doing M-x set-variable RET nxml-syntax-highlight-flag RET nil RET | |||||
11. | Adding additional Unicode blocks for Unicode entry | ||||
To add the braille block, just do M-x customize-variable RET nxml-enabled-unicode-blocks RET and then click the "Braille Patterns" check box and follow the instructions. | |||||
12. | PSGML compatibility | ||||
It's bound to nxml-backward-up-element. However, it allows an argument, just like the standard binding for C-M-u (backward-up-list). With an argument of -1, it's equivalent to nxml-up-element, which moves forward.
It has not been a design goal for nxml to minimize retraining for PSGML users. I have tried to do the best design I can, taking PSGML as one (of several) inputs. One problem is that some of the PSGML bindings are not compatible with the Emacs conventions documented in the Emacs Lisp manual. If in the future it turns out that there are lots of PSGML users trying to switch to nxml-mode, who are inhibited by incompatible and missing key bindings, then that can be addressed by adding an psgml-compatibility option. | |||||
13. | applyFollowingRules in schemaLocation | ||||
The input to the schema location process is a list of schema locating files. Parsing a schema locating file gives you a list of rules (you need to resolve relative URIs at this stage). Take the list of rules from parsing each schema locating file and append them to give you one big list. Now process <include> rules by replacing each <include> rule by the rules you get from parsing the referenced schema locating file. You can now eliminate applyFollowingRules rules from the list as follows. Replace a rule X that has the form <applyFollowingRules ruleType="T"/> by a copy (preserving order) of all the rules of type T that follow X in the list. (An implementation can in fact optimize this so it only makes a single pass over the list of rules.)
There's a commented-out description of them in nxml-mode.xml. | |||||
14. | XML file indentation | ||||
I think the recommended way is using the "customize-group" interface. If you type "M-x customize-group" and then type "nxml", you'll get a form that lets you change all user-customizable options for nxml. Scroll down there until you find the child-indent option, change the value there, then click the State button and choose "Save for Future Sessions". I think you can also set it directly in your .emacs file by adding (setq nxml-child-indent 8) | |||||
15. | Element names in Chinese | ||||
\w matches anything that has syntax class 'w' in the current syntax table, which can include non-ASCII characters as well as ASCII characters. The problem is simply that your example schema is in UTF-8 and Emacs 21 supports Unicode characters only in the ranges 0000-33ff and e000-ffff, and thus does not support Chinese (or Japanese or Korean) encoded in UTF-8. If you look at the schema in Emacs, you won't see any Chinese characters, but rather a bunch of 8-bit control characters (this is Emacs' way of ensuring that it does not damage UTF-8 files containing characters that it does not support). If you want to use nxml-mode with Chinese element names, then both the XML file and the schema need to use an encoding for Chinese that Emacs does support (e.g. Big5). \w will match Chinese "word constituent" characters from non-Unicode character sets (that's why nxml uses \w rather than a list of Unicode characters). You would need to put
at the beginning of the .rnc file to ensure that nxml correctly recognizes the encoding. | |||||
16. | Adding to mode-map | ||||
Not sure if the following is the best way, but I think it works. (defun nxml-mode-additional-keys ()
"Key bindings to add to `nxml-mode'."
(define-key nxml-mode-map "\eh" 'my-function-name)
)
(add-hook 'nxml-mode-hook 'nxml-mode-additional-keys)
| |||||
17. | paragraph fill width | ||||
How to set [emacs-nxml-mode] paragraph fill width? To set it per-buffer, do 'C-u 80 C-x f' (replace 80 with whatever width you want). To set it globally, put this in your .emacs
| |||||
18. | how I can disable MULE-UCS? | ||||
I think maybe this: M-x unload-feature un-define Or in your .emacs: (unload-feature un-define) | |||||
19. | BOM and nxml | ||||
Is it hard to do in nxml? UTF-8 can have BOM, ability to handle BOM in UTF-8 is crucial since Windows editors create files with BOM in UTF-8 by default, and nxml simply rejects to use files with BOM. Well, I'm immune; I do not have Windows on either of my computers; but it has been a very unpleasant failure in front of an audience to show that, unlike XML Schema, Relax NG can be authored in any editor, even Notepad. Only to find out that after being authored in Notepad, it cannot be used in Emacs. | |||||
20. | Is it possible to reload the schema? | ||||
I've been using the following. (define-key nxml-mode-map "\C-c\C-r" 'rng-reload-schema)
(defun rng-reload-schema ()
(interactive)
(let ((schema-filename rng-current-schema-file-name))
(when schema-filename
(setq rng-current-schema (rng-load-schema schema-filename))
(run-hooks 'rng-schema-change-hook)
(message "Reloaded schema %s" schema-filename))
(unless schema-filename
(rng-set-schema-and-validate))))
(defun rng-apply-find-schema-file (fn)
(let ((schema-filename rng-current-schema-file-name))
(unless schema-filename
(error "This file is not associated with a schema file."))
(funcall fn schema-filename)))
(defun rng-find-schema-file ()
(interactive)
(rng-apply-find-schema-file 'find-file))
(defun rng-find-schema-file-other-window ()
(interactive)
(rng-apply-find-schema-file 'find-file-other-window))
| |||||
21. | Key bindings | ||||
You can get short descriptions of all key binding by doing: M-x describe-bindings RET | |||||
22. | Adding to key-bindings | ||||
C-c C-m, split element > Here's my ugly hack. > The fun part about a proper implementation of this function would be > to decide where to put what whitespace based on context; I just punted. > (defun cabo:nxml-split-element () > (interactive "*") > (nxml-finish-element) > (insert "\n<" (xmltok-start-tag-qname) ">") > (nxml-indent-line)) > (define-key nxml-mode-map "\C-c\C-m" 'cabo:nxml-split-element) I think you have to put the modification of the keymap in a hook, because its value is by default `nil'. If `nxml-mode()' was not already called, at least once, `nxml-mode-map' is still `nil', which is an error to pass to `define-key()'.
(add-hook 'nxml-mode-hook (lambda ()
(define-key nxml-mode-map
"\C-c\C-m"
'cabo:nxml-split-element)))
I think it would be better to initialize correctly the keymap in FILE:nxml-mode.el, with something like this :
(defvar nxml-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\M-\C-u" 'nxml-backward-up-element)
(define-key map "\M-\C-d" 'nxml-down-element)
(define-key map "\M-\C-n" 'nxml-forward-element)
(define-key map "\M-\C-p" 'nxml-backward-element)
(define-key map "\M-{" 'nxml-backward-paragraph)
(define-key map "\M-}" 'nxml-forward-paragraph)
(define-key map "\M-h" 'nxml-mark-paragraph)
(define-key map "\C-c\C-f" 'nxml-finish-element)
(define-key map "\C-c\C-b" 'nxml-balanced-close-start-tag-block)
(define-key map "\C-c\C-i" 'nxml-balanced-close-start-tag-inline)
(define-key map "\C-c\C-x" 'nxml-insert-xml-declaration)
(define-key map "\C-c\C-d" 'nxml-dynamic-markup-word)
(define-key map "\C-c\C-u" 'nxml-insert-named-char)
(define-key map "/" 'nxml-electric-slash)
(define-key map [C-return] 'nxml-complete)
(when nxml-bind-meta-tab-to-complete-flag
(define-key map "\M-\t" 'nxml-complete))
map)
"Keymap used by NXML Mode.")
which lets you to write :
(require 'nxml-mode)
(define-key nxml-mode-map "\C-c\C-m" 'cabo:nxml-split-element)Furthemore, the keymap is constructed every time `nxml-mode()' is called in the present form, but only once, at load, with the above solution. Bob DuCharme adds (defun nxml-beginning-of-element () "Jump to point after start-tag." (interactive) (nxml-backward-up-element) (forward-sexp) ) (global-set-key [?\C-c (home)] 'nxml-beginning-of-element) (defun nxml-end-of-element () "Jump to point before end-tag." (interactive) (nxml-up-element) (backward-sexp) ) (global-set-key [?\C-c (end)] 'nxml-end-of-element) ; Split element: ; From 2004-05-17 e-mail to nxml-list (defun cabo:nxml-split-element () (interactive "*") (nxml-finish-element) (insert "\n<" (xmltok-start-tag-qname) ">") (nxml-indent-line)) (define-key nxml-mode-map "\C-c\C-m" 'cabo:nxml-split-element) | |||||
23. | Locate schema | ||||
I think you can (ab)use | |||||
24. | Encoding type | ||||
The preferred MIME name for ASCII is 'us-ascii', which is the name nXML supports. > I admit to not understanding why ascii should be unsupported if UTF-8 > is OK, nor understanding what encodings a parser is supposed, or > required, to support according to the XML specification. So let me > skip this, assuming that there is a real reason for it, and just ask > the bottom-line question: is there anything I can do in my .emacs to > get nXML to accept 'ascii' as a valid encoding? Adding something like (coding-system-put 'us-ascii 'mime-charset 'ascii) after loading rng-auto.el might work, but I would recommend changing your file to use 'us-ascii'. | |||||
25. | Jing error 'oneOrMore contains group' | ||||
You bumped up against one of the few restrictions of RELAX NG: you can't have an iteration (either + or *, they produce the same message) that contains a sequence (or interleave, same thing in this case) of attributes. What you have written is tantamount to requesting an attribute sequence like attribute foo, attribute bar, attribute foo, attribute bar .... be allowed. This makes no sense, given that there can only be one attribute of a given name in a given element. Fortunately, the problem is easily cured by removing the first reference to NamedElementAttribute. > When I use the inbuilt Trang tool, I can successfully convert the compact You can't expect correct results when applying Trang to a schema that Jing rejects. The corrected version does convert to a plausible XSD schema.
Try to avoid creating sequences/interleaves that contain both attributes and data. They tend to be problematic. Bob Foster goes into a deeper explanation > I have developed a grammar by reading the RelaxNG tutorial, but when I > attempt to validate it using Jing (within OxygenXML) I get an brief > error message I cannot understand: E "oneOrMore" contains "group" > contains "attribute" ConfigGroupEntry* where ConfigGroupEntry has as an alternative ConfigValue, a group that contains a group, NamedElementAttributes, that contains two attributes. The "oneOrMore" reference is because * (zeroOrMore) is defined in RELAX NG as +? (optional oneOrMore). NamedElementAttributes is obviously redundant as it is used, so a simple fix would be to take it out of ConfigValue. > When I use the inbuilt Trang tool, I can successfully convert the > compact grammar to XML form, but a conversion on to XML Schema results > in a message like "Choice between attributes and children cannot be > presented; approximating", but no schema object is produced. Trang can't convert everything, esp. an invalid schema, and even if it did the conversion could not be faithful where there is a choice between an attribute and an element. XML Schema can't describe this. > There doesn't seem to be any reference or further explanation for > parsing errors. I have spent several hours on this and will have to > abandon the use of RelaxNG unless I can obtain a speedy resolution. Don't give up. Granted the error messages from jing can be pretty cryptic, but in this case you had all the info you needed, you just didn't understand it. OTOH, if you had spent the same several hours trying to write an XML Schema with no previous knowledge of that language, I wager you wouldn't be anywhere near as far along as you are. ;-} > My grammar is shown below, including a leading * indicating the line the > validator fails on. Note that it relates to the only case of recursion > in the grammar- a ConfigGroup can contain nested ConfigGroups within > it. Is anyone able to offer some explanation as to what these problems > mean? Any general advice on how to "debug" a RelexNG grammar would also > be appreciated. First, a grammar isn't thoroughly checked until you try to validate with it, because some grammars are perfectly ok as fragments but not acceptable for validation. So exercise the grammar on simple test cases to make sure it is fully checked and gives you the result you wanted. Second, compact syntax error messages from jing come in two flavors: "syntax error," for which the only cure is to stare at the location identified and consult the syntax until you see the error, and substantive error messages, like the one you describe, that usually refer to constraints described in RELAX NG (non-compact) Oasis. In this case, you could have found the restriction by searching the restriction section for "attribute". MURATA Makoto takes up the spec references > If you check the RELAX NG specification, you'll find, in section >7.1.2, a prohibition of the path: > >oneOrMore//group//attribute Consider an illegal pattern
(element * {text}, attribute * {text})*This means that the number of attributes and that of elements are equal. Next, consider another illegal pattern
(attribute a:* {text}, attribute b:* {text})*This means that the number of attributes in the namespace for the prefix a is the same as the number of attributes in the namespace for the prefix b. To implement such patterns, we cannot use abstract machines having *finite* states, since we need one state for each natural number. Then, Bali and Miaou (which I should have finished long time ago) will become impossible. Jing constructs patterns (which are "states") lazily. Thus, the above patterns can be implemented actually. However, there are some malicious patterns which cause (an earlier version of) Jing to explode, because so many patterns have to be created during evaluation. |