X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mu-cite.el;h=cc9db01b9b22942b08248e06f8d6685fa0566c4b;hb=af83c6b70a9a90a1c4238776872a9621e3d5b1db;hp=142a925536a5397bab52cf670d8bc72cca1153a9;hpb=664347dd0140a6c1b4f0351ec7c6f7727a0f12e4;p=elisp%2Fmu-cite.git diff --git a/mu-cite.el b/mu-cite.el index 142a925..cc9db01 100644 --- a/mu-cite.el +++ b/mu-cite.el @@ -27,15 +27,15 @@ ;;; Commentary: ;; - How to use -;; 1. bytecompile this file and copy it to the apropriate directory. -;; 2. put the following lines to your ~/.emacs: -;; for EMACS 19 or later and XEmacs +;; 1. Bytecompile this file and copy it to the apropriate directory. +;; 2. Put the following lines in your ~/.emacs file: +;; For EMACS 19 or later and XEmacs ;; (autoload 'mu-cite-original "mu-cite" nil t) ;; ;; for all but message-mode ;; (add-hook 'mail-citation-hook (function mu-cite-original)) ;; ;; for message-mode only ;; (setq message-cite-function (function mu-cite-original)) -;; for EMACS 18 +;; For EMACS 18 ;; ;; for all but mh-e ;; (add-hook 'mail-yank-hooks (function mu-cite-original)) ;; ;; for mh-e only @@ -47,7 +47,6 @@ (require 'poe) (require 'pcustom) -(require 'widget) (require 'std11) (require 'alist) @@ -63,47 +62,28 @@ ;;; @ version ;;; -(defconst mu-cite-version "8.0") +(defconst mu-cite-version "8.1") -;;; @ obsoletes +;;; @ macro ;;; -;; This part will be abolished in the future. - -(eval-when-compile (require 'static)) - -(defconst mu-cite-obsolete-variable-alist - '((mu-cite/cited-prefix-regexp mu-cite-cited-prefix-regexp) - (mu-cite/default-methods-alist mu-cite-default-methods-alist) - (mu-cite/get-field-value-method-alist - mu-cite-get-field-value-method-alist) - (mu-cite/instantiation-hook mu-cite-instantiation-hook) - (mu-cite/ml-count-field-list mu-cite-ml-count-field-list) - (mu-cite/post-cite-hook mu-cite-post-cite-hook) - (mu-cite/pre-cite-hook mu-cite-pre-cite-hook) - (mu-cite/prefix-format mu-cite-prefix-format) - (mu-cite/top-format mu-cite-top-format))) - -(static-if (featurep 'xemacs) - (mapcar - (function (lambda (elem) - (apply (function define-obsolete-variable-alias) elem))) - mu-cite-obsolete-variable-alist)) - -(mapcar - (function (lambda (elem) - (apply (function define-obsolete-function-alias) elem))) - '((mu-cite/cite-original mu-cite-original) - (mu-cite/get-field-value mu-cite-get-field-value) - (mu-cite/get-value mu-cite-get-value))) +(defmacro mu-cite-remove-text-properties (string) + "Remove text properties from STRING which is read from minibuffer." + (if (or (featurep 'xemacs) + (boundp 'minibuffer-allow-text-properties);; Emacs 20.1 or later. + (not (fboundp 'set-text-properties)));; under Emacs 19.7. + string + (` (let ((obj (copy-sequence (, string)))) + (set-text-properties 0 (length obj) nil obj) + obj)))) ;;; @ set up ;;; (defgroup mu-cite nil - "yet another citation tool for GNU Emacs." + "Yet another citation tool for GNU Emacs." :prefix "mu-cite-" :group 'mail :group 'news) @@ -148,12 +128,13 @@ (cons 'id (function (lambda () - (let ((ml-name (mu-cite-get-value 'ml-name))) + (let ((ml-name (mu-cite-get-value 'ml-name)) + (ml-count (mu-cite-get-value 'ml-count))) (if ml-name (concat "[" ml-name - " : No." - (mu-cite-get-value 'ml-count) + (if ml-count + (concat " : No." ml-count)) "]") (mu-cite-get-value 'message-id)))))) (cons 'in-id @@ -186,42 +167,6 @@ ;;; @ formats ;;; -(define-widget 'mu-cite-choose-prefix-format 'group - "Widget for entering a prefix citation method." - :convert-widget - (function - (lambda (widget) - (list 'choice - :tag "Method or String" - :args (nconc - (mapcar - (function (lambda (elem) (list 'choice-item (car elem)))) - mu-cite-default-methods-alist) - '((symbol :tag "Method") - (const :tag "-" nil) - (choice-item :tag "String: \"> \"" "> ") - (string))))))) - -(define-widget 'mu-cite-choose-top-format 'group - "Widget for entering a top citation method." - :convert-widget - (function - (lambda (widget) - (list 'choice - :tag "Method or String" - :args (nconc - (mapcar - (function (lambda (elem) (list 'choice-item (car elem)))) - mu-cite-default-methods-alist) - '((symbol :tag "Method") - (const :tag "-" nil) - (choice-item :tag "String: \">>>>>\\t\"" ">>>>>\t") - (choice-item :tag "String: \" wrote:\\n\"" " wrote:\n") - (string :tag "String"))))))) - -(defun mu-cite-custom-set-variable (symbol value) - (set-default symbol (delq nil value))) - (defcustom mu-cite-cited-prefix-regexp "\\(^[^ \t\n<>]+>+[ \t]*\\|^[ \t]*$\\)" "Regexp to match the citation prefix. @@ -231,16 +176,54 @@ If match, mu-cite doesn't insert citation prefix." (defcustom mu-cite-prefix-format '(prefix-register-verbose "> ") "List to represent citation prefix. -Each elements must be string or method name." - :type '(repeat mu-cite-choose-prefix-format) - :set (function mu-cite-custom-set-variable) +Each elements must be a string or a method name." + :type (list + 'repeat + (list + 'group + :convert-widget + (function + (lambda (widget) + (list + 'choice + :tag "Method or String" + :args + (nconc + (mapcar + (function (lambda (elem) (list 'choice-item (car elem)))) + mu-cite-default-methods-alist) + '((symbol :tag "Method") + (const :tag "-" nil) + (choice-item :tag "String: \"> \"" "> ") + (string)))))))) + :set (function (lambda (symbol value) + (set-default symbol (delq nil value)))) :group 'mu-cite) (defcustom mu-cite-top-format '(in-id ">>>>>\t" from " wrote:\n") "List to represent top string of citation. -Each elements must be string or method name." - :type '(repeat mu-cite-choose-top-format) - :set (function mu-cite-custom-set-variable) +Each elements must be a string or a method name." + :type (list + 'repeat + (list + 'group + :convert-widget + (function + (lambda (widget) + (list 'choice + :tag "Method or String" + :args + (nconc + (mapcar + (function (lambda (elem) (list 'choice-item (car elem)))) + mu-cite-default-methods-alist) + '((symbol :tag "Method") + (const :tag "-" nil) + (choice-item :tag "String: \">>>>>\\t\"" ">>>>>\t") + (choice-item :tag "String: \" wrote:\\n\"" " wrote:\n") + (string :tag "String")))))))) + :set (function (lambda (symbol value) + (set-default symbol (delq nil value)))) :group 'mu-cite) @@ -287,7 +270,7 @@ registered in variable `mu-cite-get-field-value-method-alist' is called." (defcustom mu-cite-ml-count-field-list '("X-Ml-Count" "X-Mail-Count" "X-Seqno" "X-Sequence" "Mailinglist-Id") - "List of header fields which contain sequence number of mailing list." + "List of header fields which contains a sequence number of the mailing list." :type '(repeat (choice :tag "Field Name" (choice-item "X-Ml-Count") (choice-item "X-Mail-Count") @@ -296,18 +279,19 @@ registered in variable `mu-cite-get-field-value-method-alist' is called." (choice-item "Mailinglist-Id") (const :tag "-" nil) (string :tag "Other"))) - :set (function mu-cite-custom-set-variable) + :set (function (lambda (symbol value) + (set-default symbol (delq nil value)))) :group 'mu-cite) (defun mu-cite-get-ml-count-method () "A mu-cite method to return a ML-count. This function searches a field about ML-count, which is specified by -variable `mu-cite-ml-count-field-list', in a header. +the variable `mu-cite-ml-count-field-list', in a header. If the field is found, the function returns a number part of the field. Notice that please use (mu-cite-get-value 'ml-count) -instead of call the function directly." +instead of to call the function directly." (let ((field-list mu-cite-ml-count-field-list)) (catch 'tag (while field-list @@ -329,7 +313,7 @@ instead of call the function directly." (run-hooks 'mu-cite-instantiation-hook)) (defun mu-cite-get-value (item) - "Return current value of ITEM." + "Return a current value of ITEM." (let ((ret (cdr (assoc item mu-cite-methods-alist)))) (if (functionp ret) (prog1 @@ -391,8 +375,8 @@ function according to the agreed upon standard." :group 'mu-cite) (defun-maybe-cond char-category (character) - "Return string of category mnemonics for CHAR in TABLE. -CHAR can be any multilingual character + "Return a string of category mnemonics for CHAR in TABLE. +CHAR can be any multilingual character, TABLE defaults to the current buffer's category table." ((and (subr-fboundp 'char-category-set) (subr-fboundp 'category-set-mnemonics)) @@ -421,18 +405,20 @@ TABLE defaults to the current buffer's category table." (let ((i 0) (prefix (buffer-substring (line-beginning-position) - (line-end-position))) - str ret) - (while (and (= (forward-line) 0) - (setq str (buffer-substring - (progn (beginning-of-line)(point)) - (progn (end-of-line)(point)))) - (setq ret (string-compare-from-top prefix str))) - (setq prefix - (if (stringp ret) - ret - (cadr ret))) - (setq i (1+ i))) + (line-end-position)))) + (let ((init prefix) + str ret) + (while (and (= (forward-line) 0) + (setq str (buffer-substring + (progn (beginning-of-line)(point)) + (progn (end-of-line)(point)))) + (setq ret (string-compare-from-top prefix str))) + (setq prefix + (if (stringp ret) + ret + (car (cdr ret)))) + (or (string-equal init prefix) + (setq i (1+ i))))) (cond ((> i 1) prefix) ((> i 0) (goto-char (point-min)) @@ -457,7 +443,7 @@ TABLE defaults to the current buffer's category table." (goto-char (match-end 0)) (if (looking-at "[ \t]+") (goto-char (match-end 0))) - (buffer-substring (point-min)(point))) + (buffer-substring (line-beginning-position)(point))) (t ""))))) ;;;###autoload @@ -471,7 +457,11 @@ TABLE defaults to the current buffer's category table." (setq end (match-end 0))) (narrow-to-region beg end) (let* ((fill-prefix (detect-paragraph-cited-prefix)) - (pat (concat fill-prefix "\n"))) + (fill-column (max (+ 1 (current-left-margin) + (string-width fill-prefix)) + (current-fill-column))) + (pat (concat fill-prefix "\n")) + filladapt-mode) (goto-char (point-min)) (while (search-forward pat nil t) (let ((b (match-beginning 0)) @@ -513,9 +503,11 @@ TABLE defaults to the current buffer's category table." pe (match-beginning 1) s (match-end 0))) i))) - (when (and ps (< ps pe)) - (delete-region b e) - (insert (concat (substring prefix ps pe) (make-string nest ?>)))) + (if (and ps (< ps pe)) + (progn + (delete-region b e) + (insert (concat (substring prefix ps pe) + (make-string nest ?>))))) )))) (defun replace-top-string (old new) @@ -552,23 +544,4 @@ TABLE defaults to the current buffer's category table." (run-hooks 'mu-cite-load-hook) -;; This part will be abolished in the future. - -(static-unless (featurep 'xemacs) - (let ((rest mu-cite-obsolete-variable-alist) - def new-sym old-sym) - (while rest - (setq def (car rest)) - (apply (function make-obsolete-variable) def) - (setq old-sym (car def) - new-sym (car (cdr def))) - (or (get new-sym 'saved-value) ; saved? - (not (eq (eval (car (get new-sym 'standard-value))) - (symbol-value new-sym))) ; set as new name? - (and (boundp old-sym) ; old name seems used - (or (eq (symbol-value new-sym) - (symbol-value old-sym)) - (set new-sym (symbol-value old-sym))))) - (setq rest (cdr rest))))) - ;;; mu-cite.el ends here