Debian Codegraph @

mew-fib.el

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