Menu

Home

James Ahlborn

Overview

Atlassian has a wiki called Confluence. This Emacs extension allows you to interact with Confluence from Emacs.

Some of the features it supports are:

  • creating and editing pages
  • executing Wiki search
  • diffing your buffer versus the current page in the wiki
  • the following of links beneath the cursor (point)
  • an etags like history navigation (push/pop)
  • viewing/editing of labels
  • viewing/downloading of attachments
  • the quick-start describes how to use LongLines mode, which makes editing the wiki-markup much more pleasant.
  • conversion between xml and wiki format using Graham Hannington's converter
  • much, much more...

Confluence 4.0+ Support

In confluence version 4.0, Atlassian decided to change the wiki format. They did away with the "wiki" format and changed the internal document format to xml. This makes editing confluence pages via emacs much less enjoyable. However, as of version 1.6 of this library, it is possible. The somewhat simplistic confluence-xml-mode (simplistic compared to confluence-mode) is an extension of nxml-mode. It adds some minor font-lock support, but otherwise leaves you with standard xml editing support. Confluence still has built in support for translating wiki format pages to xml format pages, however, the reverse translation is more problematic.

Leveraging the excellent work of Graham Hannington, this package provides a "basic" converter from xml to wiki format, however it can be "lossy" depending on what advanced features a page contains. A confluence xml page can be converted to the wiki format using M-x confluence-toggle-page-content-type. This page can be saved as wiki format (allowing confluence to do the reverse conversion on save) or can be converted back to xml format (using the same command) and then saved (allowing you to check the final content). Note that the conversion from xml to wiki format requires the external "xsltproc" program, which is available on most unices and cygwin. Use these conversions at your own risk!

For the truly brave, you can set the custom variable confluence-xml-convert-to-wiki-on-load to t in order to automatically convert xml content to wiki content on page load.

Setting Up Confluence

Before you can use this mode to interact with your Confluence installation, you will need your Confluence (system) administrator to enable the xml-rpc interface within Confluence.

More information about the xml-rpc api is available at the Atlassian Confluence Website.

Quick Start

;; assuming confluence.el and xml-rpc.el are in your load path
(require 'confluence)

;; note, all customization must be in *one* custom-set-variables block
(custom-set-variables
 ;; ... other custimization

 ;; confluence customization
 '(confluence-url "http://intranet/confluence/rpc/xmlrpc")
 '(confluence-default-space-alist (list (cons confluence-url "your-default-space-name"))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; confluence editing support (with longlines mode)

(autoload 'confluence-get-page "confluence" nil t)

(eval-after-load "confluence"
  '(progn
     (require 'longlines)
     (progn
       (add-hook 'confluence-mode-hook 'longlines-mode)
       (add-hook 'confluence-before-save-hook 'longlines-before-revert-hook)
       (add-hook 'confluence-before-revert-hook 'longlines-before-revert-hook)
       (add-hook 'confluence-mode-hook '(lambda () (local-set-key "\C-j" 'confluence-newline-and-indent))))))

;; LongLines mode: http://www.emacswiki.org/emacs-en/LongLines
(autoload 'longlines-mode "longlines" "LongLines Mode." t)

(eval-after-load "longlines"
  '(progn
     (defvar longlines-mode-was-active nil)
     (make-variable-buffer-local 'longlines-mode-was-active)

     (defun longlines-suspend ()
       (if longlines-mode
           (progn
             (setq longlines-mode-was-active t)
             (longlines-mode 0))))

     (defun longlines-restore ()
       (if longlines-mode-was-active
           (progn
             (setq longlines-mode-was-active nil)
             (longlines-mode 1))))

     ;; longlines doesn't play well with ediff, so suspend it during diffs
     (defadvice ediff-make-temp-file (before make-temp-file-suspend-ll
                                             activate compile preactivate)
       "Suspend longlines when running ediff."
       (with-current-buffer (ad-get-arg 0)
         (longlines-suspend)))

     (add-hook 'ediff-cleanup-hook 
               '(lambda ()
                  (dolist (tmp-buf (list ediff-buffer-A
                                         ediff-buffer-B
                                         ediff-buffer-C))
                    (if (buffer-live-p tmp-buf)
                        (with-current-buffer tmp-buf
                          (longlines-restore))))))))

;; keybindings (change to suit)

;; open confluence page
(global-set-key "\C-xwf" 'confluence-get-page)

;; setup confluence mode
(add-hook 'confluence-mode-hook
          '(lambda ()
             (local-set-key "\C-xw" confluence-prefix-map)))