[cmail 8531] Re: Date & Message-id header
Yuh Ohmura
yutopia @ t3.rim.or.jp
2000年 2月 9日 (水) 17:13:29 JST
おおむらです。
In message "[cmail 8531] Re: Date & Message-id header"
on 00/02/09, Yuh Ohmura <yutopia @ t3.rim.or.jp> writes:
> In message "[cmail 8530] Re: Date & Message-id header"
> on 00/02/09, Yuuichi Teranishi <teranisi @ gohome.org> writes:
> > > ;; Emacs 19.28 and earlier
> > > ;; (replace-match NEWTEXT &optional FIXEDCASE LITERAL)
> > > ;; Emacs 20.x (?) and later
> > > ;; (replace-match NEWTEXT &optional FIXEDCASE LITERAL STRING SUBEXP)
> >
> > XEmacs 21.2.28 を見てみたら、
> > (replace-match NEWTEXT &optional FIXEDCASE LITERAL STRING STRBUFFER)
> > になってました ;_;。
とりあえず、Emacs 20.5 で SUBEXP つきですが動作するものが
できました。
あとは他の Emacsen で動作するかと、SUBEXP をはずすことなん
ですが、はずし方がわからないです T_T;;
> > APEL としては
> > (replace-match NEWTEXT &optional FIXEDCASE LITERAL STRING)
> > までにしとくべきかなあ...。
共通部分でできるだけ多くの引数をサポートするということで
しょうか。
なんか、よくわからない人間がゴミばっかり流しているような
気も… ^^;
--------------- salve! -----------------
mailto:yutopia @ t3.rim.or.jp (Yuh Ohmura)
Uri: http://www.t3.rim.or.jp/%7Eyutopia/
----------------------------------------
;; Emacs 19.28 and earlier
;; (replace-match NEWTEXT &optional FIXEDCASE LITERAL)
;; Emacs 20.x (?) and later
;; (replace-match NEWTEXT &optional FIXEDCASE LITERAL STRING SUBEXP)
(static-condition-case nil
;; compile-time check
(progn
(setq nostring "")
(replace-match "-" nil nil nostring)
(if (get 'replace-match 'defun-maybe)
(error "`replace-match' is already redefined")))
(error
;; load-time check.
(or (fboundp 'si:replace-match)
(progn
(fset 'si:replace-match (symbol-function 'replace-match))
(put 'replace-match 'defun-maybe t)
(defun replace-match (newtext &optional fixedcase literal string subexp)
"\
Replace text matched by last search with NEWTEXT.
If second arg FIXEDCASE is non-nil, do not alter case of replacement text.
Otherwise maybe capitalize the whole text, or maybe just word initials,
based on the replaced text.
If the replaced text has only capital letters
and has at least one multiletter word, convert NEWTEXT to all caps.
If the replaced text has at least one word starting with a capital letter,
then capitalize each word in NEWTEXT.
If third arg LITERAL is non-nil, insert NEWTEXT literally.
Otherwise treat `\' as special:
`\&' in NEWTEXT means substitute original matched text.
`\N' means substitute what matched the Nth `\(...\)'.
If Nth parens didn't match, substitute nothing.
`\\' means insert one `\'.
FIXEDCASE and LITERAL are optional arguments.
Leaves point at end of replacement text.
The optional fourth argument STRING can be a string to modify.
In that case, this function creates and returns a new string
which is made by replacing the part of STRING that was matched.
The optional fifth argument SUBEXP specifies a subexpression of the match.
It says to replace just that subexpression instead of the whole match.
This is useful only after a regular expression search or match
since only regular expressions have distinguished subexpressions."
(if string
(let* ((matched-data (match-data))
(len (length matched-data)))
(setq matched-data (append matched-data '(-2 -2)))
(with-temp-buffer
(insert string)
(if (and subexp (numberp subexp))
(if (>= (* subexp 2) len)
(setq subexp (/ len 2)))
(setq subexp 0))
(delete-region (+ (nth (* 2 subexp) matched-data) 1)
(+ (nth (+ (* 2 subexp) 1) matched-data) 1))
(goto-char (+ (nth (* 2 subexp) matched-data) 1))
(insert newtext)
(buffer-substring (point-min) (point-max))))
(si:replace-match newtext fixedcase literal)))))))
More information about the APEL-ja
mailing list