1 ;;; psgml-ids.el --- Management of ID/IDREFS for PSGML
2 ;; $Id: psgml-ids.el,v 2.1 2005/02/09 15:29:09 lenst Exp $
4 ;; Copyright (C) 1999 Jean-Daniel Fekete
6 ;; Author: Jean-Daniel Fekete <Jean-Daniel.Fekete@emn.fr>
8 ;; This program is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License
10 ;; as published by the Free Software Foundation; either version 2
11 ;; of the License, or (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to the Free Software
20 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 ;; Provides some extra functions to manage IDs and IDREFs in attibutes
32 (defvar sgml-record-id-p t
33 "Set to non-nil, if you want to record all referenced IDS for completion.")
35 (defvar sgml-id-list nil
36 "List of IDs available for completing IDREFs")
37 ;(make-variable-buffer-local 'sgml-id-list)
39 (defvar sgml-id-alist nil
40 "Alist of IDs available for completing IDREFs")
42 (defvar sgml-id-list-sorted-p nil
43 "Set to T when the sgml-id-list is sorted")
45 (defvar sgml-edit-idrefs-map
46 (let ((map (make-sparse-keymap 'sgml-edit-idrefs-map)))
47 (set-keymap-parent map minibuffer-local-completion-map)
48 (define-key map " " 'self-insert-command)
52 (defun sgml-id-list ()
53 (unless sgml-id-list-sorted-p
54 (setq sgml-id-list (sort sgml-id-list #'string-lessp)
55 sgml-id-list-sorted-p t
59 (defun sgml-id-alist ()
61 (setq sgml-id-alist (mapcar #'(lambda (id) (cons id id)) (sgml-id-list))))
64 (defun sgml-add-id (id)
65 (unless (or (not sgml-record-id-p) (member id sgml-id-list))
66 (push id sgml-id-list)
67 (setq sgml-id-list-sorted-p nil)))
69 (defun sgml-ids-add-from (element)
70 "Find of all attributes of type ID in ELEMENT and add their value to the
72 (let ((asl (sgml-element-attribute-specification-list element))
73 (adl (sgml-element-attlist element)))
76 (let* ((aname (sgml-attspec-name as))
77 (value (sgml-attspec-attval as))
78 (dcl-value (sgml-attdecl-declared-value
79 (sgml-lookup-attdecl aname adl))))
80 (if (and (eq dcl-value 'ID)
82 (sgml-add-id value))))))
85 (defun sgml-ids-add-current ()
87 (sgml-ids-add-from (sgml-find-context-of (point))))
89 (defun sgml-ids-add-all (&optional element)
90 "Find all the ids of elements inside ELEMENT or the top element if not
93 (let ((el (or element (sgml-top-element))))
94 (sgml-map-element-modify (function sgml-ids-add-from) el)))