1 ;;; kotl-mode.el --- Major mode for editing koutlines and associated commands.
3 ;; Copyright (C) 1993, 1994, 1995, 2007 Free Software Foundation, Inc.
4 ;; Developed with support from Motorola Inc.
6 ;; Author: Bob Weiner, Brown U.
8 ;; Maintainer: Mats Lidell <matsl@contactor.se>
9 ;; Keywords: data, hypermedia, outlines, wp
11 ;; This file is part of GNU Hyperbole.
13 ;; GNU Hyperbole is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 3, or (at
16 ;; your option) any later version.
18 ;; GNU Hyperbole is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
33 ;;; Other required Lisp Libraries
36 (mapcar 'require '(hsite hmail kview kimport kvspec kotl kmenu))
42 (defvar kotl-mode:refill-flag nil
43 "*Automatically refill cells during move, copy, promotion and demotion operations when non-nil.
44 Default value is nil. Cells with a `no-fill' attribute are never refilled
45 during such operations, regardless of the value of this flag.")
53 "The major mode used to edit and view koutlines.
54 It provides the following keys:
57 (use-local-map kotl-mode-map)
58 (set-syntax-table text-mode-syntax-table)
59 ;; Turn off filladapt minor mode if on, so that it does not interfere with
60 ;; the filling code in "kfill.el".
61 (and (boundp 'filladapt-mode) filladapt-mode (filladapt-mode -1))
62 (if (/= 3 (length (action:params (symbol-function 'fill-paragraph))))
63 ;; Some package such as filladapt has overwritten the primitives
64 ;; defined in kfill.el, so reload it.
66 ;; Ensure that outline structure data is saved when save-buffer is called
67 ;; from save-some-buffers, {C-x s}.
68 (add-hook 'local-write-file-hooks 'kotl-mode:update-buffer)
69 (mapcar 'make-local-variable
70 '(kotl-previous-mode indent-line-function indent-region-function
71 minor-mode-alist selective-display-ellipses))
72 ;; Used by kimport.el functions.
73 (if (and (boundp 'kotl-previous-mode) kotl-previous-mode)
75 (setq kotl-previous-mode major-mode
76 ;; Remove outline indication due to selective-display.
77 minor-mode-alist (copy-sequence minor-mode-alist)
78 minor-mode-alist (set:remove '(selective-display " Outline")
80 minor-mode-alist (set:remove '(selective-display " Otl")
82 ;; Remove indication that buffer is ;; narrowed.
83 mode-line-format (copy-sequence mode-line-format)
84 mode-line-format (set:remove "%n" mode-line-format)))
86 (setq indent-line-function 'kotl-mode:indent-line
87 indent-region-function 'kotl-mode:indent-region
88 local-abbrev-table text-mode-abbrev-table
90 selective-display-ellipses t
91 paragraph-start "^[ \t]*$\\|^\^L"
92 paragraph-separate "^[ \t]*$\\|^\^L")
94 ;; This major-mode setting must come after the local variable settings but
95 ;; before the koutline is formatted.
96 (setq major-mode 'kotl-mode
99 ;; If buffer has not yet been formatted for editing, format it.
101 ;; Koutline file that has been loaded and formatted for editing.
103 ;; The buffer might have been widened for inspection, so narrow to cells
105 (kfile:narrow-to-kcells))
106 ;; Koutline file that has been loaded but not yet formatted for editing.
110 (and buffer-file-name (file-exists-p buffer-file-name)))
112 ;; New koutline buffer or a foreign text buffer that must be converted to
115 (kfile:create (current-buffer))
117 ;; We have been converting a buffer from a foreign format to a koutline.
118 ;; Now that it is converted, ensure that kotl-previous-mode is set to
120 (setq kotl-previous-mode 'kotl-mode)
121 (easy-menu-add kotl-mode-menu kotl-mode-map)
122 (run-hooks 'kotl-mode-hook))
124 (defun kotl-mode:find-file-hook ()
125 (if (kview:is-p kview)
126 (kotl-mode:to-valid-position))
129 ;;; Ensure that point ends up at a valid position whenever a find-file
130 ;;; is done on a kotl-file.
131 (add-hook 'find-file-hooks 'kotl-mode:find-file-hook)
133 ;;; Ensure that outline structure data is hidden from view after a file save.
134 (add-hook 'after-save-hook 'kfile:narrow-to-kcells)
137 ;;; Editing within a single kotl
140 (fset 'kotl-mode:backward-delete-char-untabify
141 'kotl-mode:delete-backward-char)
142 (fset 'kotl-mode:backward-delete-char
143 'kotl-mode:delete-backward-char)
145 (defun kotl-mode:backward-kill-word (arg)
146 "Kill up to prefix ARG words preceding point within a single cell."
148 (or arg (setq arg 1))
151 (error "(kotl-mode:backward-kill-word): End of cell")))
154 (error "(kotl-mode:backward-kill-word): Beginning of cell"))))
158 (narrow-to-region (kcell-view:start) (kcell-view:end-contents))
159 (backward-kill-word arg))))
161 (defun kotl-mode:center-line ()
162 "Center the line point is on, within the width specified by `fill-column'.
163 This means adjusting the indentation so that it equals the distance between
164 the end of the text and `fill-column'."
166 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
167 (let ((indent (kcell-view:indent))
168 (opoint (point-marker))
171 (setq start (kotl-mode:beginning-of-line))
172 (if (setq bocp (kotl-mode:bocp))
174 ;; Add a temporary fill-prefix since this is the 1st line of the cell
175 ;; where label could interfere with centering.
176 (insert "\n\n") (insert-char ?\ indent)))
179 ;; Delete temporary fill prefix.
180 (delete-region start (+ start indent 2)))
182 ;; Move to editable point if need be.
183 (kotl-mode:to-valid-position)))
185 (defun kotl-mode:center-paragraph ()
186 "Center each nonblank line in the paragraph at or after point.
187 See `center-line' for more info."
189 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
190 (let ((indent (kcell-view:indent))
191 (opoint (point-marker))
194 (kotl-mode:to-valid-position)
196 ;; Add a temporary fill-prefix for 1st line in cell which contains a
197 ;; label, so is centered properly.
198 (insert "\n\n") (insert-char ?\ indent)
199 (kcell-view:operate 'center-paragraph)
200 ;; Delete temporary fill prefix.
201 (delete-region start (+ start indent 2))
202 ;; Return to original point.
203 (goto-char (min opoint (kcell-view:end-contents)))
204 ;; Move to editable point if need be.
205 (kotl-mode:to-valid-position)))
207 (defun kotl-mode:copy-region-as-kill (start end)
208 "Copy region between START and END within a single kcell to kill ring."
210 (kotl-mode:kill-region start end t))
212 (defun kotl-mode:copy-to-register (register start end &optional delete-flag)
213 "Copy into REGISTER the region START to END.
214 With optional prefix arg DELETE-FLAG, delete region."
215 (interactive "cCopy to register: \nr\nP")
216 (let ((indent (kcell-view:indent)))
217 (set-register register
218 (hypb:replace-match-string
219 (concat "^" (make-string indent ?\ ))
220 (buffer-substring start end)
222 (if delete-flag (delete-region start end)))
224 (defun kotl-mode:delete-backward-char (arg &optional kill-flag)
225 "Delete up to the preceding prefix ARG characters.
226 Return number of characters deleted.
227 Optional KILL-FLAG non-nil means save in kill ring instead of deleting.
228 Does not delete across cell boundaries."
231 (if current-prefix-arg
233 arg (prefix-numeric-value current-prefix-arg))))
234 (or arg (setq arg 1))
235 (kotl-mode:delete-char (- arg) kill-flag))
237 (defun kotl-mode:delete-blank-lines ()
238 "On blank line within a cell, delete all surrounding blank lines, leaving just one.
239 On isolated blank line, delete that one.
240 On nonblank line, delete all blank lines that follow it.
242 If nothing but whitespace follows point until the end of a cell, delete all
243 whitespace at the end of the cell."
245 ;; If nothing but whitespace from point until the end of cell, remove all
246 ;; cell trailing whitespace.
247 (let ((end (kcell-view:end-contents))
250 (skip-chars-forward " \t\n\r" end)
251 (not (kotl-mode:eocp)))
252 (kcell-view:operate (function (lambda () (delete-blank-lines))))
253 (setq start (kcell-view:start))
255 ;; delete any preceding whitespace
256 (skip-chars-backward " \t\n\r" start)
257 (delete-region (max start (point)) end)))
258 (kotl-mode:to-valid-position))
260 (defun kotl-mode:delete-char (arg &optional kill-flag)
261 "Delete up to prefix ARG characters following point.
262 Return number of characters deleted.
263 Optional KILL-FLAG non-nil means save in kill ring instead of deleting.
264 Does not delete across cell boundaries."
267 (if current-prefix-arg
269 arg (prefix-numeric-value current-prefix-arg))))
270 (or arg (setq arg 1))
272 (indent (kcell-view:indent))
276 (error "(kotl-mode:delete-char): End of cell")
277 (setq end (kcell-view:end)
278 arg (min arg (- end (point))))
281 (if (/= ?\ (char-syntax (following-char)))
283 del-count (1- del-count))
284 (delete-char 1 kill-flag)
285 ;; There may be non-whitespace characters in the
286 ;; indent area. Don't delete them.
288 (while (and (> count 0)
289 (= ?\ (char-syntax (following-char))))
291 (setq count (1- count))))
292 (delete-char 1 kill-flag))
294 del-count (1+ del-count)))
298 (error "(kotl-mode:delete-char): Beginning of cell")
299 (setq start (kcell-view:start)
300 arg (max arg (- start (point))))
303 (if (/= ?\ (char-syntax (preceding-char)))
305 del-count (1- del-count))
306 ;; There may be non-whitespace characters in the
307 ;; indent area. Don't delete them.
309 (while (and (> count 0)
310 (= ?\ (char-syntax (preceding-char))))
312 (setq count (1- count)))
314 (delete-char -1 kill-flag)))
315 (delete-char -1 kill-flag))
317 del-count (1+ del-count))))))
320 (defun kotl-mode:delete-horizontal-space ()
321 "Delete all spaces and tabs around point."
326 (kotl-mode:start-of-line))
328 (kotl-mode:finish-of-line)))
329 (delete-horizontal-space)))
331 (defun kotl-mode:delete-indentation (&optional arg)
332 "Join this line to previous and fix up whitespace at join.
333 If there is a fill prefix, delete it from the beginning of this line.
334 With argument, join this line to following line."
339 (let ((opoint (point)))
341 (if arg (forward-line 1))
342 (if (eq (preceding-char) ?\n)
344 (delete-region (point) (1- (point)))
345 ;; If the second line started with the fill prefix,
346 ;; delete the prefix.
348 (<= (+ (point) (length fill-prefix)) (point-max))
351 (point) (+ (point) (length fill-prefix)))))
352 (delete-region (point) (+ (point) (length fill-prefix))))
354 (goto-char opoint)))))))
356 (defun kotl-mode:fill-cell (&optional justify ignore-collapsed-p)
357 "Fill current cell within current view if it does not have a non-nil `no-fill' attribute.
358 With optional JUSTIFY, justify cell as well.
359 IGNORE-COLLAPSED-P is used when caller has already expanded cell, indicating
360 it is not collapsed."
362 (cond ((kcell-view:get-attr 'no-fill)
365 (message "Current cell has a `do not fill' attribute.")
367 ((string-match "\\`[ \t\n\r]*\\'" (kcell-view:contents))
368 ;; Cell content is all whitespace.
370 (t (let* ((indent (kcell-view:indent))
371 (opoint (set-marker (make-marker) (point)))
372 (start (kcell-view:start))
374 (end (kcell-view:end-contents))
375 temp-prefix prev-point)
377 ;; Expand cell if collapsed so that filling is done properly.
378 (if (and (not ignore-collapsed-p)
379 (setq collapsed-p (search-forward "\r" end t)))
380 (subst-char-in-region start end ?\r ?\n t))
382 ;; Add a temporary fill-prefix for first labeled line, so is
384 (insert (setq temp-prefix
385 (concat "\n\n" (make-string indent ?\ ))))
386 (while (progn (fill-paragraph justify)
387 (setq prev-point (point))
389 (and (/= (point) prev-point)
390 (< (point) (kcell-view:end-contents))
391 (if (memq (preceding-char) '(?\n ?\r))
392 (not (looking-at "[\n\r]"))
394 ;; Delete temporary fill prefix.
396 (if (looking-at temp-prefix)
397 (replace-match "" t t))
398 ;; Return to original point.
399 (setq end (kcell-view:end-contents))
400 (goto-char (min opoint end))
402 ;; If cell was collapsed before filling, collapse it again.
404 (subst-char-in-region start end ?\n ?\r t))
407 (set-marker opoint nil))
408 ;; Move to editable point if need be.
409 (kotl-mode:to-valid-position))))
411 (defun kotl-mode:fill-paragraph (&optional justify)
412 "Fill the current paragraph within the cell.
413 With optional JUSTIFY, justify the paragraph as well.
414 Ignore any non-nil no-fill attribute attached to the cell."
416 (let ((indent (kcell-view:indent))
417 (opoint (point-marker))
420 (kotl-mode:to-valid-position)
421 (setq start (point-marker))
422 ;; Add a temporary fill-prefix for 1st line in cell which contains a
423 ;; label, so is filled properly.
424 (insert "\n\n") (insert-char ?\ indent)
425 (setq end (point-marker))
426 ;; Return to original paragraph point. This is the correct formula,
427 ;; considering the fill prefix that was just added.
428 (goto-char (min (max opoint (point)) (kcell-view:end-contents)))
429 (fill-paragraph justify)
430 ;; Delete temporary fill prefix.
431 (delete-region start end)
432 ;; Return to original point.
433 (goto-char (min opoint (kcell-view:end-contents)))
434 ;; Move to editable point if need be.
435 (kotl-mode:to-valid-position)
437 (set-marker opoint nil)
438 (set-marker start nil)
439 (set-marker end nil)))
441 ;; XEmacs binds this to {M-q}.
442 (fset 'kotl-mode:fill-paragraph-or-region 'kotl-mode:fill-paragraph)
444 (defun kotl-mode:fill-tree (&optional top-p)
445 "Refill each cell within the tree whose root is at point.
446 Skip cells with a non-nil no-fill attribute.
447 With optional prefix argument TOP-P non-nil, refill all cells in the outline."
449 ;; Store list of which cells are presently collapsed.
450 (let ((collapsed-cells
452 (function (lambda (view)
453 ;; Use free variable label-sep-len bound in
454 ;; kview:map-tree for speed.
455 (kcell-view:collapsed-p nil label-sep-len)))
458 ;; Expand all cells in tree.
460 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
462 (kotl-mode:end-of-tree)
463 (subst-char-in-region
464 (point) (kcell-view:end-contents) ?\r ?\n t)))
466 ;; Refill cells without no-fill property.
467 (kview:map-tree (function (lambda (view) (kotl-mode:fill-cell)))
470 ;; Collapse temporarily expanded cells.
471 (if (delq nil collapsed-cells)
475 (if (car collapsed-cells)
476 ;; Use free variable label-sep-len bound in
477 ;; kview:map-tree for speed.
478 (kcell-view:collapse nil label-sep-len))
479 (setq collapsed-cells (cdr collapsed-cells))))
482 (defun kotl-mode:insert-buffer (buffer)
483 "Insert after point the contents of BUFFER.
484 Puts mark after the inserted text.
485 BUFFER may be a buffer or a buffer name."
486 (interactive "*bInsert buffer: ")
487 (insert-buffer buffer)
488 (kotl-mode:add-indent-to-region))
490 (defun kotl-mode:insert-file (import-from children-p)
491 "Insert each element in IMPORT-FROM as a separate cell in the current view.
492 Insert as sibling cells following the current cell unless prefix arg,
493 CHILDREN-P is non-nil, then insert as the initial children of the current
496 IMPORT-FROM may be a buffer name or file name (file name completion is
499 See documentation for `kimport:file' for information on how the type of
500 importation is determined."
502 (list (read-file-name
503 (if current-prefix-arg
504 "Buffer or file to insert as children of current cell: "
505 "Buffer or file to insert as siblings of current cell: "))
507 (kimport:file import-from (current-buffer) children-p))
509 (defun kotl-mode:insert-file-contents (filename)
510 "Insert contents of file FILENAME into current cell after point.
511 Set mark after the inserted text."
512 (interactive "*fInsert file: ")
513 (let ((tem (insert-file-contents filename)))
514 (push-mark (+ (point) (car (cdr tem)))))
515 (kotl-mode:add-indent-to-region))
517 (defun kotl-mode:insert-register (register &optional arg)
518 "Insert contents of register REGISTER at point in current cell.
519 REGISTER is a character naming the register to insert.
520 Normally puts point before and mark after the inserted text.
521 If optional second arg is non-nil, puts mark before and point after.
522 Interactively, second arg is non-nil if prefix arg is supplied."
523 (interactive "*cInsert register: \nP")
525 (let ((val (get-register register)))
527 (insert-rectangle val))
530 (kotl-mode:add-indent-to-region))
532 (princ val (current-buffer)))
533 ((and (markerp val) (marker-position val))
534 (princ (marker-position val) (current-buffer)))
536 (error "Register '%c' does not contain text" register))))
537 (if (not arg) (exchange-point-and-mark)))
539 (defun kotl-mode:just-one-space ()
540 "Delete all spaces and tabs around point and leave one space."
545 (kotl-mode:start-of-line))
547 (kotl-mode:finish-of-line)))
550 (defun kotl-mode:kill-line (&optional arg)
551 "Kill ARG lines from point."
555 (boundp 'kill-whole-line) kill-whole-line)
556 (let ((indent (kcell-view:indent)))
557 ;; Kill whole line including newline, if any.
563 (progn (setq no-newline
564 (not (search-forward "\n" nil 'stay)))
566 (or no-newline (delete-char indent)))))))
567 ;; Kill part of a line or multiple lines.
568 (let ((num-arg (prefix-numeric-value arg)))
570 ((and (null arg) (not (kotl-mode:eolp)))
571 ;; kill to eol but not newline
572 (kill-region (point) (setq arg (kotl-mode:finish-of-line))))
575 (kill-region (point) (setq arg (kotl-mode:start-of-line))))
577 ;; Find start and end of region to kill
578 (let ((start (point))
579 (end (min (kcell-view:end-contents)
580 (save-excursion (forward-line num-arg) (point)))))
581 (kotl-mode:kill-region start end))))))
582 (setq last-command 'kill-region))
584 (defun kotl-mode:kill-region (start end &optional copy-p)
585 "Kill region between START and END within a single kcell.
586 With optional COPY-P equal to 't, copy region to kill ring but does not
587 kill it. With COPY-P any other non-nil value, return region as a
588 string without affecting kill ring.
590 If the buffer is read-only and COPY-P is nil, the region will not be deleted
591 but it will be copied to the kill ring and then an error will be signaled."
593 (let ((read-only (and (not copy-p) buffer-read-only)))
594 (if read-only (setq copy-p t))
595 (if (and (number-or-marker-p start)
596 (number-or-marker-p end)
597 (eq (kcell-view:cell start)
598 (kcell-view:cell end)))
601 (let ((indent (kcell-view:indent))
603 ;; Convert region to string
604 ;; Convert all occurrences of newline + indent
605 ;; to just newline, eliminating indent.
606 ;; Then save to kill ring.
607 (setq subst-str (concat "\\([\n\r]\\)" (make-string indent ?\ ))
609 (hypb:replace-match-string
610 subst-str (buffer-substring start end) "\\1"))
613 ;; If last char of region is a newline, then delete indent in
616 start (+ end (if (memq (char-after (1- (max start end)))
620 (if (and copy-p (not (eq copy-p t)))
621 ;; Return killed region as a string.
623 (if (eq last-command 'kill-region)
624 (kill-append killed (< end start))
626 (setq this-command 'kill-region)
627 (if read-only (barf-if-buffer-read-only))
630 "(kotl-mode:kill-region): Bad region or not within a single kcell."))))
632 (fset 'kotl-mode:kill-ring-save 'kotl-mode:copy-region-as-kill)
634 (defun kotl-mode:kill-sentence (&optional arg)
635 "Kill up to prefix ARG (or 1) sentences following point within a single cell."
637 (or arg (setq arg 1))
640 (error "(kotl-mode:kill-sentence): End of cell")))
643 (error "(kotl-mode:kill-sentence): Beginning of cell"))))
646 (kotl-mode:kill-region (point)
648 (kotl-mode:forward-sentence arg)))))
650 (defun kotl-mode:kill-word (arg)
651 "Kill up to prefix ARG words following point within a single cell."
653 (or arg (setq arg 1))
656 (error "(kotl-mode:kill-word): End of cell")))
659 (error "(kotl-mode:kill-word): Beginning of cell"))))
663 (narrow-to-region (kcell-view:start) (kcell-view:end-contents))
666 (defun kotl-mode:newline (arg)
667 "Insert a newline. With ARG, insert ARG newlines.
668 In Auto Fill mode, if no numeric arg, break the preceding line if it is
671 (let ((indent (kcell-view:indent)))
676 (insert-char ?\ indent))
679 (kotl-mode:start-of-line)
683 (insert-char ?\ indent)
684 (setq arg (1- arg))))))
686 (fset 'kotl-mode:newline-and-indent 'kotl-mode:newline)
688 (defun kotl-mode:open-line (arg)
689 "Insert a newline and leave point before it.
690 With arg N, insert N newlines."
692 (let* ((bolp (and (kotl-mode:bolp) (not (kotl-mode:bocp))))
693 (indent (kcell-view:indent)))
697 (if (and (not bolp) fill-prefix)
699 (insert-char ?\ indent)))
701 (if (and bolp fill-prefix)
702 (progn (delete-horizontal-space)
703 (insert fill-prefix)))
706 (defun kotl-mode:set-fill-prefix (turn-off)
707 "Sets fill prefix to line up to point.
708 With prefix arg TURN-OFF or at begin of line, turns fill prefix off."
710 (set-fill-prefix (or turn-off (kotl-mode:bolp))))
712 (defun kotl-mode:transpose-chars (arg)
713 "Interchange characters around point, moving forward one character.
714 With prefix ARG, take character before point and drag it forward past ARG
715 other characters (backward if ARG negative).
716 If no prefix ARG and at end of line, the previous two characters are
719 (and (null arg) (kotl-mode:eolp) (kotl-mode:forward-char -1))
720 (transpose-subr 'kotl-mode:forward-char (prefix-numeric-value arg)))
722 (defun kotl-mode:transpose-lines (arg)
723 "Exchange current line and previous line, leaving point after both.
724 If no previous line, exchange current with next line.
725 With prefix ARG, take previous line and move it past ARG lines.
726 With prefix ARG = 0, interchange the line that contains point with the line
730 ((and (kotl-mode:first-line-p) (kotl-mode:last-line-p))
731 (error "(kotl-mode:transpose-lines): Only one line in outline"))
733 ;; Transpose current and previous lines or current and next lines, if no
734 ;; previous line. Leave point after both exchanged lines.
736 (let* ((point (point-marker))
737 (mark (set-marker (make-marker)
738 (if (kotl-mode:first-line-p)
739 (kotl-mode:next-line 1)
740 (kotl-mode:previous-line 1)))))
741 (kotl-mode:transpose-lines-internal point mark)
742 (goto-char (max point mark))
743 (kotl-mode:next-line 1)
744 (set-marker mark nil)))
746 ;; Transpose point and mark lines, leaving point on the line of text that
747 ;; originally contained point.
749 (kotl-mode:transpose-lines-internal (point-marker) (hypb:mark-marker t))
750 ;; This is like exchange-point-and-mark, but doesn't activate the
752 (goto-char (prog1 (hypb:mark t)
753 (set-marker (hypb:mark-marker t) (point)))))
755 ;; Move previous line past ARG next lines and leave point after previous
758 (if (kotl-mode:first-line-p)
759 (error "(kotl-mode:transpose-lines): No previous line to transpose"))
760 (kotl-mode:previous-line 1)
761 (let* ((mark (set-marker (make-marker)
762 (save-excursion (kotl-mode:next-line arg))))
763 (line-to-move (kotl-mode:delete-line)))
765 ;; Delete trailing newline if any, ignoring error.
766 (kotl-mode:delete-char 1)
769 (set-marker mark nil)
770 (kotl-mode:finish-of-line)
772 (insert-char ?\ (kcell-view:indent))
773 (insert line-to-move)
774 (kotl-mode:start-of-line)))))
776 (defun kotl-mode:transpose-paragraphs (arg)
777 "Interchange this (or next) paragraph with previous one."
779 (transpose-subr 'kotl-mode:forward-paragraph (prefix-numeric-value arg)))
781 (defun kotl-mode:transpose-sentences (arg)
782 "Interchange this (next) and previous sentence."
784 (transpose-subr 'kotl-mode:forward-sentence (prefix-numeric-value arg)))
786 (defun kotl-mode:transpose-words (arg)
787 "Interchange words around point, leaving point after both words.
788 With prefix ARG, take word before or around point and drag it forward past
789 ARG other words (backward if ARG negative). If ARG is zero, the words around
790 or after point and around or after mark are interchanged."
792 (transpose-subr 'kotl-mode:forward-word (prefix-numeric-value arg)))
794 (defun kotl-mode:zap-to-char (arg char)
795 "Kill up to and including prefix ARG'th occurrence of CHAR.
796 Goes backward if ARG is negative; error if CHAR not found."
797 (interactive "*p\ncZap to char within current cell: ")
799 (function (lambda () (zap-to-char arg char)))))
802 ;;; Editing across kotls
805 (defun kotl-mode:append-cell (contents-cell append-to-cell)
806 "Append CONTENTS-CELL to APPEND-TO-CELL.
807 APPEND-TO-CELL is refilled if neither cell has a no-fill property and
808 kotl-mode:refill-flag is enabled."
810 (let* ((label (kcell-view:label))
811 (hargs:defaults (list label label)))
814 "*+KAppend contents of cell: \n+KAppend contents of cell <%s> to cell: "))))
816 (kotl-mode:goto-cell contents-cell)
817 (let ((contents (kcell-view:contents))
818 (no-fill (kcell-view:get-attr 'no-fill)))
819 (kotl-mode:goto-cell append-to-cell)
820 (if no-fill nil (setq no-fill (kcell-view:get-attr 'no-fill)))
821 (goto-char (kcell-view:end-contents))
822 (let ((fill-prefix (make-string (kcell-view:indent) ?\ )))
825 ;; Append contents of cell beginning on its own line.
826 (insert "\n" fill-prefix))
827 (kview:insert-contents (kcell-view:cell) contents
828 (or no-fill (null kotl-mode:refill-flag))
831 (defun kotl-mode:copy-after (from-cell-ref to-cell-ref child-p)
832 "Copy tree rooted at FROM-CELL-REF to follow tree rooted at TO-CELL-REF.
833 If prefix arg CHILD-P is non-nil, make FROM-CELL-REF the first child of
834 TO-CELL-REF, otherwise make it the sibling following TO-CELL-REF.
836 Leave point at the start of the root cell of the new tree."
838 (let* ((label (kcell-view:label))
839 (hargs:defaults (list label label)))
844 (format "*+KCopy tree: \n+KCopy tree <%%s> to follow as %s of cell: "
845 (if current-prefix-arg "child" "sibling"))))
846 (list current-prefix-arg))))
848 ;; Copy tree in current view and leave point at the start of the copy.
849 (goto-char (kotl-mode:move-after from-cell-ref to-cell-ref child-p t))
850 ;; Alter the copied tree so each cell appears to be newly created.
855 (kcell:create nil (kview:id-increment view)))))
858 (defun kotl-mode:copy-before (from-cell-ref to-cell-ref parent-p)
859 "Copy tree rooted at FROM-CELL-REF to precede tree rooted at TO-CELL-REF.
860 If prefix arg PARENT-P is non-nil, make FROM-CELL-REF the first child of
861 TO-CELL-REF's parent, otherwise make it the preceding sibling of TO-CELL-REF.
863 Leave point at the start of the root cell of the new tree."
865 (let* ((label (kcell-view:label))
866 (hargs:defaults (list label label)))
870 (format "*+KCopy tree: \n+KCopy tree <%%s> to be %s of cell: "
871 (if current-prefix-arg "first child of parent"
872 "preceding sibling"))))
873 (list current-prefix-arg))))
875 ;; Copy tree in current view and leave point at the start of the copy.
876 (goto-char (kotl-mode:move-before from-cell-ref to-cell-ref parent-p t))
877 ;; Alter the copied tree so each cell appears to be newly created.
882 (kcell:create nil (kview:id-increment view)))))
885 (defun kotl-mode:copy-to-buffer (cell-ref buffer invisible-flag)
886 "Copy outline tree rooted at CELL-REF to a non-koutline BUFFER.
887 Invisible text is expanded and included in the copy only if INVISIBLE-FLAG is
888 non-nil. The tree is inserted before point in BUFFER. Use \"0\" to copy the
889 whole outline buffer."
891 (let ((label-default (kcell-view:label)))
895 (hargs:read "Copy tree without attributes: (0 for whole outline) "
896 nil label-default nil 'kcell)
897 (read-buffer "To buffer: "
898 (save-window-excursion
900 (select-frame (next-frame))
904 (y-or-n-p "Copy invisible text? "))))))
905 (message "") ;; Erase last interactive prompt, if any.
906 (setq buffer (get-buffer-create buffer))
907 (if (equal cell-ref "0")
908 (hypb:insert-region buffer (point-min) (point-max) invisible-flag)
911 (kotl-mode:goto-cell cell-ref t)
912 (save-excursion (beginning-of-line) (setq start (point)))
913 (setq end (kotl-mode:tree-end)))
914 (hypb:insert-region buffer start end invisible-flag))))
916 (defun kotl-mode:move-after (from-cell-ref to-cell-ref child-p
917 &optional copy-p fill-p)
918 "Move tree rooted at FROM-CELL-REF to follow tree rooted at TO-CELL-REF.
919 If prefix arg CHILD-P is non-nil, make FROM-CELL-REF the first child of
920 TO-CELL-REF, otherwise make it the sibling following TO-CELL-REF.
921 With optional COPY-P, copies tree rather than moving it.
923 Leave point at original location but return the tree's new start point."
925 (let* ((label (kcell-view:label))
926 (hargs:defaults (list label label)))
931 (format "*+KMove tree: \n+KMove tree <%%s> to follow as %s of cell: "
932 (if current-prefix-arg "child" "sibling"))))
933 (list current-prefix-arg))))
934 (if (and (not copy-p) (equal from-cell-ref to-cell-ref))
935 (error "(kotl-mode:move-after): Can't move tree after itself"))
936 (let* ((orig (set-marker (make-marker) (point)))
937 (label-sep-len (kview:label-separator-length kview))
938 (move-to-point (set-marker
940 (kotl-mode:goto-cell to-cell-ref t)))
941 (to-label (kcell-view:label))
942 (to-indent (kcell-view:indent nil label-sep-len))
943 (from-label (progn (kotl-mode:goto-cell from-cell-ref t)
945 (from-indent (kcell-view:indent nil label-sep-len))
946 (start (kotl-mode:tree-start))
947 (end (kotl-mode:tree-end))
948 (sib-id (if (= 0 (kotl-mode:forward-cell 1))
949 (kcell-view:idstamp)))
952 ;; We can't move a tree to a point within itself, so if that is the case
953 ;; and this is not a copy operation, signal an error.
954 (if (and (not copy-p) (>= move-to-point start) (<= move-to-point end))
955 (error "(kotl-mode:move-after): Can't move tree <%s> to within itself"
958 ;; If tree to move has a sibling, point is now at the start of the
959 ;; sibling cell. Mark its label with a property which will be deleted
960 ;; whenever the cell label is renumbered. This tells us whether or not
961 ;; to renumber the sibling separately from the tree to move.
963 ;; Move to middle of label and insert klabel-original temp property.
964 (progn (goto-char (- (point) label-sep-len 3))
965 (kproperty:set 'klabel-original t)))
967 ;; Position for insertion before deletion of tree-to-move from old
968 ;; position, in case old position precedes new one.
969 ;; Skip past either cell or tree at move-to-point.
970 (goto-char move-to-point)
972 ;; Move to insert position for first child of to-cell-ref.
973 (progn (goto-char (kcell-view:end))
974 (setq to-label (klabel:child to-label)
975 to-indent (+ to-indent (kview:level-indent kview))))
976 ;; Move to after to-cell-ref's tree for insertion as following sibling.
977 (goto-char (kotl-mode:tree-end))
978 (setq to-label (klabel:increment to-label)))
980 ;; Insert tree-to-move at new location
982 (kview:move start end (point) from-indent to-indent copy-p
983 (or fill-p kotl-mode:refill-flag))
985 ;; Ensure that point is within editable region of cell with to-label.
986 (kotl-mode:to-valid-position)
987 (setq new-tree-start (point))
989 ;; Update current cell and new siblings' labels within view.
990 (klabel-type:update-labels to-label)
995 ;; Move to sibling of tree-to-move within view and update labels within
996 ;; view of tree-to-move's original siblings.
998 (progn (kotl-mode:goto-cell sib-id t)
999 ;; Sibling labels may have already been updated if tree was
1000 ;; moved somewhere preceding its siblings.
1001 (let ((label-middle (- (point) label-sep-len 2)))
1002 (if (kproperty:get label-middle 'klabel-original)
1003 (klabel-type:update-labels from-label))))))
1007 ;; Ensure that point is within editable region of a cell.
1008 (kotl-mode:to-valid-position)
1010 (set-marker orig nil)
1011 (set-marker move-to-point nil)
1014 (defun kotl-mode:move-before (from-cell-ref to-cell-ref parent-p
1015 &optional copy-p fill-p)
1016 "Move tree rooted at FROM-CELL-REF to precede tree rooted at TO-CELL-REF.
1017 If prefix arg PARENT-P is non-nil, make FROM-CELL-REF the first child of
1018 TO-CELL-REF's parent, otherwise make it the preceding sibling of TO-CELL-REF.
1019 With optional COPY-P, copies tree rather than moving it.
1021 Leave point at original location but return the tree's new start point."
1023 (let* ((label (kcell-view:label))
1024 (hargs:defaults (list label label)))
1028 (format "*+KMove tree: \n+KMove tree <%%s> to be %s of cell: "
1029 (if current-prefix-arg "first child of parent"
1030 "preceding sibling"))))
1031 (list current-prefix-arg))))
1032 (if (and (not copy-p) (equal from-cell-ref to-cell-ref))
1033 (error "(kotl-mode:move-before): Can't move tree before itself"))
1034 (let* ((orig (set-marker (make-marker) (point)))
1035 (label-sep-len (kview:label-separator-length kview))
1036 (move-to-point (set-marker
1038 (kotl-mode:goto-cell to-cell-ref t)))
1039 (to-label (kcell-view:label))
1040 (to-indent (kcell-view:indent nil label-sep-len))
1041 (from-label (progn (kotl-mode:goto-cell from-cell-ref t)
1042 (kcell-view:label)))
1043 (from-indent (kcell-view:indent nil label-sep-len))
1044 (start (kotl-mode:tree-start))
1045 (end (kotl-mode:tree-end))
1046 (sib-id (if (= 0 (kotl-mode:forward-cell 1))
1047 (kcell-view:idstamp)))
1050 ;; We can't move a tree to a point within itself, so if that is the case
1051 ;; and this is not a copy operation, signal an error.
1052 (if (and (not copy-p) (>= move-to-point start) (<= move-to-point end))
1053 (error "(kotl-mode:move-before): Can't move tree <%s> to within itself"
1056 ;; If tree to move has a sibling, point is now at the start of the
1057 ;; sibling cell. Mark its label with a property which will be deleted
1058 ;; whenever the cell label is renumbered. This tells us whether or not
1059 ;; to renumber the sibling separately from the tree to move.
1061 ;; Move to middle of label and insert klabel-original temp property.
1062 (progn (goto-char (- (point) label-sep-len 3))
1063 (kproperty:set 'klabel-original t)))
1065 ;; Position for insertion at succeeding-tree, before deletion of
1066 ;; tree-to-move from old position, in case old position precedes new one.
1067 (goto-char move-to-point)
1069 ;; Move to insert position for first child of to-cell-ref's parent.
1070 (if (kcell-view:parent nil label-sep-len)
1071 (progn (setq to-label (klabel:child (kcell-view:label)))
1072 (goto-char (kcell-view:end)))
1073 (error "(kotl-mode:move-before): to-cell-ref's parent not in current view"))
1074 ;; Move to before to-cell-ref for insertion as preceding sibling.
1075 (goto-char (kotl-mode:tree-start)))
1077 ;; Insert tree-to-move at new location
1079 (kview:move start end (point) from-indent to-indent copy-p
1080 (or fill-p kotl-mode:refill-flag))
1082 ;; Ensure that point is within editable region of root of tree just moved.
1083 (kotl-mode:to-valid-position)
1084 (setq new-tree-start (point))
1086 ;; Update current cell and new siblings' labels within view.
1087 (klabel-type:update-labels to-label)
1092 ;; Move to sibling of tree-to-move within view and update labels within
1093 ;; view of tree-to-move's original siblings.
1096 (kotl-mode:goto-cell sib-id t)
1097 ;; Sibling labels may have already been updated if tree was
1098 ;; moved somewhere preceding its siblings.
1099 (let ((label-middle (- (point) label-sep-len 2)))
1100 (if (kproperty:get label-middle 'klabel-original)
1101 (klabel-type:update-labels from-label))))))
1105 ;; Ensure that point is within editable region of a cell.
1106 (kotl-mode:to-valid-position)
1108 (set-marker orig nil)
1109 (set-marker move-to-point nil)
1112 (defun kotl-mode:yank (&optional arg)
1113 "Reinsert the last stretch of killed text.
1114 More precisely, reinsert the stretch of killed text most recently
1115 killed OR yanked. Put point at end, and set mark at beginning.
1116 With just C-u as argument, same but put point at beginning (and mark at end).
1117 With argument N, reinsert the Nth most recently killed stretch of killed
1119 See also the command \\[kotl-mode:yank-pop]."
1122 (let* ((yank-text (current-kill (cond
1126 (indent (kcell-view:indent))
1127 (indent-str (make-string indent ?\ )))
1128 ;; Convert all occurrences of newline to newline + cell indent.
1129 ;; Then insert into buffer.
1130 (insert (hypb:replace-match-string
1131 "[\n\r]" yank-text (concat "\\0" indent-str))))
1133 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1134 ;; It is cleaner to avoid activation, even though the command
1135 ;; loop would deactivate the mark because we inserted text.
1136 (goto-char (prog1 (mark t)
1137 (set-marker (hypb:mark-marker t) (point)))))
1140 (defun kotl-mode:yank-pop (arg)
1141 "Replace just-yanked stretch of killed text with a different stretch.
1142 This command is allowed only immediately after a `yank' or a `yank-pop'.
1143 At such a time, the region contains a stretch of reinserted
1144 previously-killed text. `yank-pop' deletes that text and inserts in its
1145 place a different stretch of killed text.
1147 With no argument, the previous kill is inserted.
1148 With argument N, insert the Nth previous kill.
1149 If N is negative, this is a more recent kill.
1151 The sequence of kills wraps around, so that after the oldest one
1152 comes the newest one."
1154 (if (not (eq last-command 'kotl-mode:yank))
1155 (error "Previous command was not a yank"))
1156 (setq this-command 'kotl-mode:yank)
1157 (let ((before (< (point) (mark t))))
1158 (delete-region (point) (mark t))
1159 (set-marker (hypb:mark-marker t) (point) (current-buffer))
1160 (let* ((yank-text (current-kill arg))
1161 (indent (kcell-view:indent))
1162 (indent-str (make-string indent ?\ )))
1163 ;; Convert all occurrences of newline to newline + cell indent.
1164 ;; Then insert into buffer.
1165 (insert (hypb:replace-match-string
1166 "[\n\r]" yank-text (concat "\\0" indent-str))))
1168 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1169 ;; It is cleaner to avoid activation, even though the command
1170 ;; loop would deactivate the mark because we inserted text.
1171 (goto-char (prog1 (mark t)
1172 (set-marker (hypb:mark-marker t) (point) (current-buffer))))))
1179 ;;; Cursor and keypad key functions aliases for XEmacs.
1180 (if (not (string-match "XEmacs\\|Lucid" emacs-version))
1182 (fset 'kotl-mode:fkey-backward-char 'kotl-mode:backward-char)
1183 (fset 'kotl-mode:fkey-forward-char 'kotl-mode:forward-char)
1184 (fset 'kotl-mode:fkey-next-line 'kotl-mode:next-line)
1185 (fset 'kotl-mode:fkey-previous-line 'kotl-mode:previous-line)
1186 (fset 'kotl-mode:deprecated-scroll-down 'kotl-mode:scroll-down)
1187 (fset 'kotl-mode:deprecated-scroll-up 'kotl-mode:scroll-up)
1188 (fset 'kotl-mode:deprecated-bob 'kotl-mode:beginning-of-buffer)
1189 (fset 'kotl-mode:deprecated-eob 'kotl-mode:end-of-buffer))
1191 (defun kotl-mode:back-to-indentation ()
1192 "Move point to the first non-read-only non-whitespace character on this line."
1194 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1195 (back-to-indentation)
1196 (kotl-mode:to-valid-position))
1198 (defun kotl-mode:backward-cell (arg)
1199 "Move to prefix ARGth prior visible cell (same level) within current view.
1200 Return number of cells left to move."
1202 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1204 (kotl-mode:forward-cell (- arg))
1205 (let ((prior (= arg 0))
1206 (label-sep-len (kview:label-separator-length kview)))
1207 (while (and (> arg 0) (setq prior (kcell-view:backward t label-sep-len)))
1208 (setq arg (1- arg)))
1209 (if (or prior (not (interactive-p)))
1211 (error "(kotl-mode:backward-cell): No prior cell at same level")))))
1213 (defun kotl-mode:backward-char (&optional arg)
1214 "Move point backward ARG (or 1) characters and return point."
1216 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1217 (or arg (setq arg 1))
1220 (cond ((kotl-mode:bobp)
1221 (error "(kotl-mode:backward-char): Beginning of buffer"))
1223 (if (kcell-view:previous)
1224 (kotl-mode:end-of-cell)))
1226 (if (re-search-backward "[\n\r]" nil t)
1227 (kotl-mode:to-valid-position t)))
1228 (t (backward-char)))
1229 (setq arg (1- arg)))
1230 (kotl-mode:forward-char (- arg)))
1233 (defun kotl-mode:backward-paragraph (&optional arg)
1234 "Move backward to start of paragraph.
1235 With arg N, do it N times; negative arg -N means move forward N paragraphs.
1238 A paragraph start is the beginning of a line which is a
1239 `first-line-of-paragraph' or which is ordinary text and follows a
1240 paragraph-separating line.
1242 See `forward-paragraph' for more information."
1244 (setq arg (prefix-numeric-value arg)
1245 zmacs-region-stays t);; Maintain region highlight for XEmacs.
1246 (kotl-mode:forward-paragraph (- arg)))
1248 (fset 'kotl-mode:backward-para 'kotl-mode:backward-paragraph)
1250 (defun kotl-mode:backward-sentence (&optional arg)
1251 "Move point backward ARG (or 1) sentences and return point."
1253 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1254 (let* ((label-sep-len (kview:label-separator-length kview))
1255 ;; Setting fill prefix makes sentence commands properly recognize
1256 ;; indented paragraphs.
1257 (fill-prefix (make-string (kcell-view:indent nil label-sep-len) ?\ )))
1258 (if (kotl-mode:bobp)
1259 (error "(kotl-mode:backward-sentence): First sentence")
1260 (if (and (kotl-mode:bocp) (kcell-view:previous nil label-sep-len))
1261 (goto-char (kcell-view:end-contents)))
1262 (or arg (setq arg 1))
1266 (- (kcell-view:start nil label-sep-len)
1267 (kcell-view:indent nil label-sep-len))
1268 (kcell-view:end-contents)))
1270 (let ((opoint (point)))
1271 (backward-sentence arg)
1272 (if (= opoint (point))
1273 (progn (kcell-view:previous nil label-sep-len)
1274 (backward-sentence arg))))
1275 (kotl-mode:to-valid-position t)))))
1278 (defun kotl-mode:backward-word (&optional arg)
1279 "Move point backward ARG (or 1) words and return point."
1281 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1282 (or arg (setq arg 1))
1285 (cond ((kotl-mode:bobp) (setq arg 0))
1288 (kotl-mode:to-valid-position t)))
1291 (kotl-mode:to-valid-position t))
1292 (setq arg (1- arg)))
1293 (kotl-mode:forward-word (- arg)))
1296 (defun kotl-mode:beginning-of-buffer ()
1297 "Move point to beginning of buffer and return point."
1299 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1300 (goto-char (point-min))
1301 ;; To move to cell start.
1302 (goto-char (kcell-view:start)))
1304 (defun kotl-mode:beginning-of-cell (&optional arg)
1305 "Move point to beginning of current or ARGth - 1 prior cell and return point."
1307 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1308 (or arg (setq arg 1))
1309 (or (integer-or-marker-p arg)
1310 (error "(kotl-mode:beginning-of-cell): Wrong type arg, integer-or-marker, '%s'" arg))
1312 (goto-char (kcell-view:start))
1313 (kotl-mode:backward-cell (1- arg)))
1316 ;;; Avoid XEmacs byte-compiler bug which inserts nil for calls to this
1317 ;;; function if named kotl-mode:beginning-of-line.
1319 (defun kotl-mode:start-of-line (&optional arg)
1320 "Move point to beginning of current or ARGth - 1 line and return point."
1322 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1323 (or arg (setq arg 1))
1324 (or (integer-or-marker-p arg)
1325 (error "(kotl-mode:start-of-line): Wrong type arg, integer-or-marker, '%s'" arg))
1326 (forward-line (1- arg))
1329 (forward-char (prog1 (kcell-view:indent)
1330 (beginning-of-line))))
1333 (defalias 'kotl-mode:beginning-of-line 'kotl-mode:start-of-line)
1335 (defun kotl-mode:beginning-of-tree ()
1336 "Move point to the level 1 root of the current cell's tree.
1337 Leave point at the start of the cell."
1339 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1340 (let ((label-sep-len (kview:label-separator-length kview)))
1341 (if (/= (kcell-view:level nil label-sep-len) 1)
1342 ;; Enable user to return to this previous position if desired.
1343 (push-mark nil 'no-msg))
1344 (while (and (/= (kcell-view:level nil label-sep-len) 1)
1345 (kcell-view:parent nil label-sep-len)))
1346 (kotl-mode:beginning-of-cell)))
1348 (defun kotl-mode:down-level (arg)
1349 "Move down prefix ARG levels lower within current tree."
1351 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1353 (kotl-mode:up-level (- arg))
1354 ;; Enable user to return to this previous position if desired.
1355 (push-mark nil 'no-msg)
1357 (while (and (> arg 0) (kcell-view:child))
1358 (or child (setq child t))
1359 (setq arg (1- arg)))
1360 ;; Signal an error if couldn't move down at least 1 child level.
1363 (goto-char (hypb:mark t))
1365 (error "(kotl-mode:down-level): No child level to which to move")
1368 (defun kotl-mode:end-of-buffer ()
1369 "Move point to end of buffer and return point."
1371 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1372 (goto-char (point-max))
1373 ;; To move to cell end.
1374 (kotl-mode:to-valid-position t)
1377 (defun kotl-mode:end-of-cell (&optional arg)
1378 "Move point to end of current or ARGth - 1 succeeding cell and return point."
1380 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1381 (or arg (setq arg 1))
1382 (or (integer-or-marker-p arg)
1383 (error "(kotl-mode:end-of-cell): Wrong type arg, integer-or-marker, '%s'" arg))
1385 (goto-char (kcell-view:end-contents))
1386 (kotl-mode:forward-cell (1- arg)))
1389 ;;; Avoid XEmacs byte-compiler bug which inserts nil for calls to this
1390 ;;; function if named kotl-mode:end-of-line.
1392 (defun kotl-mode:finish-of-line (&optional arg)
1393 "Move point to end of current or ARGth - 1 line and return point."
1395 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1396 (or arg (setq arg 1))
1397 (or (integer-or-marker-p arg)
1398 (error "(kotl-mode:finish-of-line): Wrong type arg, integer-or-marker, '%s'" arg))
1399 (forward-line (1- arg))
1401 ;; May have to move backwards to before label if support labels
1405 (defalias 'kotl-mode:end-of-line 'kotl-mode:finish-of-line)
1407 (defun kotl-mode:end-of-tree ()
1408 "Move point to the last cell in tree rooted at the current cell.
1409 Leave point at the start of the cell."
1411 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1412 ;; Enable user to return to this previous position if desired.
1413 (push-mark nil 'no-msg)
1414 (let ((label-sep-len (kview:label-separator-length kview)))
1415 (if (kcell-view:forward nil label-sep-len)
1416 ;; Move to cell preceding start of next tree.
1417 (kcell-view:previous nil label-sep-len)
1418 ;; Otherwise, no next tree, so move until find last cell in tree.
1419 (let ((cell-indent (kcell-view:indent nil label-sep-len))
1420 (end-point (point)))
1421 ;; Terminate when no further cells or when reach a cell at an equal
1422 ;; or higher level in the outline than the first cell that we
1424 (while (and (kcell-view:next nil label-sep-len)
1425 (> (kcell-view:indent nil label-sep-len) cell-indent))
1426 (setq end-point (point)))
1427 (goto-char end-point)))
1428 (kotl-mode:beginning-of-cell)))
1430 (defun kotl-mode:first-sibling ()
1431 "Move point to the first sibling of the present cell.
1432 Leave point at the start of the cell or at its present position if it is
1433 already within the first sibling cell."
1435 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1436 (let ((label-sep-len (kview:label-separator-length kview)))
1437 (if (save-excursion (kcell-view:backward nil label-sep-len))
1438 ;; Enable user to return to this previous position if desired.
1439 (push-mark nil 'no-msg))
1440 (while (kcell-view:backward nil label-sep-len))))
1442 (defun kotl-mode:forward-cell (arg)
1443 "Move to prefix ARGth following cell (same level) within current view.
1444 Return number of cells left to move."
1446 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1448 (kotl-mode:backward-cell (- arg))
1449 (let ((next (= arg 0))
1450 (label-sep-len (kview:label-separator-length kview)))
1451 (while (and (> arg 0) (setq next (kcell-view:forward t label-sep-len)))
1452 (setq arg (1- arg)))
1453 (if (or next (not (interactive-p)))
1455 (error "(kotl-mode:forward-cell): No following cell at same level")))))
1457 (defun kotl-mode:forward-char (&optional arg)
1458 "Move point forward ARG (or 1) characters and return point."
1460 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1461 (or arg (setq arg 1))
1464 (cond ((and (kotl-mode:eolp) (kotl-mode:last-line-p))
1465 (error "(kotl-mode:forward-char): End of buffer"))
1467 (skip-chars-forward "\n\r")
1468 (kotl-mode:start-of-line))
1471 (kotl-mode:start-of-line))
1473 (setq arg (1- arg)))
1474 (kotl-mode:backward-char (- arg)))
1477 (defun kotl-mode:forward-paragraph (&optional arg)
1478 "Move point forward until after the last character of the current paragraph.
1479 With arg N, do it N times; negative arg -N means move backward N paragraphs.
1482 A line which `paragraph-start' matches either separates paragraphs
1483 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
1484 A paragraph end is one character before the beginning of a line which is not
1485 part of the paragraph, or the end of the buffer."
1487 (setq arg (prefix-numeric-value arg)
1488 zmacs-region-stays t);; Maintain region highlight for XEmacs.
1491 (if (kotl-mode:bocp) (setq arg (1- arg)))
1493 (start-of-paragraph-text)
1494 (setq arg (1+ arg))))
1496 (end-of-paragraph-text)
1497 (setq arg (1- arg))))
1498 (kotl-mode:to-valid-position)
1501 (fset 'kotl-mode:forward-para 'kotl-mode:forward-paragraph)
1503 (defun kotl-mode:forward-sentence (&optional arg)
1504 "Move point forward ARG (or 1) sentences and return point."
1506 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1507 (let* ((label-sep-len (kview:label-separator-length kview))
1508 ;; Setting fill prefix makes sentence commands properly recognize
1509 ;; indented paragraphs.
1510 (fill-prefix (make-string (kcell-view:indent nil label-sep-len) ?\ )))
1511 (if (kotl-mode:eobp)
1512 (error "(kotl-mode:forward-sentence): Last sentence")
1513 (if (kotl-mode:eocp) (kcell-view:next nil label-sep-len))
1514 (or arg (setq arg 1))
1518 (- (kcell-view:start nil label-sep-len)
1519 (kcell-view:indent nil label-sep-len))
1520 (kcell-view:end-contents)))
1522 (let ((opoint (point)))
1523 (forward-sentence arg)
1524 (if (= opoint (point))
1525 (progn (kcell-view:next nil label-sep-len)
1526 (forward-sentence arg))))
1527 (kotl-mode:to-valid-position)))))
1530 (defun kotl-mode:forward-word (&optional arg)
1531 "Move point forward ARG (or 1) words and return point."
1533 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1534 (or arg (setq arg 1))
1537 (cond ((kotl-mode:eobp) (setq arg 0))
1539 (skip-chars-forward "\n\r")
1540 (kotl-mode:start-of-line)))
1543 (kotl-mode:to-valid-position))
1544 ;; If point is at beginning of a cell after moving forward a word,
1545 ;; then we moved over something other than a word (some
1546 ;; punctuation or an outline autonumber); therefore, leave counter as
1547 ;; is in order to move forward over next word.
1548 (or (kotl-mode:bocp)
1549 (setq arg (1- arg))))
1550 (kotl-mode:backward-word (- arg)))
1553 (defun kotl-mode:goto-cell (cell-ref &optional error-p)
1554 "Move point to start of cell given by CELL-REF. (See 'kcell:ref-to-id'.)
1555 Return point iff CELL-REF is found within current view.
1556 With a prefix argument, CELL-REF is assigned the argument value for use
1559 Optional second arg, ERROR-P, non-nil means signal an error if CELL-REF is
1560 not found within current view. Will signal same error if called
1561 interactively when CELL-REF is not found."
1563 (list (if current-prefix-arg
1564 (format "0%d" (prefix-numeric-value current-prefix-arg))
1565 (read-string "Goto cell label or id: "))))
1567 (or (kcell:ref-to-id cell-ref)
1568 (error "(kotl-mode:goto-cell): Invalid cell reference, '%s'" cell-ref)))
1569 (let* ((opoint (point))
1572 (if (= ?| (aref cell-ref 0))
1573 ;; This is a standalone view spec, not a cell reference.
1574 (progn (kvspec:activate cell-ref) (setq found (point)))
1576 ;; !! Remove any relative specs and view specs from
1577 ;; cell-ref to form cell-id. Really should account for relative
1578 ;; specs here, but we don't yet support them.
1579 (if (string-match "\\(\\.[a-zA-Z]+\\)?\\([|:].*\\)\\|\\.[a-zA-Z]+"
1581 (setq cell-id (substring cell-ref 0 (match-beginning 0))
1582 kvspec (if (match-beginning 2)
1584 cell-ref (match-beginning 2) (match-end 2))))
1585 (setq cell-id cell-ref kvspec nil))
1587 (goto-char (point-min))
1588 (cond ((= ?0 (aref cell-id 0))
1590 (if (kview:goto-cell-id cell-id)
1591 (setq found (point))))
1594 (format "\\([\n\r][\n\r]\\|\\`\\)[ ]*%s%s"
1595 (regexp-quote cell-id)
1596 (regexp-quote (kview:label-separator kview)))
1598 (setq found (point)))
1600 (t (goto-char opoint)
1602 (if (and (not found) (or error-p (interactive-p)))
1603 (error "(kotl-mode:goto-cell): No '%s' cell in this view" cell-ref)
1604 ;; Activate any viewspec associated with cell-ref.
1605 (if kvspec (kvspec:activate kvspec))))
1608 (defun kotl-mode:head-cell ()
1609 "Move point to the start of the first visible cell at the same level as current cell.
1610 If at head cell already, do nothing and return nil."
1612 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1614 (label-sep-len (kview:label-separator-length kview)))
1615 (while (kcell-view:backward t label-sep-len)
1619 (defun kotl-mode:last-sibling ()
1620 "Move point to the last sibling of the present cell.
1621 Leave point at the start of the cell or at its present position if it is
1622 already within the last sibling cell."
1624 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1625 (let ((label-sep-len (kview:label-separator-length kview)))
1626 (if (save-excursion (kcell-view:forward nil label-sep-len))
1627 ;; Enable user to return to this previous position if desired.
1628 (push-mark nil 'no-msg))
1629 (while (kcell-view:forward nil label-sep-len))))
1631 (defun kotl-mode:mark-paragraph ()
1632 "Put point at beginning of this paragraph, mark at end.
1633 The paragraph marked is the one that contains point or follows point."
1635 (forward-paragraph 1)
1636 (kotl-mode:to-valid-position t)
1637 (hypb:push-mark nil t t)
1638 (backward-paragraph 1)
1639 (kotl-mode:to-valid-position))
1641 (defun kotl-mode:mark-whole-buffer ()
1642 "Put point at first editable character in buffer and mark at the last such character."
1644 (hypb:push-mark (point))
1645 (kotl-mode:end-of-buffer)
1646 (hypb:push-mark (point) nil t)
1647 (kotl-mode:beginning-of-buffer))
1649 (defun kotl-mode:next-cell (arg)
1650 "Move to prefix ARGth next cell (any level) within current view."
1652 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1654 (kotl-mode:previous-cell (- arg))
1655 (let ((next (= arg 0))
1656 (label-sep-len (kview:label-separator-length kview)))
1657 (while (and (> arg 0) (setq next (kcell-view:next t label-sep-len)))
1658 (setq arg (1- arg)))
1661 (error "(kotl-mode:next-cell): Last cell")))))
1663 (defun kotl-mode:next-line (arg)
1664 "Move point to ARGth next line and return point."
1666 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1667 (kotl-mode:set-temp-goal-column)
1668 (let ((orig-arg arg))
1670 (while (and (> arg 0) (= 0 (forward-line 1)))
1671 (cond ((kotl-mode:eobp)
1673 (goto-char (kcell-view:end-contents))
1674 (and (interactive-p) (= orig-arg arg)
1675 (message "(kotl-mode:next-line): Last line") (beep))
1678 ((looking-at "^$");; blank line between cells
1679 nil);; Don't count this line.
1680 (t (setq arg (1- arg)))))
1681 (kotl-mode:line-move 0)
1682 (kotl-mode:to-valid-position)
1685 (kotl-mode:previous-line (- arg)))
1687 (setq this-command 'next-line)
1690 (defun kotl-mode:next-tree ()
1691 "Move past current tree to next tree, or to last cell in tree if no next tree.
1692 Return non-nil iff there is a next tree within this koutline."
1693 (let ((start-indent (kcell-view:indent))
1694 (label-sep-len (kview:label-separator-length kview))
1696 (while (and (kcell-view:next nil label-sep-len)
1697 (setq same-tree (< start-indent
1698 (kcell-view:indent nil label-sep-len)))))
1701 (defun kotl-mode:previous-line (arg)
1702 "Move point to ARGth previous line and return point."
1704 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1705 (kotl-mode:set-temp-goal-column)
1707 (while (and (> arg 0) (= 0 (forward-line -1)))
1708 (cond ((kotl-mode:bobp)
1709 (kotl-mode:beginning-of-cell)
1711 ((looking-at "^$") ;; blank line between cells
1712 nil) ;; Don't count this line.
1713 (t (setq arg (1- arg)))))
1714 (kotl-mode:line-move 0)
1715 (kotl-mode:to-valid-position)
1718 (kotl-mode:next-line (- arg)))
1720 (setq this-command 'previous-line)
1723 (defun kotl-mode:previous-cell (arg)
1724 "Move to prefix ARGth previous cell (any level) within current view."
1726 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1728 (kotl-mode:next-cell (- arg))
1729 (let ((previous (= arg 0))
1730 (label-sep-len (kview:label-separator-length kview)))
1731 (while (and (> arg 0) (setq previous
1732 (kcell-view:previous t label-sep-len)))
1733 (setq arg (1- arg)))
1736 (error "(kotl-mode:previous-cell): First cell")))))
1738 (defun kotl-mode:scroll-down (arg)
1739 "Scroll text of current window downward ARG lines; or a windowful if no ARG."
1741 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1743 (kotl-mode:to-valid-position t))
1745 (defun kotl-mode:scroll-up (arg)
1746 "Scroll text of current window upward ARG lines; or a windowful if no ARG."
1748 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1750 (kotl-mode:to-valid-position))
1752 (defun kotl-mode:tail-cell ()
1753 "Move point to the start of the last visible cell at the same level as current cell and return t.
1754 If at tail cell already, do nothing and return nil."
1756 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1758 (label-sep-len (kview:label-separator-length kview)))
1759 (while (kcell-view:forward t label-sep-len)
1763 (defun kotl-mode:up-level (arg)
1764 "Move up prefix ARG levels higher in current outline view."
1766 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
1768 (kotl-mode:down-level (- arg))
1769 ;; Enable user to return to this previous position if desired.
1770 (push-mark nil 'no-msg)
1772 (label-sep-len (kview:label-separator-length kview))
1774 (while (and (> arg 0) (setq result (kcell-view:parent t label-sep-len)))
1775 (or parent (setq parent result))
1776 (setq arg (if (eq result 0) 0 (1- arg))))
1777 ;; Signal an error if couldn't move up at least 1 parent level.
1778 (or (and parent (not (eq parent 0)))
1780 (goto-char (hypb:mark t))
1782 (error "(kotl-mode:up-level): No parent level to which to move")
1789 (defun kotl-mode:bobp ()
1790 "Return point if at the start of the first cell in kview, else nil."
1793 (and (not (save-excursion (re-search-backward "[\n\r]" nil t)))
1796 (defun kotl-mode:bocp ()
1797 "Return point if at beginning of a kcell, else nil."
1798 (and (kotl-mode:bolp)
1799 (let ((begin-point (kcell-view:plist-point))
1803 ;; If first line-begin is less than cell begin point,
1804 ;; then we know we are on the first line of the cell.
1805 (if (setq bol (re-search-backward "^" nil t))
1806 (<= bol begin-point)))))
1809 (defun kotl-mode:bolp ()
1810 "Return point if at beginning of a kview line, else nil."
1811 (if (= (current-column) (kcell-view:indent))
1814 (defun kotl-mode:buffer-empty-p ()
1815 "Return non-nil iff there are no outline cells within current buffer."
1817 (goto-char (point-min))
1818 (looking-at "[\n\r]*\\'")))
1820 (defun kotl-mode:eobp ()
1821 "Return point if after the end of the last cell in kview, else nil."
1823 (if (looking-at "^[\n\r]*\\'") (point)))
1825 (defun kotl-mode:eocp ()
1826 "Return point if at the end of a kview cell, else nil."
1828 (looking-at "[\n\r]+\\'")
1831 (skip-chars-forward "\n\r")
1832 (kotl-mode:start-of-line)
1833 (kotl-mode:bocp)))))
1835 (fset 'kotl-mode:eolp 'eolp)
1837 (defun kotl-mode:first-cell-p ()
1838 "Return t iff point is on the first cell of the outline."
1839 (save-excursion (not (kcell-view:previous))))
1841 (fset 'kotl-mode:first-line-p 'first-line-p)
1843 (defun kotl-mode:last-cell-p ()
1844 "Return t iff point is on the last cell of the outline."
1845 (save-excursion (not (kcell-view:next))))
1847 (defun kotl-mode:last-line-p ()
1848 "Return t iff point is on the last line of the outline."
1850 (kotl-mode:finish-of-line)
1851 (looking-at "\n*\\'")))
1854 ;;; Smart Key Support
1858 (defun kotl-mode:action-key ()
1859 "Collapses, expands, links to, and scrolls through koutline cells.
1860 Invoked via a key press when in kotl-mode. It assumes that its caller has
1861 already checked that the key was pressed in an appropriate buffer and has
1862 moved the cursor to the selected buffer.
1865 (1) at the end of buffer, uncollapse and unhide all cells in view;
1866 (2) within a cell, if its subtree is hidden then show it,
1868 (3) between cells or within the read-only indentation region to the left of
1869 a cell, then move point to prior location and begin creation of a
1870 klink to some other outline cell; hit the Action Key twice to select the
1872 (4) anywhere else, scroll up a windowful."
1874 (cond ((kotl-mode:eobp) (kotl-mode:show-all))
1875 ((kotl-mode:eolp) (smart-scroll-up))
1876 ((not (kview:valid-position-p))
1877 (if (markerp action-key-depress-prev-point)
1878 (progn (select-window
1880 (marker-buffer action-key-depress-prev-point)))
1881 (goto-char (marker-position action-key-depress-prev-point))
1882 (call-interactively 'klink:create))
1883 (kotl-mode:to-valid-position)
1884 (error "(kotl-mode:action-key): Action Key released at invalid position")))
1885 (t ;; On a cell line (not at the end of line).
1886 (if (smart-outline-subtree-hidden-p)
1887 (kotl-mode:show-tree (kcell-view:label))
1888 (kotl-mode:hide-tree (kcell-view:label)))))
1889 (kotl-mode:to-valid-position))
1891 (defun kotl-mode:help-key ()
1892 "Displays properties of koutline cells, collapses all cells, and scrolls back.
1893 Invoked via an assist-key press when in kotl-mode. It assumes that its caller
1894 has already checked that the assist-key was pressed in an appropriate buffer
1895 and has moved the cursor to the selected buffer.
1897 If assist-key is pressed:
1898 (1) at the end of buffer, collapse all cells and hide all non-level-one
1900 (2) on a header line but not at the beginning or end, display properties of
1901 each cell in tree beginning at point;
1902 (3) between cells or within the read-only indentation region to the left of
1903 a cell, then move point to prior location and prompt to move one tree to
1904 a new location in the outline; hit the Action Key twice to select the
1905 tree to move and where to move it;
1906 (4) anywhere else, scroll down a windowful."
1908 (cond ((kotl-mode:eobp) (kotl-mode:overview))
1909 ((kotl-mode:eolp) (smart-scroll-down))
1910 ((not (kview:valid-position-p))
1911 (if (markerp assist-key-depress-prev-point)
1912 (progn (select-window
1914 (marker-buffer assist-key-depress-prev-point)))
1915 (goto-char (marker-position
1916 assist-key-depress-prev-point))
1917 (call-interactively 'kotl-mode:move-after))
1918 (kotl-mode:to-valid-position)
1919 (error "(kotl-mode:help-key): Help Key released at invalid position")))
1921 ;; On an outline header line but not at the start/end of line,
1922 ;; show attributes for tree at point.
1923 (kotl-mode:cell-help (kcell-view:label) (or current-prefix-arg 2)))
1924 ((smart-scroll-down)))
1925 (kotl-mode:to-valid-position))
1928 ;;; Structure Editing
1931 (defun kotl-mode:add-child ()
1932 "Add a new cell to current kview as first child of current cell."
1934 (kotl-mode:add-cell '(4)))
1936 (defun kotl-mode:add-parent ()
1937 "Add a new cell to current kview as sibling of current cell's parent."
1939 (kotl-mode:add-cell -1))
1941 (defun kotl-mode:add-cell (&optional relative-level contents plist no-fill)
1942 "Add a cell following current cell at optional RELATIVE-LEVEL with CONTENTS string, attributes in PLIST, a property list, and NO-FILL flag to prevent any filling of CONTENTS.
1944 Optional prefix arg RELATIVE-LEVEL means add as sibling if nil or >= 0, as
1945 child if equal to universal argument, {C-u}, and as sibling of current cell's
1946 parent, otherwise. If added as sibling of current level, RELATIVE-LEVEL is
1947 used as a repeat count for the number of cells to add.
1949 Return last newly added cell."
1951 (or (stringp contents) (setq contents nil))
1952 (let ((klabel (kcell-view:label))
1953 (label-sep-len (kview:label-separator-length kview))
1954 cell-level new-cell sibling-p child-p start parent
1956 (setq cell-level (kcell-view:level nil label-sep-len)
1957 child-p (equal relative-level '(4))
1958 sibling-p (and (not child-p)
1959 (cond ((not relative-level) 1)
1960 ((>= (prefix-numeric-value relative-level) 0)
1961 (prefix-numeric-value relative-level))))
1962 cells-to-add (or sibling-p 1))
1964 (setq cell-level (1+ cell-level))
1967 ;; Add as following sibling of current cell's parent.
1969 (setq cell-level (1- cell-level)
1971 parent (kcell-view:parent nil label-sep-len))
1972 (if (not (eq parent t))
1976 "(kotl-mode:add-cell): No higher level at which to add cell.")
1978 ;; Skip from point past any children to next cell.
1979 (if (kotl-mode:next-tree)
1980 ;; If found a new tree, then move back to prior cell so can add
1981 ;; new cell after it.
1982 (kcell-view:previous nil label-sep-len)))
1983 (goto-char (kcell-view:end))
1985 ;; Insert new cells into view.
1986 (if (= cells-to-add 1)
1989 (klabel:increment klabel))
1990 (child-p (klabel:child klabel))
1991 ;; add as sibling of parent of current cell
1992 (t (klabel:increment (klabel:parent klabel))))
1993 new-cell (kview:add-cell klabel cell-level contents plist
1994 (or no-fill sibling-p
1995 (not kotl-mode:refill-flag))))
1997 ;; sibling-p must be true if we are looping here so there is no need to
1998 ;; conditionalize how to increment the labels.
1999 (while (>= (setq cells-to-add (1- cells-to-add)) 0)
2000 (setq klabel (klabel:increment klabel)
2001 ;; Since new cells are at the same level as old one, don't fill
2002 ;; any of their intial contents.
2003 new-cell (kview:add-cell klabel cell-level contents plist t))))
2005 ;; Move back to last inserted cell and then move to its following
2007 (kotl-mode:to-valid-position t)
2009 (if (kcell-view:forward t label-sep-len)
2010 ;; Update the labels of these siblings and their subtrees.
2011 (klabel-type:update-labels (klabel:increment klabel))))
2013 ;; Leave point within last newly added cell and return this cell.
2014 (kotl-mode:beginning-of-cell)
2017 (defun kotl-mode:demote-tree (arg)
2018 "Move current tree a maximum of prefix ARG levels lower in current view.
2019 Each cell is refilled iff its `no-fill' attribute is nil and
2020 kotl-mode:refill-flag is non-nil. With prefix ARG = 0, cells are demoted up
2021 to one level and kotl-mode:refill-flag is treated as true."
2024 (kotl-mode:promote-tree (- arg))
2025 (let* ((label-sep-len (kview:label-separator-length kview))
2026 (orig-level (kcell-view:level nil label-sep-len))
2027 (orig-point (point))
2028 (orig-id (kcell-view:idstamp))
2031 (- (point) (kcell-view:start nil label-sep-len)))
2033 (if fill-p (setq arg 1))
2037 (while (and (> arg 0)
2039 (kcell-view:previous nil label-sep-len)))
2041 (progn (setq prev-level
2042 (kcell-view:level nil label-sep-len))
2043 (cond ((> prev-level (+ orig-level arg))
2044 ;; Don't want to demote this far
2045 ;; so keep looking at prior nodes.
2047 ((= arg (- prev-level orig-level))
2048 ;; Demote to be sibling of this kcell.
2050 ((< prev-level orig-level)
2051 ;; prev is at higher level then
2052 ;; orig, so can't demote
2056 ;; Demote below this kcell. This is
2057 ;; as far we can demote, though it may
2058 ;; not be the full amount of arg.
2061 (kotl-mode:move-after
2062 (kcell-view:label orig-point)
2063 (kcell-view:label) (= arg 0)
2065 ;; Move to start of original cell
2066 (kotl-mode:goto-cell orig-id)
2067 ;; Move to original pos within cell
2068 (forward-char orig-pos-in-cell)
2069 (kotl-mode:to-valid-position))
2071 (error "(kotl-mode:demote-tree): Cannot demote any further")))))
2073 (defun kotl-mode:exchange-cells (cell-ref-1 cell-ref-2)
2074 "Exchange CELL-REF-1 with CELL-REF-2 in current view. Don't move point."
2076 (let ((hargs:defaults
2078 (list (kcell-view:label)
2080 ((kcell-view:previous t)
2082 ((kcell-view:next t)
2085 "(kotl-mode:exchange-cells): No 2 visible cells")))))))
2087 '(interactive "*+KExchange cell: \n+KExchange cell <%s> with cell: "))))
2089 (let (kcell-1 contents-1
2092 ;; Save cell-1 attributes
2093 (kotl-mode:goto-cell cell-ref-1 t)
2094 (setq kcell-1 (kcell-view:cell)
2095 contents-1 (kcell-view:contents))
2097 ;; Save cell-2 attributes
2098 (kotl-mode:goto-cell cell-ref-2 t)
2099 (setq kcell-2 (kcell-view:cell)
2100 contents-2 (kcell-view:contents))
2102 ;; Substitute cell-1 attributes into cell-2 location.
2104 ;; Set kcell properties.
2105 (kcell-view:set-cell kcell-1)
2106 ;; If idstamp labels are on, then must exchange labels in view.
2107 (if (eq (kview:label-type kview) 'id)
2108 (klabel:set (kcell-view:idstamp)))
2109 ;; Exchange cell contents.
2110 (delete-region (kcell-view:start) (kcell-view:end-contents))
2112 (hypb:replace-match-string
2114 contents-1 (concat "\\1" (make-string (kcell-view:indent) ?\ ))))
2115 (if kotl-mode:refill-flag (kotl-mode:fill-cell))
2117 ;; Substitute cell-2 attributes into cell-1 location.
2119 ;; Set kcell properties.
2120 (kotl-mode:goto-cell cell-ref-1 t)
2121 (kcell-view:set-cell kcell-2)
2122 ;; If idstamp labels are on, then must exchange labels in view.
2123 (if (eq (kview:label-type kview) 'id)
2124 (klabel:set (kcell-view:idstamp)))
2125 ;; Exchange cell contents.
2126 (delete-region (kcell-view:start) (kcell-view:end-contents))
2127 ;; Add indentation to all but first line.
2129 (hypb:replace-match-string
2131 contents-2 (concat "\\1" (make-string (kcell-view:indent) ?\ ))))
2132 (if kotl-mode:refill-flag (kotl-mode:fill-cell)))))
2134 (defun kotl-mode:kill-contents (arg)
2135 "Kill contents of cell from point to cell end.
2136 With prefix ARG, kill entire cell contents."
2138 (kotl-mode:kill-region
2139 (if arg (kcell-view:start) (point))
2140 (kcell-view:end-contents)))
2142 (defun kotl-mode:kill-tree (&optional arg)
2143 "Kill ARG following trees starting with tree rooted at point.
2144 If ARG is not a non-positive number, nothing is done."
2146 (or (integerp arg) (setq arg 1))
2147 (let ((killed) (label (kcell-view:label))
2148 (label-sep-len (kview:label-separator-length kview))
2151 (setq start (kotl-mode:tree-start)
2152 end (kotl-mode:tree-end)
2153 sib (kcell-view:sibling-p nil nil label-sep-len)
2156 ;; Don't want to delete any prior cells, so if on last cell, ensure
2157 ;; this is the last one killed.
2158 (if (kotl-mode:last-cell-p)
2160 (kview:delete-region start end))
2161 (kview:delete-region start end)
2162 (kotl-mode:to-valid-position)))
2165 (cond (sib (klabel-type:update-labels label))
2166 ((kotl-mode:buffer-empty-p)
2167 ;; Always leave at least 1 visible cell within a view.
2168 (kview:add-cell "1" 1)))
2169 (kotl-mode:to-valid-position)))))
2171 (defun kotl-mode:mail-tree (cell-ref invisible-flag)
2172 "Mail outline tree rooted at CELL-REF. Use \"0\" for whole outline buffer.
2173 Invisible text is expanded and included in the mail only if INVISIBLE-FLAG is
2176 (let ((label-default (kcell-view:label)))
2180 (hargs:read "Mail tree: (0 for whole outline) "
2181 nil label-default nil 'kcell)
2182 (y-or-n-p "Include invisible text? "))))))
2183 (if (equal cell-ref "0")
2184 (hmail:buffer nil invisible-flag)
2187 (kotl-mode:goto-cell cell-ref t)
2189 (setq start (point))
2190 (or (= (kotl-mode:forward-cell 1) 0) (goto-char (point-max)))
2193 (hmail:region start end nil invisible-flag))))
2195 (defun kotl-mode:promote-tree (arg)
2196 "Move current tree a maximum of prefix ARG levels higher in current view.
2197 Each cell is refilled iff its `no-fill' attribute is nil and
2198 kotl-mode:refill-flag is non-nil. With prefix ARG = 0, cells are promoted up
2199 to one level and kotl-mode:refill-flag is treated as true."
2202 (kotl-mode:demote-tree (- arg))
2203 (let* ((parent) (result)
2204 (label-sep-len (kview:label-separator-length kview))
2205 (orig-point (point))
2206 (orig-id (kcell-view:idstamp))
2209 (- (point) (kcell-view:start nil label-sep-len))))
2210 (if fill-p (setq arg 1))
2214 (while (and (> arg 0)
2215 (setq result (kcell-view:parent
2217 (not (eq result 0)))
2221 (kotl-mode:move-after
2222 (kcell-view:label orig-point)
2223 (kcell-view:label) nil
2225 ;; Move to start of original cell
2226 (kotl-mode:goto-cell orig-id)
2227 ;; Move to original pos within cell
2228 (forward-char orig-pos-in-cell)
2229 (kotl-mode:to-valid-position))
2231 (error "(kotl-mode:promote-tree): Cannot promote any further")))))
2233 (defun kotl-mode:set-cell-attribute (attribute value &optional pos)
2234 "Include ATTRIBUTE VALUE with the current cell or the cell at optional POS.
2235 Replaces any existing value that ATTRIBUTE has.
2236 When called interactively, it displays the setting in the minibuffer as
2239 (let* ((plist (copy-sequence (kcell-view:plist)))
2240 (existing-attributes plist)
2242 (barf-if-buffer-read-only)
2243 ;; Remove attribute values
2245 (setcdr plist (cdr (cdr plist)))
2246 (setq plist (cdr plist)))
2247 ;; Remove read-only attributes
2248 (setq existing-attributes (set:create existing-attributes)
2249 existing-attributes (set:difference
2251 kcell:read-only-attributes))
2253 (while (zerop (length (setq attribute
2255 "Current cell attribute to set: "
2257 (mapcar 'symbol-name
2258 existing-attributes))))))
2260 (setq attribute (intern attribute)
2261 value (kcell-view:get-attr attribute))
2263 (setq value (read-expression
2264 (format "Change value of \"%s\" to: " attribute)
2265 (prin1-to-string value)))
2266 (setq value (read-expression
2267 (format "Set value of \"%s\" to: " attribute))))
2268 (list attribute value nil)))
2269 (kcell-view:set-attr attribute value pos)
2270 ;; Note that buffer needs to be saved to store new attribute value.
2271 (set-buffer-modified-p t)
2273 (message "Attribute \"%s\" set to `%s' in cell <%s>."
2274 attribute value (kcell-view:label pos))))
2276 (defun kotl-mode:split-cell (&optional arg)
2277 "Split the current cell into two cells and move to the new cell.
2278 The cell contents after point become part of the newly created cell.
2279 The default is to create the new cell as a sibling of the current cell.
2280 With optional universal ARG, {C-u}, the new cell is added as the child of
2283 (let ((new-cell-contents (kotl-mode:kill-region
2284 (point) (kcell-view:end-contents) 'string))
2285 (start (kcell-view:start)))
2286 ;; delete any preceding whitespace
2287 (skip-chars-backward " \t\n\r" start)
2288 (delete-region (max start (point)) (kcell-view:end-contents))
2289 (kotl-mode:add-cell arg new-cell-contents (kcell-view:plist))))
2291 (defun kotl-mode:transpose-cells (arg)
2292 "Exchange current and previous visible cells, leaving point after both.
2293 If no previous cell, exchange current with next cell.
2294 With prefix ARG, take current tree and move it past ARG visible cells.
2295 With prefix ARG = 0, interchange the cell that contains point with the cell
2296 that contains mark."
2298 (let ((label-sep-len (kview:label-separator-length kview)))
2300 ((save-excursion (not (or (kcell-view:next t label-sep-len)
2301 (kcell-view:previous t label-sep-len))))
2302 (error "(kotl-mode:transpose-cells): Only one visible cell in outline"))
2304 ;; Transpose current and previous cells or current and next cells, if no
2305 ;; previous cell. Leave point after both exchanged cells or within last
2308 (let ((label-1 (kcell-view:label))
2309 (prev (kcell-view:previous t label-sep-len))
2311 (or prev (kcell-view:next t label-sep-len))
2312 (setq label-2 (kcell-view:label))
2313 (kotl-mode:exchange-cells label-1 label-2)
2314 (kcell-view:next t label-sep-len)
2315 (if prev (kcell-view:next t label-sep-len))))
2317 ;; Transpose point and mark cells, moving point to the new location of the
2318 ;; cell which originally contained point.
2320 (let ((label-1 (kcell-view:label))
2322 ;; This is like exchange-point-and-mark, but doesn't activate the
2324 (goto-char (prog1 (hypb:mark t)
2325 (set-marker (hypb:mark-marker t) (point))))
2326 (setq label-2 (kcell-view:label))
2327 (kotl-mode:exchange-cells label-1 label-2)))
2329 ;; Move current tree past ARG next visible cells and leave point after
2330 ;; original cell text.
2332 (let ((mark (set-marker (make-marker)
2333 (save-excursion (kotl-mode:next-line arg)))))
2334 (kotl-mode:move-after
2336 (progn (while (and (> arg 0) (kcell-view:next t label-sep-len))
2337 (setq arg (1- arg)))
2341 (set-marker mark nil))))))
2344 ;;; Structure Viewing
2347 (defun kotl-mode:collapse-tree (&optional all-flag)
2348 "Collapse to one line each visible cell of tree rooted at point.
2349 With optional ALL-FLAG non-nil, collapse all cells visible within the current
2353 (let (buffer-read-only)
2355 (progn (kvspec:show-lines-per-cell 1)
2360 ;; Use free variable label-sep-len bound in kview:map-tree for speed.
2361 (goto-char (kcell-view:start nil label-sep-len))
2362 (subst-char-in-region (point) (kcell-view:end-contents) ?\n ?\r t)))
2365 (defun kotl-mode:expand-tree (&optional all-flag)
2366 "Expand each visible cell of tree rooted at point.
2367 With optional ALL-FLAG non-nil, expand all cells visible within the current
2371 (let (buffer-read-only)
2373 (progn (kvspec:show-lines-per-cell 0)
2378 ;; Use free variable label-sep-len bound in kview:map-tree for speed.
2379 (goto-char (kcell-view:start nil label-sep-len))
2380 (subst-char-in-region (point) (kcell-view:end-contents) ?\r ?\n t)))
2383 (defun kotl-mode:toggle-tree-expansion (&optional all-flag)
2384 "Collapse or expand each cell of tree rooted at point or all visible cells if optional prefix arg ALL-FLAG is given.
2385 If current cell is collapsed, cells will be expanded, otherwise they will be
2388 (if (kcell-view:collapsed-p)
2390 (kotl-mode:expand-tree all-flag)
2391 (kotl-mode:collapse-tree all-flag)))
2394 (defun kotl-mode:overview ()
2395 "Show the first line of each cell."
2397 (kotl-mode:show-all)
2398 (kotl-mode:collapse-tree t))
2400 (defun kotl-mode:show-all ()
2401 "Show (expand) all cells in current view."
2403 (if (kotl-mode:is-p)
2404 (progn (kview:set-attr kview 'levels-to-show 0)
2405 (kview:set-attr kview 'lines-to-show 0)
2407 (kvspec:update t))))
2409 (defun kotl-mode:top-cells ()
2410 "Collapse all level 1 cells in view and hide any deeper sublevels."
2413 (let ((modified-p (buffer-modified-p))
2415 (kvspec:levels-to-show 1)
2416 (kvspec:show-lines-per-cell 1)
2418 ;; Restore buffer modification status
2419 (set-buffer-modified-p modified-p)))
2422 (defun kotl-mode:hide-sublevels (levels-to-keep)
2423 "Hide all cells in outline at levels deeper than LEVELS-TO-KEEP (a number).
2424 Shows any hidden cells within LEVELS-TO-KEEP. 1 is the first level. 0 means
2425 display all levels of cells."
2427 (kvspec:levels-to-show levels-to-keep)
2428 ;; The prior call might have shown more lines per cell than the current
2429 ;; viewspec supports, so reset lines per cell.
2430 (kvspec:lines-to-show)
2433 (defun kotl-mode:hide-subtree (&optional cell-ref show-flag)
2434 "Hide subtree, ignoring root, at optional CELL-REF (defaults to cell at point)."
2439 (kotl-mode:goto-cell cell-ref t)
2440 (kotl-mode:beginning-of-cell))
2441 (let ((start (kcell-view:end-contents))
2442 (end (kotl-mode:tree-end t))
2445 (subst-char-in-region start end ?\r ?\n t)
2446 (subst-char-in-region start end ?\n ?\r t)))))
2448 (defun kotl-mode:show-subtree (&optional cell-ref)
2449 "Show subtree, ignoring root, at optional CELL-REF (defaults to cell at point)."
2451 (kotl-mode:hide-subtree cell-ref t))
2453 (defun kotl-mode:hide-tree (&optional cell-ref show-flag)
2454 "Collapse tree rooted at optional CELL-REF (defaults to cell at point)."
2458 (let ((start (if cell-ref
2459 (kotl-mode:goto-cell cell-ref t)
2460 (kotl-mode:beginning-of-cell)))
2461 (end (kotl-mode:tree-end t))
2464 (subst-char-in-region start end ?\r ?\n t)
2465 (subst-char-in-region start end ?\n ?\r t)))))
2467 (defun kotl-mode:show-tree (&optional cell-ref)
2468 "Display fully expanded tree rooted at CELL-REF."
2470 (kotl-mode:hide-tree cell-ref t))
2473 (defun kotl-mode:cell-attributes (all-flag)
2474 "Display a temporary buffer with the attributes of the current kcell.
2475 With prefix arg ALL-FLAG non-nil, display the attributes of all visible
2476 kcells in the current buffer.
2478 See also the documentation for `kotl-mode:cell-help'."
2480 (with-output-to-temp-buffer
2481 (hypb:help-buf-name "Kotl")
2484 (kotl-mode:print-attributes kview)
2485 (let ((label-sep-len (kview:label-separator-length kview)))
2486 (kotl-mode:beginning-of-buffer)
2487 (while (progn (kotl-mode:print-attributes kview)
2488 (kcell-view:next t label-sep-len))))))))
2490 (defun kotl-mode:cell-help (&optional cell-ref cells-flag)
2491 "Display a temporary buffer with CELL-REF's attributes.
2492 CELL-REF defaults to current cell.
2493 Optional prefix arg CELLS-FLAG selects the cells to print:
2494 If = 1, print CELL-REF's cell only;
2495 If > 1, print CELL-REF's visible tree (the tree rooted at CELL-REF);
2496 If < 1, print all visible cells in current view (CELL-REF is not used).
2498 See also the documentation for `kotl-mode:cell-attributes'."
2500 (let* ((label (kcell-view:label))
2501 (hargs:defaults (list label label)))
2503 (let ((arg (prefix-numeric-value current-prefix-arg)))
2508 (format "+KDisplay properties of koutline %s: "
2509 (if (= arg 1) "cell" "tree"))))))
2510 (list current-prefix-arg))))
2511 (or (integerp cells-flag)
2512 (setq cells-flag (prefix-numeric-value cells-flag)))
2513 (or (stringp cell-ref) (setq cell-ref (kcell-view:label)))
2514 (with-output-to-temp-buffer
2515 (hypb:help-buf-name "Koutline")
2517 (if (equal cell-ref "0")
2519 (hattr:report (kcell:plist (kview:top-cell kview)))
2521 (cond ((= cells-flag 1) nil)
2523 (kview:map-tree 'kotl-mode:print-attributes kview t t))
2525 (t (kotl-mode:cell-attributes t))))
2526 (cond ((= cells-flag 1)
2527 (kotl-mode:goto-cell cell-ref)
2528 (kotl-mode:print-attributes kview))
2530 (kotl-mode:goto-cell cell-ref)
2531 (kview:map-tree 'kotl-mode:print-attributes kview nil t))
2533 (t (kotl-mode:cell-attributes t)))))))
2535 (defun kotl-mode:get-cell-attribute (attribute &optional pos)
2536 "Return ATTRIBUTE's value for the current cell or the cell at optional POS.
2537 When called interactively, it displays the value in the minibuffer."
2538 (interactive "SCurrent cell attribute to get: ")
2539 (let ((value (kcell-view:get-attr attribute pos)))
2541 (message "Attribute \"%s\" = `%s' in cell <%s>."
2542 attribute value (kcell-view:label pos)))
2546 ;;; Private functions
2549 (defun kotl-mode:add-indent-to-region (&optional indent start end)
2550 "Add current cell's indent to current region.
2551 Optionally, INDENT and region START and END may be given."
2552 (or (integerp indent) (setq indent (kcell-view:indent)))
2555 (narrow-to-region (or start (point)) (or end (hypb:mark t)))
2556 (goto-char (point-min))
2557 (replace-regexp "\n" (concat "\n" (make-string indent ?\ ))))))
2559 (defun kotl-mode:delete-line (&optional pos)
2560 "Delete and return contents of cell line at point or optional POS as a string.
2561 Does not delete newline at end of line."
2563 (if pos (goto-char pos))
2564 (if (kview:valid-position-p)
2565 (let ((bol (kotl-mode:start-of-line))
2566 (eol (kotl-mode:finish-of-line)))
2568 (buffer-substring bol eol)
2569 (delete-region bol eol)))
2570 (error "(kotl-mode:delete-line): Invalid position, '%d'" (point)))))
2572 (defun kotl-mode:indent-line (arg)
2573 ;; Disallow the indent-line command.
2574 (error "(kotl-mode:indent-line): Insert spaces to indent each line."))
2576 (defun kotl-mode:indent-region (start end)
2577 ;; User might try to indent across cells. This would be bad, so disallow
2578 ;; the indent-region command.
2579 (error "(kotl-mode:indent-region): Insert spaces to indent each line."))
2581 (defun kotl-mode:is-p ()
2582 "Signal an error if current buffer is not a Hyperbole outline, else return t."
2583 (if (kview:is-p kview)
2586 "(kotl-mode:is-p): Command requires a current Hyperbole outline.")))
2588 (defun kotl-mode:tree-end (&optional omit-end-newlines)
2589 "Return end point of current cell's tree within this view.
2590 If optional OMIT-END-NEWLINES is non-nil, point returned precedes any
2591 newlines at end of tree."
2592 (let* ((label-sep-len (kview:label-separator-length kview))
2593 (start-indent (kcell-view:indent nil label-sep-len))
2596 (while (and (setq next (kcell-view:next nil label-sep-len))
2597 (< start-indent (kcell-view:indent nil label-sep-len))))
2599 (goto-char (progn (kcell-view:previous nil label-sep-len)
2601 ;; Avoid skipping too far at end of file.
2602 ((re-search-forward "[\n\r][\n\r]" nil t))
2603 (t (goto-char (point-max))))
2604 (if omit-end-newlines (skip-chars-backward "\n\r"))
2607 (defun kotl-mode:tree-start ()
2608 "Return beginning of line position preceding current cell's start point."
2609 (save-excursion (goto-char (kcell-view:start)) (beginning-of-line)
2612 (defun kotl-mode:line-move (arg)
2613 "Move point ARG visible lines forward within an outline."
2614 (if (not (integerp selective-display))
2616 ;; Move by arg lines, but ignore invisible ones.
2621 (setq arg (1- arg)))
2623 (vertical-motion -1)
2625 (setq arg (1+ arg))))
2626 (move-to-column (or goal-column temporary-goal-column))
2629 (defun kotl-mode:print-attributes (kview)
2630 "Print to the `standard-output' stream the attributes of the current visible kcell.
2631 Takes argument KVIEW (so it can be used with 'kview:map-tree' and so that
2632 KVIEW is bound correctly) but always operates upon the current view."
2633 ;; Move to start of visible cell to avoid printing attributes for an
2634 ;; invisible kcell which point may be over.
2635 ;; Print first line of cell for reference.
2638 (buffer-substring (progn (beginning-of-line) (point))
2639 (progn (kview:end-of-actual-line)
2642 (hattr:report (kcell:plist (kcell-view:cell)))
2645 (defun kotl-mode:set-temp-goal-column ()
2646 (if (not (or (eq last-command 'next-line)
2647 (eq last-command 'previous-line)))
2648 (setq temporary-goal-column
2649 (if (and track-eol (eolp)
2650 ;; Don't count beg of empty line as end of line
2651 ;; unless we just did explicit end-of-line.
2652 (or (not (bolp)) (eq last-command 'end-of-line)))
2654 (current-column)))))
2656 (defun kotl-mode:to-valid-position (&optional backward-p)
2657 "Move point to the nearest non-read-only position within current koutline view.
2658 With optional BACKWARD-P, move backward if possible to get to valid position."
2659 (if (kview:valid-position-p)
2661 (let ((label-sep-len (kview:label-separator-length kview)))
2662 (cond ((kotl-mode:bobp)
2663 (goto-char (kcell-view:start nil label-sep-len)))
2665 (skip-chars-backward "\n\r"))
2666 (t (let ((indent (kcell-view:indent nil label-sep-len)))
2669 (skip-chars-backward "\n\r")
2670 (skip-chars-forward "\n\r")))
2671 (setq indent (kcell-view:indent nil label-sep-len))
2672 (if (< (current-column) indent)
2673 (move-to-column indent))))))))
2675 (defun kotl-mode:transpose-lines-internal (start end)
2676 "Transpose lines at START and END markers within an outline.
2677 Leave point at end of line now residing at START."
2679 (kview:valid-position-p start)
2680 (kview:valid-position-p end))
2681 (let* ((pline (kotl-mode:delete-line start))
2684 (setq mline (kotl-mode:delete-line))
2688 ;; Set non-point and non-mark markers to point nowhere before signalling
2690 (or (eq start (point-marker))
2691 (eq start (hypb:mark-marker t))
2692 (set-marker start nil))
2693 (or (eq end (point-marker))
2694 (eq end (hypb:mark-marker t))
2695 (set-marker start nil))
2696 (error "(kotl-mode:transpose-lines): Point or mark is at an invalid position")))
2698 (defun kotl-mode:update-buffer ()
2699 "Update current view buffer in preparation for saving."
2700 (if (kview:is-p kview)
2701 (let ((mod-p (buffer-modified-p))
2702 (start (window-start)))
2705 (set-buffer-modified-p mod-p))
2706 (set-window-start nil (max (point-min) start) t)
2711 (defvar kotl-mode-map nil
2712 "Keymap containing koutliner editing and viewing commands.")
2716 (if (string-match "XEmacs\\|Lucid" emacs-version)
2718 (copy-keymap text-mode-map)))
2719 ;; Overload edit keys to deal with structure and labels.
2722 (if (string-match "XEmacs\\|Lucid" emacs-version)
2726 (setq local-cmd (intern-soft
2727 (concat "kotl-mode:" (symbol-name cmd))))
2728 ;; Only bind key locally if kotl-mode local-cmd has already
2729 ;; been defined and cmd is a valid function.
2730 (if (and local-cmd (fboundp cmd))
2732 ;; Make local-cmd have the same property list as cmd,
2733 ;; e.g. so pending-delete property is the same.
2734 (setplist local-cmd (symbol-plist cmd))
2737 (lambda (key) (define-key kotl-mode-map key local-cmd)))
2738 (where-is-internal cmd))))))
2742 (setq local-cmd (intern-soft
2743 (concat "kotl-mode:" (symbol-name cmd))))
2744 ;; Only bind key locally if kotl-mode local-cmd has already
2745 ;; been defined and cmd is a valid function.
2746 (if (and local-cmd (fboundp cmd))
2748 ;; Make local-cmd have the same property list as cmd,
2749 ;; e.g. so pending-delete property is the same.
2750 (setplist local-cmd (symbol-plist cmd))
2751 (substitute-key-definition
2752 cmd local-cmd kotl-mode-map global-map))))))
2756 backward-delete-char
2757 backward-delete-char-untabify
2768 delete-backward-char
2770 delete-horizontal-space
2775 fill-paragraph-or-region
2808 transpose-paragraphs
2818 (define-key kotl-mode-map "\C-c@" 'kotl-mode:mail-tree)
2819 (define-key kotl-mode-map "\C-c+" 'kotl-mode:append-cell)
2820 (define-key kotl-mode-map "\C-c," 'kotl-mode:beginning-of-cell)
2821 (define-key kotl-mode-map "\C-c." 'kotl-mode:end-of-cell)
2822 (define-key kotl-mode-map "\C-c<" 'kotl-mode:first-sibling)
2823 (define-key kotl-mode-map "\C-c>" 'kotl-mode:last-sibling)
2824 (define-key kotl-mode-map "\C-c^" 'kotl-mode:beginning-of-tree)
2825 (define-key kotl-mode-map "\C-c$" 'kotl-mode:end-of-tree)
2826 (define-key kotl-mode-map "\C-ca" 'kotl-mode:add-child)
2827 (define-key kotl-mode-map "\C-c\C-a" 'kotl-mode:show-all)
2828 (define-key kotl-mode-map "\C-cb" 'kvspec:toggle-blank-lines)
2829 (define-key kotl-mode-map "\C-c\C-b" 'kotl-mode:backward-cell)
2830 (define-key kotl-mode-map "\C-cc" 'kotl-mode:copy-after)
2831 (define-key kotl-mode-map "\C-c\C-c" 'kotl-mode:copy-before)
2832 (define-key kotl-mode-map "\C-c\M-c" 'kotl-mode:copy-to-buffer)
2833 (define-key kotl-mode-map "\C-cd" 'kotl-mode:down-level)
2834 (define-key kotl-mode-map "\C-c\C-d" 'kotl-mode:down-level)
2835 (define-key kotl-mode-map "\C-ce" 'kotl-mode:exchange-cells)
2836 (define-key kotl-mode-map "\C-c\C-f" 'kotl-mode:forward-cell)
2837 (define-key kotl-mode-map "\C-cg" 'kotl-mode:goto-cell)
2838 (define-key kotl-mode-map "\C-ch" 'kotl-mode:cell-help)
2839 (define-key kotl-mode-map "\C-c\C-h" 'kotl-mode:hide-tree)
2840 (define-key kotl-mode-map "\M-\C-h" 'kotl-mode:hide-subtree)
2841 ;; Override this global binding for set-selective-display with a similar
2842 ;; function appropriate for kotl-mode.
2843 (define-key kotl-mode-map "\C-x$" 'kotl-mode:hide-sublevels)
2844 (define-key kotl-mode-map "\C-i" 'kotl-mode:demote-tree)
2845 (define-key kotl-mode-map "\M-\C-i" 'kotl-mode:promote-tree)
2846 (define-key kotl-mode-map "\C-j" 'kotl-mode:add-cell)
2847 (define-key kotl-mode-map "\M-j" 'kotl-mode:fill-paragraph)
2848 (define-key kotl-mode-map "\C-c\M-j" 'kotl-mode:fill-cell)
2849 (define-key kotl-mode-map "\M-\C-j" 'kotl-mode:fill-tree)
2850 (define-key kotl-mode-map "\C-c\C-k" 'kotl-mode:kill-tree)
2851 (define-key kotl-mode-map "\C-ck" 'kotl-mode:kill-contents)
2852 (define-key kotl-mode-map "\C-c\C-i" 'kotl-mode:set-cell-attribute)
2853 (define-key kotl-mode-map "\C-cl" 'klink:create)
2854 (define-key kotl-mode-map "\C-c\C-l" 'kview:set-label-type)
2855 (define-key kotl-mode-map "\C-c\M-l" 'kview:set-label-separator)
2856 (define-key kotl-mode-map "\C-m" 'kotl-mode:newline)
2857 (define-key kotl-mode-map "\C-cm" 'kotl-mode:move-after)
2858 (define-key kotl-mode-map "\C-c\C-m" 'kotl-mode:move-before)
2859 (define-key kotl-mode-map "\C-c\C-n" 'kotl-mode:next-cell)
2860 (define-key kotl-mode-map "\C-c\C-o" 'kotl-mode:overview)
2861 (define-key kotl-mode-map "\C-c\C-p" 'kotl-mode:previous-cell)
2862 (define-key kotl-mode-map "\C-cp" 'kotl-mode:add-parent)
2863 (if (memq (global-key-binding "\M-q") '(fill-paragraph
2864 fill-paragraph-or-region))
2866 (define-key kotl-mode-map "\C-c\M-q" 'kotl-mode:fill-cell)
2867 (define-key kotl-mode-map "\M-\C-q" 'kotl-mode:fill-tree)))
2868 (define-key kotl-mode-map "\C-cs" 'kotl-mode:split-cell)
2869 (define-key kotl-mode-map "\C-c\C-s" 'kotl-mode:show-tree)
2870 (define-key kotl-mode-map "\C-c\C-\\" 'kotl-mode:show-tree)
2871 (define-key kotl-mode-map "\M-s" 'kotl-mode:center-line)
2872 (define-key kotl-mode-map "\M-S" 'kotl-mode:center-paragraph)
2873 (define-key kotl-mode-map "\C-ct" 'kotl-mode:transpose-cells)
2874 (define-key kotl-mode-map "\C-c\C-t" 'kotl-mode:top-cells)
2875 (define-key kotl-mode-map "\C-cu" 'kotl-mode:up-level)
2876 (define-key kotl-mode-map "\C-c\C-u" 'kotl-mode:up-level)
2877 (define-key kotl-mode-map "\C-c\C-v" 'kvspec:activate)
2878 (define-key kotl-mode-map "\C-x\C-w" 'kfile:write))
2880 (easy-menu-define kotl-mode-menu kotl-mode-map "Kotl Mode Menu." kmenu:menu)
2882 (provide 'kotl-mode)
2884 ;;; kotl-mode.el ends here