Mercurial > emacs
view lisp/nxml/nxml-rap.el @ 110523:a5ad4f188e19
Synch Semantic to CEDET 1.0.
Move CEDET ChangeLog entries to new file lisp/cedet/ChangeLog.
* semantic.el (semantic-version): Update to 2.0.
(semantic-mode-map): Add "," and "m" bindings.
(navigate-menu): Update.
* semantic/symref.el (semantic-symref-calculate-rootdir):
New function.
(semantic-symref-detect-symref-tool): Use it.
* semantic/symref/grep.el (semantic-symref-grep-shell): New var.
(semantic-symref-perform-search): Use it. Calculate root dir with
semantic-symref-calculate-rootdir.
(semantic-symref-derive-find-filepatterns): Improve error message.
* semantic/symref/list.el
(semantic-symref-results-mode-map): New bindings.
(semantic-symref-auto-expand-results): New option.
(semantic-symref-results-dump): Obey auto-expand.
(semantic-symref-list-expand-all, semantic-symref-regexp)
(semantic-symref-list-contract-all)
(semantic-symref-list-map-open-hits)
(semantic-symref-list-update-open-hits)
(semantic-symref-list-create-macro-on-open-hit)
(semantic-symref-list-call-macro-on-open-hits): New functions.
(semantic-symref-list-menu-entries)
(semantic-symref-list-menu): New vars.
(semantic-symref-list-map-open-hits): Move cursor to beginning of
match before calling the mapped function.
* semantic/doc.el
(semantic-documentation-comment-preceeding-tag): Do nothing if the
mode doesn't provide comment-start-skip.
* semantic/scope.el
(semantic-analyze-scope-nested-tags-default): Strip duplicates.
(semantic-analyze-scoped-inherited-tag-map): Take the tag we are
looking for as part of the scoped tags list.
* semantic/html.el (semantic-default-html-setup): Add
senator-step-at-tag-classes.
* semantic/decorate/include.el
(semantic-decoration-on-unknown-includes): Change light bgcolor.
(semantic-decoration-on-includes-highlight-default): Check that
the include tag has a postion.
* semantic/complete.el (semantic-collector-local-members):
(semantic-complete-read-tag-local-members)
(semantic-complete-jump-local-members): New class and functions.
(semantic-complete-self-insert): Save excursion before completing.
* semantic/analyze/complete.el
(semantic-analyze-possible-completions-default): If no completions
are found, return the raw by-name-only completion list. Add FLAGS
arguments. Add support for 'no-tc (type constraint) and
'no-unique, or no stripping duplicates.
(semantic-analyze-possible-completions-default): Add FLAGS arg.
* semantic/util-modes.el
(semantic-stickyfunc-show-only-functions-p): New option.
(semantic-stickyfunc-fetch-stickyline): Don't show stickytext for
the very first line in a buffer.
* semantic/util.el (semantic-hack-search)
(semantic-recursive-find-nonterminal-by-name)
(semantic-current-tag-interactive): Deleted.
(semantic-describe-buffer): Fix expand-nonterminal. Add
lex-syntax-mods, type relation separator char, and command
separation char.
(semantic-sanity-check): Only message if called interactively.
* semantic/tag.el (semantic-tag-deep-copy-one-tag): Copy the
:filename property and the tag position.
* semantic/lex-spp.el (semantic-lex-spp-lex-text-string):
Add recursion limit.
* semantic/imenu.el (semantic-imenu-bucketize-type-members):
Make this buffer local, not the obsoleted variable.
* semantic/idle.el: Add breadcrumbs support.
(semantic-idle-summary-current-symbol-info-default)
(semantic-idle-tag-highlight)
(semantic-idle-completion-list-default): Use
semanticdb-without-unloaded-file-searches for speed, and to
conform to the controls that specify if the idle timer is supposed
to be parsing unparsed includes.
(semantic-idle-symbol-highlight-face)
(semantic-idle-symbol-maybe-highlight): Rename from *-summary-*.
Callers changed.
(semantic-idle-work-parse-neighboring-files-flag): Default to nil.
(semantic-idle-work-update-headers-flag): New var.
(semantic-idle-work-for-one-buffer): Use it.
(semantic-idle-local-symbol-highlight): Rename from
semantic-idle-tag-highlight.
(semantic-idle-truncate-long-summaries): New option.
* semantic/ia.el (semantic-ia-cache)
(semantic-ia-get-completions): Deleted. Callers changed.
(semantic-ia-show-variants): New command.
(semantic-ia-show-doc): If doc is empty, don't make a temp buffer.
(semantic-ia-show-summary): If there isn't anything to show, say so.
* semantic/grammar.el (semantic-grammar-create-package):
Save the buffer even in batch mode.
* semantic/fw.el
(semanticdb-without-unloaded-file-searches): New macro.
* semantic/dep.el (semantic-dependency-find-file-on-path):
Fix case dereferencing ede-object when it is a list.
* semantic/db-typecache.el (semanticdb-expand-nested-tag)
(semanticdb-typecache-faux-namespace): New functions.
(semanticdb-typecache-file-tags)
(semanticdb-typecache-merge-streams): Use them.
(semanticdb-typecache-file-tags): When deriving tags from a file,
give the mode a chance to monkey with the tag copy.
(semanticdb-typecache-find-default): Wrap find in save-excursion.
(semanticdb-typecache-find-by-name-helper): Merge found names down.
* semantic/db-global.el
(semanticdb-enable-gnu-global-in-buffer): Don't show messages if
GNU Global is not available and we don't want to throw an error.
* semantic/db-find.el (semanticdb-find-result-nth-in-buffer):
When trying to normalize the tag to a buffer, don't error if
set-buffer method doesn't exist.
* semantic/db-file.el (semanticdb-save-db): Simplify msg.
* semantic/db.el (semanticdb-refresh-table): If forcing a
refresh on a file not in a buffer, use semantic-find-file-noselect
and delete the buffer after use.
(semanticdb-current-database-list): When calculating root via
hooks, force it through true-filename and skip the list of
possible roots.
* semantic/ctxt.el (semantic-ctxt-imported-packages): New.
* semantic/analyze/debug.el
(semantic-analyzer-debug-insert-tag): Reset standard output to
current buffer.
(semantic-analyzer-debug-global-symbol)
(semantic-analyzer-debug-missing-innertype): Change "prefix" to
"symbol" in messages.
* semantic/analyze/refs.el: (semantic-analyze-refs-impl)
(semantic-analyze-refs-proto): When calculating value, make sure
the found tag is 'similar' to the originating tag.
(semantic--analyze-refs-find-tags-with-parent): Attempt to
identify matches via imported symbols of parents.
(semantic--analyze-refs-full-lookup-with-parents): Do a deep
search during the brute search.
* semantic/analyze.el
(semantic-analyze-find-tag-sequence-default): Be robust to
calculated scopes being nil.
* semantic/bovine/c.el (semantic-c-describe-environment): Add
project macro symbol array.
(semantic-c-parse-lexical-token): Add recursion limit.
(semantic-ctxt-imported-packages, semanticdb-expand-nested-tag):
New overrides.
(semantic-expand-c-tag-namelist): Split a full type from a typedef
out to its own tag.
(semantic-expand-c-tag-namelist): Do not split out a typedef'd
inline type if it is an anonymous type.
(semantic-c-reconstitute-token): Use the optional initializers as
a clue that some function is probably a constructor. When
defining the type of these constructors, split the parent name,
and use only the class part, if applicable.
* semantic/bovine/c-by.el:
* semantic/wisent/python-wy.el: Regenerate.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sat, 18 Sep 2010 22:49:54 -0400 |
parents | 1d1d5d9bd884 |
children | 376148b31b5e |
line wrap: on
line source
;;; nxml-rap.el --- low-level support for random access parsing for nXML mode ;; Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. ;; Author: James Clark ;; Keywords: XML ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. ;;; Commentary: ;; This uses xmltok.el to do XML parsing. The fundamental problem is ;; how to handle changes. We don't want to maintain a complete parse ;; tree. We also don't want to reparse from the start of the document ;; on every keystroke. However, it is not possible in general to ;; parse an XML document correctly starting at a random point in the ;; middle. The main problems are comments, CDATA sections and ;; processing instructions: these can all contain things that are ;; indistinguishable from elements. Literals in the prolog are also a ;; problem. Attribute value literals are not a problem because ;; attribute value literals cannot contain less-than signs. ;; ;; Our strategy is to keep track of just the problematic things. ;; Specifically, we keep track of all comments, CDATA sections and ;; processing instructions in the instance. We do this by marking all ;; except the first character of these with a non-nil nxml-inside text ;; property. The value of the nxml-inside property is comment, ;; cdata-section or processing-instruction. The first character does ;; not have the nxml-inside property so we can find the beginning of ;; the construct by looking for a change in a text property value ;; (Emacs provides primitives for this). We use text properties ;; rather than overlays, since the implementation of overlays doesn't ;; look like it scales to large numbers of overlays in a buffer. ;; ;; We don't in fact track all these constructs, but only track them in ;; some initial part of the instance. The variable `nxml-scan-end' ;; contains the limit of where we have scanned up to for them. ;; ;; Thus to parse some random point in the file we first ensure that we ;; have scanned up to that point. Then we search backwards for a ;; <. Then we check whether the < has an nxml-inside property. If it ;; does we go backwards to first character that does not have an ;; nxml-inside property (this character must be a <). Then we start ;; parsing forward from the < we have found. ;; ;; The prolog has to be parsed specially, so we also keep track of the ;; end of the prolog in `nxml-prolog-end'. The prolog is reparsed on ;; every change to the prolog. This won't work well if people try to ;; edit huge internal subsets. Hopefully that will be rare. ;; ;; We keep track of the changes by adding to the buffer's ;; after-change-functions hook. Scanning is also done as a ;; prerequisite to fontification by adding to fontification-functions ;; (in the same way as jit-lock). This means that scanning for these ;; constructs had better be quick. Fortunately it is. Firstly, the ;; typical proportion of comments, CDATA sections and processing ;; instructions is small relative to other things. Secondly, to scan ;; we just search for the regexp <[!?]. ;; ;; One problem is unclosed comments, processing instructions and CDATA ;; sections. Suppose, for example, we encounter a <!-- but there's no ;; matching -->. This is not an unexpected situation if the user is ;; creating a comment. It is not helpful to treat the whole of the ;; file starting from the <!-- onwards as a single unclosed comment ;; token. Instead we treat just the <!-- as a piece of not well-formed ;; markup and continue. The problem is that if at some later stage a ;; --> gets added to the buffer after the unclosed <!--, we will need ;; to reparse the buffer starting from the <!--. We need to keep ;; track of these reparse dependencies; they are called dependent ;; regions in the code. ;;; Code: (require 'xmltok) (require 'nxml-util) (defvar nxml-prolog-end nil "Integer giving position following end of the prolog.") (make-variable-buffer-local 'nxml-prolog-end) (defvar nxml-scan-end nil "Marker giving position up to which we have scanned. nxml-scan-end must be >= nxml-prolog-end. Furthermore, nxml-scan-end must not be an inside position in the following sense. A position is inside if the following character is a part of, but not the first character of, a CDATA section, comment or processing instruction. Furthermore all positions >= nxml-prolog-end and < nxml-scan-end that are inside positions must have a non-nil `nxml-inside' property whose value is a symbol specifying what it is inside. Any characters with a non-nil `fontified' property must have position < nxml-scan-end and the correct face. Dependent regions must also be established for any unclosed constructs starting before nxml-scan-end. There must be no `nxml-inside' properties after nxml-scan-end.") (make-variable-buffer-local 'nxml-scan-end) (defsubst nxml-get-inside (pos) (get-text-property pos 'nxml-inside)) (defsubst nxml-clear-inside (start end) (nxml-debug-clear-inside start end) (remove-text-properties start end '(nxml-inside nil))) (defsubst nxml-set-inside (start end type) (nxml-debug-set-inside start end) (put-text-property start end 'nxml-inside type)) (defun nxml-inside-end (pos) "Return the end of the inside region containing POS. Return nil if the character at POS is not inside." (if (nxml-get-inside pos) (or (next-single-property-change pos 'nxml-inside) (point-max)) nil)) (defun nxml-inside-start (pos) "Return the start of the inside region containing POS. Return nil if the character at POS is not inside." (if (nxml-get-inside pos) (or (previous-single-property-change (1+ pos) 'nxml-inside) (point-min)) nil)) ;;; Change management (defun nxml-scan-after-change (start end) "Restore `nxml-scan-end' invariants after a change. The change happened between START and END. Return position after which lexical state is unchanged. END must be > `nxml-prolog-end'. START must be outside any 'inside' regions and at the beginning of a token." (if (>= start nxml-scan-end) nxml-scan-end (let ((inside-remove-start start) xmltok-errors xmltok-dependent-regions) (while (or (when (xmltok-forward-special (min end nxml-scan-end)) (when (memq xmltok-type '(comment cdata-section processing-instruction)) (nxml-clear-inside inside-remove-start (1+ xmltok-start)) (nxml-set-inside (1+ xmltok-start) (point) xmltok-type) (setq inside-remove-start (point))) (if (< (point) (min end nxml-scan-end)) t (setq end (point)) nil)) ;; The end of the change was inside but is now outside. ;; Imagine something really weird like ;; <![CDATA[foo <!-- bar ]]> <![CDATA[ stuff --> <!-- ]]> --> ;; and suppose we deleted "<![CDATA[f" (let ((inside-end (nxml-inside-end end))) (when inside-end (setq end inside-end) t)))) (nxml-clear-inside inside-remove-start end) (nxml-clear-dependent-regions start end) (nxml-mark-parse-dependent-regions)) (when (> end nxml-scan-end) (set-marker nxml-scan-end end)) end)) ;; n-s-p only called from nxml-mode.el, where this variable is defined. (defvar nxml-prolog-regions) (defun nxml-scan-prolog () (goto-char (point-min)) (let (xmltok-dtd xmltok-errors xmltok-dependent-regions) (setq nxml-prolog-regions (xmltok-forward-prolog)) (setq nxml-prolog-end (point)) (nxml-clear-inside (point-min) nxml-prolog-end) (nxml-clear-dependent-regions (point-min) nxml-prolog-end) (nxml-mark-parse-dependent-regions)) (when (< nxml-scan-end nxml-prolog-end) (set-marker nxml-scan-end nxml-prolog-end))) ;;; Dependent regions (defun nxml-adjust-start-for-dependent-regions (start end pre-change-length) (let ((overlays (overlays-in (1- start) start)) (adjusted-start start)) (while overlays (let* ((overlay (car overlays)) (ostart (overlay-start overlay))) (when (and (eq (overlay-get overlay 'category) 'nxml-dependent) (< ostart adjusted-start)) (let ((funargs (overlay-get overlay 'nxml-funargs))) (when (apply (car funargs) (append (list start end pre-change-length ostart (overlay-end overlay)) (cdr funargs))) (setq adjusted-start ostart))))) (setq overlays (cdr overlays))) adjusted-start)) (defun nxml-mark-parse-dependent-regions () (while xmltok-dependent-regions (apply 'nxml-mark-parse-dependent-region (car xmltok-dependent-regions)) (setq xmltok-dependent-regions (cdr xmltok-dependent-regions)))) (defun nxml-mark-parse-dependent-region (fun start end &rest args) (let ((overlay (make-overlay start end nil t t))) (overlay-put overlay 'category 'nxml-dependent) (overlay-put overlay 'nxml-funargs (cons fun args)))) (put 'nxml-dependent 'evaporate t) (defun nxml-clear-dependent-regions (start end) (let ((overlays (overlays-in start end))) (while overlays (let* ((overlay (car overlays)) (category (overlay-get overlay 'category))) (when (and (eq category 'nxml-dependent) (<= start (overlay-start overlay))) (delete-overlay overlay))) (setq overlays (cdr overlays))))) ;;; Random access parsing (defun nxml-token-after () "Return the position after the token containing the char after point. Sets up the variables `xmltok-type', `xmltok-start', `xmltok-name-end', `xmltok-name-colon', `xmltok-attributes', `xmltok-namespace-attributes' in the same was as does `xmltok-forward'. The prolog will be treated as a single token with type `prolog'." (let ((pos (point))) (if (< pos nxml-prolog-end) (progn (setq xmltok-type 'prolog xmltok-start (point-min)) (min nxml-prolog-end (point-max))) (nxml-ensure-scan-up-to-date) (if (nxml-get-inside pos) (save-excursion (nxml-move-outside-backwards) (xmltok-forward) (point)) (save-excursion (if (or (eq (char-after) ?<) (search-backward "<" (max (point-min) nxml-prolog-end) t)) (nxml-move-outside-backwards) (goto-char (if (<= (point-min) nxml-prolog-end) nxml-prolog-end (or (nxml-inside-end (point-min)) (point-min))))) (while (and (nxml-tokenize-forward) (<= (point) pos))) (point)))))) (defun nxml-token-before () "Return the position after the token containing the char before point. Sets variables like `nxml-token-after'." (if (/= (point-min) (point)) (save-excursion (goto-char (1- (point))) (nxml-token-after)) (setq xmltok-start (point)) (setq xmltok-type nil) (point))) (defun nxml-tokenize-forward () (let (xmltok-dependent-regions xmltok-errors) (when (and (xmltok-forward) (> (point) nxml-scan-end)) (cond ((memq xmltok-type '(comment cdata-section processing-instruction)) (nxml-with-unmodifying-text-property-changes (nxml-set-inside (1+ xmltok-start) (point) xmltok-type))) (xmltok-dependent-regions (nxml-mark-parse-dependent-regions))) (set-marker nxml-scan-end (point))) xmltok-type)) (defun nxml-move-tag-backwards (bound) "Move point backwards outside any 'inside' regions or tags. Point will not move past `nxml-prolog-end'. Point will either be at BOUND or a '<' character starting a tag outside any 'inside' regions. Ignores dependent regions. As a precondition, point must be >= BOUND." (nxml-move-outside-backwards) (when (not (equal (char-after) ?<)) (if (search-backward "<" bound t) (progn (nxml-move-outside-backwards) (when (not (equal (char-after) ?<)) (search-backward "<" bound t))) (goto-char bound)))) (defun nxml-move-outside-backwards () "Move point to first character of the containing special thing. Leave point unmoved if it is not inside anything special." (let ((start (nxml-inside-start (point)))) (when start (goto-char (1- start)) (when (nxml-get-inside (point)) (error "Char before inside-start at %s had nxml-inside property %s" (point) (nxml-get-inside (point))))))) (defun nxml-ensure-scan-up-to-date () (let ((pos (point))) (when (< nxml-scan-end pos) (save-excursion (goto-char nxml-scan-end) (let (xmltok-errors xmltok-dependent-regions) (while (when (xmltok-forward-special pos) (when (memq xmltok-type '(comment processing-instruction cdata-section)) (nxml-with-unmodifying-text-property-changes (nxml-set-inside (1+ xmltok-start) (point) xmltok-type))) (if (< (point) pos) t (setq pos (point)) nil))) (nxml-clear-dependent-regions nxml-scan-end pos) (nxml-mark-parse-dependent-regions) (set-marker nxml-scan-end pos)))))) ;;; Element scanning (defun nxml-scan-element-forward (from &optional up) "Scan forward from FROM over a single balanced element. Point must be between tokens. Return the position of the end of the tag that ends the element. `xmltok-start' will contain the position of the start of the tag. If UP is non-nil, then scan past end-tag of element containing point. If no element is found, return nil. If a well-formedness error prevents scanning, signal an `nxml-scan-error'. Point is not moved." (let ((open-tags (and up t)) found) (save-excursion (goto-char from) (while (cond ((not (nxml-tokenize-forward)) (when (consp open-tags) (nxml-scan-error (cadr open-tags) "Start-tag has no end-tag")) nil) ((eq xmltok-type 'start-tag) (setq open-tags (cons (xmltok-start-tag-qname) (cons xmltok-start open-tags))) t) ((eq xmltok-type 'end-tag) (cond ((not open-tags) nil) ((not (consp open-tags)) (setq found (point)) nil) ((not (string= (car open-tags) (xmltok-end-tag-qname))) (nxml-scan-error (+ 2 xmltok-start) "Mismatched end-tag; \ expected `%s'" (car open-tags))) ((setq open-tags (cddr open-tags)) t) (t (setq found (point)) nil))) ((memq xmltok-type '(empty-element partial-empty-element)) (if open-tags t (setq found (point)) nil)) ((eq xmltok-type 'partial-end-tag) (cond ((not open-tags) nil) ((not (consp open-tags)) (setq found (point)) nil) ((setq open-tags (cddr open-tags)) t) (t (setq found (point)) nil))) ((eq xmltok-type 'partial-start-tag) (nxml-scan-error xmltok-start "Missing `>'")) (t t)))) found)) (defun nxml-scan-element-backward (from &optional up bound) "Scan backward from FROM over a single balanced element. Point must be between tokens. Return the position of the end of the tag that starts the element. `xmltok-start' will contain the position of the start of the tag. If UP is non-nil, then scan past start-tag of element containing point. If BOUND is non-nil, then don't scan back past BOUND. If no element is found, return nil. If a well-formedness error prevents scanning, signal an `nxml-scan-error'. Point is not moved." (let ((open-tags (and up t)) token-end found) (save-excursion (goto-char from) (while (cond ((or (< (point) nxml-prolog-end) (not (search-backward "<" (max (or bound 0) nxml-prolog-end) t))) (when (and (consp open-tags) (not bound)) (nxml-scan-error (cadr open-tags) "End-tag has no start-tag")) nil) ((progn (nxml-move-outside-backwards) (save-excursion (nxml-tokenize-forward) (setq token-end (point))) (eq xmltok-type 'end-tag)) (setq open-tags (cons (xmltok-end-tag-qname) (cons xmltok-start open-tags))) t) ((eq xmltok-type 'start-tag) (cond ((not open-tags) nil) ((not (consp open-tags)) (setq found token-end) nil) ((and (car open-tags) (not (string= (car open-tags) (xmltok-start-tag-qname)))) (nxml-scan-error (1+ xmltok-start) "Mismatched start-tag; \ expected `%s'" (car open-tags))) ((setq open-tags (cddr open-tags)) t) (t (setq found token-end) nil))) ((memq xmltok-type '(empty-element partial-empty-element)) (if open-tags t (setq found token-end) nil)) ((eq xmltok-type 'partial-end-tag) (setq open-tags (cons nil (cons xmltok-start open-tags))) t) ((eq xmltok-type 'partial-start-tag) ;; if we have only a partial-start-tag ;; then it's unlikely that there's a matching ;; end-tag, so it's probably not helpful ;; to treat it as a complete start-tag (nxml-scan-error xmltok-start "Missing `>'")) (t t)))) found)) (defun nxml-scan-error (&rest args) (signal 'nxml-scan-error args)) (put 'nxml-scan-error 'error-conditions '(error nxml-error nxml-scan-error)) (put 'nxml-scan-error 'error-message "Scan over element that is not well-formed") (provide 'nxml-rap) ;; arch-tag: cba241ec-4c59-4ef3-aa51-2cf92b3dd24f ;;; nxml-rap.el ends here