comparison lisp/mu/mu-cite.el @ 86:364816949b59 r20-0b93

Import from CVS: tag r20-0b93
author cvs
date Mon, 13 Aug 2007 09:09:02 +0200
parents c0c698873ce1
children 0d2f883870bc
comparison
equal deleted inserted replaced
85:c661705957e0 86:364816949b59
1 ;;; mu-cite.el --- yet another citation tool for GNU Emacs 1 ;;; mu-cite.el --- yet another citation tool for GNU Emacs
2 2
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc. 3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
4 4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> 5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; MINOURA Makoto <minoura@netlaputa.or.jp> 6 ;; MINOURA Makoto <minoura@netlaputa.or.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp> 7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Maintainer: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp> 8 ;; Maintainer: Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
9 ;; Version: $Revision: 1.2 $ 9 ;; Version: $Revision: 1.3 $
10 ;; Keywords: mail, news, citation 10 ;; Keywords: mail, news, citation
11 11
12 ;; This file is part of tl (Tiny Library). 12 ;; This file is part of MU (Message Utilities).
13 13
14 ;; This program is free software; you can redistribute it and/or 14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as 15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at 16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version. 17 ;; your option) any later version.
52 52
53 ;;; @ version 53 ;;; @ version
54 ;;; 54 ;;;
55 55
56 (defconst mu-cite/RCS-ID 56 (defconst mu-cite/RCS-ID
57 "$Id: mu-cite.el,v 1.2 1996/12/28 21:02:58 steve Exp $") 57 "$Id: mu-cite.el,v 1.3 1997/01/30 02:22:36 steve Exp $")
58 (defconst mu-cite/version (get-version-string mu-cite/RCS-ID)) 58 (defconst mu-cite/version (get-version-string mu-cite/RCS-ID))
59 59
60 60
61 ;;; @ formats 61 ;;; @ formats
62 ;;; 62 ;;;
388 )) 388 ))
389 389
390 390
391 ;;; @ message editing utilities 391 ;;; @ message editing utilities
392 ;;; 392 ;;;
393 393
394 (defvar cited-prefix-regexp "^[^ \t>]*[>|]+[ \t#]*" 394 (defvar citation-mark-chars ">}|"
395 "*Regexp to match the citation prefix.") 395 "*String of characters for citation delimiter. [mu-cite.el]")
396
397 (defun detect-paragraph-cited-prefix ()
398 (save-excursion
399 (goto-char (point-min))
400 (let ((i 0)
401 (prefix
402 (buffer-substring
403 (progn (beginning-of-line)(point))
404 (progn (end-of-line)(point))
405 ))
406 str ret)
407 (while (and (= (forward-line) 0)
408 (setq str (buffer-substring
409 (progn (beginning-of-line)(point))
410 (progn (end-of-line)(point))))
411 (setq ret (string-compare-from-top prefix str))
412 )
413 (setq prefix (second ret))
414 (setq i (1+ i))
415 )
416 (cond ((> i 1) prefix)
417 ((> i 0)
418 (goto-char (point-min))
419 (save-restriction
420 (narrow-to-region (point)
421 (+ (point)(length prefix)))
422 (goto-char (point-max))
423 (if (re-search-backward
424 (concat "[" citation-mark-chars "]") nil t)
425 (progn
426 (goto-char (match-end 0))
427 (if (looking-at "[ \t]+")
428 (goto-char (match-end 0))
429 )
430 (buffer-substring (point-min)(point))
431 )
432 prefix)))
433 ((progn
434 (goto-char (point-max))
435 (re-search-backward (concat "[" citation-mark-chars "]")
436 nil t)
437 )
438 (goto-char (match-end 0))
439 (if (looking-at "[ \t]+")
440 (goto-char (match-end 0))
441 )
442 (buffer-substring (point-min)(point))
443 )
444 (t ""))
445 )))
396 446
397 (defun fill-cited-region (beg end) 447 (defun fill-cited-region (beg end)
398 (interactive "*r") 448 (interactive "*r")
399 (save-excursion 449 (save-excursion
400 (save-restriction 450 (save-restriction
401 (goto-char end) 451 (goto-char end)
402 (while (not (eolp)) 452 (and (search-backward "\n" nil t)
403 (backward-char) 453 (setq end (match-end 0))
404 ) 454 )
405 (setq end (point))
406 (narrow-to-region beg end) 455 (narrow-to-region beg end)
407 (goto-char (point-min)) 456 (let* ((fill-prefix (detect-paragraph-cited-prefix))
408 (let* ((fill-prefix 457 (pat (concat fill-prefix "\n"))
409 (let* ((str1 (buffer-substring
410 (progn (beginning-of-line)(point))
411 (progn (end-of-line)(point))
412 ))
413 (str2 (let ((p0 (point)))
414 (forward-line)
415 (if (> (count-lines p0 (point)) 0)
416 (buffer-substring
417 (progn (beginning-of-line)(point))
418 (progn (end-of-line)(point))
419 ))))
420 (ret (string-compare-from-top str1 str2))
421 )
422 (if ret
423 (let ((prefix (nth 1 ret)))
424 (if (string-match cited-prefix-regexp prefix)
425 (substring prefix 0 (match-end 0))
426 prefix))
427 (goto-char (point-min))
428 (if (re-search-forward cited-prefix-regexp nil t)
429 (buffer-substring (match-beginning 0) (match-end 0))
430 ))))
431 (pat (concat "\n" fill-prefix))
432 ) 458 )
433 (goto-char (point-min)) 459 (goto-char (point-min))
434 (while (search-forward pat nil t) 460 (while (search-forward pat nil t)
435 (let ((b (match-beginning 0)) 461 (let ((b (match-beginning 0))
436 (e (match-end 0)) 462 (e (match-end 0))
447 )) 473 ))
448 ) 474 )
449 (goto-char (point-min)) 475 (goto-char (point-min))
450 (fill-region (point-min) (point-max)) 476 (fill-region (point-min) (point-max))
451 )))) 477 ))))
452
453 (defvar citation-mark-chars ">}|")
454 478
455 (defun compress-cited-prefix () 479 (defun compress-cited-prefix ()
456 (interactive) 480 (interactive)
457 (save-excursion 481 (save-excursion
458 (goto-char (point-min)) 482 (goto-char (point-min))