aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Engster2012-07-28 11:19:53 +0200
committerDavid Engster2012-07-28 11:19:53 +0200
commit049a0936caca462a2f12107813a24b70eeb97c3e (patch)
treefbb31b6c6c9d9385738b6b408e6bf89cd327c3d0
parentdf81cd291bc12c494fdeaeb7849ad7ef754dbbc1 (diff)
downloademacs-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/ChangeLog8
-rw-r--r--lisp/xml.el77
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 @@
12012-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
12012-07-27 Fabián Ezequiel Gallina <fgallina@cuca> 92012-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
127would be represented by 127would be represented by
128 128
129 '(\"\" . \"foo\")." 129 '(\"\" . \"foo\").
130
131If you'd just like a plain symbol instead, use 'symbol-qnames in
132the 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.
314Return the top node with all its children. 317Return the top node with all its children.
315If PARSE-DTD is non-nil, the DTD is parsed rather than skipped. 318If PARSE-DTD is non-nil, the DTD is parsed rather than skipped.
316If PARSE-NS is non-nil, then QNAMES are expanded." 319
320If PARSE-NS is non-nil, then QNAMES are expanded. By default,
321the variable `xml-default-ns' is the mapping from namespaces to
322URIs, and expanded names will be returned as a cons
323
324 (\"namespace:\" . \"foo\").
325
326If PARSE-NS is an alist, it will be used as the mapping from
327namespace to URIs instead.
328
329If it is the symbol 'symbol-qnames, expanded names will be
330returned as a plain symbol 'namespace:foo instead of a cons.
331
332Both 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'.
329If BUFFER is nil, it defaults to the current buffer. 347If BUFFER is nil, it defaults to the current buffer.
330If PARSE-DTD is non-nil, parse the DTD and return it as the first 348If PARSE-DTD is non-nil, parse the DTD and return it as the first
331element of the list. 349element of the list.
332If PARSE-NS is non-nil, expand QNAMES." 350If PARSE-NS is non-nil, then QNAMES are expanded. By default,
351the variable `xml-default-ns' is the mapping from namespaces to
352URIs, and expanded names will be returned as a cons
353
354 (\"namespace:\" . \"foo\").
355
356If PARSE-NS is an alist, it will be used as the mapping from
357namespace to URIs instead.
358
359If it is the symbol 'symbol-qnames, expanded names will be
360returned as a plain symbol 'namespace:foo instead of a cons.
361
362Both 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
387During namespace-aware parsing, any name without a namespace is 419During namespace-aware parsing, any name without a namespace is
388put into the namespace identified by DEFAULT. nil is used to 420put into the namespace identified by DEFAULT. nil is used to
389specify that the name shouldn't be given a namespace." 421specify that the name shouldn't be given a namespace.
422Expanded names will by default be returned as a cons. If you
423would like to get plain symbols instead, provide a cons cell
424
425 (symbol-qnames . ALIST)
426
427in 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.
405If PARSE-DTD is non-nil, the DTD of the document, if any, is parsed and 447If PARSE-DTD is non-nil, the DTD of the document, if any, is parsed and
406returned as the first element in the list. 448returned as the first element in the list.
407If PARSE-NS is non-nil, expand QNAMES; if the value of PARSE-NS 449If PARSE-NS is non-nil, expand QNAMES; for further details, see
408is a list, use it as an alist mapping namespaces to URIs. 450`xml-parse-region'.
409 451
410Return one of: 452Return 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 ?