Initial Commit
[packages] / xemacs-packages / mew / mew / mew-fib.el
1 ;;; mew-fib.el --- Filling blanks for Mew
2
3 ;; Author:  Yoshinari NOMURA <nom@csce.kyushu-u.ac.jp>
4 ;; Created: Nov 29, 1994
5 ;; Revised: Aug 30, 1999
6
7 ;;; Code:
8
9 (defconst mew-fib-version "mew-fib.el version 0.12")
10
11 (require 'mew-func)
12
13 (defvar mew-fib-item-file "~/.mew-fib")
14 (defvar mew-fib-item-alist nil)
15
16 (defun mew-fib-split (str)
17   (let (ret match)
18     (while (string-match "[\t \n]*\\([^,]+\\)" str)
19       (setq  match (substring str (match-beginning 1) (match-end 1))
20              str (substring str (match-end 0))
21              match (if (string-match "[\t \n]+$" match)
22                        (substring match 0 (match-beginning 0))
23                      match)
24              ret (cons match ret)))
25     (reverse ret)))
26
27 (defun mew-fib-make-alist ()
28   (save-excursion
29     (let ((fib-file (expand-file-name mew-fib-item-file))
30           item val ret tmp-val)
31       (setq mew-fib-item-alist nil)
32       (mew-set-buffer-tmp)
33       (if (file-exists-p fib-file)
34           (insert-file-contents fib-file))
35       (goto-char (point-min))
36       (delete-matching-lines "^[ \t]*[;#%]")
37       (while (re-search-forward "^\\([^:]+\\):[ \t]*\\(.*\\)$" nil t)
38         (setq item    (buffer-substring (match-beginning 1) (match-end 1))
39               tmp-val (buffer-substring (match-beginning 2) (match-end 2))
40               val (if (string= tmp-val "") val tmp-val)
41               ret (append ret (mapcar (function (lambda (arg)
42                                                   (cons (downcase arg) val)))
43                                       (mew-fib-split item)))))
44       ret)))
45
46 (defun mew-fib-fill-default ()
47   "Fill |>item<| according to the information from .mew-fib"
48   (interactive)
49   (save-excursion
50     (let (begin end str)
51       (setq mew-fib-item-alist (mew-fib-make-alist))
52       (goto-char (point-min))
53       (while (re-search-forward "|>\\([^<]+\\)<|" nil t)
54         (setq begin (match-beginning 1)
55               end (match-end 1)
56               str (buffer-substring begin end))
57         (delete-region begin end)
58         (backward-char 2)
59         (insert (or (cdr (assoc (downcase str) mew-fib-item-alist)) str)))
60     )))
61
62 (defun mew-fib-delete-frame ()
63   "Delete all quotations, '|>' and '<|'. This is the finishing stroke."
64   (interactive)
65   (save-excursion
66     (goto-char (point-min))
67     (while (re-search-forward "|>\\|<|" nil t)
68       (replace-match "" nil t)
69       )))
70
71 (defun mew-fib-flush-input ()
72   "Flush the fib item on the current point."
73   (interactive)
74   (save-excursion
75     (let ((ptr (point)))
76       (if (and (search-backward "|>" nil t)
77                (looking-at "|>\\([^<]+\\)<|")
78                (>= ptr (match-beginning 1))
79                (<= ptr (match-end 1)))
80           (delete-region (match-beginning 1)
81                          (match-end 1))))))
82
83 (defun mew-fib-next-item ()
84   "Jump to the next fib item."
85   (interactive)
86   (if (re-search-forward "|>\\([^<]+\\)<|" nil t)
87       (backward-char 2)
88     (goto-char (point-min))
89     (re-search-forward "|>\\([^<]+\\)<|" nil t)))
90
91 (defun mew-fib-previous-item ()
92   "Jump to the previous fib item."
93   (interactive)
94   (if (re-search-backward "|>\\([^<]+\\)<|" nil t)
95       (forward-char 2)
96     (goto-char (point-max))
97     (re-search-backward "|>\\([^<]+\\)<|" nil t)))
98
99 (provide 'mew-fib)
100
101 ;;; Copyright Notice:
102
103 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999 Mew developing team.
104 ;; All rights reserved.
105
106 ;; Redistribution and use in source and binary forms, with or without
107 ;; modification, are permitted provided that the following conditions
108 ;; are met:
109 ;; 
110 ;; 1. Redistributions of source code must retain the above copyright
111 ;;    notice, this list of conditions and the following disclaimer.
112 ;; 2. Redistributions in binary form must reproduce the above copyright
113 ;;    notice, this list of conditions and the following disclaimer in the
114 ;;    documentation and/or other materials provided with the distribution.
115 ;; 3. Neither the name of the team nor the names of its contributors
116 ;;    may be used to endorse or promote products derived from this software
117 ;;    without specific prior written permission.
118 ;; 
119 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
120 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
121 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
122 ;; PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
123 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
124 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
125 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
126 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
127 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
128 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
129 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
130
131 ;;; mew-fib.el ends here