annotate lisp/hyperbole/kotl/klink.el @ 36:c53a95d3c46d r19-15b101

Import from CVS: tag r19-15b101
author cvs
date Mon, 13 Aug 2007 08:53:38 +0200
parents 4103f0995bd7
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: klink.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Implicit reference to a kcell action type, for use in koutlines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs V19 Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: extensions, hypermedia, outlines, wp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner & Kellie Clark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; ORIG-DATE: 15-Nov-93 at 12:15:16
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 24
diff changeset
11 ;; LAST-MOD: 6-Mar-97 at 01:19:19 by Bob Weiner
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; link =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; < pathname [, cell-ref] [, position] >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; < @ cell-ref > ;; In same buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; < journal-name, journal-item-number [, cell-ref] [, position] >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; pathname =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; path ;; display path in Emacs buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; !path ;; execute pathname within a shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; &path ;; execute path as a windowed program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; -path ;; Load as an Emacs Lisp program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; cell-ref =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; cell - 1a, 012, 1.2, 1a=012 (both relative and absolute ids separated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; by an equal sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; range - 1a-5c, 1a-+3 (include 3 cells past 1a) (not yet implemented)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; tree - 1a+ (not yet implemented)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; optionally followed by a period and 1 or more relative position specs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; (not yet implemented):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; previous-cell - .b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; down-a-level - .d
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; end-of-branch - .e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; follow-next-link - .l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; return-to-prev-location - .r
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; return-to-prev-buffer - .rf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; sibling - .s, .2s for 2 siblings forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; tail-of-tree - .t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; up-a-level - .u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; last char of cell - .f
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; and then optionally followed by any amount of whitespace, a pipe `|'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; character and then one or more view specification characters. (Augment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; viewspec characters may be given instead, preceded by a colon. They are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; ignored for now.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; position (relative to cell start) = (not yet implemented)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; char-pos, e.g. 28 or C28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; word-num, e.g. W5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; line-num, e.g. L2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; paragraph-num, e.g. P3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; regexp-match, e.g. "regexp"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun klink:create (reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Insert at point an implicit link to REFERENCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 REFERENCE should be a cell-ref or a string containing \"filename, cell-ref\".
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 24
diff changeset
68 See documentation for `kcell:ref-to-id' for valid cell-ref formats."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; Don't change the name or delete default-dir used here. It is referenced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; in "hargs.el" for argument getting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (let ((default-dir default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (barf-if-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (list 'interactive "*+LInsert link to <[file,] cell-id [|vspecs]>: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (barf-if-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; Reference generally is a string. It may be a list as a string, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; "(\"file\" \"cell\")", in which case, we remove the unneeded internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; double quotes and then parse it with pattern matching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (and (stringp reference) (> (length reference) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (= (aref reference 0) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (setq reference (hypb:replace-match-string "\\\"" reference "" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (let ((default-dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 file-ref cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (setq reference (klink:parse reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 file-ref (car reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 cell-ref (car (cdr reference)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; Don't need filename if link is to a cell in current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if (and file-ref (equal buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (expand-file-name file-ref default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq file-ref nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (cond (file-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (setq file-ref (hpath:relative-to file-ref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; "./" prefix, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if (string-match "^\\./" file-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (setq file-ref (substring file-ref (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (insert "<" file-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (if cell-ref (insert ", " cell-ref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (insert ">"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (cell-ref (insert "<@ " cell-ref ">"))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 24
diff changeset
101 (t (error "(klink:create) Invalid reference, `%s'" reference)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defun klink:at-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 "Return non-nil iff point is within a klink.
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
105 See documentation for the `actypes::link-to-kotl' function for valid klink
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
106 formats. Value returned is a list of: link-label, link-start-position, and
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 link-end-position, (including delimiters)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (let (bol klink referent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (if (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; If this is an OO-Browser listing buffer, ignore anything that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; looks like a klink, e.g. a C++ <template> class.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (if (fboundp 'br-browser-buffer-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (not (br-browser-buffer-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; Don't match to C/C++ lines like: #include < path >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (setq bol (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (require 'hmouse-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (not (looking-at smart-c-include-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; Don't match Elisp print objects such as #<buffer>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (and (search-backward "<" bol t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (/= (preceding-char) ?#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; Don't match to \<(explicit)> Hyperbole buttons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (/= (char-after (1+ (point))) ?\()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (setq klink (hbut:label-p t "<" ">" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (stringp (setq referent (car klink)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; Eliminate matches to e-mail address like, <user@domain>.
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
130 (not (string-match "[^<> \t\n][!&@]" referent))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
131 ;; Eliminate matches to URLs
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
132 (not (string-match "\\`[a-zA-Z]+:" referent))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
133 ;; Don't match to <HTML> and </SGML> tags.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
134 (not (and (memq major-mode
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
135 (if (boundp 'id-select-markup-modes)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
136 id-select-markup-modes
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
137 '(html-mode sgml-mode)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
138 ;; Assume , followed by a number is a klink.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
139 (not (string-match ",\\s *[0-9]" referent))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 0
diff changeset
140 (string-match "\\`[a-zA-Z!/]" referent))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 klink)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;; Hyperbole type definitions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (defib klink ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "Follows a link delimited by <> to a koutline cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 See documentation for the `link-to-kotl' function for valid klink formats."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (let* ((link-and-pos (klink:at-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (link (car link-and-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (start-pos (car (cdr link-and-pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (if link
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (progn (ibut:label-set link-and-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (hact 'klink:act link start-pos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defact link-to-kotl (link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 "Displays at the top of another window the referent pointed to by LINK.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 LINK may be of any of the following forms, with or without delimiters:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 < pathname [, cell-ref] >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 < [-!&] pathname >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 < @ cell-ref >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 24
diff changeset
164 See documentation for `kcell:ref-to-id' for valid cell-ref formats."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (interactive "sKotl link specifier: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (or (stringp link) (error "(link-to-kotl): Non-string link argument, %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 link))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ((or (string-match (format "\\`<?\\s *@\\s *\\(%s\\)\\s *>?\\'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 klink:cell-ref-regexp) link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (string-match (format "\\`<?\\s *\\([|:]%s\\)\\s *>?\\'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 klink:cell-ref-regexp) link))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; < @ cell-ref > or < |viewspec > or < :augment-viewspec >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (hact 'link-to-kcell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (kcell:ref-to-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (substring link (match-beginning 1) (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (format "\\`<?\\s *\\([^ \t\n,<>]+\\)\\s *\\(,\\s *\\(%s\\)\\)?\\s *>?\\'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 klink:cell-ref-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; < pathname [, cell-ref] >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (hact 'link-to-kcell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (substring link (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (if (match-end 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (kcell:ref-to-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (substring link (match-beginning 3) (match-end 3))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 "\\`<?\\s *\\(\\([-!&]\\)?\\s *[^ \t\n,<>]+\\)\\s *>?\\'" link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; < [-!&] pathname >
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (hpath:find-other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (substring link (match-beginning 1) (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (t (error "(link-to-kotl): Invalid link specifier, %s" link))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defun klink:act (link start-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (let ((obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; Perform klink's action which is to jump to link referent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (hact 'link-to-kotl link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; Update klink label if need be, which might be in a different buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; than the current one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (klink:update-label link start-pos obuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (defun klink:parse (reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 "Returns (file-ref cell-ref) list parsed from REFERENCE string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 Either element of the list may be nil if REFERENCE does not contain that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 element. REFERENCE should be one of the following forms (and may include an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 optional pair of <> delimiters:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (pathname, cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 pathname, cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 |viewspec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 :augment-viewspec (ignored for now)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 24
diff changeset
219 See documentation for `kcell:ref-to-id' for valid cell-ref formats."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (or (stringp reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (error "(klink:parse): Non-string reference argument, %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 reference))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 "\\`\\s *[<\(]?\\s *\\([^|: \t\n\r,<>][^ \t\n\r,<>]*\\)\\s *,\\s *\\(%s\\)\\s *[\)>]?\\s *\\'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 klink:cell-ref-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; pathname cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (list (substring reference (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (substring reference (match-beginning 2) (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ((string-match (format "\\`\\s *<?\\s *\\(%s\\)\\s *>?\\s *\\'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 klink:cell-ref-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (list nil (substring reference (match-beginning 1) (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (t (error "(klink:parse): Invalid reference specifier, %s" reference))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defun klink:replace-label (klink link-buf start new-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "Replace out of date relative id in a link reference of the form, relid=idstamp."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (set-buffer link-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (message "Relative label should be `%s' in klink <%s>."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 new-label klink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (cond ((or (looking-at "<\\s *@\\s *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (looking-at "[^,]+,\\s *"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (zap-to-char 1 ?=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (insert new-label ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (t nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (defun klink:update-label (klink start link-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 "Update label of KLINK if its relative cell id has changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 Assume point is in klink referent buffer, where the klink points."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if (and (stringp klink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 "[@,]\\s *\\([*0-9][*.0-9a-zA-Z]*\\)\\s *=\\s *0[0-9]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 klink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; Then klink has both relative and permanent ids.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (let* ((label (substring klink (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (new-label (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (if (and new-label (not (equal label new-label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (klink:replace-label klink link-buf start new-label)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;;; Private variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (defvar klink:cell-ref-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 "[|:0-9a-zA-Z][|:.*~=0-9a-zA-Z \t\n\r]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 "Regexp matching a cell reference including relative and view specs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 Contains no groupings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (provide 'klink)