diff options
| author | David Engster | 2012-07-28 11:19:53 +0200 |
|---|---|---|
| committer | David Engster | 2012-07-28 11:19:53 +0200 |
| commit | 049a0936caca462a2f12107813a24b70eeb97c3e (patch) | |
| tree | fbb31b6c6c9d9385738b6b408e6bf89cd327c3d0 | |
| parent | df81cd291bc12c494fdeaeb7849ad7ef754dbbc1 (diff) | |
| download | emacs-049a0936caca462a2f12107813a24b70eeb97c3e.tar.gz emacs-049a0936caca462a2f12107813a24b70eeb97c3e.zip | |
Maybe return expanded XML qnames as plain symbols (Bug#11916).
* xml.el (xml-node-name, xml-parse-file, xml-parse-region):
Explanation of new 'symbol-qnames feature in doc-strings.
(xml-maybe-do-ns): Return expanded names as plain symbols if
'symbol-qnames was provided in XML-NS argument (Bug#11916).
(xml-parse-tag-1): Deal with new definition of PARSE-NS argument.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/xml.el | 77 |
2 files changed, 72 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 33d59c200c1..a158e4f347a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2012-07-28 David Engster <deng@randomsample.de> | ||
| 2 | |||
| 3 | * xml.el (xml-node-name, xml-parse-file, xml-parse-region): | ||
| 4 | Explanation of new 'symbol-qnames feature in doc-strings. | ||
| 5 | (xml-maybe-do-ns): Return expanded names as plain symbols if | ||
| 6 | 'symbol-qnames was provided in XML-NS argument (Bug#11916). | ||
| 7 | (xml-parse-tag-1): Deal with new definition of PARSE-NS argument. | ||
| 8 | |||
| 1 | 2012-07-27 Fabián Ezequiel Gallina <fgallina@cuca> | 9 | 2012-07-27 Fabián Ezequiel Gallina <fgallina@cuca> |
| 2 | 10 | ||
| 3 | Consistent completion in inferior python with emacs -nw. | 11 | Consistent completion in inferior python with emacs -nw. |
diff --git a/lisp/xml.el b/lisp/xml.el index e2788e5e756..179fdd6b5cc 100644 --- a/lisp/xml.el +++ b/lisp/xml.el | |||
| @@ -126,7 +126,10 @@ tag. For example, | |||
| 126 | 126 | ||
| 127 | would be represented by | 127 | would be represented by |
| 128 | 128 | ||
| 129 | '(\"\" . \"foo\")." | 129 | '(\"\" . \"foo\"). |
| 130 | |||
| 131 | If you'd just like a plain symbol instead, use 'symbol-qnames in | ||
| 132 | the PARSE-NS argument." | ||
| 130 | 133 | ||
| 131 | (car node)) | 134 | (car node)) |
| 132 | 135 | ||
| @@ -313,7 +316,22 @@ only those characters, have whitespace syntax.") | |||
| 313 | "Parse the well-formed XML file FILE. | 316 | "Parse the well-formed XML file FILE. |
| 314 | Return the top node with all its children. | 317 | Return the top node with all its children. |
| 315 | If PARSE-DTD is non-nil, the DTD is parsed rather than skipped. | 318 | If PARSE-DTD is non-nil, the DTD is parsed rather than skipped. |
| 316 | If PARSE-NS is non-nil, then QNAMES are expanded." | 319 | |
| 320 | If PARSE-NS is non-nil, then QNAMES are expanded. By default, | ||
| 321 | the variable `xml-default-ns' is the mapping from namespaces to | ||
| 322 | URIs, and expanded names will be returned as a cons | ||
| 323 | |||
| 324 | (\"namespace:\" . \"foo\"). | ||
| 325 | |||
| 326 | If PARSE-NS is an alist, it will be used as the mapping from | ||
| 327 | namespace to URIs instead. | ||
| 328 | |||
| 329 | If it is the symbol 'symbol-qnames, expanded names will be | ||
| 330 | returned as a plain symbol 'namespace:foo instead of a cons. | ||
| 331 | |||
| 332 | Both features can be combined by providing a cons cell | ||
| 333 | |||
| 334 | (symbol-qnames . ALIST)." | ||
| 317 | (with-temp-buffer | 335 | (with-temp-buffer |
| 318 | (insert-file-contents file) | 336 | (insert-file-contents file) |
| 319 | (xml--parse-buffer parse-dtd parse-ns))) | 337 | (xml--parse-buffer parse-dtd parse-ns))) |
| @@ -329,7 +347,21 @@ If END is nil, it defaults to `point-max'. | |||
| 329 | If BUFFER is nil, it defaults to the current buffer. | 347 | If BUFFER is nil, it defaults to the current buffer. |
| 330 | If PARSE-DTD is non-nil, parse the DTD and return it as the first | 348 | If PARSE-DTD is non-nil, parse the DTD and return it as the first |
| 331 | element of the list. | 349 | element of the list. |
| 332 | If PARSE-NS is non-nil, expand QNAMES." | 350 | If PARSE-NS is non-nil, then QNAMES are expanded. By default, |
| 351 | the variable `xml-default-ns' is the mapping from namespaces to | ||
| 352 | URIs, and expanded names will be returned as a cons | ||
| 353 | |||
| 354 | (\"namespace:\" . \"foo\"). | ||
| 355 | |||
| 356 | If PARSE-NS is an alist, it will be used as the mapping from | ||
| 357 | namespace to URIs instead. | ||
| 358 | |||
| 359 | If it is the symbol 'symbol-qnames, expanded names will be | ||
| 360 | returned as a plain symbol 'namespace:foo instead of a cons. | ||
| 361 | |||
| 362 | Both features can be combined by providing a cons cell | ||
| 363 | |||
| 364 | (symbol-qnames . ALIST)." | ||
| 333 | ;; Use fixed syntax table to ensure regexp char classes and syntax | 365 | ;; Use fixed syntax table to ensure regexp char classes and syntax |
| 334 | ;; specs DTRT. | 366 | ;; specs DTRT. |
| 335 | (unless buffer | 367 | (unless buffer |
| @@ -386,26 +418,36 @@ is nil. | |||
| 386 | 418 | ||
| 387 | During namespace-aware parsing, any name without a namespace is | 419 | During namespace-aware parsing, any name without a namespace is |
| 388 | put into the namespace identified by DEFAULT. nil is used to | 420 | put into the namespace identified by DEFAULT. nil is used to |
| 389 | specify that the name shouldn't be given a namespace." | 421 | specify that the name shouldn't be given a namespace. |
| 422 | Expanded names will by default be returned as a cons. If you | ||
| 423 | would like to get plain symbols instead, provide a cons cell | ||
| 424 | |||
| 425 | (symbol-qnames . ALIST) | ||
| 426 | |||
| 427 | in the XML-NS argument." | ||
| 390 | (if (consp xml-ns) | 428 | (if (consp xml-ns) |
| 391 | (let* ((nsp (string-match ":" name)) | 429 | (let* ((symbol-qnames (eq (car-safe xml-ns) 'symbol-qnames)) |
| 430 | (nsp (string-match ":" name)) | ||
| 392 | (lname (if nsp (substring name (match-end 0)) name)) | 431 | (lname (if nsp (substring name (match-end 0)) name)) |
| 393 | (prefix (if nsp (substring name 0 (match-beginning 0)) default)) | 432 | (prefix (if nsp (substring name 0 (match-beginning 0)) default)) |
| 394 | (special (and (string-equal lname "xmlns") (not prefix))) | 433 | (special (and (string-equal lname "xmlns") (not prefix))) |
| 395 | ;; Setting default to nil will insure that there is not | 434 | ;; Setting default to nil will insure that there is not |
| 396 | ;; matching cons in xml-ns. In which case we | 435 | ;; matching cons in xml-ns. In which case we |
| 397 | (ns (or (cdr (assoc (if special "xmlns" prefix) | 436 | (ns (or (cdr (assoc (if special "xmlns" prefix) |
| 398 | xml-ns)) | 437 | (if symbol-qnames (cdr xml-ns) xml-ns))) |
| 399 | ""))) | 438 | ""))) |
| 400 | (cons ns (if special "" lname))) | 439 | (if (and symbol-qnames |
| 440 | (not (string= prefix "xmlns"))) | ||
| 441 | (intern (concat ns lname)) | ||
| 442 | (cons ns (if special "" lname)))) | ||
| 401 | (intern name))) | 443 | (intern name))) |
| 402 | 444 | ||
| 403 | (defun xml-parse-tag (&optional parse-dtd parse-ns) | 445 | (defun xml-parse-tag (&optional parse-dtd parse-ns) |
| 404 | "Parse the tag at point. | 446 | "Parse the tag at point. |
| 405 | If PARSE-DTD is non-nil, the DTD of the document, if any, is parsed and | 447 | If PARSE-DTD is non-nil, the DTD of the document, if any, is parsed and |
| 406 | returned as the first element in the list. | 448 | returned as the first element in the list. |
| 407 | If PARSE-NS is non-nil, expand QNAMES; if the value of PARSE-NS | 449 | If PARSE-NS is non-nil, expand QNAMES; for further details, see |
| 408 | is a list, use it as an alist mapping namespaces to URIs. | 450 | `xml-parse-region'. |
| 409 | 451 | ||
| 410 | Return one of: | 452 | Return one of: |
| 411 | - a list : the matching node | 453 | - a list : the matching node |
| @@ -425,9 +467,16 @@ Return one of: | |||
| 425 | 467 | ||
| 426 | (defun xml-parse-tag-1 (&optional parse-dtd parse-ns) | 468 | (defun xml-parse-tag-1 (&optional parse-dtd parse-ns) |
| 427 | "Like `xml-parse-tag', but possibly modify the buffer while working." | 469 | "Like `xml-parse-tag', but possibly modify the buffer while working." |
| 428 | (let ((xml-validating-parser (or parse-dtd xml-validating-parser)) | 470 | (let* ((xml-validating-parser (or parse-dtd xml-validating-parser)) |
| 429 | (xml-ns (cond ((consp parse-ns) parse-ns) | 471 | (xml-ns |
| 430 | (parse-ns xml-default-ns)))) | 472 | (cond ((eq parse-ns 'symbol-qnames) |
| 473 | (cons 'symbol-qnames xml-default-ns)) | ||
| 474 | ((or (consp (car-safe parse-ns)) | ||
| 475 | (and (eq (car-safe parse-ns) 'symbol-qnames) | ||
| 476 | (listp (cdr parse-ns)))) | ||
| 477 | parse-ns) | ||
| 478 | (parse-ns | ||
| 479 | xml-default-ns)))) | ||
| 431 | (cond | 480 | (cond |
| 432 | ;; Processing instructions, like <?xml version="1.0"?>. | 481 | ;; Processing instructions, like <?xml version="1.0"?>. |
| 433 | ((looking-at "<\\?") | 482 | ((looking-at "<\\?") |
| @@ -475,7 +524,9 @@ Return one of: | |||
| 475 | (equal "http://www.w3.org/2000/xmlns/" | 524 | (equal "http://www.w3.org/2000/xmlns/" |
| 476 | (caar attr))) | 525 | (caar attr))) |
| 477 | (push (cons (cdar attr) (cdr attr)) | 526 | (push (cons (cdar attr) (cdr attr)) |
| 478 | xml-ns)))) | 527 | (if (symbolp (car xml-ns)) |
| 528 | (cdr xml-ns) | ||
| 529 | xml-ns))))) | ||
| 479 | (setq children (list attrs (xml-maybe-do-ns node-name "" xml-ns))) | 530 | (setq children (list attrs (xml-maybe-do-ns node-name "" xml-ns))) |
| 480 | (cond | 531 | (cond |
| 481 | ;; is this an empty element ? | 532 | ;; is this an empty element ? |