You are not logged in Log in Join
You are here: Home » Members » Alastair Burt » Editing ZWikis with Emacs

Log in
Name

Password

 

Editing ZWikis with Emacs

Emacs ZWiki Mode

This document introduces zwiki-mode-plus.el, an Emacs mode for editing Wiki pages, residing on a Zope-based ZWiki. I developed it because I cannot envisage editing structured text without using filladapt.el to handle the indentation. Using Netscape's text-editing widget is purgatory.

There is another ZWiki mode for Emacs written by Simon Michael, the author of ZWiki itself. This version has two main advantages:

  • It offers to create new ZWiki pages if they do not already exist. It does this via xmlrpc.
  • It does not lose undo information when a page is saved.

The xmlrpc.el code might be of more general use.

Currently, the ZWiki Python code is not very friendly to external programs that want to create pages via xmlrpc, so an external method has to be installed on the server. Hopefully, future versions of ZWiki will allow more direct access and this external method will no longer be needed.

What You Do

  1. Get hold of four files:

    Put the files somewhere in the Emacs load-path. You will also need to have w3 installed. It is standard with XEmacs distributions.

  2. Add the following to a file in the Extensions directory and add an external method for create_zwiki_page in the same directory as the ZWiki pages or somewhere above it in the acquisition hierarchy:
          import xmlrpclib
    
          def page_exists(self, page):
              if page in self.REQUEST.PARENTS[1].objectIds():
                  return xmlrpclib.True
              else:
                  return xmlrpclib.False
    
          def create_zwiki_page(self, page, text="\n"):
              self.create(text=text, page=page, REQUEST=self.REQUEST)
              ## Avoid redirection to HTML page
              self.REQUEST.RESPONSE.setStatus(200)
              return self.page_exists(page)
    
  3. Put something like the following in your ~/.emacs file:
          ;; For editing Zope ZWikis
    
          ;; To treat certain files automatically as ZWiki pages:
          (push
           (cons (concat "<YOUR FTP HOST>:"
                         ".*/\\(\\b[A-Z]+[a-z]+[A-Z][A-Za-z]*[0-9]*\\|"
                         "\\b[A-Z][A-Z]+[a-z][A-Za-z]*[0-9]*\\)$")
             'zwiki-mode)
           auto-mode-alist)
    
          (autoload 'zwiki-mode "zwiki-mode-plus"
            "Major mode for editing a zwiki page via ftp." t)
          (autoload 'zwiki-edit-via-ftp "zwiki-mode-plus"
            "Find the FTP file corresponding to the HTTP URL" t)
    
          ;; ZWiki is so good I am going to give it a global binding:
    
          (global-set-key '[(control c) z] 'zwiki-edit-via-ftp)
    

My typical mode of operation is then to visit a ZWiki site in a web browser. When I see a page I want to edit, I type control-c z in Emacs and paste in the HTTP URL. From then on, I just edit ZWiki pages via ftp in Emacs and they automatically get treated as ZWiki pages. Occasionally, I type control-c control-b in a ZWiki page to see how the page displays in a browser. New ZWiki pages are created for me when I call ffap with a cursor over a ZWikiName. If you do not use ffap, you can call the command zwiki-find-page explicitly.

Simple Use Without Page Creation

If you do not need the page creating functions, you can use zwiki-mode-plus.el on its own. In that case, you will not need the files xmlrpc.el and xml-parse.el, and you will not need to install the external method. In addition, if you do not use zwiki-edit-via-ftp or zope-browse-via-http, to switch between web browsing and ftp editing of the same file, you will not need the w3 package and the zope-hacks.el file.