How to edit Wikit pages with Emacs

Instructions: save the script below to a file ("httpwiki", say), run it like

  tclsh httpwiki eget 33 > 33

(note that you need to know the number of the page you want to edit!), edit the newly-created file "33" with Emacs and follow the instructions at the top of the file.

This script is somewhat Unix-centric.

If something goes wrong and you're not in the mood to fix it youself, send mail to [email protected].

99nov16 Eduardo Ochs

MHo 2006/05/16: the regexp does not work (anymore). Don't know if this one is always correct, but for now it works:

 {.+<textarea .+>(.*)</textarea>}

  package require http 1.0

  proc getpage {wikiurl N} {
    set s [http_data [http_get $wikiurl/${N}@]]
    if {[regexp "\n<textarea \[^\n>\]*>\n(.*)\n</textarea>" $s -> text]} {
      regsub -all {\&quot;} $text {"} text
      regsub -all {\&lt;}   $text {<} text
      regsub -all {\&gt;}   $text {>} text
      regsub -all {\&amp;}  $text {&} text
    } else {
      error "Bad edit page"
    return $text

  proc sendpage {wikiurl N text} {
    set answer [http_data [http_get $wikiurl/$N.html \
        -query [http_formatQuery C $text]]]

  proc emacsheader {argv0 wikiurl N} {
    return \
  "; To send back the edited version, place the cursor at the beginning
  ; of the first non-void line after the S-expression and do a C-x C-e.
  (shell-command-on-region (point) (point-max)
    \"$argv0 send $wikiurl $N\")\n\n\n"

  if {$argc!=3} {
    puts stderr "Usage: $argv0 get|eget|send wikiurl pagenumber"
    puts stderr "Example: $argv0 eget 33 | tee 33"
    puts stderr "  then edit the file \"33\" with Emacs and follow the instructions there."
    exit 1
  foreach {action wikiurl N} $argv {}

  switch $action {
    get {
      puts -nonewline [getpage $wikiurl $N]
    eget {
      puts -nonewline "[emacsheader $argv0 $wikiurl $N][getpage $wikiurl $N]"
    send {
      sendpage $wikiurl $N [read stdin]
    default {
      puts stderr "Bad action!"
      exit 1

MHo: Again, I've problems with special-char's like ÄÖÜäöüß - encoding convertfrom uft-8 doesn't helped yet...

Category Wikit