この記事は emacs の php-mode.el の設定例です。
w3m-mode で function.xxx.html にアクセスできるように修正します。
$ diff -u php-mode.el.orig php-mode.el.w3m
--- php-mode.el.orig 2008-11-05 01:29:19.000000000 +0900
+++ php-mode.el.w3m 2010-02-23 14:51:26.000000000 +0900
@@ -544,7 +544,15 @@
(defun php-search-documentation ()
"Search PHP documentation for the word at point."
(interactive)
- (browse-url (concat php-search-url (current-word t))))
+ (w3m-browse-url (concat php-search-url "function."
+ (my-str-replace "_" "-" (downcase (current-word t)))
+ ".html")))
+(defun my-str-replace (search replace subject)
+ (let ((xxx -1))
+ (while xxx
+ (setq xxx (string-match search subject (+ 1 xxx)))
+ (if xxx (setq subject (replace-match replace nil nil subject)))))
+ subject)
;; Define function for browsing manual
(defun php-browse-manual ()
string-match, replace-match でセットで扱うので replace-match に変数が足りないように見えますが動作します。
phpで書くと下記のようなイメージになります。
この例の場合 elisp の方は search に指定する文字が2バイト以上でも変換できますが php の方はできません。
<?php
function my_str_replace($search, $replace, $subject)
{
$xxx = -1; // phpの場合は、すでに関数内でローカル変数です。
while ($xxx !== false)
{
$xxx = strpos($subject, $search);
if ($xxx !== false)
{
$subject[$xxx] = $replace; // 推薦されない文字列のアクセス方法です。
}
}
return $subject;
}
print my_str_replace("_", "-", "_1_2_3_4_5_6_7_8_9_0_") . "\n";
print my_str_replace("_", "-", "") . "\n";
print my_str_replace("_", "-", "__") . "\n";
print my_str_replace("_", "-", "--") . "\n";
print my_str_replace("_", "-", "str_replace") . "\n";
print my_str_replace("_", "-", "htmlspecialchars") . "\n";
?>