annotate lisp/tl/tu-replace.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents
children 4b173ad71786
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; tu-replace.el --- a replacing utility for GNU Emacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995,1996 MORIOKA Tomohiko
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6 ;; Version: $Id: tu-replace.el,v 1.1.1.1 1996/12/18 03:55:31 steve Exp $
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7 ;; Keywords: replace
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9 ;; This file is part of tl (Tiny Library).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; along with this program; see the file COPYING. If not, write to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26 ;;; Commentary:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 ;; - How to install.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 ;; 1. bytecompile this file and copy it to the apropriate directory.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30 ;; 2. put the following lines to your ~/.emacs:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31 ;; (autoload 'edit-replace-region "tu-replace" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 ;; - How to use.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 ;; 1. mark in beginning of region you want to replace.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 ;; 2. go to end of region you want to replace.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35 ;; 3. type M-x edit-replace-region [CR]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36 ;; then entering to ``edit-replace mode''.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 ;; 4. edit replacement string.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 ;; 5. type C-c C-c then specified region will be replaced.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 (defvar edit-replace-mode-map nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 (if (null edit-replace-mode-map)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45 (setq edit-replace-mode-map (copy-keymap text-mode-map))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 (define-key edit-replace-mode-map
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 "\C-c\C-c" (function edit-replace-query-replace))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 (make-variable-buffer-local 'edit-replace-original-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 (make-variable-buffer-local 'edit-replace-start-point)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 (make-variable-buffer-local 'edit-replace-end-point)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54 (defvar edit-replace-original-buffer nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (defvar edit-replace-start-point nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 (defvar edit-replace-end-point nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 (defun edit-replace-region (beg end &optional str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 (interactive "r")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 (let ((the-buf (current-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 (buf (get-buffer-create " *edit-replace*")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 (pop-to-buffer buf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 (setq major-mode 'edit-replace)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 (setq mode-name "edit for replace")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 (use-local-map edit-replace-mode-map)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 (setq edit-replace-original-buffer the-buf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 (setq edit-replace-start-point beg)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68 (setq edit-replace-end-point end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (defun edit-replace-query-replace ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 (interactive)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 (let ((beg edit-replace-start-point)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 (end edit-replace-end-point)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 str
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 (rstr (buffer-string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 (switch-to-buffer edit-replace-original-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 (setq str (buffer-substring beg end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 (goto-char beg)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 (query-replace str rstr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 ;;; tu-replace.el ends here