• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/emulation/

Lines Matching +refs:tpu +refs:replace

0 ;;; tpu-edt.el --- Emacs emulating TPU emulating EDT
28 ;; TPU-edt is based on tpu.el by Jeff Kowalski and Bob Covey.
70 ;; key map. The TPU-edt module tpu-mapper creates this map and stores it
73 ;; the commentary in tpu-mapper.el for details.
92 ;; approximation of free mode, see the commentary in tpu-extras.el for
119 ;; commands are available, they are: replace, exit, quit, include, and
139 ;; replace command work with regular expressions. [A regular expression
163 ;; prompt> emacs -f tpu-edt
165 ;; If you've already started emacs, turn on TPU-edt using the tpu-edt
167 ;; and type `tpu-edt' followed by a carriage return.
173 ;; (tpu-edt)
186 ;; (tpu-edt)
189 ;; (tpu-set-scroll-margins "10%" "15%")
196 ;; (tpu-add-word-separators "]\\[-_,.\"=+()'/*#:!&;$")
213 ;; (define-key SS3-map "w" 'tpu-paragraph) ; KP7
218 ;; (global-set-key [kp_7] 'tpu-paragraph) ; KP7
222 ;; (tpu-version)
228 ;; mode, find, find next, replace, and substitute accept emacs regular
242 ;; next one. This can cause global replace and substitute commands to loop
245 ;; replace "^" "> " <add "> " to beginning of line>
246 ;; replace "$" "00711" <add "00711" to end of line>
279 (defgroup tpu nil
281 :prefix "tpu-"
288 (defconst tpu-version "4.5" "TPU-edt version number.")
294 (defcustom tpu-have-ispell t
297 :group 'tpu)
299 (defcustom tpu-kill-buffers-silently nil
302 :group 'tpu)
304 (defcustom tpu-percent-scroll 75
307 :group 'tpu)
309 (defcustom tpu-pan-columns 16
310 "*Number of columns the tpu-pan functions scroll left or right."
312 :group 'tpu)
318 ;;; o tpu-mark o tpu-set-mark
319 ;;; o mode line section o tpu-load-xkeys
321 (defconst tpu-lucid-emacs-p
330 (define-key map "A" 'tpu-previous-line) ; up
331 (define-key map "B" 'tpu-next-line) ; down
332 (define-key map "D" 'tpu-backward-char) ; left
333 (define-key map "C" 'tpu-forward-char) ; right
335 (define-key map "1~" 'tpu-search) ; Find
336 (define-key map "2~" 'tpu-paste) ; Insert Here
337 (define-key map "3~" 'tpu-cut) ; Remove
338 (define-key map "4~" 'tpu-select) ; Select
339 (define-key map "5~" 'tpu-scroll-window-down) ; Prev Screen
340 (define-key map "6~" 'tpu-scroll-window-up) ; Next Screen
351 (define-key map "21~" 'tpu-exit) ; F10
352 (define-key map "23~" 'tpu-insert-escape) ; F11 (ESC)
353 (define-key map "24~" 'tpu-next-beginning-of-line) ; F12 (BS)
354 (define-key map "25~" 'tpu-delete-previous-word) ; F13 (LF)
355 (define-key map "26~" 'tpu-toggle-overwrite-mode) ; F14
356 (define-key map "28~" 'tpu-help) ; HELP
358 (define-key map "31~" 'tpu-goto-breadcrumb) ; F17
368 (define-key map "A" 'tpu-move-to-beginning) ; up-arrow
369 (define-key map "B" 'tpu-move-to-end) ; down-arrow
375 (define-key map "3~" 'tpu-store-text) ; Remove
376 (define-key map "4~" 'tpu-unselect) ; Select
377 (define-key map "5~" 'tpu-previous-window) ; Prev Screen
378 (define-key map "6~" 'tpu-next-window) ; Next Screen
396 (define-key map "31~" 'tpu-drop-breadcrumb) ; F17
405 (define-key map "A" 'tpu-move-to-beginning) ; up-arrow
406 (define-key map "B" 'tpu-move-to-end) ; down-arrow
412 (define-key map "R" 'tpu-search) ; PF3
413 (define-key map "S" 'tpu-undelete-lines) ; PF4
415 (define-key map "q" 'tpu-change-case) ; KP1
416 (define-key map "r" 'tpu-delete-to-eol) ; KP2
417 (define-key map "s" 'tpu-special-insert) ; KP3
418 (define-key map "t" 'tpu-move-to-end) ; KP4
419 (define-key map "u" 'tpu-move-to-beginning) ; KP5
420 (define-key map "v" 'tpu-paste) ; KP6
422 (define-key map "x" 'tpu-fill) ; KP8
423 (define-key map "y" 'tpu-replace) ; KP9
424 (define-key map "m" 'tpu-undelete-words) ; KP-
425 (define-key map "l" 'tpu-undelete-char) ; KP,
426 (define-key map "n" 'tpu-unselect) ; KP.
427 (define-key map "M" 'tpu-substitute) ; KPenter
436 (define-key map "\C-A" 'tpu-toggle-overwrite-mode) ; ^A
446 (define-key map "\C-K" 'tpu-define-macro-key) ; ^K
455 (define-key map "\C-T" 'tpu-toggle-control-keys) ; ^T
458 (define-key map "\C-w" 'tpu-write-current-buffers) ; ^W
465 (define-key map "$" 'tpu-add-at-eol) ; $
466 (define-key map "%" 'tpu-goto-percent) ; %
470 (define-key map "*" 'tpu-toggle-regexp) ; *
472 (define-key map "," 'tpu-goto-breadcrumb) ; ,
474 (define-key map "." 'tpu-drop-breadcrumb) ; .
475 (define-key map "/" 'tpu-emacs-replace) ; /
487 (define-key map ";" 'tpu-trim-line-ends) ; ;
491 (define-key map "?" 'tpu-spell-check) ; ?
492 (define-key map "A" 'tpu-toggle-newline-and-indent) ; A
493 (define-key map "B" 'tpu-next-buffer) ; B
496 (define-key map "E" 'tpu-exit) ; E
497 (define-key map "F" 'tpu-set-cursor-free) ; F
498 (define-key map "G" 'tpu-get) ; G
500 (define-key map "I" 'tpu-include) ; I
501 (define-key map "K" 'tpu-kill-buffer) ; K
502 (define-key map "L" 'tpu-what-line) ; L
504 (define-key map "N" 'tpu-next-file-buffer) ; N
507 (define-key map "Q" 'tpu-quit) ; Q
508 (define-key map "R" 'tpu-toggle-rectangle) ; R
509 (define-key map "S" 'replace) ; S
510 (define-key map "T" 'tpu-line-to-top-of-window) ; T
512 (define-key map "V" 'tpu-version) ; V
514 (define-key map "X" 'tpu-save-all-buffers-kill-emacs) ; X
520 (define-key map "^" 'tpu-add-at-bol) ; ^
523 (define-key map "a" 'tpu-toggle-newline-and-indent) ; a
524 (define-key map "b" 'tpu-next-buffer) ; b
527 (define-key map "e" 'tpu-exit) ; e
528 (define-key map "f" 'tpu-set-cursor-free) ; f
529 (define-key map "g" 'tpu-get) ; g
531 (define-key map "i" 'tpu-include) ; i
532 (define-key map "k" 'tpu-kill-buffer) ; k
535 (define-key map "n" 'tpu-next-file-buffer) ; n
538 (define-key map "q" 'tpu-quit) ; q
539 (define-key map "r" 'tpu-toggle-rectangle) ; r
540 (define-key map "s" 'replace) ; s
541 (define-key map "t" 'tpu-line-to-top-of-window) ; t
543 (define-key map "v" 'tpu-version) ; v
545 (define-key map "x" 'tpu-save-all-buffers-kill-emacs) ; x
561 (define-key map "A" 'tpu-previous-line) ; up
562 (define-key map "B" 'tpu-next-line) ; down
563 (define-key map "C" 'tpu-forward-char) ; right
564 (define-key map "D" 'tpu-backward-char) ; left
566 (define-key map "Q" 'tpu-help) ; PF2
567 (define-key map "R" 'tpu-search-again) ; PF3
568 (define-key map "S" 'tpu-delete-current-line) ; PF4
569 (define-key map "p" 'tpu-line) ; KP0
570 (define-key map "q" 'tpu-word) ; KP1
571 (define-key map "r" 'tpu-end-of-line) ; KP2
572 (define-key map "s" 'tpu-char) ; KP3
573 (define-key map "t" 'tpu-advance-direction) ; KP4
574 (define-key map "u" 'tpu-backup-direction) ; KP5
575 (define-key map "v" 'tpu-cut) ; KP6
576 (define-key map "w" 'tpu-page) ; KP7
577 (define-key map "x" 'tpu-scroll-window) ; KP8
578 (define-key map "y" 'tpu-append-region) ; KP9
579 (define-key map "m" 'tpu-delete-current-word) ; KP-
580 (define-key map "l" 'tpu-delete-current-char) ; KP,
581 (define-key map "n" 'tpu-select) ; KP.
587 (defvar tpu-global-map
602 (defvar tpu-last-replaced-text ""
603 "Last text deleted by a TPU-edt replace command.")
604 (defvar tpu-last-deleted-region ""
606 (defvar tpu-last-deleted-lines ""
608 (defvar tpu-last-deleted-words ""
610 (defvar tpu-last-deleted-char ""
613 (defvar tpu-searching-forward t
615 (defvar tpu-search-last-string ""
617 (defvar tpu-search-overlay (make-overlay 1 1)
619 (overlay-put tpu-search-overlay 'face 'bold)
621 (defvar tpu-replace-overlay (make-overlay 1 1)
623 (overlay-put tpu-replace-overlay 'face 'highlight)
625 (defvar tpu-regexp-p nil
626 "If non-nil, TPU-edt uses regexp search and replace routines.")
627 (defvar tpu-rectangular-p nil
629 (defvar tpu-advance t
631 (defvar tpu-reverse nil
633 (defvar tpu-control-keys nil
635 (defvar tpu-xkeys-file nil
638 (defvar tpu-rectangle-string nil
640 (defvar tpu-direction-string nil
643 (defvar tpu-add-at-bol-hist nil
644 "History variable for tpu-edt-add-at-bol function.")
645 (defvar tpu-add-at-eol-hist nil
646 "History variable for tpu-edt-add-at-eol function.")
647 (defvar tpu-regexp-prompt-hist nil
648 "History variable for search and replace functions.")
654 (defvar tpu-newline-and-indent-p nil
656 (make-variable-buffer-local 'tpu-newline-and-indent-p)
658 (defvar tpu-newline-and-indent-string nil
660 (make-variable-buffer-local 'tpu-newline-and-indent-string)
662 (defvar tpu-saved-delete-func nil
664 (make-variable-buffer-local 'tpu-saved-delete-func)
666 (defvar tpu-buffer-local-map nil
668 (make-variable-buffer-local 'tpu-buffer-local-map)
679 (defvar tpu-original-mm-alist minor-mode-alist)
681 (defvar tpu-mark-flag "")
682 (make-variable-buffer-local 'tpu-mark-flag)
684 (defun tpu-set-mode-line (for-tpu)
686 (let ((entries '((tpu-newline-and-indent-p tpu-newline-and-indent-string)
687 (tpu-rectangular-p tpu-rectangle-string)
688 (tpu-direction-string tpu-direction-string)
689 (tpu-mark-flag tpu-mark-flag))))
691 (if for-tpu
695 (defun tpu-update-mode-line nil
697 (setq tpu-mark-flag (if transient-mark-mode "" (if (tpu-mark) " @" " ")))
700 (cond (tpu-lucid-emacs-p
701 (add-hook 'zmacs-deactivate-region-hook 'tpu-update-mode-line)
702 (add-hook 'zmacs-activate-region-hook 'tpu-update-mode-line))
704 (add-hook 'activate-mark-hook 'tpu-update-mode-line)
705 (add-hook 'deactivate-mark-hook 'tpu-update-mode-line)))
716 (defvar tpu-match-beginning-mark (make-marker))
717 (defvar tpu-match-end-mark (make-marker))
719 (defun tpu-set-match nil
723 (setq tpu-match-beginning-mark (copy-marker (match-beginning 0) t))
724 (setq tpu-match-end-mark (copy-marker (match-end 0))))
726 (defun tpu-unset-match nil
728 (set-marker tpu-match-beginning-mark nil)
729 (set-marker tpu-match-end-mark nil))
731 (defun tpu-match-beginning nil
733 (marker-position tpu-match-beginning-mark))
735 (defun tpu-match-end nil
737 (marker-position tpu-match-end-mark))
739 (defun tpu-check-match nil
740 "Returns t if point is between tpu-match markers.
741 Otherwise sets the tpu-match markers to nil and returns nil."
748 (equal (marker-buffer tpu-match-beginning-mark) (current-buffer))
749 (>= (point) (marker-position tpu-match-beginning-mark))
751 (< (point) (marker-position tpu-match-end-mark))
752 (and (= (marker-position tpu-match-beginning-mark)
753 (marker-position tpu-match-end-mark))
754 (= (marker-position tpu-match-end-mark) (point))))) t)
756 (tpu-unset-match) nil)))
758 (defun tpu-show-match-markers nil
761 (if (markerp tpu-match-beginning-mark)
763 (marker-position tpu-match-beginning-mark)
764 (marker-position tpu-match-end-mark)
765 (marker-buffer tpu-match-end-mark)
772 (defun tpu-caar (thingy) (car (car thingy)))
773 (defun tpu-cadr (thingy) (car (cdr thingy)))
777 (defun tpu-mark nil
781 (cond (tpu-lucid-emacs-p (mark (not zmacs-regions)))
784 (defun tpu-set-mark (pos)
793 (defun tpu-string-prompt (prompt history-symbol)
797 (defvar tpu-last-answer nil "Most recent response to tpu-y-or-n-p.")
799 (defun tpu-y-or-n-p (prompt &optional not-yes)
809 (setq tpu-last-answer t))
811 (setq tpu-last-answer nil))
812 ((= ans ?\r) (setq tpu-last-answer (not not-yes)))
817 tpu-last-answer)
819 (defun tpu-local-set-key (key func)
822 (cond ((not (keymapp tpu-buffer-local-map))
823 (setq tpu-buffer-local-map (if (current-local-map)
826 (use-local-map tpu-buffer-local-map)))
829 (defun tpu-current-line nil
838 (defvar tpu-breadcrumb-plist nil
841 (defun tpu-drop-breadcrumb (num)
844 (put tpu-breadcrumb-plist num (list (current-buffer) (point)))
847 (defun tpu-goto-breadcrumb (num)
850 (cond ((get tpu-breadcrumb-plist num)
851 (switch-to-buffer (car (get tpu-breadcrumb-plist num)))
852 (goto-char (tpu-cadr (get tpu-breadcrumb-plist num)))
861 (defun tpu-change-case (num)
865 (cond ((tpu-mark)
872 (tpu-unselect t)))
873 ((tpu-check-match)
874 (let ((beg (tpu-match-beginning)) (end (tpu-match-end)))
880 (tpu-unset-match)))
886 (forward-char (if tpu-reverse -1 1))
889 (defun tpu-fill (num)
893 (cond ((tpu-mark)
894 (fill-region (point) (tpu-mark) num)
895 (tpu-unselect t))
899 (defun tpu-version nil
904 tpu-version))
906 (defun tpu-reset-screen-size (height width)
912 (defun tpu-toggle-newline-and-indent nil
915 (cond (tpu-newline-and-indent-p
916 (setq tpu-newline-and-indent-string "")
917 (setq tpu-newline-and-indent-p nil)
918 (tpu-local-set-key "\C-m" 'newline))
920 (setq tpu-newline-and-indent-string " AutoIndent")
921 (setq tpu-newline-and-indent-p t)
922 (tpu-local-set-key "\C-m" 'newline-and-indent)))
923 (tpu-update-mode-line)
926 (if tpu-newline-and-indent-p " and indents." "."))))
928 (defun tpu-spell-check nil
932 (cond (tpu-have-ispell
933 (if (tpu-mark) (ispell-region (tpu-mark) (point)) (ispell-buffer)))
935 (if (tpu-mark) (spell-region (tpu-mark) (point)) (spell-buffer))))
936 (if (tpu-mark) (tpu-unselect t)))
938 (defun tpu-toggle-overwrite-mode nil
942 (tpu-local-set-key "\177" tpu-saved-delete-func)
945 (setq tpu-saved-delete-func (local-key-binding "\177"))
946 (tpu-local-set-key "\177" 'picture-backward-clear-column)
949 (defun tpu-special-insert (num)
956 (defun tpu-quoted-insert (num)
968 (defun tpu-include (file)
974 (defun tpu-get (file)
979 (defun tpu-what-line nil
991 (defun tpu-exit nil
998 (defun tpu-quit nil
1006 (if (tpu-y-or-n-p
1017 (define-minor-mode tpu-edt-mode
1020 (if tpu-edt-mode (tpu-edt-on) (tpu-edt-off)))
1022 (defalias 'TPU-EDT-MODE 'tpu-edt-mode)
1025 (defalias 'tpu-edt 'tpu-edt-on)
1026 (defalias 'TPU-EDT 'tpu-edt-on)
1028 ;; Note: The following functions have no `tpu-' prefix. This is unavoidable.
1030 ;; so tpu-edt.el users expect things like M-x exit RET and M-x help RET
1034 (defalias 'exit 'tpu-exit)
1035 (defalias 'EXIT 'tpu-exit)
1037 (defalias 'Get 'tpu-get)
1038 (defalias 'GET 'tpu-get)
1040 (defalias 'include 'tpu-include)
1041 (defalias 'INCLUDE 'tpu-include)
1043 (defalias 'quit 'tpu-quit)
1044 (defalias 'QUIT 'tpu-quit)
1046 (defalias 'spell 'tpu-spell-check)
1047 (defalias 'SPELL 'tpu-spell-check)
1049 (defalias 'what\ line 'tpu-what-line)
1050 (defalias 'WHAT\ LINE 'tpu-what-line)
1052 (defalias 'replace 'tpu-lm-replace)
1053 (defalias 'REPLACE 'tpu-lm-replace)
1055 (defalias 'help 'tpu-help)
1056 (defalias 'HELP 'tpu-help)
1058 (defalias 'set\ cursor\ free 'tpu-set-cursor-free)
1059 (defalias 'SET\ CURSOR\ FREE 'tpu-set-cursor-free)
1061 (defalias 'set\ cursor\ bound 'tpu-set-cursor-bound)
1062 (defalias 'SET\ CURSOR\ BOUND 'tpu-set-cursor-bound)
1064 (defalias 'set\ scroll\ margins 'tpu-set-scroll-margins)
1065 (defalias 'SET\ SCROLL\ MARGINS 'tpu-set-scroll-margins)
1069 (defalias 'tpu-error 'error)
1082 (defvar tpu-help-keypad-map "\f
1105 (defvar tpu-help-text "
1155 section of tpu-edt.el. This section can be accessed through the standard
1170 tpu-edt under `emulations'.
1176 (defvar tpu-help-enter (format "%s" "\eOM")) ; tpu-help enter key symbol
1177 (defvar tpu-help-return (format "%s" "\r")) ; tpu-help enter key symbol
1178 (defvar tpu-help-N "N") ; tpu-help "N" symbol
1179 (defvar tpu-help-n "n") ; tpu-help "n" symbol
1180 (defvar tpu-help-P "P") ; tpu-help "P" symbol
1181 (defvar tpu-help-p "p") ; tpu-help "p" symbol
1183 (defun tpu-help nil
1192 (insert tpu-help-keypad-map)
1193 (insert tpu-help-text)
1199 (tpu-move-to-beginning)
1201 (tpu-line-to-top-of-window)
1205 (while (not (equal tpu-help-return fkey))
1223 (cond ((equal tpu-help-enter fkey)
1226 ((or (equal tpu-help-N fkey) (equal tpu-help-n fkey))
1234 (tpu-line-to-top-of-window))))
1235 ((or (equal tpu-help-P fkey) (equal tpu-help-p fkey))
1244 (tpu-line-to-top-of-window))))
1245 ((not (equal tpu-help-return fkey))
1256 (defun tpu-insert-escape nil
1261 (defun tpu-insert-formfeed nil
1270 (defvar tpu-saved-control-r nil "Saved value of Control-r.")
1272 (defun tpu-end-define-macro-key (key)
1277 (global-set-key "\C-r" tpu-saved-control-r))
1279 (defun tpu-define-macro-key nil
1282 (setq tpu-saved-control-r (global-key-binding "\C-r"))
1283 (global-set-key "\C-r" 'tpu-end-define-macro-key)
1290 (defun tpu-kill-buffer nil
1291 "Kills the current buffer. If tpu-kill-buffers-silently is non-nil,
1294 (if tpu-kill-buffers-silently (set-buffer-modified-p nil))
1297 (defun tpu-save-all-buffers-kill-emacs nil
1303 (defun tpu-write-current-buffers nil
1308 (defun tpu-next-buffer nil
1313 (defun tpu-next-file-buffer nil
1316 (let ((list (tpu-make-file-buffer-list (buffer-list))))
1318 (if (not list) (tpu-error "No other buffers."))
1321 (defun tpu-make-file-buffer-list (buffer-list)
1328 (defun tpu-next-window nil
1334 (defun tpu-previous-window nil
1344 (defun tpu-toggle-regexp nil
1345 "Switches in and out of regular expression search and replace mode."
1347 (setq tpu-regexp-p (not tpu-regexp-p))
1348 (tpu-set-search)
1351 (if tpu-regexp-p "en" "dis"))))
1353 (defun tpu-regexp-prompt (prompt)
1354 "Read a string, adding 'RE' to the prompt if tpu-regexp-p is set."
1355 (let ((re-prompt (concat (if tpu-regexp-p "RE ") prompt)))
1356 (read-from-minibuffer re-prompt nil nil nil 'tpu-regexp-prompt-hist)))
1358 (defun tpu-search-highlight nil
1359 (if (tpu-check-match)
1360 (move-overlay tpu-search-overlay
1361 (tpu-match-beginning) (tpu-match-end) (current-buffer))
1362 (unless (equal (overlay-start tpu-search-overlay)
1363 (overlay-end tpu-search-overlay))
1364 (move-overlay tpu-search-overlay 1 1 (current-buffer)))))
1366 (defun tpu-search nil
1370 (tpu-set-search)
1371 (tpu-search-internal ""))
1373 (defun tpu-search-forward nil
1377 (setq tpu-searching-forward t)
1378 (tpu-set-search t)
1379 (tpu-search-internal ""))
1381 (defun tpu-search-reverse nil
1385 (setq tpu-searching-forward nil)
1386 (tpu-set-search t)
1387 (tpu-search-internal ""))
1389 (defun tpu-search-again nil
1393 (tpu-search-internal tpu-search-last-string))
1395 ;; tpu-set-search defines the search functions used by the TPU-edt internal
1401 ;; tpu-advance tpu-backup
1402 ;; tpu-toggle-regexp tpu-toggle-search-direction (t)
1403 ;; tpu-search tpu-lm-replace
1404 ;; tpu-search-forward (t) tpu-search-reverse (t)
1405 ;; tpu-search-forward-exit (t) tpu-search-backward-exit (t)
1407 (defun tpu-set-search (&optional arg)
1410 (if (not arg) (setq tpu-searching-forward tpu-advance))
1411 (cond (tpu-searching-forward
1412 (cond (tpu-regexp-p
1413 (fset 'tpu-emacs-search 're-search-forward)
1414 (fset 'tpu-emacs-rev-search 're-search-backward))
1416 (fset 'tpu-emacs-search 'search-forward)
1417 (fset 'tpu-emacs-rev-search 'search-backward))))
1419 (cond (tpu-regexp-p
1420 (fset 'tpu-emacs-search 're-search-backward)
1421 (fset 'tpu-emacs-rev-search 're-search-forward))
1423 (fset 'tpu-emacs-search 'search-backward)
1424 (fset 'tpu-emacs-rev-search 'search-forward))))))
1426 (defun tpu-search-internal (pat &optional quiet)
1428 (setq tpu-search-last-string
1429 (if (not (string= "" pat)) pat (tpu-regexp-prompt "Search: ")))
1431 (tpu-unset-match)
1432 (tpu-adjust-search)
1435 (and case-fold-search (tpu-check-search-case tpu-search-last-string))))
1437 (cond ((tpu-emacs-search tpu-search-last-string nil t)
1438 (tpu-set-match) (goto-char (tpu-match-beginning)))
1441 (tpu-adjust-search t)
1444 (let ((tpu-searching-forward (not tpu-searching-forward)))
1445 (tpu-adjust-search)
1446 (setq found (tpu-emacs-rev-search tpu-search-last-string nil t))
1451 (cond ((tpu-y-or-n-p
1453 (if tpu-searching-forward "reverse" "forward")))
1454 (goto-char pos) (tpu-set-match)
1455 (tpu-toggle-search-direction))))
1461 (if tpu-regexp-p "RE " "") tpu-search-last-string)))))))))
1463 (defalias 'tpu-search-internal-core (symbol-function 'tpu-search-internal))
1465 (defun tpu-check-search-case (string)
1468 (if tpu-regexp-p
1478 (defun tpu-adjust-search (&optional arg)
1481 (if tpu-searching-forward
1485 (defun tpu-toggle-search-direction nil
1489 (setq tpu-searching-forward (not tpu-searching-forward))
1490 (tpu-set-search t)
1493 (if tpu-searching-forward "for" "back"))))
1495 (defun tpu-search-forward-exit nil
1498 (setq tpu-searching-forward t)
1499 (tpu-set-search t)
1502 (defun tpu-search-backward-exit nil
1505 (setq tpu-searching-forward nil)
1506 (tpu-set-search t)
1513 (defun tpu-select (&optional quiet)
1516 (cond ((tpu-mark)
1517 (tpu-unselect quiet))
1519 (tpu-set-mark (point))
1520 (tpu-update-mode-line)
1523 (defun tpu-unselect (&optional quiet)
1528 (tpu-set-mark nil)
1529 (tpu-update-mode-line)
1536 (defun tpu-toggle-rectangle nil
1539 (setq tpu-rectangular-p (not tpu-rectangular-p))
1540 (setq tpu-rectangle-string (if tpu-rectangular-p " Rect" ""))
1541 (tpu-update-mode-line)
1544 (if tpu-rectangular-p "en" "dis"))))
1546 (defun tpu-arrange-rectangle nil
1552 (cond ((> (point) (tpu-mark)) ; point on lower line
1568 (defun tpu-cut-text nil
1570 The text is saved for the tpu-paste command."
1572 (cond ((tpu-mark)
1573 (cond (tpu-rectangular-p
1574 (tpu-arrange-rectangle)
1575 (picture-clear-rectangle (point) (tpu-mark) (not overwrite-mode))
1576 (tpu-unselect t))
1578 (setq tpu-last-deleted-region
1579 (buffer-substring (tpu-mark) (point)))
1580 (delete-region (tpu-mark) (point))
1581 (tpu-unselect t))))
1582 ((tpu-check-match)
1583 (let ((beg (tpu-match-beginning)) (end (tpu-match-end)))
1584 (setq tpu-last-deleted-region (buffer-substring beg end))
1586 (tpu-unset-match)))
1588 (tpu-error "No selection active."))))
1590 (defun tpu-store-text nil
1592 The text is saved for the tpu-paste command."
1594 (cond ((tpu-mark)
1595 (cond (tpu-rectangular-p
1597 (tpu-arrange-rectangle)
1599 (extract-rectangle (point) (tpu-mark))))
1600 (tpu-unselect t))
1602 (setq tpu-last-deleted-region
1603 (buffer-substring (tpu-mark) (point)))
1604 (tpu-unselect t))))
1605 ((tpu-check-match)
1606 (setq tpu-last-deleted-region
1607 (buffer-substring (tpu-match-beginning) (tpu-match-end)))
1608 (tpu-unset-match))
1610 (tpu-error "No selection active."))))
1612 (defun tpu-cut (arg)
1616 (if arg (tpu-store-text) (tpu-cut-text)))
1618 (defun tpu-append-region (arg)
1619 "Append selected region to the tpu-cut buffer. In the absence of an
1622 (cond ((tpu-mark)
1624 (setq tpu-last-deleted-region
1625 (concat tpu-last-deleted-region
1628 (tpu-unselect t)))
1629 ((tpu-check-match)
1630 (let ((beg (tpu-match-beginning)) (end (tpu-match-end)))
1631 (setq tpu-last-deleted-region
1632 (concat tpu-last-deleted-region
1635 (tpu-unset-match)))
1637 (tpu-error "No selection active."))))
1639 (defun tpu-delete-current-line (num)
1648 (setq tpu-last-deleted-lines
1652 (defun tpu-delete-to-eol (num)
1660 (setq tpu-last-deleted-lines
1664 (defun tpu-delete-to-bol (num)
1670 (tpu-next-beginning-of-line num)
1671 (setq tpu-last-deleted-lines
1675 (defun tpu-delete-current-word (num)
1680 (tpu-forward-to-word num)
1681 (setq tpu-last-deleted-words
1685 (defun tpu-delete-previous-word (num)
1690 (tpu-backward-to-word num)
1691 (setq tpu-last-deleted-words
1695 (defun tpu-delete-current-char (num)
1700 (setq tpu-last-deleted-char (char-after (point)))
1712 (defun tpu-paste (num)
1717 (cond (tpu-rectangular-p
1724 (insert tpu-last-deleted-region)))
1727 (defun tpu-undelete-lines (num)
1733 (insert tpu-last-deleted-lines)
1737 (defun tpu-undelete-words (num)
1743 (insert tpu-last-deleted-words)
1747 (defun tpu-undelete-char (num)
1753 (insert tpu-last-deleted-char)
1761 (defun tpu-replace nil
1764 (cond ((tpu-mark)
1766 (setq tpu-last-replaced-text (buffer-substring beg end))
1768 (insert tpu-last-deleted-region)
1769 (tpu-unselect t)))
1770 ((tpu-check-match)
1771 (let ((beg (tpu-match-beginning)) (end (tpu-match-end)))
1772 (setq tpu-last-replaced-text (buffer-substring beg end))
1773 (replace-match tpu-last-deleted-region
1774 (not case-replace) (not tpu-regexp-p))
1775 (tpu-unset-match)))
1777 (tpu-error "No selection active."))))
1779 (defun tpu-substitute (num)
1782 A negative argument means replace all occurrences of the search string."
1784 (cond ((or (tpu-mark) (tpu-check-match))
1785 (while (and (not (= num 0)) (or (tpu-mark) (tpu-check-match)))
1787 (tpu-replace)
1788 (if tpu-searching-forward (forward-char -1) (goto-char beg))
1789 (if (= num 1) (tpu-search-internal tpu-search-last-string)
1790 (tpu-search-internal-core tpu-search-last-string)))
1793 (tpu-error "No selection active."))))
1795 (defun tpu-lm-replace (from to)
1797 (interactive (list (tpu-regexp-prompt "Old String: ")
1798 (tpu-regexp-prompt "New String: ")))
1802 ;; Can't replace null strings
1803 (if (string= "" from) (tpu-error "No string to replace."))
1806 (tpu-set-search)
1807 (tpu-search-internal from t)
1809 ;; Loop on replace question - yes, no, all, last, or quit.
1811 (if (not (tpu-check-match)) (setq doit nil)
1813 (move-overlay tpu-replace-overlay
1814 (tpu-match-beginning) (tpu-match-end) (current-buffer))
1820 (replace-match to (not case-replace) (not tpu-regexp-p))
1822 (if tpu-searching-forward (forward-char -1) (goto-char beg)))
1823 (tpu-search-internal from t))
1826 (tpu-search-internal from t))
1831 (replace-match to (not case-replace) (not tpu-regexp-p))
1833 (if tpu-searching-forward (forward-char -1) (goto-char beg)))
1834 (tpu-search-internal-core from t)
1835 (while (tpu-check-match)
1837 (replace-match to (not case-replace) (not tpu-regexp-p))
1839 (if tpu-searching-forward (forward-char -1) (goto-char beg)))
1840 (tpu-search-internal-core from t)))
1845 (replace-match to (not case-replace) (not tpu-regexp-p))
1847 (if tpu-searching-forward (forward-char -1) (goto-char beg)))
1851 (tpu-unset-match)
1854 (move-overlay tpu-replace-overlay 1 1 (current-buffer))
1857 (defun tpu-emacs-replace (&optional dont-ask)
1858 "A TPU-edt interface to the Emacs replace functions. If TPU-edt is
1860 replace functions are used. If an argument is supplied, replacements
1866 (if tpu-regexp-p 'replace-regexp 'replace-string)))
1869 (if tpu-regexp-p 'query-replace-regexp 'query-replace)))))
1871 (defun tpu-add-at-bol (text)
1875 (list (tpu-string-prompt "String to add: " 'tpu-add-at-bol-hist)))
1876 (if (string= "" text) (tpu-error "No string specified."))
1877 (cond ((tpu-mark)
1879 (if (> (point) (tpu-mark)) (exchange-point-and-mark))
1880 (while (and (< (point) (tpu-mark)) (re-search-forward "^" (tpu-mark) t))
1881 (if (< (point) (tpu-mark)) (replace-match text))))
1882 (tpu-unselect t))
1887 (replace-match text))))))
1889 (defun tpu-add-at-eol (text)
1893 (list (tpu-string-prompt "String to add: " 'tpu-add-at-eol-hist)))
1894 (if (string= "" text) (tpu-error "No string specified."))
1895 (cond ((tpu-mark)
1897 (if (> (point) (tpu-mark)) (exchange-point-and-mark))
1898 (while (< (point) (tpu-mark))
1900 (if (<= (point) (tpu-mark)) (insert text))
1902 (tpu-unselect t))
1909 (defun tpu-trim-line-ends nil
1922 (defun tpu-char (num)
1926 (if tpu-advance (tpu-forward-char num) (tpu-backward-char num)))
1928 (defun tpu-forward-char (num)
1933 (defun tpu-backward-char (num)
1942 (defvar tpu-word-separator-list '()
1944 (defvar tpu-skip-chars "^ \t"
1948 (defun tpu-word (num)
1952 (if tpu-advance (tpu-forward-to-word num) (tpu-backward-to-word num)))
1954 (defun tpu-forward-to-word (num)
1963 ((memq (char-after (point)) tpu-word-separator-list)
1967 (skip-chars-forward tpu-skip-chars end)
1971 (defun tpu-backward-to-word (num)
1980 ((memq (char-after (1- (point))) tpu-word-separator-list)
1984 (skip-chars-backward tpu-skip-chars end)
1989 (defun tpu-add-word-separators (separators)
1996 (cond ((not (memq char tpu-word-separator-list))
1997 (setq tpu-word-separator-list
1998 (append ss tpu-word-separator-list))
2000 (setq tpu-skip-chars (concat tpu-skip-chars "\\-")))
2002 (setq tpu-skip-chars (concat tpu-skip-chars "\\\\")))
2004 (setq tpu-skip-chars (concat tpu-skip-chars "\\^")))
2006 (setq tpu-skip-chars (concat tpu-skip-chars ss))))))
2009 (defun tpu-reset-word-separators nil
2012 (setq tpu-word-separator-list nil)
2013 (setq tpu-skip-chars "^ \t"))
2015 (defun tpu-set-word-separators (separators)
2018 (tpu-reset-word-separators)
2019 (tpu-add-word-separators separators))
2025 (defun tpu-next-line (num)
2032 (defun tpu-previous-line (num)
2039 (defun tpu-next-beginning-of-line (num)
2046 (defun tpu-end-of-line (num)
2050 (if tpu-advance (tpu-next-end-of-line num) (tpu-previous-end-of-line num)))
2052 (defun tpu-next-end-of-line (num)
2059 (defun tpu-previous-end-of-line (num)
2065 (defun tpu-current-end-of-line nil
2072 (defun tpu-line (num)
2076 (if tpu-advance (tpu-forward-line num) (tpu-backward-line num)))
2078 (defun tpu-forward-line (num)
2084 (defun tpu-backward-line (num)
2095 (defun tpu-paragraph (num)
2099 (if tpu-advance
2100 (tpu-next-paragraph num) (tpu-previous-paragraph num)))
2102 (defun tpu-next-paragraph (num)
2116 (defun tpu-previous-paragraph (num)
2135 (defun tpu-page (num)
2139 (if tpu-advance (forward-page num) (backward-page num))
2146 (defun tpu-scroll-window (num)
2150 (if tpu-advance (tpu-scroll-window-up num) (tpu-scroll-window-down num)))
2152 (defun tpu-scroll-window-down (num)
2156 (let* ((beg (tpu-current-line))
2158 (lines (* num (/ (* height tpu-percent-scroll) 100))))
2162 (defun tpu-scroll-window-up (num)
2166 (let* ((beg (tpu-current-line))
2168 (lines (* num (/ (* height tpu-percent-scroll) 100))))
2172 (defun tpu-pan-right (num)
2173 "Pan right tpu-pan-columns (16 by default).
2174 Accepts a prefix argument for the number of tpu-pan-columns to scroll."
2176 (scroll-left (* tpu-pan-columns num)))
2178 (defun tpu-pan-left (num)
2179 "Pan left tpu-pan-columns (16 by default).
2180 Accepts a prefix argument for the number of tpu-pan-columns to scroll."
2182 (scroll-right (* tpu-pan-columns num)))
2184 (defun tpu-move-to-beginning nil
2189 (defun tpu-move-to-end nil
2195 (defun tpu-goto-percent (perc)
2199 (tpu-error "Percentage %d out of range 0 < percent < 100." perc)
2202 (defun tpu-beginning-of-window nil
2207 (defun tpu-end-of-window nil
2212 (defun tpu-line-to-bottom-of-window nil
2217 (defun tpu-line-to-top-of-window nil
2226 (defun tpu-advance-direction nil
2229 (setq tpu-direction-string " Advance")
2230 (setq tpu-advance t)
2231 (setq tpu-reverse nil)
2232 (tpu-set-search)
2233 (tpu-update-mode-line))
2235 (defun tpu-backup-direction nil
2238 (setq tpu-direction-string " Reverse")
2239 (setq tpu-advance nil)
2240 (setq tpu-reverse t)
2241 (tpu-set-search)
2242 (tpu-update-mode-line))
2244 (defun tpu-toggle-direction nil
2247 (if tpu-advance (tpu-backup-direction) (tpu-advance-direction)))
2266 (define-key minibuffer-local-map "\eOt" 'tpu-search-forward-exit) ;KP4
2267 (define-key minibuffer-local-map "\eOu" 'tpu-search-backward-exit) ;KP5
2274 (defvar tpu-control-keys-map
2277 (define-key map "\C-a" 'tpu-toggle-overwrite-mode) ; ^A
2279 (define-key map "\C-e" 'tpu-current-end-of-line) ; ^E
2280 (define-key map "\C-h" 'tpu-next-beginning-of-line) ; ^H (BS)
2281 (define-key map "\C-j" 'tpu-delete-previous-word) ; ^J (LF)
2282 (define-key map "\C-k" 'tpu-define-macro-key) ; ^K
2283 (define-key map "\C-l" 'tpu-insert-formfeed) ; ^L (FF)
2285 (define-key map "\C-u" 'tpu-delete-to-bol) ; ^U
2286 (define-key map "\C-v" 'tpu-quoted-insert) ; ^V
2288 (define-key map "\C-z" 'tpu-exit) ; ^Z
2291 (defun tpu-set-control-keys ()
2293 (tpu-reset-control-keys 'tpu))
2295 (defun tpu-reset-control-keys (tpu-style)
2297 (let ((parent (keymap-parent tpu-global-map)))
2298 (if tpu-style
2299 (if (eq parent tpu-control-keys-map)
2301 ;; Insert tpu-control-keys-map in the global map.
2302 (set-keymap-parent tpu-control-keys-map parent)
2303 (set-keymap-parent tpu-global-map tpu-control-keys-map))
2304 (if (not (eq parent tpu-control-keys-map))
2306 ;; Remove tpu-control-keys-map from the global map.
2307 (set-keymap-parent tpu-global-map (keymap-parent parent))
2308 (set-keymap-parent tpu-control-keys-map nil)))
2309 (setq tpu-control-keys tpu-style)))
2311 (defun tpu-toggle-control-keys nil
2314 (tpu-reset-control-keys (not tpu-control-keys))
2317 (if tpu-control-keys "TPU-edt" "Emacs"))))
2323 (defun tpu-next-history-element (n)
2329 (defun tpu-previous-history-element (n)
2335 (defun tpu-arrow-history nil
2338 (dolist (cur (where-is-internal 'tpu-previous-line))
2339 (define-key read-expression-map cur 'tpu-previous-history-element)
2340 (define-key minibuffer-local-map cur 'tpu-previous-history-element)
2342 ;; (define-key minibuffer-local-ns-map cur 'tpu-previous-history-element)
2343 ;; (define-key minibuffer-local-completion-map cur 'tpu-previous-history-element)
2344 ;; (define-key minibuffer-local-must-match-map cur 'tpu-previous-history-element)
2347 (dolist (cur (where-is-internal 'tpu-next-line))
2348 (define-key read-expression-map cur 'tpu-next-history-element)
2349 (define-key minibuffer-local-map cur 'tpu-next-history-element)
2351 ;; (define-key minibuffer-local-ns-map cur 'tpu-next-history-element)
2352 ;; (define-key minibuffer-local-completion-map cur 'tpu-next-history-element)
2353 ;; (define-key minibuffer-local-must-match-map cur 'tpu-next-history-element)
2360 (defun tpu-load-xkeys (file)
2363 `~/.tpu-lucid-keys' for Lucid emacs, and `~/.tpu-keys' for Emacs."
2367 (tpu-xkeys-file
2368 (setq file (expand-file-name tpu-xkeys-file)))
2369 (tpu-lucid-emacs-p
2371 (expand-file-name "~/.tpu-lucid-keys"))))
2374 (expand-file-name "~/.tpu-keys")))
2378 (expand-file-name "~/.tpu-gnu-keys")))
2379 (tpu-copy-keyfile
2381 (expand-file-name "~/.tpu-gnu-keys")) file))))
2391 file, run the tpu-mapper.el program. It came with TPU-edt. It
2394 (let ((file "tpu-mapper.el")
2408 (if (tpu-y-or-n-p "Do you want to run it now? ")
2414 (defun tpu-copy-keyfile (oldname newname)
2424 from `~/.tpu-gnu-keys' to `~/.tpu-keys'. With your permission,
2436 (and (tpu-y-or-n-p "Copy key definitions to the new file now? ")
2439 (tpu-error (message "Sorry, couldn't copy - %s." (cdr conditions)))))
2447 (defun tpu-edt-on ()
2450 ;; First, activate tpu-global-map, while protecting the original keymap.
2451 (set-keymap-parent tpu-global-map global-map)
2452 (setq global-map tpu-global-map)
2456 (add-hook 'post-command-hook 'tpu-search-highlight)
2457 (tpu-set-mode-line t)
2458 (tpu-advance-direction)
2463 (tpu-set-control-keys)
2464 (and window-system (tpu-load-xkeys nil))
2465 (tpu-arrow-history)
2466 ;; Then protect tpu-global-map from user modifications.
2471 (setq tpu-edt-mode t))
2473 (defun tpu-edt-off ()
2476 (tpu-reset-control-keys nil)
2477 (remove-hook 'post-command-hook 'tpu-search-highlight)
2478 (tpu-set-mode-line nil)
2482 ;; Remove tpu-global-map from the global map.
2486 (if (eq tpu-global-map parent)
2489 (setq tpu-edt-mode nil))
2491 (provide 'tpu-edt)
2494 ;;; tpu-edt.el ends here