自慢の.emacsを貼り付けよう

このエントリーをはてなブックマークに追加
562559
>>561
おかげさんでMeadowでも動いたよ。
regionがある場合はregionからワードを取ってくるように改造してくだせい。

■Googleまとめ版 その1

;; replace-in-string (MeadowとかのEmacs20系には必要)
(defun replace-in-string (str regexp newtext &optional literal)
"Replaces all matches in STR for REGEXP with NEWTEXT string,
and returns the new string.
Optional LITERAL non-nil means do a literal replacement.
Otherwise treat \\ in NEWTEXT string as special:
\\& means substitute original matched text,
\\N means substitute match for \(...\) number N,
\\\\ means insert one \\."
;;; (check-argument-type 'stringp str)
;;; (check-argument-type 'stringp newtext)
(let ((rtn-str "")
(start 0)
(special)
match prev-start)
(while (setq match (string-match regexp str start))
(setq prev-start start
start (match-end 0)
rtn-str
(concat
rtn-str
(substring str prev-start match)
(cond (literal newtext)
(t (mapconcat
(lambda (c)
(if special
(progn
(setq special nil)
(cond ((eq c ?\\) "\\")
((eq c ?&)
(substring str
(match-beginning 0)
(match-end 0)))
((and (>= c ?0) (<= c ?9))
(if (> c (+ ?0 (length
(match-data))))
;; Invalid match num
(error "Invalid match num: %c" c)
(setq c (- c ?0))
(substring str
(match-beginning c)
(match-end c))))
(t (char-to-string c))))
(if (eq c ?\\) (progn (setq special t) nil)
(char-to-string c))))
newtext ""))))))
(concat rtn-str (substring str start))))