annotate lisp/hyperbole/kotl/kfile.el @ 27:0a3286277d9b

Added tag r19-15b96 for changeset 441bb1e64a06
author cvs
date Mon, 13 Aug 2007 08:51:34 +0200
parents 376386a54a3c
children c53a95d3c46d
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: kfile.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Save and restore kotls from files.
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: 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: 10/31/93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; LAST-MOD: 1-Nov-95 at 00:46:41 by Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; Other required Elisp libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 (mapcar 'require '(kproperty kotl-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Loads menus under non-tty InfoDock, XEmacs or Emacs19; does nothing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 (and (not (featurep 'kmenu)) hyperb:window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 (or hyperb:lemacs-p hyperb:emacs19-p) (require 'kmenu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defconst kfile:version "Kotl-4.0"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 "Version number of persistent data format used for saving koutlines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Entry Points
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defun kfile:find (file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "Find a file FILE-NAME containing a kotl or create one if none exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 Return the new kview."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (list (kfile:read-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 "Find koutline file: " nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (let ((existing-file (file-exists-p file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (and existing-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (not (file-readable-p file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "(kfile:find): \"%s\" is not readable. Check permissions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (setq buffer (find-file file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; Finding the file may have already done a kfile:read as invoked through
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; kotl-mode via a file local variable setting. If so, don't read it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (kfile:read buffer existing-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (or (eq major-mode 'kotl-mode) (kotl-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defun kfile:view (file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "View an existing kotl version-2 file FILE-NAME in a read-only mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (list (kfile:read-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "View koutline file: " t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (let ((existing-file (file-exists-p file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if existing-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (if (not (file-readable-p file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 "(kfile:view): \"%s\" is not readable. Check permissions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (error "(kfile:view): \"%s\" does not exist."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (view-file file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (kfile:narrow-to-kcells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defun kfile:create (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 "Create a new koutline file attached to BUFFER, with a single empty level 1 kotl cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 Return file's kview."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (or buffer (setq buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if (not (bufferp buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (error "(kfile:create): Invalid buffer argument, %s" buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (if buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (error "(kfile:create): %s is read-only" buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (let ((empty-p (zerop (buffer-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 import-from view standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (not empty-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; This is a foreign file whose elements must be converted into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; koutline cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (progn (setq import-from (kimport:copy-and-set-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (erase-buffer))) ;; We copied the contents to `import-from'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (setq view (kview:create (buffer-name buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 standard-output (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (princ ";; -*- Mode: kotl -*- \n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (prin1 kfile:version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (princ " ;; file-format\n\^_\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; Ensure that last cell has two newlines after it so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; kfile:insert-attributes finds it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (princ "\n\n\^_\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (princ "\^_\n;; depth-first kcell attributes\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; Ensure that display is narrowed to cell region only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (kfile:narrow-to-kcells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if empty-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; This is a new koutline file. Always need at least one visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; cell within a view. Insert initial empty cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (progn (kview:add-cell "1" 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; Mark view unmodified, so if kill right away, there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; Move to first cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (goto-char (kcell-view:start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; Import buffer. Next line is necessary or the importation will fail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; Import foreign buffer as koutline cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (kimport:file import-from (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; If import buffer name starts with a space, kill it, as it is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; longer needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (if (= ?\ (aref (buffer-name import-from) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (kill-buffer import-from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 view))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defun kfile:is-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "Iff current buffer contains an unformatted or formatted koutline, return file format version string, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (let (ver-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (setq ver-string (read (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (and (stringp ver-string) (string-match "^Kotl-" ver-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ver-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (error nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defun kfile:read (buffer existing-file-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "Create a new kotl view by reading BUFFER or create an empty view when EXISTING-FILE-P is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 Return the new view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (let (ver-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (cond ((not (bufferp buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (error "(kfile:read): Argument must be a buffer, '%s'." buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ((not existing-file-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (kfile:create buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (not (setq ver-string (kfile:is-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (error "(kfile:read): '%s' is not a koutline file." buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ((equal ver-string "Kotl-4.0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (kfile:read-v4-or-v3 buffer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ((equal ver-string "Kotl-3.0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (kfile:read-v4-or-v3 buffer t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ((equal ver-string "Kotl-2.0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (kfile:read-v2 buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ((equal ver-string "Kotl-1.0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (error "(kfile:read): V1 koutlines are no longer supported"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (t (error "(kfile:read): '%s' has unknown kotl version, %s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 buffer ver-string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defun kfile:read-v2 (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 "Create a kotl view by reading kotl version-2 BUFFER. Return the new view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (let ((standard-input buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 cell-count label-type label-min-width label-separator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 level-indent cell-data kotl-structure view kcell-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; Skip past cell contents here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (search-forward "\n\^_" nil t 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; Read rest of file data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (setq cell-count (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 label-type (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 label-min-width (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 label-separator (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 level-indent (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 cell-data (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 kotl-structure (read))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; kcell-list is a depth-first list of kcells to be attached to the cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; contents within the kview down below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (setq kcell-list (kfile:build-structure-v2 kotl-structure cell-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 view (kview:create (buffer-name buffer) cell-count label-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 level-indent label-separator label-min-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (kfile:narrow-to-kcells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; Add attributes to cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (kfile:insert-attributes-v2 view kcell-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; Mark view unmodified and move to first cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (goto-char (kcell-view:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 view))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (defun kfile:read-v4-or-v3 (buffer v3-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 "Create a koutline view by reading version-4 BUFFER. Return the new view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 If V3-FLAG is true, read as a version-3 buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (let ((standard-input buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 cell-count label-type label-min-width label-separator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 level-indent cell-data view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;; Skip past cell contents here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (search-forward "\n\^_" nil t 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; Read rest of file data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if v3-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 nil ;; V3 files did not store viewspecs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (kvspec:initialize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (setq kvspec:current (read)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (setq cell-count (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 label-type (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 label-min-width (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 label-separator (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 level-indent (read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 cell-data (read))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (setq view (kview:create (buffer-name buffer) cell-count label-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 level-indent label-separator label-min-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (kfile:narrow-to-kcells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; Add attributes to cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (kfile:insert-attributes-v3 view cell-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; Mark view unmodified and move to first cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (goto-char (kcell-view:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 view))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defun kfile:update (&optional visible-only-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 "Update kfile internal structure so that view is ready for saving to a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 Leave outline file expanded with structure data showing unless optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 VISIBLE-ONLY-P is non-nil. Signal an error if kotl is not attached to a file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (let* ((top (kview:top-cell kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (file (kcell:get-attr top 'file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (label-type (kview:label-type kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (label-min-width (kview:label-min-width kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (label-separator (kview:label-separator kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (level-indent (kview:level-indent kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; If this happens to be non-nil, it is virtually impossible to save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; a file, so ensure it is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (debug-on-error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (cond ((null file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (error "(kfile:update): Current outline is not attached to a file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ((not (file-writable-p file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (error "(kfile:update): File \"%s\" is not writable." file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (let* ((buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (id-counter (kcell:get-attr top 'id-counter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (kotl-data (make-vector (1+ id-counter) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (standard-output (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (opoint (set-marker (make-marker) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (kcell-num 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; Prepare cell data for saving.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (kfile:narrow-to-kcells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (setq cell (kcell-view:cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (aset kotl-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 kcell-num
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (kotl-data:create cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setq kcell-num (1+ kcell-num))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 kview t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; Save top cell, 0, last since above loop may increment the total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; number of cells counter stored in it, if any invalid cells are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; encountered.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (aset kotl-data 0 (kotl-data:create top))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (setq id-counter (kcell:get-attr top 'id-counter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (if (search-forward "\n\^_\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (delete-region (point-min) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (princ ";; -*- Mode: kotl -*- \n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (prin1 kfile:version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (princ " ;; file-format\n\^_\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; Skip past cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (if (search-forward "\n\^_\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ;; Get rid of excess blank lines after last cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (progn (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (skip-chars-backward "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (delete-region (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; Ensure that last cell has two newlines after it so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; kfile:insert-attributes finds it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (princ "\n\n\^_\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (princ (format (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "%S ;; kvspec:current\n%d ;; id-counter\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "%S ;; label-type\n%d ;; label-min-width\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "%S ;; label-separator\n%d ;; level-indent\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 kvspec:current id-counter label-type label-min-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 label-separator level-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (princ "\^_\n;; depth-first kcell attributes\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (kfile:pretty-print kotl-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;; Don't re-narrow buffer by default since this is used in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;; write-contents-hooks after save-buffer has widened buffer. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;; buffer is narrowed here, only the narrowed portion will be saved to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ;; the file. Narrow as an option since saving only the portion of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ;; file visible in a view may be useful in some situations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (if visible-only-p (kfile:narrow-to-kcells))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;; Return point to its original position as given by the opoint marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (set-marker opoint nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;;; Next function is adapted from 'file-write' of GNU Emacs 19, copyright FSF,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;;; under the GPL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (defun kfile:write (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 "Write current outline to FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (interactive "FWrite outline file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (if (or (null file) (string-equal file ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (error "(kfile:write): Invalid file name, \"%s\"" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;; If arg is just a directory, use same file name, but in that directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (if (and (file-directory-p file) buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (setq file (concat (file-name-as-directory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (file-name-nondirectory buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (kcell:set-attr (kview:top-cell kview) 'file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (set-visited-file-name file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ;; Set-visited-file-name clears local-write-file-hooks that we use to save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;; koutlines properly, so reinitialize local variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (kotl-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (set-buffer-modified-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; This next line must come before the save-buffer since write-file-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 ;; can make use of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (kview:set-buffer-name kview (buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (save-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (defun kfile:build-structure-v2 (kotl-structure cell-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 "Build cell list from the KOTL-STRUCTURE and its CELL-DATA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 Assumes all arguments are valid. CELL-DATA is a vector of cell fields read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 from a koutline file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 Return list of outline cells in depth first order. Invisible top cell is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 included in the list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (let ((stack) (sibling-p) (cell-list) func cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (lambda (item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (setq func (cdr (assoc item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (cons "\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (setq stack (cons sibling-p stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 sibling-p nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (cons "\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (setq sibling-p (car stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 stack (cdr stack)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (cond (func (funcall func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 ;; 0th cell was created with kview:create.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ((equal item 0) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (t (setq cell (kotl-data:to-kcell-v2 (aref cell-data item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 cell-list (cons cell cell-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 sibling-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 kotl-structure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (nreverse cell-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (defun kfile:insert-attributes-v2 (kview kcell-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 "Set cell attributes within kview for each element in KCELL-LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 Assumes all cell contents are already in kview and that no cells are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 hidden."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (skip-chars-forward "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ;; !!! Won't work if label-type is 'no.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ;; Here we search past the cell identifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;; for the location at which to place cell properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; Be sure not to skip past a period which may terminate the label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (if (re-search-forward "[A-Za-z0-9]\\(\\.?[A-Za-z0-9]\\)*" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (kproperty:set 'kcell (car kcell-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (setq kcell-list (cdr kcell-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (search-forward "\n\n" nil t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (defun kfile:insert-attributes-v3 (kview kcell-vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 "Set cell attributes within kview for each element in KCELL-VECTOR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 Assumes all cell contents are already in kview and that no cells are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 hidden."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (let ((kcell-num 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (skip-chars-forward "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ;; !!! Won't work if label-type is 'no.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;; Here we search past the cell identifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 ;; for the location at which to place cell properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 ;; Be sure not to skip past a period which may terminate the label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (if (re-search-forward "[A-Za-z0-9]\\(\\.?[A-Za-z0-9]\\)*" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (kproperty:set 'kcell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (kotl-data:to-kcell-v3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (aref kcell-vector kcell-num)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (setq kcell-num (1+ kcell-num))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (search-forward "\n\n" nil t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (defun kfile:narrow-to-kcells ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 "Narrow kotl file to kcell section only."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (let ((start-text) (end-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; Skip to start of kcells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (if (search-forward "\n\^_" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (setq start-text (1+ (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ;; Skip past end of kcells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (if (and start-text (search-forward "\n\^_" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (setq end-text (1+ (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (if (and start-text end-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (progn (narrow-to-region start-text end-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 "(kfile:narrow-to-kcells): Cannot find start or end of kcells"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (defun kfile:print-to-string (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 "Return a string containing OBJECT, any Lisp object, in pretty-printed form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 Quoting characters are used when needed to make output that `read' can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 handle, whenever this is possible."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (set-buffer (get-buffer-create " kfile:print-to-string"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (let ((emacs-lisp-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (emacs-lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (let ((print-escape-newlines kfile:escape-newlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (prin1 object (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; (message "%06d" (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ((looking-at "\\s\(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (while (looking-at "\\s(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ((and (looking-at "\\(quote[ \t]+\\)\\([^.)]\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (> (match-beginning 1) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (= ?\( (char-after (1- (match-beginning 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ;; Make sure this is a two-element list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (goto-char (match-beginning 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ;; (looking-at "[ \t]*\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ;; Avoid mucking with match-data; does this test work?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (char-equal ?\) (char-after (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ;; -1 gets the paren preceding the quote as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (delete-region (1- (match-beginning 1)) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (insert "'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (if (looking-at "[ \t]*\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (delete-region (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (error "Malformed quote"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (backward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ((condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (prog1 t (down-list 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (progn (skip-chars-forward " \t") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (if (not (char-equal ?' (char-after (1- (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (insert ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 ((condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (prog1 t (up-list 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (while (looking-at "\\s)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (progn (skip-chars-forward " \t") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (if (not (char-equal ?' (char-after (1- (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (insert ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (t (goto-char (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (indent-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (kill-buffer (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (defun kfile:pretty-print (object &optional stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 "Output the pretty-printed representation of OBJECT, any Lisp object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 Quoting characters are printed when needed to make output that `read'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 can handle, whenever this is possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 Output stream is STREAM, or value of `standard-output' (which see)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (princ (kfile:print-to-string object) (or stream standard-output)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (defun kfile:read-name (prompt existing-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 "PROMPT for and read a koutline file name. EXISTING-P means must exist."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (let ((filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (while (not filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (setq filename (read-file-name prompt nil nil existing-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (if (or (null filename) (equal filename ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (progn (ding) (setq filename nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (defvar kfile:escape-newlines t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 "Value of print-escape-newlines used by 'kfile:print-to-string' function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (provide 'kfile)