pukiwiki-mode-on-https

emacsのメジャーモードであるpukiwiki-modeはその名の通りpukiwikiで構築されたサイトを編集するためのモードだ。しかし、このモードはhttpsには対応していないという欠点があるため、知人が残念がっていた。
そこで、改造してhttps対応版を作成した。curlを呼出して通信させることで手っ取り早く実現できた。とは言え、半日程度はかかってしまうあたり、まだ不慣れな感じである。
とりあえず改造した部分のdiffを書いておく。Ver2.3からの差分である。もちろんライセンスはGPL扱いで。

*** ./pukiwiki-mode.el	Sun Nov 19 10:58:32 2005
--- ./pukiwiki-mode.el	Sun Apr  8 23:15:53 2007
***************
*** 5701,5705 ****
    (let (connection server port path buf str len)
      (string-match
!      "^http://\\([^/:]+\\)\\(:\\([0-9]+\\)\\)?\\(/.*$\\)" url)
      (setq server (match-string 1 url)
            port (string-to-int (or (match-string 3 url) "80"))
--- 5701,5705 ----
    (let (connection server port path buf str len)
      (string-match
!      "^https?://\\([^/:]+\\)\\(:\\([0-9]+\\)\\)?\\(/.*$\\)" url)
      (setq server (match-string 1 url)
            port (string-to-int (or (match-string 3 url) "80"))
***************
*** 5714,5759 ****
                   (concat "*result from " server "*")))
        (set-buffer buf)
        (erase-buffer)
!       (setq connection
!             (as-binary-process
!              (open-network-stream
!               (concat "*request to " server "*")
!               buf
!               (if (pukiwiki-no-proxy-domain-p url) server
!                 (or http-proxy-server server))
!               (if (pukiwiki-no-proxy-domain-p url) port
!                 (or http-proxy-port port)))))
!       (set-process-coding-system connection 'binary 'binary)
!       ;;(set-process-sentinel connection 'ignore)
!       (set-process-sentinel connection 'pukiwiki-http-fetch-sentinel)
!       (process-send-string
!        connection
!        (concat (if (eq method 'post)
!                    (concat "POST " path)
!                  (concat "GET " path (if (> len 0)
!                                          (concat "?" str))))
!                " HTTP/1.0\r\n"
!                (concat "Host: " server "\r\n")
!                "Connection: close\r\n"
!                "Content-type: application/x-www-form-urlencoded\r\n"
!                (if (and user pass)
!                    (concat "Authorization: Basic "
!                            (base64-encode-string
!                             (concat user ":" pass))
!                            "\r\n"))
!                (if (eq method 'post)
!                    (concat "Content-length: " (int-to-string len) "\r\n"
!                            "\r\n"
!                            str))
!                "\r\n"))
!       (while pukiwiki-http-fetch-running
!         (unless (accept-process-output connection pukiwiki-process-timeout)
!           (error "HTTP fetch: Connection timeout!"))
!         (sit-for pukiwiki-process-sentinel-interval))
!       (delete-process connection)
        (goto-char (point-min))
        (save-excursion
          (if (re-search-forward
!              "HTTP/1.[01] \\([0-9][0-9][0-9]\\) \\(.*\\)" nil t)
              (let ((code (match-string 1))
                    (desc (match-string 2)))
--- 5714,5744 ----
                   (concat "*result from " server "*")))
        (set-buffer buf)
+       (make-variable-buffer-local 'coding-system-for-read)
+       (setq coding-system-for-read 'binary)
        (erase-buffer)
!       
!       (with-temp-buffer
!         (insert (concat str "\r\n"))
!         (call-process-region 1 (buffer-size) "curl" nil buf nil
!                              "--silent"
!                              "--insecure"
!                              "--include"
!                              (if (and user pass) (concat "-u" user ":" pass) "")
!                              url
!                              (if http-proxy-server
!                                  (concat
!                                   (concat "-x " http-proxy-server)
!                                   (if http-proxy-port
!                                       (concat ":" http-proxy-port) ""))
!                                "")
!                              (if (eq method 'post) "" "-G")
!                              "--data" "@-"))
! 
        (goto-char (point-min))
        (save-excursion
          (if (re-search-forward
!              "HTTP/1\\.[01] \\([0-9][0-9][0-9]\\) \\(.*\\)" nil t)
!             (progn
!               (if (equal (match-string 1) "100") (re-search-forward "HTTP/1\\.[01] \\([0-9][0-9][0-9]\\) \\(.*\\)" nil t))
              (let ((code (match-string 1))
                    (desc (match-string 2)))
***************
*** 5790,5794 ****
                                         url method user pass data)))))))
                      (t
!                      (cons code desc))))
            buf)))))
  
--- 5775,5779 ----
                                         url method user pass data)))))))
                      (t
!                      (cons code desc)))))
            buf)))))
  

Document ID: 8f769af269b7b5dbd98ac08c1313a2c9