(mu-modules-to-compile): Add `mu-register'.
[elisp/mu-cite.git] / mu-cite.el
1 ;;; mu-cite.el --- yet another citation tool for GNU Emacs
2
3 ;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;;         MINOURA Makoto <minoura@netlaputa.or.jp>
7 ;;         Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Maintainer: Katsumi Yamaoka <yamaoka@jpl.org>
9 ;; Keywords: mail, news, citation
10
11 ;; This file is part of MU (Message Utilities).
12
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
17
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30 ;; - How to use
31 ;;   1. bytecompile this file and copy it to the apropriate directory.
32 ;;   2. put the following lines to your ~/.emacs:
33 ;;      for EMACS 19 or later and XEmacs
34 ;;              (autoload 'mu-cite-original "mu-cite" nil t)
35 ;;              ;; for all but message-mode
36 ;;              (add-hook 'mail-citation-hook (function mu-cite-original))
37 ;;              ;; for message-mode only
38 ;;              (setq message-cite-function (function mu-cite-original))
39 ;;      for EMACS 18
40 ;;              ;; for all but mh-e
41 ;;              (add-hook 'mail-yank-hooks (function mu-cite-original))
42 ;;              ;; for mh-e only
43 ;;              (add-hook 'mh-yank-hooks (function mu-cite-original))
44
45 ;;; Code:
46
47 (eval-when-compile (require 'cl))
48
49 ;; Pickup some macros, e.g. `with-temp-buffer', for old Emacsen.
50 (require 'poe)
51
52 ;; Pickup `char-category' for XEmacs.
53 (require 'emu)
54
55 (require 'custom)
56 (require 'std11)
57 (require 'alist)
58
59
60 ;;; @ version
61 ;;;
62
63 (defconst mu-cite-version "8.0")
64
65
66 ;;; @ obsoletes
67 ;;;
68
69 ;; This part will be abolished in the future.
70
71 ;; variables
72 (eval-when-compile (require 'static))
73
74 (defvar mu-cite/registration-file)
75 (defvar mu-cite-registration-file)
76 (defmacro mu-cite-registration-file ()
77   (if (fboundp 'defvaralias)
78       'mu-cite-registration-file
79     '(if (and (not noninteractive)
80               (boundp 'mu-cite/registration-file))
81          (prog1
82              (if (yes-or-no-p
83                   (format "Obsolete variable `%s' found, use anyway? "
84                           'mu-cite/registration-file))
85                  (symbol-value 'mu-cite/registration-file)
86                mu-cite-registration-file)
87            (message "You should use `%s' instead of `%s'."
88                     'mu-cite-registration-file 'mu-cite/registration-file)
89            (sleep-for 1))
90        mu-cite-registration-file)))
91
92 (eval-and-compile
93   (defconst mu-cite-obsolete-variable-alist
94     '((mu-cite/allow-null-string-registration
95        mu-cite-allow-null-string-registration)
96       (mu-cite/citation-name-alist      mu-cite-citation-name-alist)
97       (mu-cite/cited-prefix-regexp      mu-cite-cited-prefix-regexp)
98       (mu-cite/default-methods-alist    mu-cite-default-methods-alist)
99       (mu-cite/instantiation-hook       mu-cite-instantiation-hook)
100       (mu-cite/minibuffer-history       mu-cite-minibuffer-history)
101       (mu-cite/ml-count-field-list      mu-cite-ml-count-field-list)
102       (mu-cite/post-cite-hook           mu-cite-post-cite-hook)
103       (mu-cite/pre-cite-hook            mu-cite-pre-cite-hook)
104       (mu-cite/prefix-format            mu-cite-prefix-format)
105       (mu-cite/registration-file        mu-cite-registration-file)
106       (mu-cite/top-format               mu-cite-top-format)))
107
108   (mapcar
109    (function
110     (lambda (elem)
111       (apply (function make-obsolete-variable) elem)
112       (when (and (not noninteractive)
113                  (boundp (car elem)))
114         (apply (function message)
115                "WARNING: `%s' is an obsolete variable, use `%s' instead."
116                elem))
117       (static-if (fboundp 'defvaralias) ; It may exists in XEmacs.
118           (apply (function defvaralias) elem)
119         (when (boundp (car elem))
120           (eval (list 'defvar (cadr elem) (car elem)))))))
121    mu-cite-obsolete-variable-alist)
122   )
123
124 ;; functions
125 (eval-and-compile
126   (defconst mu-cite-obsolete-function-alist
127     '((mu-cite/add-citation-name        mu-cite-add-citation-name)
128       (mu-cite/cite-original            mu-cite-original)
129       (mu-cite/eval-format              mu-cite-eval-format)
130       (mu-cite/get-citation-name        mu-cite-get-citation-name)
131       (mu-cite/get-field-value          mu-cite-get-field-value)
132       (mu-cite/get-ml-count-method      mu-cite-get-ml-count-method)
133       (mu-cite/get-prefix-method        mu-cite-get-prefix-method)
134       (mu-cite/get-prefix-register-method
135        mu-cite-get-prefix-register-method)
136       (mu-cite/get-prefix-register-verbose-method
137        mu-cite-get-prefix-register-verbose-method)
138       (mu-cite/get-value                mu-cite-get-value)
139       (mu-cite/load-registration-file   mu-cite-load-registration-file)
140       (mu-cite/make-methods             mu-cite-make-methods)
141       (mu-cite/save-registration-file   mu-cite-save-registration-file)))
142
143   (mapcar
144    (function (lambda (elem)
145                (apply (function define-obsolete-function-alias) elem)))
146    mu-cite-obsolete-function-alist)
147   )
148
149
150 ;;; @ set up
151 ;;;
152
153 (defgroup mu-cite nil
154   "yet another citation tool for GNU Emacs."
155   :prefix "mu-cite-"
156   :group 'mail
157   :group 'news)
158
159 (defvar mu-cite-default-methods-alist
160   (list (cons 'from
161               (function
162                (lambda ()
163                  (mu-cite-get-field-value "From"))))
164         (cons 'date
165               (function
166                (lambda ()
167                  (mu-cite-get-field-value "Date"))))
168         (cons 'message-id
169               (function
170                (lambda ()
171                  (mu-cite-get-field-value "Message-Id"))))
172         (cons 'subject
173               (function
174                (lambda ()
175                  (mu-cite-get-field-value "Subject"))))
176         (cons 'ml-name
177               (function
178                (lambda ()
179                  (mu-cite-get-field-value "X-Ml-Name"))))
180         (cons 'ml-count (function mu-cite-get-ml-count-method))
181         (cons 'address-structure
182               (function
183                (lambda ()
184                  (car
185                   (std11-parse-address-string (mu-cite-get-value 'from))))))
186         (cons 'full-name
187               (function
188                (lambda ()
189                  (std11-full-name-string
190                   (mu-cite-get-value 'address-structure)))))
191         (cons 'address
192               (function
193                (lambda ()
194                  (std11-address-string
195                   (mu-cite-get-value 'address-structure)))))
196         (cons 'id
197               (function
198                (lambda ()
199                  (let ((ml-name (mu-cite-get-value 'ml-name)))
200                    (if ml-name
201                        (concat "["
202                                ml-name
203                                " : No."
204                                (mu-cite-get-value 'ml-count)
205                                "]")
206                      (mu-cite-get-value 'message-id))))))
207         (cons 'in-id
208               (function
209                (lambda ()
210                  (let ((id (mu-cite-get-value 'id)))
211                    (if id
212                        (format ">>>>> In %s \n" id)
213                      "")))))
214         (cons 'prefix (function mu-cite-get-prefix-method))
215         (cons 'prefix-register
216               (function mu-cite-get-prefix-register-method))
217         (cons 'prefix-register-verbose
218               (function mu-cite-get-prefix-register-verbose-method))
219         (cons 'x-attribution
220               (function
221                (lambda ()
222                  (mu-cite-get-field-value "X-Attribution"))))
223         ))
224
225
226 ;;; @ formats
227 ;;;
228
229 (defcustom mu-cite-cited-prefix-regexp
230   "\\(^[^ \t\n<>]+>+[ \t]*\\|^[ \t]*$\\)"
231   "Regexp to match the citation prefix.
232 If match, mu-cite doesn't insert citation prefix."
233   :type 'regexp
234   :group 'mu-cite)
235
236 (defcustom mu-cite-prefix-format '(prefix-register-verbose "> ")
237   "List to represent citation prefix.
238 Each elements must be string or method name."
239   :type (list 'repeat
240               (nconc '(choice :tag "String or Method name")
241                      (mapcar
242                       (function
243                        (lambda (elem) (list 'choice-item (car elem))))
244                       mu-cite-default-methods-alist)
245                      '((symbol :tag "Other Method")
246                        (item "-")
247                        (choice-item :tag "String: \"> \"" "> ")
248                        (string :tag "Other String"))))
249   :group 'mu-cite)
250
251 (defcustom mu-cite-top-format '(in-id ">>>>>\t" from " wrote:\n")
252   "List to represent top string of citation.
253 Each elements must be string or method name."
254   :type (list 'repeat
255               (nconc
256                '(choice :tag "String or Method name")
257                (mapcar
258                 (function
259                  (lambda (elem) (list 'choice-item (car elem))))
260                 mu-cite-default-methods-alist)
261                '((symbol :tag "Other Method")
262                  (item "-")
263                  (choice-item :tag "String: \">>>>>\\t\"" ">>>>>\t")
264                  (choice-item :tag "String: \" wrote:\\n\"" " wrote:\n")
265                  (string :tag "Other String"))))
266   :group 'mu-cite)
267
268
269 ;;; @ hooks
270 ;;;
271
272 (defcustom mu-cite-load-hook nil
273   "List of functions called after mu-cite is loaded.
274 Use this hook to add your own methods to `mu-cite-default-methods-alist'."
275   :type 'hook
276   :group 'mu-cite)
277
278 (defcustom mu-cite-instantiation-hook nil
279   "List of functions called just before narrowing to the message."
280   :type 'hook
281   :group 'mu-cite)
282
283 (defcustom mu-cite-pre-cite-hook nil
284   "List of functions called before citing a region of text."
285   :type 'hook
286   :group 'mu-cite)
287
288 (defcustom mu-cite-post-cite-hook nil
289   "List of functions called after citing a region of text."
290   :type 'hook
291   :group 'mu-cite)
292
293
294 ;;; @ field
295 ;;;
296
297 (defvar mu-cite-get-field-value-method-alist nil
298   "Alist major-mode vs. function to get field-body of header.")
299
300 (defun mu-cite-get-field-value (name)
301   (or (std11-field-body name)
302       (let ((method (assq major-mode mu-cite-get-field-value-method-alist)))
303         (when method
304           (funcall (cdr method) name)))))
305
306
307 ;;; @ prefix registration
308 ;;;
309
310 (defcustom mu-cite-registration-file (expand-file-name "~/.mu-cite.el")
311   "The name of the user environment file for mu-cite."
312   :type 'file
313   :group 'mu-cite)
314
315 (defcustom mu-cite-allow-null-string-registration nil
316   "If non-nil, null-string citation-name is registered."
317   :type 'boolean
318   :group 'mu-cite)
319
320 (defcustom mu-cite-registration-file-coding-system-for-read nil
321   "Coding system for reading registration file."
322   :group 'mu-cite)
323
324 (defcustom mu-cite-registration-file-coding-system-for-write nil
325   "Coding system for writing registration file."
326   :group 'mu-cite)
327
328 (defcustom mu-cite-registration-file-modes 384
329   "Mode bits of `mu-cite-registration-file', as an integer."
330   :type 'integer
331   :group 'mu-cite)
332
333 (defvar mu-cite-registration-symbol 'mu-cite-citation-name-alist)
334
335 (defvar mu-cite-citation-name-alist nil)
336 (unless (eq 'mu-cite-citation-name-alist mu-cite-registration-symbol)
337   (setq mu-cite-citation-name-alist
338         (symbol-value mu-cite-registration-symbol)))
339 (defvar mu-cite-minibuffer-history nil)
340
341 ;; get citation-name from the database
342 (defun mu-cite-get-citation-name (from)
343   (cdr (assoc from mu-cite-citation-name-alist)))
344
345 ;; register citation-name to the database
346 (defun mu-cite-add-citation-name (name from)
347   (setq mu-cite-citation-name-alist
348         (put-alist from name mu-cite-citation-name-alist))
349   (mu-cite-save-registration-file))
350
351 ;; load/save registration file
352 ;;(defun mu-cite-load-registration-file ()
353 ;;  (let ((file mu-cite-registration-file))
354 ;;    (when (and file
355 ;;             (file-readable-p file))
356 ;;      (let ((alist
357 ;;           (with-temp-buffer
358 ;;             (eval
359 ;;              (` (let ((, mu-cite-registration-symbol))
360 ;;                   (if mu-cite-registration-file-coding-system-for-read
361 ;;                       (insert-file-contents-as-coding-system
362 ;;                        mu-cite-registration-file-coding-system-for-read
363 ;;                        file)
364 ;;                     (insert-file-contents file))
365 ;;                   (condition-case nil
366 ;;                       (progn
367 ;;                         (eval-current-buffer)
368 ;;                         (, mu-cite-registration-symbol))
369 ;;                     (error nil))))))))
370 ;;      (when alist
371 ;;        (setq mu-cite-citation-name-alist alist))))))
372 (defun mu-cite-load-registration-file ()
373   (let ((file (mu-cite-registration-file)))
374     (when (and file
375                (file-readable-p file))
376       (let ((alist
377              (with-temp-buffer
378                (eval
379                 (` (let ((, mu-cite-registration-symbol)
380                          mu-cite/citation-name-alist)
381                      (if mu-cite-registration-file-coding-system-for-read
382                          (insert-file-contents-as-coding-system
383                           mu-cite-registration-file-coding-system-for-read
384                           file)
385                        (insert-file-contents file))
386                      (condition-case nil
387                          (progn
388                            (eval-current-buffer)
389                            (or mu-cite/citation-name-alist
390                                (, mu-cite-registration-symbol)))
391                        (error nil))))))))
392         (when alist
393           (setq mu-cite-citation-name-alist alist))))))
394 (add-hook 'mu-cite-load-hook (function mu-cite-load-registration-file))
395
396 (defun mu-cite-save-registration-file ()
397   ;;(let ((file mu-cite-registration-file))
398   (let ((file (mu-cite-registration-file)))
399     (when file
400       (with-temp-buffer
401         (setq buffer-file-name file)
402         (insert ";;; " (file-name-nondirectory file) "\n")
403         (insert ";;; This file is generated automatically by mu-cite "
404                 mu-cite-version "\n\n")
405         (insert "(setq "
406                 (symbol-name mu-cite-registration-symbol)
407                 "\n      '(")
408         (insert (mapconcat
409                  (function prin1-to-string)
410                  mu-cite-citation-name-alist "\n        "))
411         (insert "\n        ))\n\n")
412         (insert ";;; "
413                 (file-name-nondirectory file)
414                 " ends here.\n")
415         (write-region 1 1 file nil 'nomsg)
416         (condition-case nil
417             (set-file-modes file mu-cite-registration-file-modes)
418           (error nil))
419         (if mu-cite-registration-file-coding-system-for-write
420             (save-buffer-as-coding-system
421              mu-cite-registration-file-coding-system-for-write)
422           (save-buffer))))))
423
424
425 ;;; @ item methods
426 ;;;
427
428 ;;; @@ ML count
429 ;;;
430
431 (defcustom mu-cite-ml-count-field-list
432   '("X-Ml-Count" "X-Mail-Count" "X-Seqno" "X-Sequence" "Mailinglist-Id")
433   "List of header fields which contain sequence number of mailing list."
434   :type '(repeat (choice (choice-item "X-Ml-Count")
435                          (choice-item "X-Mail-Count")
436                          (choice-item "X-Seqno")
437                          (choice-item "X-Sequence")
438                          (choice-item "Mailinglist-Id")
439                          (item "-")
440                          (string :tag "Other")))
441   :group 'mu-cite)
442
443 (defun mu-cite-get-ml-count-method ()
444   (let ((field-list mu-cite-ml-count-field-list))
445     (catch 'tag
446       (while field-list
447         (let* ((field (car field-list))
448                (ml-count (mu-cite-get-field-value field)))
449           (when (and ml-count (string-match "[0-9]+" ml-count))
450             (throw 'tag
451                    (substring ml-count
452                               (match-beginning 0)(match-end 0))))
453           (setq field-list (cdr field-list)))))))
454
455
456 ;;; @@ prefix and registration
457 ;;;
458
459 (defun mu-cite-get-prefix-method ()
460   (or (mu-cite-get-citation-name (mu-cite-get-value 'address))
461       ">"))
462
463 (defun mu-cite-get-prefix-register-method ()
464   (let ((addr (mu-cite-get-value 'address)))
465     (or (mu-cite-get-citation-name addr)
466         (let ((return
467                (read-string "Citation name? "
468                             (or (mu-cite-get-value 'x-attribution)
469                                 (mu-cite-get-value 'full-name))
470                             'mu-cite-minibuffer-history)))
471           (when (and (or mu-cite-allow-null-string-registration
472                          (not (string-equal return "")))
473                      (y-or-n-p (format "Register \"%s\"? " return)))
474             (mu-cite-add-citation-name return addr))
475           return))))
476
477 (defun mu-cite-get-prefix-register-verbose-method ()
478   (let* ((addr (mu-cite-get-value 'address))
479          (return1 (mu-cite-get-citation-name addr))
480          (return (read-string "Citation name? "
481                               (or return1
482                                   (mu-cite-get-value 'x-attribution)
483                                   (mu-cite-get-value 'full-name))
484                               'mu-cite-minibuffer-history)))
485     (when (and (or mu-cite-allow-null-string-registration
486                    (not (string-equal return "")))
487                (not (string-equal return return1))
488                (y-or-n-p (format "Register \"%s\"? " return)))
489       (mu-cite-add-citation-name return addr))
490     return))
491
492
493 ;;; @ fundamentals
494 ;;;
495
496 (defvar mu-cite-methods-alist nil)
497
498 (defun mu-cite-make-methods ()
499   (setq mu-cite-methods-alist
500         (copy-alist mu-cite-default-methods-alist))
501   (run-hooks 'mu-cite-instantiation-hook))
502
503 (defun mu-cite-get-value (item)
504   (let ((ret (cdr (assoc item mu-cite-methods-alist))))
505     (if (functionp ret)
506         (prog1
507             (setq ret (save-excursion (funcall ret)))
508           (set-alist 'mu-cite-methods-alist item ret))
509       ret)))
510
511 (defun mu-cite-eval-format (list)
512   (mapconcat (function
513               (lambda (elt)
514                 (cond ((stringp elt) elt)
515                       ((symbolp elt) (mu-cite-get-value elt)))))
516              list ""))
517
518
519 ;;; @ main function
520 ;;;
521
522 ;;;###autoload
523 (defun mu-cite-original ()
524   "Citing filter function.
525 This is callable from the various mail and news readers' reply
526 function according to the agreed upon standard."
527   (interactive)
528   (mu-cite-make-methods)
529   (save-restriction
530     (when (< (mark t) (point))
531       (exchange-point-and-mark))
532     (narrow-to-region (point)(point-max))
533     (run-hooks 'mu-cite-pre-cite-hook)
534     (let ((last-point (point))
535           (top (mu-cite-eval-format mu-cite-top-format))
536           (prefix (mu-cite-eval-format mu-cite-prefix-format)))
537       (when (re-search-forward "^-*$" nil nil)
538         (forward-line 1))
539       (widen)
540       (delete-region last-point (point))
541       (insert top)
542       (setq last-point (point))
543       (while (< (point)(mark t))
544         (unless (looking-at mu-cite-cited-prefix-regexp)
545           (insert prefix))
546         (forward-line 1))
547       (goto-char last-point))
548     (run-hooks 'mu-cite-post-cite-hook)))
549
550
551 ;;; @ message editing utilities
552 ;;;
553
554 (defcustom citation-mark-chars ">}|"
555   "String of characters for citation delimiter."
556   :type 'string
557   :group 'mu-cite)
558
559 (defcustom citation-disable-chars "<{"
560   "String of characters not allowed as citation-prefix."
561   :type 'string
562   :group 'mu-cite)
563
564 (defun detect-paragraph-cited-prefix ()
565   (save-excursion
566     (goto-char (point-min))
567     (let ((i 0)
568           (prefix
569            (buffer-substring
570             (progn (beginning-of-line)(point))
571             (progn (end-of-line)(point))))
572           str ret)
573       (while (and (= (forward-line) 0)
574                   (setq str (buffer-substring
575                              (progn (beginning-of-line)(point))
576                              (progn (end-of-line)(point))))
577                   (setq ret (string-compare-from-top prefix str)))
578         (setq prefix
579               (if (stringp ret)
580                   ret
581                 (cadr ret)))
582         (incf i))
583       (cond ((> i 1) prefix)
584             ((> i 0)
585              (goto-char (point-min))
586              (save-restriction
587                (narrow-to-region (point)
588                                  (+ (point)(length prefix)))
589                (goto-char (point-max))
590                (if (re-search-backward
591                     (concat "[" citation-mark-chars "]") nil t)
592                    (progn
593                      (goto-char (match-end 0))
594                      (when (looking-at "[ \t]+")
595                        (goto-char (match-end 0)))
596                      (buffer-substring (point-min)(point)))
597                  prefix)))
598             ((progn
599                (goto-char (point-max))
600                (re-search-backward
601                 (concat "[" citation-disable-chars "]") nil t)
602                (re-search-backward
603                 (concat "[" citation-mark-chars "]") nil t))
604              (goto-char (match-end 0))
605              (when (looking-at "[ \t]+")
606                (goto-char (match-end 0)))
607              (buffer-substring (point-min)(point)))
608             (t "")))))
609
610 (defun fill-cited-region (beg end)
611   (interactive "*r")
612   (save-excursion
613     (save-restriction
614       (goto-char end)
615       (and (search-backward "\n" nil t)
616            (setq end (match-end 0)))
617       (narrow-to-region beg end)
618       (let* ((fill-prefix (detect-paragraph-cited-prefix))
619              (pat (concat fill-prefix "\n")))
620         (goto-char (point-min))
621         (while (search-forward pat nil t)
622           (let ((b (match-beginning 0))
623                 (e (match-end 0)))
624             (delete-region b e)
625             (when (and (> b (point-min))
626                        (let ((cat (char-category
627                                    (char-before b))))
628                          (or (string-match "a" cat)
629                              (string-match "l" cat))))
630               (insert " "))))
631         (goto-char (point-min))
632         (fill-region (point-min) (point-max))))))
633
634 (defun compress-cited-prefix ()
635   (interactive)
636   (save-excursion
637     (goto-char (point-min))
638     (re-search-forward
639      (concat "^" (regexp-quote mail-header-separator) "$") nil t)
640     (while (re-search-forward
641             (concat "^\\([ \t]*[^ \t\n" citation-mark-chars "]*["
642                     citation-mark-chars "]\\)+") nil t)
643       (let* ((b (match-beginning 0))
644              (e (match-end 0))
645              (prefix (buffer-substring b e))
646              ps pe (s 0)
647              (nest (let ((i 0))
648                      (when (string-match "<[^<>]+>" prefix)
649                        (setq prefix (substring prefix 0 (match-beginning 0))))
650                      (while (string-match
651                              (concat "\\([" citation-mark-chars "]+\\)[ \t]*")
652                              prefix s)
653                        (setq i (+ i (- (match-end 1)(match-beginning 1)))
654                              ps s
655                              pe (match-beginning 1)
656                              s (match-end 0)))
657                      i)))
658         (when (and ps (< ps pe))
659           (delete-region b e)
660           (insert (concat (substring prefix ps pe) (make-string nest ?>))))
661         ))))
662
663 (defun replace-top-string (old new)
664   (interactive "*sOld string: \nsNew string: ")
665   (while (re-search-forward
666           (concat "^" (regexp-quote old)) nil t)
667     (replace-match new)))
668
669 (defun string-compare-from-top (str1 str2)
670   (let* ((len1 (length str1))
671          (len2 (length str2))
672          (len (min len1 len2))
673          (p 0)
674          c1 c2)
675     (while (and (< p len)
676                 (progn
677                   (setq c1 (aref str1 p)
678                         c2 (aref str2 p))
679                   (eq c1 c2)))
680       (setq p (+ p (char-length c1))))
681     (and (> p 0)
682          (let ((matched (substring str1 0 p))
683                (r1 (and (< p len1)(substring str1 p)))
684                (r2 (and (< p len2)(substring str2 p))))
685            (if (eq r1 r2)
686                matched
687              (list 'seq matched (list 'or r1 r2)))))))
688
689
690 ;;; @ obsoletes
691 ;;;
692
693 ;; This part will be abolished in the future.
694
695 (static-unless (fboundp 'defvaralias)
696   (mapcar
697    (function
698     (lambda (elem)
699       (eval (list 'defvar (car elem) (cadr elem)))))
700    mu-cite-obsolete-variable-alist))
701
702
703 ;;; @ end
704 ;;;
705
706 (provide 'mu-cite)
707
708 (run-hooks 'mu-cite-load-hook)
709
710 ;;; mu-cite.el ends here