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