;;; nxml-outln.el --- outline support for nXML mode
-;; Copyright (C) 2004 Free Software Foundation, Inc.
+;; Copyright (C) 2004, 2007-2011 Free Software Foundation, Inc.
;; Author: James Clark
;; Keywords: XML
-;; This program 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 2 of
-;; the License, or (at your option) any later version.
+;; This file is part of GNU Emacs.
-;; This program 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.
+;; 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.
-;; You should have received a copy of the GNU General Public
-;; License along with this program; if not, write to the Free
-;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
-;; MA 02111-1307 USA
+;; 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:
(defcustom nxml-section-element-name-regexp
"article\\|\\(sub\\)*section\\|chapter\\|div\\|appendix\\|part\\|preface\\|reference\\|simplesect\\|bibliography\\|bibliodiv\\|glossary\\|glossdiv"
- "*Regular expression matching the name of elements used as sections.
+ "Regular expression matching the name of elements used as sections.
An XML element is treated as a section if:
- its local name (that is, the name without the prefix) matches
:type 'regexp)
(defcustom nxml-heading-element-name-regexp "title\\|head"
- "*Regular expression matching the name of elements used as headings.
+ "Regular expression matching the name of elements used as headings.
An XML element is only recognized as a heading if it occurs as or
within the first child of an element that is recognized as a section.
See the variable `nxml-section-element-name-regexp' for more details."
:type 'regexp)
(defcustom nxml-outline-child-indent 2
- "*Indentation in an outline for child element relative to parent element."
+ "Indentation in an outline for child element relative to parent element."
:group 'nxml
:type 'integer)
-(defface nxml-heading-face
+(defface nxml-heading
'((t (:weight bold)))
"Face used for the contents of abbreviated heading elements."
- :group 'nxml-highlighting-faces)
+ :group 'nxml-faces)
-(defface nxml-outline-indicator-face
+(defface nxml-outline-indicator
'((t (:inherit default)))
"Face used for `+' or `-' before element names in outlines."
- :group 'nxml-highlighting-faces)
+ :group 'nxml-faces)
-(defface nxml-outline-active-indicator-face
- '((t (:box t :inherit nxml-outline-indicator-face)))
+(defface nxml-outline-active-indicator
+ '((t (:box t :inherit nxml-outline-indicator)))
"Face used for clickable `+' or `-' before element names in outlines."
- :group 'nxml-highlighting-faces)
+ :group 'nxml-faces)
-(defface nxml-outline-ellipsis-face
+(defface nxml-outline-ellipsis
'((t (:bold t :inherit default)))
"Face used for `...' in outlines."
- :group 'nxml-highlighting-faces)
+ :group 'nxml-faces)
(defvar nxml-heading-scan-distance 1000
"Maximum distance from section to scan for heading.")
(defun nxml-hide-all-text-content ()
"Hide all text content in the buffer.
Anything that is in a section but is not a heading will be hidden.
-The visibility of headings at any level will not be changed. See the
+The visibility of headings at any level will not be changed. See the
variable `nxml-section-element-name-regexp' for more details on how to
customize which elements are recognized as sections and headings."
(interactive)
(defun nxml-show-direct-text-content ()
"Show the text content that is directly part of the section containing point.
Each subsection will be shown according to its individual state, which
-will not be changed. The section containing point is the innermost
-section that contains the character following point. See the variable
+will not be changed. The section containing point is the innermost
+section that contains the character following point. See the variable
`nxml-section-element-name-regexp' for more details on how to
customize which elements are recognized as sections and headings."
(interactive)
(defun nxml-show-direct-subheadings ()
"Show the immediate subheadings of the section containing point.
The section containing point is the innermost section that contains
-the character following point. See the variable
+the character following point. See the variable
`nxml-section-element-name-regexp' for more details on how to
customize which elements are recognized as sections and headings."
(interactive)
"Hide the text content that is directly part of the section containing point.
The heading of the section will remain visible. The state of
subsections will not be changed. The section containing point is the
-innermost section that contains the character following point. See the
+innermost section that contains the character following point. See the
variable `nxml-section-element-name-regexp' for more details on how to
customize which elements are recognized as sections and headings."
(interactive)
The text content will also be hidden, leaving only the heading of the
section itself visible. The state of the subsections will also be
changed to hide their headings, so that \\[nxml-show-direct-text-content]
-would show only the heading of the subsections. The section containing
+would show only the heading of the subsections. The section containing
point is the innermost section that contains the character following
point. See the variable `nxml-section-element-name-regexp' for more
details on how to customize which elements are recognized as sections
(defun nxml-hide-text-content ()
"Hide text content at all levels in the section containing point.
The section containing point is the innermost section that contains
-the character following point. See the variable
+the character following point. See the variable
`nxml-section-element-name-regexp' for more details on how to
customize which elements are recognized as sections and headings."
(interactive)
"Show the subheadings at all levels of the section containing point.
The visibility of the text content at all levels in the section is not
changed. The section containing point is the innermost section that
-contains the character following point. See the variable
+contains the character following point. See the variable
`nxml-section-element-name-regexp' for more details on how to
customize which elements are recognized as sections and headings."
(interactive)
"Hide text content other than that directly in the section containing point.
Hide headings other than those of ancestors of that section and their
immediate subheadings. The section containing point is the innermost
-section that contains the character following point. See the variable
+section that contains the character following point. See the variable
`nxml-section-element-name-regexp' for more details on how to
customize which elements are recognized as sections and headings."
(interactive)
(when change
(nxml-set-outline-state section-start-pos
(cdr change)))))
-
+
(defun nxml-section-tag-transform-outline-state (startp
section-start-pos
&optional
;; Display
-(defun nxml-refresh-outline ()
+(defsubst nxml-token-start-tag-p ()
+ (or (eq xmltok-type 'start-tag)
+ (eq xmltok-type 'partial-start-tag)))
+
+(defsubst nxml-token-end-tag-p ()
+ (or (eq xmltok-type 'end-tag)
+ (eq xmltok-type 'partial-end-tag)))
+
+(defun nxml-refresh-outline ()
"Refresh the outline to correspond to the current XML element structure."
(interactive)
(save-excursion
indent of the start-tag of the current element, or nil if no
containing element has a non-nil OUTLINE-STATE. TAG-QNAMES is a list
of the qnames of the open elements. Point is after the title content.
-Leave point after the closing end-tag Return t if we had a
+Leave point after the closing end-tag. Return t if we had a
non-transparent child section."
(let ((last-pos (point))
(transparent-depth 0)
had-children))
(defconst nxml-highlighted-less-than
- (propertize "<" 'face 'nxml-tag-delimiter-face))
+ (propertize "<" 'face 'nxml-tag-delimiter))
(defconst nxml-highlighted-greater-than
- (propertize ">" 'face 'nxml-tag-delimiter-face))
+ (propertize ">" 'face 'nxml-tag-delimiter))
(defconst nxml-highlighted-colon
- (propertize ":" 'face 'nxml-element-colon-face))
+ (propertize ":" 'face 'nxml-element-colon))
(defconst nxml-highlighted-slash
- (propertize "/" 'face 'nxml-tag-slash-face))
+ (propertize "/" 'face 'nxml-tag-slash))
(defconst nxml-highlighted-ellipsis
- (propertize "..." 'face 'nxml-outline-ellipsis-face))
+ (propertize "..." 'face 'nxml-outline-ellipsis))
(defconst nxml-highlighted-empty-end-tag
(concat nxml-highlighted-ellipsis
nxml-highlighted-greater-than))
(defconst nxml-highlighted-inactive-minus
- (propertize "-" 'face 'nxml-outline-indicator-face))
+ (propertize "-" 'face 'nxml-outline-indicator))
(defconst nxml-highlighted-active-minus
- (propertize "-" 'face 'nxml-outline-active-indicator-face))
+ (propertize "-" 'face 'nxml-outline-active-indicator))
(defconst nxml-highlighted-active-plus
- (propertize "+" 'face 'nxml-outline-active-indicator-face))
+ (propertize "+" 'face 'nxml-outline-active-indicator))
(defun nxml-display-section (last-pos
section-start-pos
(if colon
(concat (propertize (substring qname 0 colon)
'face
- 'nxml-element-prefix-face)
+ 'nxml-element-prefix)
nxml-highlighted-colon
(propertize (substring qname (1+ colon))
'face
- 'nxml-element-local-name-face))
+ 'nxml-element-local-name))
(propertize qname
'face
- 'nxml-element-local-name-face))))
+ 'nxml-element-local-name))))
(defun nxml-outline-display-single-line-end-tag (last-pos)
(nxml-outline-set-overlay 'nxml-outline-display-hide
t)
'display
nxml-highlighted-empty-end-tag))
-
+
(defun nxml-outline-display-multi-line-end-tag (last-pos start-tag-indent)
(let ((indentp (save-excursion
(goto-char last-pos)
(put 'nxml-outline-display-heading 'help-echo nxml-outline-show-help)
(put 'nxml-outline-display-heading 'nxml-outline-display t)
(put 'nxml-outline-display-heading 'evaporate t)
-(put 'nxml-outline-display-heading 'face 'nxml-heading-face)
+(put 'nxml-outline-display-heading 'face 'nxml-heading)
(defvar nxml-outline-hiding-tag-map
(let ((map (make-sparse-keymap)))
&optional
front-advance
rear-advance)
- "Replace any nxml-outline-display overlays between START and END.
+ "Replace any `nxml-outline-display' overlays between START and END.
Overlays are removed if they overlay the region between START and END,
-and have a non-nil nxml-outline-display property (typically via their
-category). If CATEGORY is non-nil, they will be replaced with a new overlay
-with that category from START to END. If CATEGORY is nil, no new
-overlay will be created."
+and have a non-nil `nxml-outline-display' property (typically via their
+category). If CATEGORY is non-nil, they will be replaced with a new
+overlay with that category from START to END. If CATEGORY is nil,
+no new overlay will be created."
(when (< start end)
(let ((overlays (overlays-in start end))
overlay)
(let ((pos (condition-case err
(and (nxml-scan-element-forward (point) t)
xmltok-start)
- nil)))
+ (nxml-scan-error nil))))
(end-of-line)
(skip-chars-backward " \t")
(cond ((not pos)
;;; Navigating section structure
-(defsubst nxml-token-start-tag-p ()
- (or (eq xmltok-type 'start-tag)
- (eq xmltok-type 'partial-start-tag)))
-
-(defsubst nxml-token-end-tag-p ()
- (or (eq xmltok-type 'end-tag)
- (eq xmltok-type 'partial-end-tag)))
-
(defun nxml-token-starts-line-p ()
(save-excursion
(goto-char xmltok-start)
(defun nxml-section-tag-forward ()
"Move forward past the first tag that is a section start- or end-tag.
-Return xmltok-type for tag.
+Return `xmltok-type' for tag.
If no tag found, return nil and move to the end of the buffer."
(let ((case-fold-search nil)
(tag-regexp (nxml-make-section-tag-regexp))
nil)
(t))))
xmltok-type)
-
+
(defun nxml-section-tag-backward ()
"Move backward to the end of a tag that is a section start- or end-tag.
-The position of the end of the tag must be <= point
+The position of the end of the tag must be <= point.
Point is at the end of the tag. `xmltok-start' is the start."
(let ((case-fold-search nil)
(start (point))
"Try to move back to the start of the section containing point.
The start of the section must be <= point.
Only visible sections are included unless INVISIBLE-OK is non-nil.
-If found, return t. Otherwise move to point-min and return nil.
+If found, return t. Otherwise move to `point-min' and return nil.
If unbalanced section tags are found, signal an `nxml-outline-error'."
(when (or (nxml-after-section-start-tag)
(nxml-section-tag-backward))
(heading-regexp (concat "\\`\\("
nxml-heading-element-name-regexp
"\\)\\'"))
-
+
(section-regexp (concat "\\`\\("
nxml-section-element-name-regexp
"\\)\\'"))