File: psgml-ids.el

package info (click to toggle)
psgml 1.3.2-12
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,168 kB
  • ctags: 1,045
  • sloc: lisp: 10,073; sh: 497; makefile: 53
file content (95 lines) | stat: -rw-r--r-- 2,986 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;;; psgml-ids.el --- Management of ID/IDREFS for PSGML
;; $Id: psgml-ids.el,v 2.1 2005/02/09 15:29:09 lenst Exp $

;; Copyright (C) 1999 Jean-Daniel Fekete

;; Author: Jean-Daniel Fekete <Jean-Daniel.Fekete@emn.fr>

;; 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 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.
;; 
;; 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., 675 Mass Ave, Cambridge, MA 02139, USA.

;;; Commentary:

;; Provides some extra functions to manage IDs and IDREFs in attibutes


(provide 'psgml-ids)
(require 'psgml)
(require 'psgml-api)


(defvar sgml-record-id-p t
  "Set to non-nil, if you want to record all referenced IDS for completion.")

(defvar sgml-id-list nil
  "List of IDs available for completing IDREFs")
;(make-variable-buffer-local 'sgml-id-list)

(defvar sgml-id-alist nil
  "Alist of IDs available for completing IDREFs")

(defvar sgml-id-list-sorted-p nil
  "Set to T when the sgml-id-list is sorted")

(defvar sgml-edit-idrefs-map
  (let ((map (make-sparse-keymap 'sgml-edit-idrefs-map)))
    (set-keymap-parent map minibuffer-local-completion-map)
    (define-key map " " 'self-insert-command)
    map))


(defun sgml-id-list ()
  (unless sgml-id-list-sorted-p
    (setq sgml-id-list (sort sgml-id-list #'string-lessp)
	  sgml-id-list-sorted-p t
	  sgml-id-alist nil))
  sgml-id-list)

(defun sgml-id-alist ()
  (unless sgml-id-alist
    (setq sgml-id-alist (mapcar #'(lambda (id) (cons id id)) (sgml-id-list))))
  sgml-id-alist)

(defun sgml-add-id (id)
  (unless (or (not sgml-record-id-p) (member id sgml-id-list))
    (push id sgml-id-list)
    (setq sgml-id-list-sorted-p nil)))

(defun sgml-ids-add-from (element)
  "Find of all attributes of type ID in ELEMENT and add their value to the
sgml-id-list."
  (let ((asl (sgml-element-attribute-specification-list element))
	(adl (sgml-element-attlist element)))

    (dolist (as asl)
      (let* ((aname (sgml-attspec-name as))
	     (value (sgml-attspec-attval as))
	     (dcl-value (sgml-attdecl-declared-value
			 (sgml-lookup-attdecl aname adl))))
	(if (and (eq dcl-value 'ID)
		 value)
	    (sgml-add-id value))))))


(defun sgml-ids-add-current ()
  (interactive)
  (sgml-ids-add-from (sgml-find-context-of (point))))

(defun sgml-ids-add-all (&optional element)
  "Find all the ids of elements inside ELEMENT or the top element if not
specified"
  (interactive)
  (let ((el (or element (sgml-top-element))))
    (sgml-map-element-modify (function sgml-ids-add-from) el)))