--- pukiwiki-mode.el.orig 2004-09-01 15:51:25.735782700 +0900 +++ pukiwiki-mode.el 2004-09-02 20:44:24.279724000 +0900 @@ -60,6 +60,9 @@ (require 'poem))) (require 'derived) +(when (featurep 'xemacs) + (require 'overlay)) + (defconst pukiwiki-mode-version (let ((revision "$Revision: 1.22 $")) (string-match "\\([0-9.]+\\)" revision) @@ -565,7 +568,15 @@ (message "Sending... ") ;; 文字コードが変更されていた時に戻しておく - (if (string= buffer-file-coding-system (pukiwiki-site-coding-system)) + (if (string= + (if (featurep 'xemacs) + (let ((coding-system-string + (format "%s" buffer-file-coding-system))) + (string-match "#]*\\)>" + coding-system-string) + (match-string 1 coding-system-string)) + buffer-file-coding-system) + (pukiwiki-site-coding-system)) () (set-buffer-file-coding-system (pukiwiki-site-coding-system))) ;; 半角カタカナは全角に変換して送信 @@ -1145,6 +1156,20 @@ (http-url-hexify-string pagename (pukiwiki-site-coding-system))))))) +(defun pukiwiki-replace-regexp (regexp replacement parm start end) + "pukiwiki-mode 用の replace-regexp." + (let ((top start) (bottom end)) + (goto-char top) + (catch 'range-over + (while (re-search-forward regexp nil t) + (replace-match replacement nil nil)) + (if (>= (point) bottom) (throw 'range-over t))))) + +(defun pukiwiki-replace-string (regexp replacement parm start end) + "pukiwiki-mode 用の replace-string." + (let ((top start) (bottom end)) + (perform-replace regexp replacement nil nil nil))) + (defun pukiwiki-index-show-diff (arg &optional day) "現在のバッファとサーバのデータを比較し、表示する。" (interactive "P") @@ -1228,13 +1253,13 @@ (pukiwiki-edit-rename-buffer site-name pagename (format "diff-to-%s" age) nil) (insert (cdr (assoc 'body diff-contents))) - (replace-regexp + (pukiwiki-replace-regexp "^ $" "" nil (point-min) (point-max)) - (replace-string + (pukiwiki-replace-string "" "+" nil (point-min) (point-max)) - (replace-string + (pukiwiki-replace-string "" "-" nil (point-min) (point-max)) - (replace-string + (pukiwiki-replace-string "" "" nil (point-min) (point-max)) (goto-char (point-min)) (pukiwiki-replace-entity-refs) @@ -1775,6 +1800,37 @@ (set-buffer-modified-p nil) (current-buffer)))) +;; Pukiwiki 1.3 系に対処。 +(defvar pukiwiki-pukiwiki-version-check-string + "^\\s-*\"PukiWiki\"\\s-+\\([.0-9]+\\)" + "Pukiwiki のバージョン判別のための正規表現。") +(defvar pukiwiki-1-3-p nil + "Pukiwiki のバージョンが 1.3 系なら t, そうでなければ nil。") + +(defvar pukiwiki-fetch-index-regexp nil + "index として抽出する anchor の正規表現。") +(defvar pukiwiki-fetch-index-regexp-1.3 + "
  • ]*>\\([^<]*\\)\\([^<]*\\)*
  • " + "index として抽出する anchor の正規表現の Pukiwiki 1.3系用。") + +(defvar pukiwiki-fetch-index-regexp-1.4-later + "
  • ]*>\\([^<]*\\)[]*\\([^<]*\\)[]*
  • " + "index として抽出する anchor の正規表現の Pukiwiki 1.4以降用。") + +(defun pukiwiki-pukiwiki-version-check () + "Pukiwiki のバージョンを判別し、該当する regexp を設定する。" + (let () + (save-match-data + (re-search-forward pukiwiki-pukiwiki-version-check-string nil t nil) + (if (string-match "1.3[.0-9]*" (match-string 1)) + (progn + (setq pukiwiki-1-3-p t) + (setq pukiwiki-fetch-index-regexp pukiwiki-fetch-index-regexp-1.3)) + (setq pukiwiki-1-3-p nil) + (setq pukiwiki-fetch-index-regexp + pukiwiki-fetch-index-regexp-1.4-later)) + (beginning-of-buffer)))) + (defun pukiwiki-fetch-index (site-info) "ページ一覧を取得する。" (let (indexes history (i 1) @@ -1784,10 +1840,10 @@ (when (bufferp buf) (save-excursion (set-buffer buf) + (pukiwiki-pukiwiki-version-check) (re-search-forward "
      " nil t nil) (while (re-search-forward - ;;"
    • ]*>\\([^<]*\\)\\([^<]*\\)
    • " - "
    • ]*>\\([^<]*\\)[]*\\([^<]*\\)[]*
    • " + pukiwiki-fetch-index-regexp nil t nil) (setq indexes (cons @@ -1942,7 +1998,10 @@ ;;;encoding に対応する charset のリストを取得する。 ;;;Meadow2 (Emacs21) でも動くかどうか未確認 ;;;うまくいかなければ、自分で対応を定義すれば良い - (mycharsetlist (coding-system-get mycodingsystem 'safe-charsets)) + (mycharsetlist + (if (featurep 'xemacs) + (find-charset-region (point-min) (point-max)) + (coding-system-get mycodingsystem 'safe-charsets))) ) (goto-char beg) ;;;リージョンの先頭に移動 (while (< (point) end) ;;;リージョン内を順に調べる @@ -1963,8 +2022,10 @@ ;;結果の表示 (if (< 0 mycount) (error "文字コードの異なる文字が含まれています")) - (if transient-mark-mode - (setq deactivate-mark t)) ;;;region を色つけしている時、色を解除 + (if (boundp 'transient-mark-mode) + (if transient-mark-mode + (setq deactivate-mark t)) ;;;region を色つけしている時、色を解除 + ) ))) (defun pukiwiki-check-jisx0201 () @@ -2113,22 +2174,22 @@ (goto-char (point-min)) (keep-lines "^-") (goto-char (point-min)) - (replace-string "&new{" "" nil (point-min) (point-max)) - (replace-string "&new{" "" nil (point-min) (point-max)) - (replace-string "SIZE(10){" "" nil (point-min) (point-max)) - (replace-regexp "}[;]*" "" nil (point-min) (point-max)) - (replace-regexp + (pukiwiki-replace-string "&new{" "" nil (point-min) (point-max)) + (pukiwiki-replace-string "&new{" "" nil (point-min) (point-max)) + (pukiwiki-replace-string "SIZE(10){" "" nil (point-min) (point-max)) + (pukiwiki-replace-regexp "}[;]*" "" nil (point-min) (point-max)) + (pukiwiki-replace-regexp "^\\([-]+\\)\\([^\n\r]+\\)[ ]*--[ ]*\\[\\[\\([^]\n\r]+\\)\\]\\] \\([^\n\r]+\\)[ ]*$" "\\1 \\4 [\\3]\n \\2" nil (point-min) (point-max)) - (replace-regexp + (pukiwiki-replace-regexp "^\\([-]+\\)\\([^\n\r]+\\)[ ]*--[ ]*\\([^[\n\r]+\\)[ ]*$" "\\1 \\3 [名無し]\n \\2" nil (point-min) (point-max)) - (replace-regexp "[ ]+$" + (pukiwiki-replace-regexp "[ ]+$" "" nil (point-min) (point-max)) - (replace-regexp "\n" + (pukiwiki-replace-regexp "\n" "\n\n" nil (point-min) (point-max)) (goto-char (point-min)) @@ -2159,7 +2220,7 @@ ;; "_" ;; nil (point-min) (point-max)) (fill-region (point-min) (point-max)) - (replace-regexp "\n[ ]*\n" + (pukiwiki-replace-regexp "\n[ ]*\n" "\n" nil (point-min) (point-max)) (setq contents (buffer-substring-no-properties @@ -2276,9 +2337,8 @@ ;; 定義を読みやすく処理 (goto-char (point-min)) - (replace-regexp "^:\\([^|\n\r]+\\)|\\([^\n\r]+\\)$" - "\\1\n\n\t\\2\n" - nil (point-min) (point-max)) + (pukiwiki-replace-regexp "^:\\([^|\n\r]+\\)|\\([^\n\r]+\\)$" + "\\1\n\n\t\\2\n" nil (point-min) (point-max)) ;; コメントを読みやすく処理 (goto-char (point-min)) @@ -2357,29 +2417,45 @@ (insert "#ref(" (car lst) ")\n") (setq lst (cdr lst))))))) +;; for XEmacs. +(if (featurep 'xemacs) + (defun x-color-defined-p (color) + (valid-color-name-p color))) + (defun pukiwiki-set-face-color () - (let ((color nil) (str nil) (ov nil)) + (let ((color nil) (str nil) (ov nil) start) (goto-char (point-min)) (while (re-search-forward - "COLOR(\\([^)]+\\)){\\([^\n\r]+\\)}" nil t) + (if pukiwiki-auto-insert + "COLOR(\\([^)]+\\)){\\([^}]+\\)}" + "COLOR(\\([^)]+\\)){\\([^}\n\r]+\\)}") + nil t) (setq color (match-string 1)) (setq str (match-string 2)) - (delete-region (match-beginning 0) - (match-end 0)) + (setq start (match-beginning 0)) + (delete-region start (match-end 0)) (insert str) (when (x-color-defined-p color) - (setq ov (make-overlay (line-beginning-position) - (point))) - (overlay-put ov 'face (cons - (cons 'background-color "white") - (cons 'foreground-color color))) + (setq ov (make-overlay start (point))) + (overlay-put ov + 'face + (if (featurep 'xemacs) + (progn + (make-face (intern color)) + (set-face-foreground (intern color) color) + (intern color)) + (cons (cons 'background-color "white") + (cons 'foreground-color color)))) (overlay-put ov 'priority 0))))) (defun pukiwiki-set-bold () (goto-char (point-min)) (let ((start nil) (str nil) (ov nil)) (while (re-search-forward - "\\([']+\\)\\([^'\n\r]+\\)\\([']+\\)" nil t) + (if pukiwiki-auto-insert + "\\([']+\\)\\([^']+\\)\\([']+\\)" + "\\([']+\\)\\([^'\n\r]+\\)\\([']+\\)") + nil t) (setq start (match-string 1)) (setq str (match-string 2)) (delete-region (match-beginning 0) @@ -2574,6 +2650,27 @@ (defun pukiwiki-http-fetch-sentinel (proc str) (setq pukiwiki-http-fetch-running nil)) +;; no-proxy-domain に対処。 +(defcustom pukiwiki-no-proxy-domains-list '(localhost) + "*Domain list that don't via proxy server." + :group 'pukiwiki + :type '(repeat (string :format "Domain name: %v +" :size 0))) + +(defun pukiwiki-no-proxy-domain-p (url) + "proxy server の指定があるときで、proxy を介さないドメインかを調べる。" + (let (host domain) + (save-match-data + (when + (and pukiwiki-no-proxy-domains-list + (string-match "^[a-z]+://\\([^/:]+\\)" url) + (catch 'domain-match + (setq host (match-string 1 url)) + (dolist (domain pukiwiki-no-proxy-domains-list) + (when (string-match (concat "\\(^\\|\\.\\)" (regexp-quote domain) "$") host) + (throw 'domain-match t))))) + t)))) + (defun pukiwiki-http-fetch (url method &optional user pass data) "Fetch via HTTP. @@ -2590,7 +2687,7 @@ "^http://\\([^/:]+\\)\\(:\\([0-9]+\\)\\)?\\(/.*$\\)" url) (setq server (match-string 1 url) port (string-to-int (or (match-string 3 url) "80")) - path (if http-proxy-server url (match-string 4 url))) + path (if (pukiwiki-no-proxy-domain-p url) (match-string 4 url) url)) (setq str (mapconcat '(lambda (x) (concat (car x) "=" (cdr x))) @@ -2606,8 +2703,8 @@ (open-network-stream (concat "*request to " server "*") buf - (or http-proxy-server server) - (or http-proxy-port port)))) + (if (pukiwiki-no-proxy-domain-p url) server http-proxy-server) + (if (pukiwiki-no-proxy-domain-p url) port http-proxy-port)))) (set-process-coding-system connection 'binary 'binary) ;;(set-process-sentinel connection 'ignore) (set-process-sentinel connection 'pukiwiki-http-fetch-sentinel) @@ -2672,7 +2769,7 @@ "^http://\\([^/:]+\\)\\(:\\([0-9]+\\)\\)?\\(/.*$\\)" url) (setq server (match-string 1 url) port (string-to-int (or (match-string 3 url) "80")) - path (if http-proxy-server url (match-string 4 url))) + path (if (pukiwiki-no-proxy-domain-p url) (match-string 4 url) url)) (save-excursion (setq buf (get-buffer-create (concat "*result from " server "*"))) @@ -2682,8 +2779,8 @@ (open-network-stream (concat "*request to " server "*") buf - (or http-proxy-server server) - (or http-proxy-port port))) + (if (pukiwiki-no-proxy-domain-p url) server http-proxy-server) + (if (pukiwiki-no-proxy-domain-p url) port http-proxy-port))) (set-process-coding-system connection 'binary 'binary) (set-process-sentinel connection 'pukiwiki-download-sentinel) (process-send-string