annotate xquery-mode.el @ 67:a9b2a2335782 default tip

make setting advert whiten as well if needed, handle naked div in replying to html
author Henry S Thompson <ht@inf.ed.ac.uk>
date Sat, 21 Dec 2024 20:00:43 +0000
parents 7b2c4ed36302
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
1 ;;; xquery-mode.el --- A simple mode for editing xquery programs
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
2 ;; Time-stamp: <2005-03-26 18:05:39 sacharya>
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
3
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
4 ;;; Copyright (C) 2005 Suraj Acharya
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
5
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
6 ;; Author: Suraj Acharya <sacharya@cs.indiana.edu>
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
7
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
8 ;; This file is not part of GNU Emacs.
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
9
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
10 ;; xquery-mode.el is free software; you can redistribute it
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
11 ;; and/or modify it under the terms of the GNU General Public License
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
12 ;; as published by the Free Software Foundation; either version 2, or
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
13 ;; (at your option) any later version.:
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
14
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
15 ;; This software is distributed in the hope that it will be useful,
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
18 ;; GNU General Public License for more details.
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
19
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
24
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
25 ;;; Commentary:
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
26 ;;;
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
27
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
28 (require 'nxml-mode)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
29 (require 'generic-mode)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
30 ;;; Code:
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
31 (define-generic-mode 'xquery-mode
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
32 '(("(:" . ":)") ("!-" . "->"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
33 '("xquery" "version" "encoding" "at" "module" "namespace" "child" "descendant" "parent" "attribute" "self" "descendant-or-self" "ancestor" "following-sibling" "preceding-sibling" "following" "preceding" "ancestor-or-self" "declare" "function" "option" "ordering" "ordered" "unordered" "default" "order" "external" "or" "and" "div" "idiv" "mod" "in" "construction" "satisfies" "return" "then" "else" "boundary-space" "base-uri" "preserve" "strip" "copy-namespaces" "no-preserve" "inherit" "no-inherit" "to" "where" "collation" "intersect" "union" "except" "as" "case" "instance" "of" "castable" "item" "element" "schema-element" "schema-attribute" "processing-instruction" "comment" "text" "empty" "import" "schema" "is" "eq" "ne" "gt" "ge" "lt" "le" "some" "every" "for" "let" "cast" "treat" "validate" "document-node" "document" "node" "if" "typeswitch" "by" "stable" "ascending" "descending" "greatest" "least" "variable") ;keywords
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
34 '(("\\(\\$\\w+\\)" 1 font-lock-variable-name-face) ;; \\(\\s_\\|\\w\\)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
35 ("\\(\\w*:?\\w+\\)\\s *(" 1 font-lock-function-name-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
36 ("\\(<\\)\\(/?\\)\\(\\w*\\)\\(:?\\)\\(\\w+\\).*?\\(/?\\)\\(>\\)"
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
37 (1 'nxml-tag-delimiter-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
38 (2 'nxml-tag-slash-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
39 (3 'nxml-element-prefix-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
40 (4 'nxml-element-colon-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
41 (5 'nxml-element-local-name-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
42 (6 'nxml-tag-slash-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
43 (7 'nxml-tag-delimiter-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
44 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
45 ("\\(\\w*\\)\\(:?\\)\\(\\w+\\)=\\([\"']\\)\\(.*?\\)\\([\"']\\)"
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
46 (1 'nxml-attribute-prefix-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
47 (2 'nxml-attribute-colon-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
48 (3 'nxml-attribute-local-name-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
49 (4 'nxml-attribute-value-delimiter-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
50 (5 'nxml-attribute-value-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
51 (6 'nxml-attribute-value-delimiter-face))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
52 ("\\(/\\)\\(\\w*\\)\\(:?\\)\\(\\w+\\)"
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
53 (1 font-lock-constant-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
54 (2 font-lock-constant-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
55 (3 font-lock-constant-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
56 (4 font-lock-constant-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
57 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
58 ("as\\s +\\(\\w*:?\\w+\\)"
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
59 (1 font-lock-type-face)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
60 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
61 ) ;font-lock-list
21
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
62 '(".xq[ml]?$") ;auto-mode-list
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
63 '(xquery-set-indent-function xquery-set-up-syntax-table) ;function list
15
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
64 "A Major mode for editing xquery."
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
65 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
66
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
67
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
68
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
69 (defun xquery-set-indent-function ()
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
70 "Set the indent function for xquery mode."
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
71 (setq nxml-prolog-end (point-min))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
72 (setq nxml-scan-end (copy-marker (point-min) nil))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
73 (set (make-local-variable 'indent-line-function) 'xquery-indent-line)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
74 (make-local-variable 'forward-sexp-function)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
75 (setq forward-sexp-function 'xquery-forward-sexp)
21
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
76 ;;(local-set-key "/" 'nxml-electric-slash)
15
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
77 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
78
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
79 (defun xquery-forward-sexp (&optional arg)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
80 "Xquery forward s-expresssion.
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
81 This function is not very smart, it tries to use
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
82 `nxml-forward-balanced-item' if it sees '>' or '<' characters in
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
83 the direction you are going, and uses the regular `forward-sexp'
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
84 otherwise. "
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
85 (if (> arg 0)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
86 (progn
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
87 (if (looking-at "[ \t]*<")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
88 (nxml-forward-balanced-item arg)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
89 (let ((forward-sexp-function nil)) (forward-sexp arg))))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
90 (if (looking-back ">[ \t]*")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
91 (nxml-forward-balanced-item arg)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
92 (let ((forward-sexp-function nil)) (forward-sexp arg))))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
93 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
94
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
95
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
96 (defun xquery-set-up-syntax-table ()
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
97 "Allow the hypen character to be recognized as part of a xquery symbol."
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
98 (modify-syntax-entry ?- "w" (syntax-table))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
99 (modify-syntax-entry ?/ "." (syntax-table))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
100 ;; set-up the syntax table correctly for parentheis type characters
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
101 (modify-syntax-entry ?\{ "(}" (syntax-table))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
102 (modify-syntax-entry ?\} "){" (syntax-table))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
103 (modify-syntax-entry ?\[ "(]" (syntax-table))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
104 (modify-syntax-entry ?\] ")]" (syntax-table))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
105 (modify-syntax-entry ?\( "()1" (syntax-table))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
106 (modify-syntax-entry ?\) ")(4" (syntax-table))
21
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
107 ;;(modify-syntax-entry ?\< "(>" (syntax-table))
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
108 ;;(modify-syntax-entry ?\> ")<" (syntax-table))
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
109 ;; xquery comments are like (: :) -- handled above at mode decl
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
110 ;;(modify-syntax-entry ?\: ".23" (syntax-table))
15
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
111 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
112
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
113
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
114
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
115 (defun xquery-indent-line ()
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
116 "Indent current line as xquery code."
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
117 (interactive)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
118 (let ((savep (> (current-column) (current-indentation)))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
119 (indent (condition-case err (max (xquery-calculate-indentation) 0)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
120 (error (message "%S" err)))))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
121 (if savep
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
122 (save-excursion (indent-line-to indent))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
123 (indent-line-to indent))))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
124
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
125 (defvar xquery-start-block-regexp "[ \t]*\\((\|{\\|for\\|let\\|where\\|return\\|if\\|else\\|typeswitch\\|declare[ \t]+function\\|.*[({]$\\)"
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
126 "A regular expression which indicates that a xquery block is starting.")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
127
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
128 (defvar xquery-flwr-block-regexp "[ \t]*\\(for\\|let\\|where\\|return\\|order\\|stable\\s *order\\)")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
129
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
130 (defvar xquery-indent-size 2
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
131 "The size of each indent level.")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
132
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
133 (defvar xquery-indent-debug nil)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
134
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
135 (defun xquery-toggle-debug-indent ()
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
136 "Toggle the debug flag used in `xquery-calculate-indentation'. "
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
137 (interactive)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
138 (setq xquery-indent-debug (not xquery-indent-debug))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
139 (message (concat "xquery-indent-debug is " (if xquery-indent-debug "en" "dis") "abled"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
140 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
141
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
142 (defun xquery-calculate-indentation ()
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
143 "Return the column to which the current line should be indented."
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
144 (beginning-of-line)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
145 (if (bobp)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
146 0 ; First line is always non-indented
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
147 (skip-chars-forward " \t")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
148 (cond
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
149 ;; do nothing if this is a comment
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
150 ((eq (get-text-property (point) 'face) 'font-lock-comment-face) (current-indentation))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
151
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
152 ((looking-at "\\(</?\\w\\|{\\)") ;; xml constructor or enclosed expressions
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
153 (if xquery-indent-debug
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
154 (message "xquery-indent-debug: xml constructor"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
155 (let ((nxml-prolog-end (point-min))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
156 (nxml-scan-end (copy-marker (point-min) nil)))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
157 (nxml-compute-indent)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
158 ))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
159
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
160 ;; for close braces or else statements indent to the same level as the opening {
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
161 ((looking-at "}")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
162 (if xquery-indent-debug
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
163 (message "xquery-indent-debug: }"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
164 (save-excursion
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
165 (backward-up-list)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
166 (let ((cc (current-column)))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
167 (beginning-of-line)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
168 (if (looking-at xquery-start-block-regexp)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
169 (current-indentation)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
170 cc))))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
171
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
172 ((looking-at "else")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
173 (if xquery-indent-debug
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
174 (message "xquery-indent-debug: else"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
175 (save-excursion
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
176 (xquery-previous-non-empty-line)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
177 (- (current-indentation) xquery-indent-size)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
178 ))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
179
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
180 ;; for close parens, indent to the start of the func call
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
181 ((looking-at ")")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
182 (if xquery-indent-debug
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
183 (message "xquery-indent-debug: )"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
184 (save-excursion
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
185 (backward-up-list)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
186 (if (looking-back "\\w+\\s *")
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
187 (backward-word))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
188 (current-column)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
189 ))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
190
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
191 ;; order flwr expressions on the same column
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
192 ((save-excursion
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
193 (when
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
194 (and
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
195 (looking-at xquery-flwr-block-regexp)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
196 (progn
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
197 (xquery-previous-non-empty-line)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
198 (beginning-of-line)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
199 (looking-at xquery-flwr-block-regexp)))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
200 (if xquery-indent-debug
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
201 (message "xquery-indent-debug: nested flwr"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
202 (current-indentation)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
203 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
204 ))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
205
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
206 ;; if this is the first non-empty line after a block, indent xquery-indent-size chars relative to the block
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
207 ((save-excursion
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
208 (xquery-previous-non-empty-line)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
209 (beginning-of-line)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
210 (when (looking-at xquery-start-block-regexp)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
211 (if xquery-indent-debug
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
212 (message "xquery-indent-debug: first line in block"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
213 (+ xquery-indent-size (current-indentation))))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
214 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
215
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
216 ;; for everything else indent relative to the outer list
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
217 (t
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
218 (if xquery-indent-debug
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
219 (message "xquery-indent-debug: everyting else"))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
220 (save-excursion (xquery-previous-non-empty-line) (current-indentation)))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
221 )))
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
222
21
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
223 (when (featurep 'xemacs)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
224 (unless (functionp 'looking-back)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
225 ;; from GNU Emacs subr.el
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
226 (defun looking-back (regexp &optional limit greedy)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
227 "Return non-nil if text before point matches regular expression
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
228 REGEXP.
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
229 Like `looking-at' except matches before point, and is slower.
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
230 LIMIT if non-nil speeds up the search by specifying a minimum
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
231 starting position, to avoid checking matches that would start
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
232 before LIMIT.
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
233 If GREEDY is non-nil, extend the match backwards as far as possible,
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
234 stopping when a single additional previous character cannot be part
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
235 of a match for REGEXP."
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
236 (let ((start (point))
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
237 (pos
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
238 (save-excursion
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
239 (and (re-search-backward (concat "\\(?:" regexp
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
240 "\\)\\=") limit t)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
241 (point)))))
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
242 (if (and greedy pos)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
243 (save-restriction
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
244 (narrow-to-region (point-min) start)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
245 (while (and (> pos (point-min))
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
246 (save-excursion
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
247 (goto-char pos)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
248 (backward-char 1)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
249 (looking-at (concat "\\(?:" regexp
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
250 "\\)\\'"))))
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
251 (setq pos (1- pos)))
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
252 (save-excursion
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
253 (goto-char pos)
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
254 (looking-at (concat "\\(?:" regexp "\\)\\'")))))
7b2c4ed36302 for new maritain
ht
parents: 15
diff changeset
255 (not (null pos))))))
15
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
256
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
257 (defun xquery-previous-non-empty-line ()
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
258 "Move to the last non-empty line."
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
259 (re-search-backward "\\S " (point-min) t)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
260 )
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
261
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
262 (provide 'xquery-mode)
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
263
75ab6d7af627 *** empty log message ***
ht
parents:
diff changeset
264 ;;; xquery-mode.el ends here