aboutsummaryrefslogtreecommitdiffhomepage
path: root/generic/span-extent.el
blob: adf85813c7deec12dc20070b2ec2a171cfe3e55d (plain)
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
96
97
98
99
100
101
102
103
104
;; This file implements spans in terms of extents, for xemacs.
;;
;; Copyright (C) 1998 LFCS Edinburgh
;; Author:	Healfdene Goguen
;; Maintainer:  David Aspinall <da@dcs.ed.ac.uk>
;; License:     GPL (GNU GENERAL PUBLIC LICENSE)
;;
;; $Id$

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;               Bridging the emacs19/xemacs gulf                   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Now define "spans" in terms of extents.

(defsubst make-span (start end)
  "Make a span for the range [START, END) in current buffer."
  (make-extent start end))

(defsubst detach-span (span)
  "Remove SPAN from its buffer."
  (detach-extent span))

(defsubst set-span-endpoints (span start end)
  "Set the endpoints of SPAN to START, END."
  (set-extent-endpoints span start end))

(defsubst set-span-property (span name value)
  "Set SPAN's property NAME to VALUE."
  (set-extent-property span name value))

(defsubst span-read-only (span)
  "Set SPAN to be read only."
  (set-span-property span 'read-only t))

(defsubst span-read-write (span)
  "Set SPAN to be writeable."
  (set-span-property span 'read-only nil))

(defun span-give-warning ()
  "Give a warning message."
  (message "You should not edit here!"))

(defun span-write-warning (span)
  "Give a warning message when SPAN is changed."
  ;; FIXME: implement this in XEmacs, perhaps with after-change-functions
  (set-span-property span 'read-only nil))

(defsubst span-property (span name)
  "Return SPAN's value for property PROPERTY."
  (extent-property span name))

(defsubst delete-span (span)
  "Delete SPAN."
  (let ((predelfn (span-property span 'span-delete-action)))
    (and predelfn (funcall predelfn)))
  (delete-extent span))

(defsubst mapcar-spans (fn start end prop &optional val)
  "Apply function FN to all spans between START and END with property PROP set"
  (mapcar-extents fn nil (current-buffer) start end  nil prop val))

(defsubst span-at (pt prop)
  "Return the smallest SPAN at point PT with property PROP."
  (extent-at pt nil prop))

(defsubst span-at-before (pt prop)
  "Return the smallest SPAN at before PT with property PROP.
A span is before PT if it covers the character before PT."
  (extent-at pt nil prop nil 'before))
  
(defsubst span-start (span)
  "Return the start position of SPAN, or nil if SPAN is detatched."
  (extent-start-position span))

(defsubst span-end (span)
  "Return the end position of SPAN, or nil if SPAN is detatched."
  (extent-end-position span))

(defsubst prev-span (span prop)
  "Return span before SPAN with property PROP."
  (extent-at (extent-start-position span) nil prop nil 'before))

(defsubst next-span (span prop)
  "Return span after SPAN with property PROP."
  (extent-at (extent-end-position span) nil prop nil 'after))

(defsubst span-live-p (span)
    "Return non-nil if SPAN is live and in a live buffer."
  (and span
       (extent-live-p span)
       (buffer-live-p (extent-object span))
       ;; PG 3.4: add third test here to see not detached.
       (not (extent-detached-p span))))

(defun span-raise (span)
  "Function added for FSF Emacs compatibility.  Do nothing here."
  nil)

(defalias 'span-object 'extent-object)
(defalias 'span-string 'extent-string)
  

(provide 'span-extent)