[Emacs] org2blogでWordPressのタグを取得すると文字化けする件の修正

Emacsのorg2blogでは記事を書く際にカテゴリ名やタグ名を M-x org2blog/wp-complete-category で補完することができます。しかし日本語タグ名の補完では表示される候補が文字化けの様な形になるため修正しました。

変更箇所は、オリジナルではタグの取得を"slug"で行っていた部分を"name"で取得するようにしています。タグスラッグ -> タグ名ですね。変更はこの部分だけのわずか1箇所でありますがアドバイスで上書きしています。

(defun org2blog/wp-login:override (&optional blog-name)
  "Logs into the blog. Initializes the internal data structures."
  (interactive)
  (if (not org2blog/wp-blog-alist)
      (error "Set `org2blog/wp-blog-alist' to be able to use org2blog."))
  (let ()
    (setq org2blog/wp-blog-name
          (or
           ;; Use the provided name
           blog-name
           ;; OR Use the only entry in alist
           (and (equal (length org2blog/wp-blog-alist) 1)
                (car (car org2blog/wp-blog-alist)))
           ;; OR Prompt user
           (completing-read
            "Blog to login into? ([Tab] to see list): "
            (mapcar 'car org2blog/wp-blog-alist) nil t)))
    (unless (> (length org2blog/wp-blog-name) 1)
      (error "Invalid blog name"))
    (setq org2blog/wp-blog (assoc org2blog/wp-blog-name org2blog/wp-blog-alist)
          org2blog/wp-server-xmlrpc-url (plist-get (cdr org2blog/wp-blog) :url)
          org2blog/wp-server-userid (plist-get (cdr org2blog/wp-blog) :username)
          org2blog/wp-server-blogid (or (plist-get (cdr org2blog/wp-blog) :id) "1")
          org2blog/wp-server-pass
          (or
           (plist-get (cdr org2blog/wp-blog) :password)
           (read-passwd (format "%s Weblog password? " org2blog/wp-blog-name)))
          ;; Fetch and save category list
          org2blog/wp-categories-list
          (mapcar (lambda (category) (cdr (assoc "categoryName" category)))
                  (metaweblog-get-categories org2blog/wp-server-xmlrpc-url
                                             org2blog/wp-server-userid
                                             org2blog/wp-server-pass
                                             org2blog/wp-server-blogid))
          ;; Fetch and save tag list
          org2blog/wp-tags-list
          (mapcar (lambda (tag) (cdr (assoc "name" tag)))
                  (wp-get-tags org2blog/wp-server-xmlrpc-url
                               org2blog/wp-server-userid
                               org2blog/wp-server-pass
                               org2blog/wp-server-blogid))
          ;; Fetch and save page list
          org2blog/wp-pages-list
          (mapcar (lambda (pg)
                    (cons (cdr (assoc "page_title" pg))
                          (cdr (assoc "page_id" pg))))
                  (wp-get-pagelist org2blog/wp-server-xmlrpc-url
                                   org2blog/wp-server-userid
                                   org2blog/wp-server-pass
                                   org2blog/wp-server-blogid)))
    (setq org2blog/wp-logged-in t)
    (message "Logged in")))
(advice-add 'org2blog/wp-login :override 'org2blog/wp-login:override)

これでカテゴリ名もタグ名も自由に補完できるようになった。便利!

スポンサーリンク
スポンサーリンク