1 ;;; rng-util.el --- utility functions for RELAX NG library
3 ;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
6 ;; Keywords: XML, RelaxNG
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
29 (defun rng-make-datatypes-uri (uri)
30 (if (string-equal uri
"")
31 ;; The spec doesn't say to do this, but it's perfectly conformant
32 ;; and better than using nil, I think.
33 'http
://relaxng.org
/ns
/structure
/1.0
36 (defconst rng-xsd-datatypes-uri
37 (rng-make-datatypes-uri "http://www.w3.org/2001/XMLSchema-datatypes"))
39 (defconst rng-builtin-datatypes-uri
(rng-make-datatypes-uri ""))
41 (defun rng-uniquify-eq (list)
42 "Destructively remove any element from LIST that is eq to
47 (if (eq (car head
) (cadr head
))
48 (setcdr head
(cddr head
)))
49 (setq head
(cdr head
)))
52 (defun rng-uniquify-equal (list)
53 "Destructively remove any element from LIST that is equal to
58 (if (equal (car head
) (cadr head
))
59 (setcdr head
(cddr head
)))
60 (setq head
(cdr head
)))
63 (defun rng-blank-p (str) (string-match "\\`[ \t\n\r]*\\'" str
))
65 (defun rng-substq (new old list
)
66 "Replace first member of LIST (if any) that is eq to OLD by NEW.
67 LIST is not modified."
68 (cond ((null list
) nil
)
70 (cons new
(cdr list
)))
72 (let ((tail (cons (car list
)
77 (let ((item (car rest
)))
78 (setq rest
(cdr rest
))
86 (cons item nil
))))))))
89 (defun rng-complete-before-point (start table prompt
&optional predicate hist
)
90 "Complete text between START and point.
91 Replaces the text between START and point with a string chosen using a
92 completion table and, when needed, input read from the user with the
94 Returns the new string if either a complete and unique completion was
95 determined automatically or input was read from the user. Otherwise,
97 TABLE is an alist, a symbol bound to a function or an obarray as with
98 the function `completing-read'.
99 PROMPT is the string to prompt with if user input is needed.
100 PREDICATE is nil or a function as with `completing-read'.
101 HIST, if non-nil, specifies a history list as with `completing-read'."
102 (let* ((orig (buffer-substring-no-properties start
(point)))
103 (completion (try-completion orig table predicate
)))
104 (cond ((not completion
)
105 (if (string= orig
"")
106 (message "No completions available")
107 (message "No completion for %s" (rng-quote-string orig
)))
110 ((eq completion t
) orig
)
111 ((not (string= completion orig
))
112 (delete-region start
(point))
114 (cond ((not (rng-completion-exact-p completion table predicate
))
115 (message "Incomplete")
117 ((eq (try-completion completion table predicate
) t
)
120 (message "Complete but not unique")
124 (let ((saved-minibuffer-setup-hook
125 (default-value 'minibuffer-setup-hook
)))
126 (add-hook 'minibuffer-setup-hook
127 'minibuffer-completion-help
130 (completing-read prompt
136 (setq-default minibuffer-setup-hook
137 saved-minibuffer-setup-hook
))))
138 (delete-region start
(point))
142 (defun rng-completion-exact-p (string table predicate
)
143 (cond ((symbolp table
)
144 (funcall table string predicate
'lambda
))
146 (intern-soft string table
))
147 (t (assoc string table
))))
149 (defun rng-quote-string (s)
150 (concat "\"" s
"\""))
152 (defun rng-escape-string (s)
153 (replace-regexp-in-string "[&\"<>]"
163 (defun rng-collapse-space (string)
165 (replace-regexp-in-string "[ \t\r\n]+" " " string t t
))
166 (when (string-match "\\` " string
)
167 (setq string
(substring string
1)))
168 (when (string-match " \\'" string
)
169 (setq string
(substring string
0 -
1)))
174 ;; arch-tag: 2dc233e0-5e7a-488f-bfc4-5909512dbaf0
175 ;;; rng-util.el ends here