;; radwikiedit - edit wiki pages from emacs ;; Copyright (C) 2006 RADLogic Pty Ltd. ;; ;; This library is free software; you can redistribute it and/or ;; modify it under the terms of the GNU Lesser General Public ;; License as published by the Free Software Foundation; ;; version 2.1 of the License. ;; ;; This library is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; Lesser General Public License for more details. ;; ;; See http://www.fsf.org/licensing/licenses/lgpl.txt for full license text. ;; Emacs functions for working with radwikiedit (MoinMoin) ;; ;; radwiki-edit-page ;; Create a new wiki page or edit an existing wiki page. ;; This pulls the text from an existing page, allows the user to edit it, ;; and pushes the changes back. ;; (Note: No locking is implemented, so concurrent edits may cause pain.) ;; ;; radwiki-post ;; Add a block of text the top of an existing wiki page. ;; Remember to leave blank lines for new paragraphs. ;; ;; radwiki-attach-file ;; Attach a file to a wiki page. ;; ;; Configuration variables: ;; ;; radwiki-wiki-url ;; Set this to the base URL for the wiki, ;; e.g. http://somewiki.wik/wiki ;; ;; radwiki-cookie-file ;; Set this to your cookie file ;; (this ensures changes are attributed to your wiki username) ;; e.g. ${HOME}/.mozilla/firefox/some_dir/cookies.txt ;; ;; Author: Tim Wegener ;; ;; These variables must be defined by the user (in ~/.emacs say) ;;(setq radwiki-wiki-url "http://yourwiki.wik/wiki") ;;(setq radwiki-cookie-file "${HOME}/wikicookies.txt") ;;(setq radwiki-command "radwikiedit") (if (not (equal radwiki-cookie-file "")) (setq radwiki-cookie-opt (concat " -c " radwiki-cookie-file)) (setq radwiki-cookie-opt "")) (defun radwiki-add-on-region (page summary start end &optional cmdopts) "Add the text of the region to the top of the specified wiki page." (interactive "MEnter wiki page name: \nMEnter edit summary: \nr") (shell-command-on-region start end (concat radwiki-command " -u " radwiki-wiki-url radwiki-cookie-opt " -f - " cmdopts " -p " page " -s '" summary "'" " add" ))) (defun radwiki-set-on-region (page summary start end &optional cmdopts) "Set the text of the wiki page to the text of the region." (interactive "MEnter wiki page name: \nMEnter edit summary: \nr") (shell-command-on-region start end (concat radwiki-command " -u " radwiki-wiki-url radwiki-cookie-opt " -f - " cmdopts " -p " page " -s '" summary "'" " set" ))) (defun radwiki-edit-page (page) "Edit an existing wiki page." (interactive "MEnter wiki page name: \n") (save-excursion (setq radwiki-buffer-name (concat "*radwiki:" page "*")) (pop-to-buffer (get-buffer-create radwiki-buffer-name)) (set-buffer radwiki-buffer-name) (shell-command (concat radwiki-command " -u " radwiki-wiki-url radwiki-cookie-opt " -p " page " -q" " get" ) (current-buffer) ) (message "Edit radwiki page. Type C-c C-c when done") (defun radwiki-edit-finish-wrapper (summary) (interactive "MEnter one-line summary: \n") ;; The following implements a lexical closure. ;; Need to do this to give the page variable to the function that ;; is called later on. (lexical-let (page page) (radwiki-edit-finish page summary)) ) (local-set-key "\C-c\C-c" 'radwiki-edit-finish-wrapper) (setq buffer-offer-save 1) ;; Prompt user if quitting with open entry. ) ) (defun radwiki-edit-finish (page summary) "Finish a radwiki entry started with radwiki-edit-page." (interactive "MEnter wiki page: \nMEnter one-line summary: \n") (setq page (substring (buffer-name) 9 -1)) (radwiki-set-on-region page summary (point-min) (point-max)) (local-set-key "\C-c\C-c" nil) (kill-buffer (current-buffer)) (other-window -1) ;; In case two windows are open. ) (defun radwiki-post () "Post an addition to a wiki page." (interactive) (save-excursion (setq radwiki-buffer-name (concat "*radwiki*")) (pop-to-buffer (get-buffer-create radwiki-buffer-name)) (set-buffer radwiki-buffer-name) (message "Edit radwiki page addition. Type C-c C-c when done") (local-set-key "\C-c\C-c" 'radwiki-post-finish) (setq buffer-offer-save 1) ;; Prompt user if quitting with open entry. ) ) (defun radwiki-post-finish (page summary) "Finish a radwiki entry started with radwiki-post." (interactive "MEnter wiki page name: \nMEnter one-line summary: \n") (radwiki-add-on-region page summary (point-min) (point-max)) (local-set-key "\C-c\C-c" nil) (kill-buffer (current-buffer)) (other-window -1) ;; In case two windows are open. ) (defun radwiki-attach-file (page filename rename) "Prompt for filename to upload wikipage attachment." (interactive "MEnter wiki page name: \nFEnter filename to attach: \nMEnter new name for uploaded file (blank for same): \n") (shell-command (concat radwiki-command " -u " radwiki-wiki-url radwiki-cookie-opt " -p " page " -f " filename " -r '" rename "'" " attach" ) ) )