55ed49ca33b62bc8ef20828215d8feac5a65cde9
[elisp/tm.git] / tl-str.el
1 ;;;
2 ;;; $Id: tl-str.el,v 1.4 1994/09/01 06:02:25 morioka Exp morioka $
3 ;;;
4
5 (provide 'tl-str)
6
7 (defun fill-cited-region (beg end)
8   (interactive "*r")
9   (save-excursion
10     (save-restriction
11       (goto-char end)
12       (while (not (eolp))
13         (backward-char)
14         )
15       (setq end (point))
16       (narrow-to-region beg end)
17       (goto-char (point-min))
18       (let* ((fill-prefix
19               (and (re-search-forward "^[^ \t>]*[>|]+[ \t#]*" nil t)
20                    (buffer-substring (match-beginning 0)
21                                      (match-end 0)
22                                      )))
23              (pat (concat "\n" fill-prefix))
24              )
25         (goto-char (point-min))
26         (while (search-forward pat nil t)
27           (replace-match "")
28           )
29         (goto-char (point-min))
30         (fill-region (point-min) (point-max))
31         ))))
32
33 (defun replace-top-string (&optional old new)
34   (interactive)
35   (if (null old)
36       (setq old (read-string "old string is ? "))
37     )
38   (if (null new)
39       (setq new (read-string "new string is ? "))
40     )
41   (while (re-search-forward (concat "^" (regexp-quote old)) nil t)
42     (replace-match new)
43     ))
44
45 (defun replace-as-filename (str)
46   (let ((dest "")
47         (i 0)(len (length str))
48         chr)
49     (while (< i len)
50       (setq chr (elt str i))
51       (if (or (and (<= ?+ chr)(<= chr ?.))
52               (and (<= ?0 chr)(<= chr ?:))
53               (= chr ?=)
54               (and (<= ?@ chr)(<= chr ?\[))
55               (and (<= ?\] chr)(<= chr ?_))
56               (and (<= ?a chr)(<= chr ?{))
57               (and (<= ?} chr)(<= chr ?~))
58               )
59           (setq dest (concat dest
60                              (char-to-string chr)))
61         )
62       (setq i (+ i 1))
63       )
64     dest))