This is a really simple mode to edit pages on Oddmuse wikis (such as EmacsWiki) using GNU Emacs.
Project is currently hosted on savannah at
oddmuse is also at: Lisp:oddmuse.el (not the latest version though).
It works in Emacs 22 and further (if you use Emacs 21, check the section below).
No this mode is not dead (not yet). I just did not have time for ages ;)
I have switched to Yaoddmuse. So I’m finding someone to take over OddmuseMode. If you are interested in it, it’s yours! – rubikitch
I am interested if no one is taking over it before I do :) But best of all, why not concentrate our efforts in merging the two modes ? Yaoddmuse is doing quite a good job maybe it would be best to obsolete OddMuseMode? ? I do not see any reason to have two different modes. Anyway, I can take over maintainership.– XavierMaillard
I think it’s unnecessary to continue use Oddmuse, Yaoddmuse have all features of Oddmuse. IMO, Oddmuse should be obsolete. – AndyStewart
We still need to understand why I should stop using Oddmuse. You did not give good reasons (asynchronous fetching is not something I must have). I’d rather want to see efforts in porting Oddmuse features into Yaoddmuse (and vice versa). If nobody is interested in doing so, Oddmuse must stay alive thus I am applying to maintain it (I have several features and ideas in mind). – XavierMaillard
OddmuseMode is yours!
For a more powerful Oddmuse mode, see Yaoddmuse.
Add the file to your LoadPath, and add the following to your InitFile:
(require 'oddmuse)
(setq url-proxy-services '(("http" . "your.proxy.host:portnumber")) ; if needed
(oddmuse-mode-initialize)
If you plan to edit EmacsWiki, continue reading.
Some wikis, such as EmacsWiki, use a text captcha to protect pages from being edited. The following code bypasses this test:
(add-hook 'oddmuse-mode-hook
(lambda ()
(unless (string-match "question" oddmuse-post)
(when (string-match "EmacsWiki" oddmuse-wiki)
(setq oddmuse-post (concat "uihnscuskc=1;" oddmuse-post)))
(when (string-match "OddmuseWiki" oddmuse-wiki)
(setq oddmuse-post (concat "ham=1;" oddmuse-post))))))
Use ‘M-x oddmuse-edit’ to get started. Use EmacsWiki as the wiki and SandBox as the page to edit. :)
Use ‘C-c C-o’ to follow links, use ‘C-u C-c C-o’ to specify the target page yourself, and use ‘C-c C-c’ to save changes.
You can use ‘M-x oddmuse-post’ in any buffer. It doesn’t have to be in Oddmuse Mode.
Note: if post doesn’t work, check if you should use the captcha-bypassing code above.
At the bottom of oddmuse.el is the following code that bootstraps itself to the EmacsWiki:
(emacswiki-post "oddmuse.el")
From the end of the line just press ‘C-x C-e’.
Current oddmuse.el uses url.el which is a standard library of Emacs22. If you use Emacs21, use oddmuse-curl.el instead. It requires #curl# (a command-line http client, amongst many other things).
curl for URL retriever. (deprecated)If you use oddmuse-curl.el on Windows, you’ll need to install curl and use a decent shell for ‘shell-command-on-region’, like:
(setq explicit-shell-file-name "cmd.exe") (setq shell-command-switch "/e:4096 /c")
OddmuseMode is now hosted on savannah and is using Bazaar as its DVC.
So, in order to submit patches, bugs or anything else related to OddmuseMode, please try to use as much as you can savannah’s services.
Project page: http://savannah.nongnu.org/projects/oddmuse-el
Wouldn’t it be cool if one could use the usual footnote-mode commands to create footnotes in oddmuse page, if they are not too “unwiki”?
e.g. Here [#1] is an example for a footnote is oddmuse. Footnotes: [:1][1] no, it's actually here.
If we really wanted footnotes, we should support them better. In fact, there’s an Oddmuse extension that does just that. I just didn’t install it on this site. And to be honest, I see no need for them on the web: I believe footnotes belong to the world of print instead of the world of hypertext. See the Style section in Community:FootNote. – AlexSchroeder
The way oddmuse.el invokes curl doesn’t appear to be compatible with tcsh. Here’s what I see when I C-c C-c:
Oddmuse Minor set to t generator: KristjánJónasson from selfjall.rhi.hi.is last-modified: 2007-10-09T23:35Z revision: 1105 Save ?(y or n) Wrote /Users/ted/wikis/EmacsWiki/SandBox tcsh: Unmatched '.
This may be overstaying shell-quoting problem. I just fixed it! – rubikitch
(please do not modify this section. I am trying to track all OddmuseMode contributors and their contributions just in case I need it).
I tested OddmuseMode in SandBox, but could not handle Japanese chars. Here is a patch. – rubikitch
--- oddmuse.el 2006/12/29 11:00:40 1.1
+++ oddmuse.el 2006/12/29 11:01:45
@@ -144,7 +144,9 @@
(pop-to-buffer (get-buffer name))
(let ((command oddmuse-get-command)
(url (cdr (assoc wiki oddmuse-wikis)))
- (buf (get-buffer-create name)))
+ (buf (get-buffer-create name))
+ (coding-system-for-read 'utf-8)
+ (coding-system-for-write 'utf-8))
(setq command (replace-regexp-in-string "%w" url command t t)
command (replace-regexp-in-string "%t" pagename command t t))
(shell-command command buf)
@@ -191,7 +193,9 @@
(set (make-local-variable 'oddmuse-page-name)
(read-from-minibuffer "Pagename: " (buffer-name))))
(let ((command oddmuse-post-command)
- (url (cdr (assoc oddmuse-wiki oddmuse-wikis))))
+ (url (cdr (assoc oddmuse-wiki oddmuse-wikis)))
+ (coding-system-for-read 'utf-8)
+ (coding-system-for-write 'utf-8))
(setq command (replace-regexp-in-string "%w" url command t t)
command (replace-regexp-in-string "%t" oddmuse-page-name command t t)
command (replace-regexp-in-string "%s" summary command t t)
A similar patch has been suggested before by email. I think that there must be a better solution, however. After all, not all Oddmuse wikis will be UTF-8 encoded wikis. That’s just the default. And in theory at least Emacs should be able to do this – similar to how it determines the coding system used in files. The solution will probably involve something with ‘default-process-coding-system’. Using ‘undecided’ as ‘coding-system-for-read’ has it’s problems. The manual says:
‘undecided’, which determine the coding system from the data, do not work entirely reliably with asynchronous subprocess output. This is because Emacs handles asynchronous subprocess output in batches, as it arrives. If the coding system leaves the character code conversion unspecified, or leaves the end-of-line conversion unspecified, Emacs must try to detect the proper conversion from one batch at a time, and this does not always work.But it should be possible to inhibit decoding, insert the raw bytes in a unibyte buffer, and do something such as call the functions on ‘auto-coding-functions’ or similar. I just don’t know enough about it right now to know what to do. But using an explicit option for Oddmuse wikis seems like the wrong thing to do.
What do you think? – AlexSchroeder
Though I have not implemented, I think of two ideas:
‘oddmuse-wikis’. Of course the default is utf-8 ("TestWiki" "http://www.emacswiki.org/cgi-bin/test" utf-8)‘sgml-tag-alist’ and ‘skeleton-transformation’.‘oddmuse-read-pagename’Awesome mode, though. :)
– nschum
Reflected your comment. thank you. – rubikitch
I get an error about ‘defvaralias’ in Emacs 24. Requiring SkeletonMode fixes it.
I’ve also put the ‘require’ for cl.el in an ‘eval-when-compile’ after removing a few unnecessary cl-isms. I haven’t seen an error after using Oddmuse Mode for a month with this change. Emacs would probably complain during byte compilation if a require ‘cl was needed at runtime. – AaronHawley
--- oddmuse.el 2009-02-22 18:22:58.000000000 -0400
+++ oddmuse.el 2012-02-13 15:37:42.867008300 -0500
@@ -125,8 +125,8 @@
;;
;;; Code:
-(require 'cl)
+(require 'skeleton)
-(eval-when-compile (require 'sgml-mode) (require 'skeleton))
+(eval-when-compile (require 'sgml-mode) (require 'cl))
(require 'url)
(defcustom oddmuse-directory "~/emacs/oddmuse"
@@ -395,7 +395,7 @@
(let* ((triplet (assoc wiki oddmuse-wikis))
(url (cadr triplet))
(oddmuse-page-name pagename)
- (coding (caddr triplet))
+ (coding (nth 2 triplet))
(buf (find-file-noselect
(concat oddmuse-directory "/" wiki "/" pagename))))
(setq url (oddmuse-format-url url oddmuse-get coding))
@@ -490,7 +490,7 @@
(let* ((triplet (assoc oddmuse-wiki oddmuse-wikis))
(url (cadr triplet))
(oddmuse-minor (if oddmuse-minor "on" "off"))
- (coding (caddr triplet))
+ (coding (nth 2 triplet))
(check-url (oddmuse-format-url url oddmuse-revision-check coding)))
(when (y-or-n-p (oddmuse-revision-check-prompt check-url coding))
(let ((text (buffer-string)))
@@ -511,7 +511,7 @@
(let* ((wiki (or wiki-arg
(completing-read "Wiki: " oddmuse-wikis nil t oddmuse-wiki)))
(url (cadr (assoc wiki oddmuse-wikis)))
- (coding (caddr (assoc wiki oddmuse-wikis)))
+ (coding (nth 2(assoc wiki oddmuse-wikis)))
table)
(setq url (oddmuse-format-url url oddmuse-index-get coding))
(prog1
@@ -559,7 +559,6 @@
(oddmuse-edit wiki pagename)))
(erase-buffer)
(insert "DeletedPage")
- (setq oddmuse-dangerous-p t)
(oddmuse-post (concat "DeletedPage - reason: " summary)))
;;;###autoload
@@ -582,7 +581,7 @@
(defun oddmuse-url (wiki pagename)
"Get the URL of oddmuse wiki."
(condition-case v
- (concat (or (cadr (assoc wiki oddmuse-wikis)) (error)) "/" pagename)
+ (concat (or (cadr (assoc wiki oddmuse-wikis)) (error nil)) "/" pagename)
(error nil)))
;; (oddmuse-url "EmacsWiki" "OddmuseMode")
I was annoyed that I couldn’t set the Wiki when I was in a new page without having to post the page first. The following patch to oddmuse.el adds a command ‘M-x oddmuse-set-wiki’ to set the Wiki. I’ve also tried to reduce some code duplication by adding a function called ‘oddmuse-read-wiki’ and a command ‘M-x oddmuse-set-pagename’. – AaronHawley
--- oddmuse.el 2009-02-22 18:22:58.000000000 -0400
+++ oddmuse.el 2009-06-01 15:02:55.000000000 -0400
@@ -278,11 +278,11 @@
("pre" \n) ("tt") ("u")))
(set (make-local-variable 'skeleton-transformation) 'identity)
(and buffer-file-name
- (set (make-local-variable 'oddmuse-wiki)
- (file-name-nondirectory
- (substring (file-name-directory buffer-file-name) 0 -1)))
- (set (make-local-variable 'oddmuse-page-name)
- (file-name-nondirectory buffer-file-name))
+ (oddmuse-set-wiki
+ (file-name-nondirectory
+ (substring (file-name-directory buffer-file-name) 0 -1)))
+ (oddmuse-set-pagename
+ (file-name-nondirectory buffer-file-name))
;; Initialize oddmuse-minor according to `oddmuse-use-always-minor'
(set (make-local-variable 'oddmuse-minor)
oddmuse-use-always-minor))
@@ -341,10 +341,20 @@
(concat url "?" (oddmuse-format args coding)))
(defun oddmuse-read-wiki-and-pagename ()
- "Read an wikiname and a pagename of `oddmuse-wikis' with completion."
- (let ((wiki (completing-read "Wiki: " oddmuse-wikis nil t oddmuse-wiki)))
+ "Read a Wiki name and a pagename of `oddmuse-wikis' with completion."
+ (let ((wiki (oddmuse-read-wiki)))
(list wiki (oddmuse-read-pagename wiki))))
+(defun oddmuse-read-wiki ()
+ "Read a Wiki name with completion."
+ (completing-read "Wiki: " oddmuse-wikis nil t oddmuse-wiki))
+
+(defun oddmuse-set-wiki (wiki)
+ "Set Wiki name to WIKI."
+ (interactive (list (oddmuse-read-wiki)))
+ (set (make-local-variable 'oddmuse-wiki)
+ wiki))
+
(defun oddmuse-retrieve (url method buffer coding &optional data)
"Retrieve URL with METHOD, and put response content to BUFFER.
Content is decoded with CODING.
@@ -482,11 +492,9 @@
(interactive "sSummary: ")
;; when using prefix or on a buffer that is not in oddmuse-mode
(when (or (not oddmuse-wiki) current-prefix-arg)
- (set (make-local-variable 'oddmuse-wiki)
- (completing-read "Wiki: " oddmuse-wikis nil t)))
+ (oddmuse-set-wiki (oddmuse-read-wiki)))
(when (not oddmuse-page-name)
- (set (make-local-variable 'oddmuse-page-name)
- (read-from-minibuffer "Pagename: " (buffer-name))))
+ (oddmuse-set-pagename (oddmuse-read-pagename oddmuse-wiki)))
(let* ((triplet (assoc oddmuse-wiki oddmuse-wikis))
(url (cadr triplet))
(oddmuse-minor (if oddmuse-minor "on" "off"))
@@ -509,7 +517,7 @@
This command is used to reflect new pages to `oddmuse-pages-hash'."
(interactive)
(let* ((wiki (or wiki-arg
- (completing-read "Wiki: " oddmuse-wikis nil t oddmuse-wiki)))
+ (oddmuse-read-wiki)))
(url (cadr (assoc wiki oddmuse-wikis)))
(coding (caddr (assoc wiki oddmuse-wikis)))
table)
@@ -524,6 +532,12 @@
"Read a pagename of WIKI with completion."
(completing-read "Pagename: " (oddmuse-make-completion-table wiki)))
+(defun oddmuse-set-pagename (page)
+ "Set page name to PAGE."
+ (interactive (list (oddmuse-read-pagename oddmuse-wiki)))
+ (set (make-local-variable 'oddmuse-page-name)
+ page))
+
;;;###autoload
(defun oddmuse-revert ()
"Revert this oddmuse page."
I think ‘oddmuse-revision-check-command’ should use curl instead of w3m. On OSX, neither wget nor w3m are part of the system, but curl is. I love page completion. :) – AlexSchroeder
Hmm, curl does not have html → text converter but w3m has. I leave it to you. – rubikitch
You probably already knew about the RSS 3.0 “Text” format for Recent changes. Here’s an example: http://www.emacswiki.org/cgi-bin/emacs?action=rc;raw=1 to check for the last change to a certain page only, use http://www.emacswiki.org/cgi-bin/emacs?action=rc;raw=1;rcidonly=SandBox;showedit=1. The default number of days for RecentChanges is seven, thus the URL will give you the last change in the last seven days.
The latest revision of Oddmuse now also supports the “Text” format for history pages: http://www.emacswiki.org/cgi-bin/emacs?action=history;raw=1;id=SandBox.
The history action will only show revisions that are still available on the system, whereas the rc action will show all changes within the specified time window. If you don’t specify a time window, the default is seven days. You can specify a time window using days=30 or from=1 (where from=n uses seconds since the start of the epoch). Unfortunately looking at recent changes older than 90 days will currently be stopped by RAM limitations on the wiki process. I should work on that code to no longer slurp the entire log file. ;)
Anyway, here are two examples.
Example 1: Alpinobombus:~ alex$ curl -silent 'http://www.emacswiki.org/cgi-bin/emacs?action=history;raw=1;id=SandBox' | grep ^revision | head -n 1 | cut -d ' ' -f 2 → 1065
Example 2: Alpinobombus:~ alex$ curl -silent 'http://www.emacswiki.org/cgi-bin/emacs?action=rc;raw=1;showedit=1;rcidonly=SandBox' | grep ^revision | head -n 1 | cut -d ' ' -f 2 → 1065
Either way should work. What do you think? – AlexSchroeder
--- oddmuse.el 2007/06/16 15:12:09 1.16 +++ oddmuse.el 2007/07/02 16:18:15 @@ -176,7 +176,7 @@ ") (defvar oddmuse-revision-check-command - "echo \"`w3m -dump '%w?action=history;id=%t' | grep '\(current\)'`: save?\"" + "curl -silent '%w?action=rc;raw=1;showedit=1;rcidonly=%t' | egrep '^generator|last-modified|revision' | tail -3; echo 'Save ?'" "Command to use for checking current revision of this page. It must print the page to stdout.
Thank you for information. How about this patch?
I am fed up with all emacs modes putting their files everywhere onto my filesystem. I mean, I do not want to see all this stuff getting in my way every time. So I am tweaking/modifying all of them to try to use the same location based on what is recommended by the freedesktop team and based on what data it should hold.
Here is a pretty tiny patch that just tries to follow the XDG_CACHE_HOME policy (see http://standards.freedesktop.org/basedir-spec).
--- oddmuse.el 2008-04-21 08:06:52.000000000 +0200 +++ oddmuse.el.new 2008-07-27 05:27:58.000000000 +0200 @@ -128,7 +128,7 @@ (eval-when-compile (require 'sgml-mode) (require 'skeleton)) (require 'url) -(defcustom oddmuse-directory "~/emacs/oddmuse" +(defcustom oddmuse-directory (concat (or (getenv "XDG_CACHE_HOME") "~/.cache") "/emacs/oddmuse") "Directory to store oddmuse pages." :type '(string) :group 'oddmuse)
I tested it ad it works. – XavierMaillard
Now that Emacs has url-retrieve, would it be ok to add support for it ? I already have something working for the default oddmuse-edit function but I am not an expert at all and there are probably things I could not do with url-retrieve (eg. Revision Check Command).
One thing we could already do is to change oddmuse-get-command to something like
(if (fboundp 'url-retrieve)
'url-retrieve
oddmuse-get-external-command)
(defvar oddmuse-get-external-command (executable-find "curl")
"*Tool to use if we do not have `url-retrieve'.")
(defvar oddmuse-get-command-options ...
"*Arguments to pass to retrieve an url.
This list of arguments should apply either to
`oddmuse-get-command' or `oddmuse-get-external-command'")
etc...
What do you think ? There is some small adaptations to do here and there to support url-retrieve but it is not that difficult. If interested, we could work in collaboration. – XavierMaillard
Does url-retrieve support HTTP POST method? If so, patches are welcome! – rubikitch
Implemented! – rubikitch
If I create a new page it doesn’t get added to the oddmuse-pages-hash. The following patch should do the trick. – AaronHawley
--- oddmuse.el 2009-02-22 18:22:58.000000000 -0400
+++ oddmuse.el 2009-04-13 01:36:25.000000000 -0400
@@ -497,7 +497,18 @@
(and buffer-file-name (basic-save-buffer))
(oddmuse-retrieve url "POST" nil coding
(oddmuse-format oddmuse-post coding))
- (message "Posted")))))
+ (message "Posted")
+ ;; Instead of `M-x oddmuse-compute-pagename-completion-table',
+ ;; if the page is new, then add it to the beginning of the
+ ;; completion table.
+ (if (null (member (list oddmuse-page-name)
+ (gethash oddmuse-wiki
+ oddmuse-pages-hash)))
+ (puthash oddmuse-wiki
+ (cons (list oddmuse-page-name)
+ (gethash oddmuse-wiki
+ oddmuse-pages-hash))
+ oddmuse-pages-hash))))))
(defun oddmuse-make-completion-table (wiki)
"Create pagename completion table for WIKI. if available, return precomputed one."
This patch provides ImenuMode support to Oddmuse by creating entries for each heading. A better implementation would make the menu hierarchical. – AaronHawley
--- oddmuse.el 2009-02-22 18:22:58.000000000 -0400
+++ oddmuse.el 2009-06-11 10:25:42.000000000 -0400
@@ -228,6 +228,9 @@
(defvar oddmuse-revision-check-regexp "^\\(generator\\|last-modified\\|revision\\).+"
"A revision check regexp used to show prompt.")
+(defvar oddmuse-imenu-regexp "^\\(=+\\)\\s-*\\(.*?\\)\\s-*\\1"
+ "A regular expression for headings to be added to an index menu.")
+
(defvar oddmuse-minor nil
"Is this editing a minor change ?")
@@ -287,7 +290,9 @@
(set (make-local-variable 'oddmuse-minor)
oddmuse-use-always-minor))
- (setq indent-tabs-mode nil))
+ (setq indent-tabs-mode nil
+ imenu-generic-expression
+ (list (list nil oddmuse-imenu-regexp 2))))
(autoload 'sgml-tag "sgml-mode" t)
Oddmuse-mode seems not to work on Windows with Cygwin. Or else I am not understanding the guide given on this page. – KristjánJónasson
Try the latest version, then eval this sexp.
(shell-command-to-string (let ((url "http://www.emacswiki.org/cgi-bin/emacs") (oddmuse-page-name "OddmuseMode")) (oddmuse-format-command oddmuse-revision-check-command)))
What is the supposed way of dealing with multiple wikis where you use different usernames? I’d find it very convenient to define those in oddmuse-wikis. --StefanKamphausen
Yes. Add site-specific username into optional 3rd element (0-origin). Then define oddmuse-username function to get username. – rubikitch
When I try (emacswiki-post “…”) I get the error “error in process sentinel: Symbol’s value as variable is void: url-http-attempt-keepalives”. I see that url-http-attempt-keepalives is defined in the url-http file, so it seems oddmuse.el should (require 'url-http) if it’s going to use this variable.
When posting, the result 403 Forbidden seems to have no effect. This happens if the page in question is protected via the (optional) questionasker module. For an example, check my homepage. Basically you either need to provide the answer to a secret question, or you need to know a (not so secret) additional parameter to supply with the request. – AlexSchroeder
When using the new version without curl and oddmuse-post’ing to a password protected wiki one receives no errormessage. The old version with curl showed the forbidden message of the wiki itself.
This falls into the same category as my (older) question above how to use wikis with username and password, I think. – StefanKamphausen
When I want to create a new EmacsWiki entry from my OddmuseMode, it does not work. Instead, it returns the SourceCode? of the 404 ErrorPage?.
How am I supposed to post new pages to EmacsWiki ?
When I try it, I get the new page (ie. the new buffer is called EmacsWiki:SandBox2) containing the default text “This page does not exist, but you can create it now.” Just replace the content with the new content and you’re done. – AlexSchroeder
Okay, maybe, OddmuseMode should treat these pages differently and automatically empty the buffer. I will try to add this to my TodoList? – XavierMaillard
I’ve tried adding support for asynchronous “get” and “post” functions of Oddmuse mode. The patch so far is preliminary and ignores interactive bits like the page name completion or the prompt for checking the revision. I’d rather get feedback on this most minimal patch to see if it is something Oddmuse could use. I’m sure what I’ve done could use some improvement, and it should be checked for bugs. I haven’t used it much myself. Further, this change could be probably written better than I have done so myself.
The patch replaces ‘oddmuse-retrieve’ using the original but only using the asynchronous support of ‘url-retrieve’ instead of ‘url-retrieve-synchronously’. The new function added to support ‘url-retrieve’, ‘oddmuse-response-callback’, is also based on ‘oddmuse-process-response’. So, there’s a bit of code duplication here that suggests a few significant changes should be made to give asynchronous support but avoid duplication.
The original ‘oddmuse-retrieve’ is renamed ‘oddmuse-retrieve-synchronously’, since it needs to stick around for the ‘oddmuse-revision-check-prompt’ and the ‘oddmuse-retrieve-to-string’ functions.
One change in behavior I’ve noticed is the buffer is modified (the DirtyBit? is on in the ModeLine). I’d say that’s a feature and not a bug, because attempts at ‘basic-save-buffer’ in the code will work now. I admit, I always liked that visiting a Wiki page would never clobber my local files unless I actually edited and saved . – AaronHawley
--- oddmuse.el 2008-04-21 02:06:19.000000000 -0500
+++ oddmuse.el 2009-02-13 22:39:48.000000000 -0500
@@ -319,7 +319,8 @@
(let ((wiki (completing-read "Wiki: " oddmuse-wikis nil t oddmuse-wiki)))
(list wiki (oddmuse-read-pagename wiki))))
-(defun oddmuse-retrieve (url method buffer coding &optional data)
+(defun oddmuse-retrieve-synchronously (url method buffer coding &optional data)
+ ;; Previously oddmuse-retrieve.
"Retrieve URL with METHOD, and put response content to BUFFER.
Content is decoded with CODING.
If DATA is non-nil, it is used to POST data."
@@ -330,13 +331,47 @@
(url-request-data data))
(oddmuse-process-response (url-retrieve-synchronously url) buffer coding)))
+(defun oddmuse-retrieve (url method buffer coding &optional data)
+ "Retrieve URL with METHOD, and put response content to BUFFER.
+Content is decoded with CODING.
+If DATA is non-nil, it is used to POST data."
+ ;; Copied from oddmuse-retrieve-synchronously
+ (let* ((url-request-extra-headers
+ (and (string= method "POST")
+ '(("Content-type: application/x-www-form-urlencoded;"))))
+ (url-request-method method)
+ (url-request-data data))
+ (url-retrieve url 'oddmuse-response-callback
+ (list buffer coding))))
+
(defun oddmuse-retrieve-to-string (url method coding &optional data)
"Return a string retrieved with URL.
see: `oddmuse-retrieve'"
(with-temp-buffer
- (oddmuse-retrieve url method (current-buffer) coding data)
+ (oddmuse-retrieve-synchronously url method (current-buffer) coding data)
(buffer-string)))
+(defun oddmuse-response-callback (status buffer coding)
+ "Put response body from RESPONSE-BUFFER to BUFFER.
+It is decoded with CODING.
+The STATUS is passed from `url-retrieve'."
+ ;; Copied from oddmuse-process-response.
+ (declare (special url-http-end-of-headers))
+ (when buffer
+ (let ((response-buffer (current-buffer)))
+ (with-current-buffer buffer
+ (insert
+ (with-current-buffer response-buffer
+ (set-buffer-multibyte t)
+ (goto-char (1+ url-http-end-of-headers))
+ (decode-coding-region
+ (point) (point-max)
+ (coding-system-change-eol-conversion coding 'dos))
+ (buffer-substring (point) (point-max))))
+ (goto-char (point-min))
+ (switch-to-buffer buffer))
+ (kill-buffer response-buffer))))
+
(defun oddmuse-process-response (response-buffer buffer coding)
"Put response body from RESPONSE-BUFFER to BUFFER.
It is decoded with CODING."
@@ -427,7 +462,7 @@
(defun oddmuse-revision-check-prompt (url coding)
(with-temp-buffer
- (oddmuse-retrieve url "GET" (current-buffer) coding)
+ (oddmuse-retrieve-synchronously url "GET" (current-buffer) coding)
(goto-char (point-min))
(let (list)
(while (re-search-forward oddmuse-revision-check-regexp nil t)
If I generate the patch without duplicating the ‘oddmuse-retrieve’ and ‘oddmuse-process-response’, the changes for asynchronous support become very minimal. – AaronHawley
--- oddmuse.el 2008-04-21 02:06:19.000000000 -0500
+++ oddmuse.el 2009-02-14 00:19:07.000000000 -0500
@@ -323,25 +323,30 @@
"Retrieve URL with METHOD, and put response content to BUFFER.
Content is decoded with CODING.
If DATA is non-nil, it is used to POST data."
+ ;; Copied from oddmuse-retrieve-synchronously
(let* ((url-request-extra-headers
(and (string= method "POST")
'(("Content-type: application/x-www-form-urlencoded;"))))
(url-request-method method)
(url-request-data data))
- (oddmuse-process-response (url-retrieve-synchronously url) buffer coding)))
+ (url-retrieve url 'oddmuse-response-callback
+ (list buffer coding))))
(defun oddmuse-retrieve-to-string (url method coding &optional data)
"Return a string retrieved with URL.
see: `oddmuse-retrieve'"
(with-temp-buffer
- (oddmuse-retrieve url method (current-buffer) coding data)
+ (oddmuse-retrieve-synchronously url method (current-buffer) coding data)
(buffer-string)))
-(defun oddmuse-process-response (response-buffer buffer coding)
+(defun oddmuse-response-callback (status buffer coding)
"Put response body from RESPONSE-BUFFER to BUFFER.
-It is decoded with CODING."
+It is decoded with CODING.
+The STATUS is passed from `url-retrieve'."
+ ;; Copied from oddmuse-process-response.
(declare (special url-http-end-of-headers))
(when buffer
+ (let ((response-buffer (current-buffer)))
(with-current-buffer buffer
(insert
(with-current-buffer response-buffer
@@ -351,8 +356,9 @@
(point) (point-max)
(coding-system-change-eol-conversion coding 'dos))
(buffer-substring (point) (point-max))))
- (goto-char (point-min))))
- (kill-buffer response-buffer))
+ (goto-char (point-min))
+ (switch-to-buffer buffer))
+ (kill-buffer response-buffer))))
;;;###autoload
(defun oddmuse-edit (wiki pagename)
@@ -427,7 +433,7 @@
(defun oddmuse-revision-check-prompt (url coding)
(with-temp-buffer
- (oddmuse-retrieve url "GET" (current-buffer) coding)
+ (oddmuse-retrieve-synchronously url "GET" (current-buffer) coding)
(goto-char (point-min))
(let (list)
(while (re-search-forward oddmuse-revision-check-regexp nil t)
Cool. Is asynchronous something OddmuseMode should have? – AaronHawley
‘url-retrieve-synchronous’ to handle wiki page, so it will hang emacs when it work, and fix this problem need ‘url-retrieve’ and use unique buffer to hande. And those chnage not just a patch to oddmuse.el, need rewrite all module for hande asynchronous process. And the patch’s size is bigger than size of oddmuse.el, and will make the code of oddmus.el became dirty, i need clear and module code to add new feature (like post command). So i rewrite new one. – AndyStewartI’m not convinced the changes to handle asynchronous processing are as significant as you have described. You could disprove me by showing how my patch is lacking. Would you? – AaronHawley
I agree with Aaron. In the other hand I do not really understand the need for asynchronous fetching. This is why I won’t use Yaoddmuse. Can somebody explain the need for this “feature” ? – XavierMaillard
Having used my asynchronous patch to OddmuseMode for a week, I’ve found the only benefit is not seeing Emacs freeze up when loading or uploading pages. I’ve never once had time to edit in other buffers while waiting for pages to load.
Instead, I’ve found myself frustrated because after loading a page and issuing commands like ‘isearch-forward’ – nothing happens since there’s no text to search until the asynchronous callback returns it. Perhaps my patch is lacking, but Yaoddmuse doesn’t fair any better, either. – AaronHawley
See WikiModeDiscussion for similar stuff, and also RuseWikiMode is based on OddmuseMode.