1;;; wikipedia-mode.el --- Mode for editing Wikipedia articles off-line
2;; Copyright (C) 2003, 2004, 2006 Chong Yidong, Uwe Brauer
4;; Author: Chong Yidong <cyd at stupidchicken com>
5;; Maintainer: Uwe Brauer <oub at mat.ucm.es>
8;; $Id: wikipedia-mode.el,v 1.5 2006/05/30 15:16:45 oub Exp oub $
11;; This file is not part of GNU Emacs.
15;; This file is free software; you can redistribute it and/or
16;; modify it under the terms of the GNU General Public License as
17;; published by the Free Software Foundation; either version 2 of
18;; the License, or (at your option) any later version.
20;; This file is distributed in the hope that it will be
21;; useful, but WITHOUT ANY WARRANTY; without even the implied
22;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
23;; PURPOSE. See the GNU General Public License for more details.
25;; You should have received a copy of the GNU General Public
26;; License along with GNU Emacs; if not, write to the Free
27;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34;; This is `wikipedia-mode', a major mode for editing articles written
35;; in the markup language used by Wikipedia, the free on-line
36;; encyclopedia (http://www.wikipedia.org). It is intended to work
37;; with GNU Emacs 21.x, and Xemacs 21.4.x. See below for details.
39;; wikipedia mode can be found also at:
40;; http://en.wikipedia.org/wiki/Wikipedia:Wikipedia-mode.el
42;;{{{ INSTALLING WIKIPEDIA-MODE
44;; Installing wikipedia-mode
45;; =========================
47;; Save wikipedia-mode.el in a convenient directory, preferably in
48;; your `load-path'. Add the following to your `user-init-file':
50;; (autoload 'wikipedia-mode
52;; "Major mode for editing documents in Wikipedia markup." t)
54;; If you did not save wikipedia-mode.el in your `load-path', you must
55;; use the full pathname. On MS Windows, use forward slashes (/)
56;; rather than back slashes (\) to indicate the directory, e.g.:
58;; (autoload 'wikipedia-mode
59;; "C:/Documents and Settings/USERNAME/.emacs.d/Wikipedia-mode.el"
60;; "Major mode for editing documents in Wikipedia markup." t)
62;; If you want to associate filenames ending in ".wiki" with
63;; wikipedia-mode, add the following to your init file:
65;; (setq auto-mode-alist
66;; (cons '("\\.wiki\\'" . wikipedia-mode) auto-mode-alist))
72;; This is not a real requirements but I highly recommend to use
73;; outline-magic written by Carsten Dominik. If you don't want to use it
74;; you have to comment out the relevant reference to outline magic.
76;; http://www.astro.uva.nl/~dominik/Tools/outline-magic.el
83;;{{{ RECOMMENDATIONS INSTALLING LONGLINES-MODE
85;; Installing longlines-mode
86;; =========================
88;; Wikipedia articles don't use newline characters to break paragraphs
89;; into lines, so each paragraph looks like a super-long line to
90;; Emacs. To let Emacs handle "soft word wrapping", you need to
91;; download a third-party package, longlines-mode.
93;; Download longlines.el, saving into your `load-path':
95;; http://www.emacswiki.org/elisp/longlines.el
97;; Add the following to your `user-init-file':
99;; (autoload 'longlines-mode "longlines.el"
100;; "Minor mode for editing long lines." t)
103;; WARNING: if you insert text from one file in wikipedia-mode to
104;; another file in wikipedia-mode I strongly recommend, to turn
105;; longlines-mode off, before the copying!
109;;{{{ RECOMMENDATIONS INSTALLING PABBREV-MODE
111;; Installing longlines-mode
112;; =========================
114;; You may find pabbrev.el useful, which can be found at
115;; http://www.russet.org.uk/download/emacs/pabbrev.el
120;;{{{ Xemacs or (GNU) Emacs
122;; Xemacs or (GNU) Emacs
123;; =====================
124;; Usually that is a question of taste. However almost all wikipedia
125;; articles nowadays use UTF8 coding, so the question which of the
126;; Macsen to use, boils down to which degree UTF8 support is
127;; implemented (no mule Xemacs is ruled out). While Xemacs has the
128;; better font support, the UTF8 support still is not complete and
129;; hence at the time being it is sad for the maintainer (a long time
130;; Xemacs user) to recommend NOT to use Xemacs, even not 21.5.x, which
131;; has a much better implemented UTF8 coding engine. That might
132;; however change in the foreseeable future....
133;; WARNING: at least for me in Debian testing/unstable Emacs does not
134;; ship all fonts necessary for a flawless editing of UTF8 files. For
135;; example you can chose Greek input, write Greek text, but then when
136;; you close and open the file again, the Greek symbol are not
137;; displayed but you see empty blocks. The reason seems that emacs
138;; chooses for the input fonts other fonts as for the display (don't
139;; ask me). However for installing the (ugly) UTF8 compatible fonts
140;; from ..... solved that problem.
145;;{{{ INSTALLING EE-HELPER or MOZEX
147;; Installing the helper programs.
148;; =========================
149;; Helper Programs: MozEx and EE-HELPER. There are two possibilities
150;; in order to use Emacs as an external editor
152;; (1) EE-HELPER: This is perl script which will communicate with
153;; the wikipedia server. However that sometimes be slow.
155;; PROS: if the editor supports UTF8, then ee-helper will
156;; pass the coding flawlessly.
158;; CONTRA: the problem with this script is that it directly
159;; communicates with the wikipedia site and does not
160;; warn you about simultaneous editing. Use it with
161;; care!!! Moreover section editing is not implemented.
163;; (2) MozEx: this is a Java-script which allows to communicate
164;; Mozilla (or Firefox) directly with Emacs.
166;; PROS: After finishing editing you use the wikipedia
167;; software to submit your changes and not the script,
168;; so you are warned about possible conflicting editing.
170;; CONTRA: the official version does not support UTF8,
171;; however there is now a new semi official version which
176;; Installing ee-helper
177;; ====================
179;; Download the perl script from
181;; http://meta.wikimedia.org/wiki/Help:External_editors
183;; and follow the instructions. configure the .ee-ini file. chance in
184;; your personal wikipedia-mode-map account setting the editing
185;; functions: activate the `external editor' option.
190;; If your web browser is Mozilla or Firefox, take a look at the MozEx
191;; extension, which allows you to call Emacs for editing text boxes:
193;; http://mozex.mozdev.org/development.html
197;; http://www.emacswiki.org/cgi-bin/wiki/FireFox
199;; If you mostly use MozEx to edit Wikipedia articles, it might be
200;; worthwhile to tell Emacs to enter wikipedia-mode whenever it is
201;; called by MozEx. Just add this to your `user-init-file':
203;; (add-to-list 'auto-mode-alist '("mozex.\\.*" . wikipedia-mode))
205;; Recall: you have to click on edit (either edit article or edit
206;; section), then use mouse3 (or shift f10), then select
207;; mozex, then edit textarea: Edit-->mouse3-->mozex-->Edit
208;; Textarea. After editing, you have to _click_ on the
209;; text in the browser otherwise Mozilla will ignore your
218;; ==================================
219;; (1) Font setting has changed.
220;; (2) Some makeup formats have been added: italics, bold, strong
222;; (3) outline-cycle from Carsten Dominiks outline-magic has been
224;; (4) "Draft", "send" and "reply" (for discussion pages)
225;; abilities `based' on ideas of John Wigleys remember.el: see
226;; the functions wikipedia-draft-*
227;; RATIONALE: This comes handy in 2 situations
228;; 1. You are editing articles which various authors (this I
229;; think is the usual case), you then want not to submit
230;; your edit immediately but want to copy it somewhere and
231;; to continue later. You can use the following functions
233;; wikipedia-draft-buffer \C-c\C-b
234;; wikipedia-draft-region \C-c\C-r
235;; then the buffer/region will be appended to the
236;; wikipedia-draft-data-file (default is
237;; "~/Wiki/discussions/draft.wiki", which you can visit via
238;; wikipedia-draft-view-draft) and it will be
239;; surrounded by the ^L marks in order to set a page.
240;; moreover on top on that a section header == will be
241;; inserted, which consists of the Word Draft, a subject
242;; you are asked for and a date stamp.
244;; Another possibility consists in using the function
245;; wikipedia-draft, bound to \C-c \C-m then a new buffer
246;; will opened already in wikipedia mode. You edit and then
247;; either can send the content of the buffer to the
248;; wikipedia-draft-data-file in the same manner as
249;; described above using the function
250;; wikipedia-draft-buffer (bound to \C-c\C-k)
252;; BACK: In order to copy/send the content of temporary
253;; buffer or of a page in the wikipedia-draft-data-file
254;; back in to your wikipedia file, use the function
255;; wikipedia-send-draft-to-mozex bound to "\C-c\C-c". You
256;; will be asked to which buffer to copy your text!
259;; 2. You want to reply in a discussion page to a specific
260;; contribution, you can use either the function
262;; \\[wikipedia-reply-at-point-simple] bound to [(meta shift r)]
263;; which inserts a newline, a hline, and the signature of
264;; the author. Or can use
265;; \\[wikipedia-draft-reply] bound [(meta r)]
266;; which does the same as wikipedia-reply-at-point-simple
267;; but in a temporary draft buffer.
269;; BACK: In order to copy/send the content of that buffer
270;; back in to your wikipedia file, use the function
271;; \\[wikipedia-send-draft-to-mozex] bound to "\C-c\C-c". You
272;; will be asked to which buffer to copy your text! If
273;; you want a copy to be send to your draft file, use
274;; the variable wikipedia-draft-send-archive
279;;{{{ NEW FUNCTIONS AND VARIABLES
286;; wikipedia-insert-enumerate
287;; wikipedia-insert-itemize
288;; wikipedia-insert-strong-emphasis
289;; wikipedia-insert-bold
290;; wikipedia-insert-italics
291;; wikipedia-insert-header
292;; wikipedia-insert-link
293;; wikipedia-turn-on-outline-minor-mode
294;; wikipedia-insert-signature
295;; wikipedia-insert-hline
296;; wikipedia-unfill-paragraph-or-region
297;; wikipedia-start-paragraph
298;; wikipedia-hardlines
299;; wikipedia-outline-magic-keys
300;; wikipedia-enhance-indent
301;; wikipedia-yank-prefix
302;; wikipedia-simple-outline-promote
303;; wikipedia-simple-outline-demote
304;; wikipedia-next-long-line
305;; wikipedia-unfill-paragraph
306;; wikipedia-rename-buffer
308;; wikipedia-draft-buffer-desc
309;; wikipedia-draft-append-to-file
310;; wikipedia-draft-page
311;; wikipedia-draft-region (&optional beg end)
312;; wikipedia-draft-buffer
313;; wikipedia-draft-clipboard
314;; wikipedia-draft-mode
315;; wikipedia-draft-view-draft
316;; wikipedia-mark-section
317;; wikipedia-activate-region
318;; wikipedia-copy-page-to-register
319;; wikipedia-insert-page-to-register
320;; wikipedia-send-draft-to-mozex (target-buffer)
321;; wikipedia-reply-at-point-simple
322;; wikipedia-draft-reply
323;; wikipedia-insert-quotation-with-signature
324;; wikipedia-insert-quotation
327;;---------------------
328;; wikipedia-enumerate-with-terminate-paragraph
329;; wikipedia-draft-buffer "*Wikipedia-Draft*"
330;; wikipedia-draft-mode-map
331;; wikipedia-draft-mode-hook
332;; wikipedia-draft-register ?R
333;; wikipedia-draft-filter-functions
334;; wikipedia-draft-handler-functions '(wikipedia-draft-append-to-file)
335;; wikipedia-draft-data-file "~/Wiki/discussions/draft.wiki"
336;; wikipedia-draft-leader-text "== "
337;; wikipedia-draft-page ?S
338;; wikipedia-draft-send-archive
339;; wikipedia-reply-with-quote
343;;====================================
345;; ------------------------------------
346;; wikipedia-insert-audio
347;; wikipedia-insert-bible-verse-template
348;; wikipedia-insert-bible-verse-template-old
349;; wikipedia-insert-image
350;; wikipedia-insert-link-www
351;; wikipedia-insert-user
352;; wikipedia-mark-signature
353;; wikipedia-outline-cycle
354;; wikipedia-reply-at-signature
355;; wikipedia-terminate-paragraph-and-indent
356;; wikipedia-yank-prefix
358;; NEW VARIABLES (defvar, defcustom, defconst)
359;; ----------------------
360;; wikipedia-reply-with-hline
361;; wikipedia-user-simplify-signature
362;; wikipedia-english-or-german
363;; wikipedia-draft-reply-register ?M
364;; wikipedia-mode-version
374;; * Implement TeX highlighting in <math> environment
375;; * Implement (La)TeX input syntax, following the ideas of CDlatex.el
376;; * Make outline-cycle work correctly
377;; * wikipedia-reply-at-point-simple should use regexp!
388(defconst wikipedia-mode-version (concat "0." (substring "$Revision: 1.5 $" 13 14))
389 "$Id: wikipedia-mode.el,v 1.5 2006/05/30 15:16:45 oub Exp oub $
391Report bugs to: Uwe Brauer oub at mat.ucm.es")
396(defvar wikipedia-simple-tags
397 '("b" "big" "blockquote" "br" "caption" "code" "center" "cite" "del"
398 "dfn" "dl" "em" "i" "ins" "kbd" "math" "nowiki" "ol" "pre" "samp"
399 "small" "strike" "strong" "sub" "sup" "tt" "u" "ul" "var")
400 "Tags that do not accept arguments.")
402(defvar wikipedia-complex-tags
403 '("a" "div" "font" "table" "td" "th" "tr")
404 "Tags that accept arguments.")
406(defvar wikipedia-url-protocols
407 '("ftp" "gopher" "http" "https" "mailto" "news")
408 "Valid protocols for URLs in Wikipedia articles.")
414(defvar font-wikipedia-sedate-face 'font-wikipedia-sedate-face
415 "Face to use for Wikipedia minor keywords.")
417(defvar font-wikipedia-italic-face 'font-wikipedia-italic-face
418 "Face to use for Wikipedia italics.")
419(defvar font-wikipedia-bold-face 'font-wikipedia-bold-face
420 "Face to use for Wikipedia bolds.")
421(defvar font-wikipedia-math-face 'font-wikipedia-math-face
422 "Face to use for Wikipedia math environments.")
423(defvar font-wikipedia-string-face 'font-wikipedia-string-face
424 "Face to use for strings. This is set by Font Wikipedia.")
425(defvar font-wikipedia-verbatim-face 'font-wikipedia-verbatim-face
426 "Face to use for text in verbatim macros or environments.")
431(defface font-wikipedia-bold-face
432 (let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit bold))
433 ((assq :weight custom-face-attributes) '(:weight bold))
435 `((((class grayscale) (background light))
436 (:foreground "DimGray" ,@font))
437 (((class grayscale) (background dark))
438 (:foreground "LightGray" ,@font))
439 (((class color) (background light))
440 (:foreground "DarkOliveGreen" ,@font))
441 (((class color) (background dark))
442 (:foreground "OliveDrab" ,@font))
444 "Face used to highlight text to be typeset in bold."
445 :group 'font-wikipedia-highlighting-faces)
447(defface font-wikipedia-italic-face
448 (let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit italic))
449 ((assq :slant custom-face-attributes) '(:slant italic))
451 `((((class grayscale) (background light))
452 (:foreground "DimGray" ,@font))
453 (((class grayscale) (background dark))
454 (:foreground "LightGray" ,@font))
455 (((class color) (background light))
456 (:foreground "DarkOliveGreen" ,@font))
457 (((class color) (background dark))
458 (:foreground "OliveDrab" ,@font))
460 "Face used to highlight text to be typeset in italic."
461 :group 'font-wikipedia-highlighting-faces)
463(defface font-wikipedia-math-face
464 (let ((font (cond ((assq :inherit custom-face-attributes)
465 '(:inherit underline))
466 (t '(:underline t)))))
467 `((((class grayscale) (background light))
468 (:foreground "DimGray" ,@font))
469 (((class grayscale) (background dark))
470 (:foreground "LightGray" ,@font))
471 (((class color) (background light))
472 (:foreground "SaddleBrown"))
473 (((class color) (background dark))
474 (:foreground "burlywood"))
476 "Face used to highlight math."
477 :group 'font-wikipedia-highlighting-faces)
479(defface font-wikipedia-sedate-face
480 '((((class grayscale) (background light)) (:foreground "DimGray"))
481 (((class grayscale) (background dark)) (:foreground "LightGray"))
482 (((class color) (background light)) (:foreground "DimGray"))
483 (((class color) (background dark)) (:foreground "LightGray"))
484 ;;;(t (:underline t))
486 "Face used to highlight sedate stuff."
487 :group 'font-wikipedia-highlighting-faces)
489(defface font-wikipedia-string-face
490 (let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit italic))
491 ((assq :slant custom-face-attributes) '(:slant italic))
493 `((((type tty) (class color))
494 (:foreground "green"))
495 (((class grayscale) (background light))
496 (:foreground "DimGray" ,@font))
497 (((class grayscale) (background dark))
498 (:foreground "LightGray" ,@font))
499 (((class color) (background light))
500 (:foreground "RosyBrown"))
501 (((class color) (background dark))
502 (:foreground "LightSalmon"))
504 "Face used to highlight strings."
505 :group 'font-wikipedia-highlighting-faces)
507(defface font-wikipedia-warning-face
508 (let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit bold))
509 ((assq :weight custom-face-attributes) '(:weight bold))
511 `((((class grayscale)(background light))
512 (:foreground "DimGray" ,@font))
513 (((class grayscale)(background dark))
514 (:foreground "LightGray" ,@font))
515 (((class color)(background light))
516 (:foreground "red" ,@font))
517 (((class color)(background dark))
518 (:foreground "red" ,@font))
520 "Face for important keywords."
521 :group 'font-wikipedia-highlighting-faces)
523(defface font-wikipedia-verbatim-face
524 (let ((font (if (and (assq :inherit custom-face-attributes)
525 (if (featurep 'xemacs)
526 (find-face 'fixed-pitch)
527 (facep 'fixed-pitch)))
528 '(:inherit fixed-pitch)
529 '(:family "courier"))))
530 `((((class grayscale) (background light))
531 (:foreground "DimGray" ,@font))
532 (((class grayscale) (background dark))
533 (:foreground "LightGray" ,@font))
534 (((class color) (background light))
535 (:foreground "SaddleBrown" ,@font))
536 (((class color) (background dark))
537 (:foreground "burlywood" ,@font))
539 "Face used to highlight TeX verbatim environments."
540 :group 'font-wikipedia-highlighting-faces)
543 (defvar wikipedia-font-lock-keywords
546 ;; Apostrophe-style text markup
547 (cons "''''\\([^']\\|[^']'\\)*?\\(''''\\|\n\n\\)"
548 'font-lock-builtin-face)
549 (cons "'''\\([^']\\|[^']'\\)*?\\('''\\|\n\n\\)"
550; 'font-lock-builtin-face)
551 'font-wikipedia-bold-face)
552 (cons "''\\([^']\\|[^']'\\)*?\\(''\\|\n\n\\)"
553 'font-wikipedia-italic-face)
555 ;; Headers and dividers
556 (list "^\\(==+\\)\\(.*\\)\\(\\1\\)"
557 '(1 font-lock-builtin-face)
558; '(2 wikipedia-header-face)
559 '(2 font-wikipedia-sedate-face)
560 '(3 font-lock-builtin-face))
561 (cons "^-----*" 'font-lock-builtin-face)
563 ;; Bare URLs and ISBNs
564 (cons (concat "\\(^\\| \\)" (regexp-opt wikipedia-url-protocols t)
565 "://[-A-Za-z0-9._\/~%+&#?!=()@]+")
566 'font-lock-variable-name-face)
567 (cons "\\(^\\| \\)ISBN [-0-9A-Z]+" 'font-lock-variable-name-face)
569 ;; Colon indentation, lists, definitions, and tables
570 (cons "^\\(:+\\|[*#]+\\||[}-]?\\|{|\\)" 'font-lock-builtin-face)
572 (list "^\\(;\\)\\([^:\n]*\\)\\(:?\\)"
573 '(1 font-lock-builtin-face)
574 '(2 font-lock-keyword-face)
575 '(3 font-lock-builtin-face))
581 (list (concat "\\(</?\\)"
582 (regexp-opt wikipedia-simple-tags t) "\\(>\\)")
583 '(1 font-lock-builtin-face t t)
584 '(2 font-lock-function-name-face t t)
585 '(3 font-lock-builtin-face t t))
586 (list (concat "\\(</?\\)"
587 (regexp-opt wikipedia-complex-tags t)
588 "\\(\\(?: \\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?\\)\\(>\\)")
589 '(1 font-lock-builtin-face t t)
590 '(2 font-lock-function-name-face t t)
591 '(3 font-lock-keyword-face t t)
592 '(4 font-lock-builtin-face t t))
593 (cons (concat "<!-- \\([^->]\\|>\\|-\\([^-]\\|-[^>]\\)\\)*-->")
594 '(0 font-lock-comment-face t t))
600 (list (concat "\\(\\[\\)\\(\\(?:"
601 (regexp-opt wikipedia-url-protocols)
602 "\\)://[-A-Za-z0-9._\/~%-+&#?!=()@]+\\)\\(\\(?: [^]\n]*\\)?\\)\\(\\]\\)")
603 '(1 font-lock-builtin-face t t)
604 '(2 font-lock-variable-name-face t t)
605 '(3 font-lock-keyword-face t t)
606 '(4 font-lock-builtin-face t t))
612 '("\\(\\[\\[\\)\\([^]\n|]*\\)\\(|?\\)\\([^]\n]*\\)\\(\\]\\]\\)"
613 (1 font-lock-builtin-face t t)
614 (2 font-lock-variable-name-face t t)
615 (3 font-lock-builtin-face t t)
616 (4 font-lock-keyword-face t t)
617 (5 font-lock-builtin-face t t))
620 '("\\({{\\)\\(.+?\\)\\(}}\\)"
621 (1 font-lock-builtin-face t t)
622 (2 font-lock-variable-name-face t t)
623 (3 font-lock-builtin-face t t))
625 ;; Character entity references
626 (cons "&#?[a-zA-Z0-9]+;" '(0 font-lock-type-face t t))
629 (cons "^ .*$" '(0 font-lock-constant-face t t))
631 ;; Math environment (uniform highlight only, no TeX markup)
632 (list "<math>\\(\\(\n?.\\)*\\)</math>"
633 '(1 font-lock-keyword-face t t))))
639;;{{{ Menu and header stuff
641(defvar wikipedia-imenu-generic-expression
642 (list '(nil "^==+ *\\(.*[^\n=]\\)==+" 1))
643 "Imenu expression for `wikipedia-mode'. See `imenu-generic-expression'.")
645(defun wikipedia-next-header ()
646 "Move point to the end of the next section header."
648 (let ((oldpoint (point)))
650 (if (re-search-forward "\\(^==+\\).*\\1" (point-max) t)
653 (message "No section headers after point."))))
655(defun wikipedia-prev-header ()
656 "Move point to the start of the previous section header."
658 (unless (re-search-backward "\\(^==+\\).*\\1" (point-min) t)
659 (message "No section headers before point.")))
663;;{{{ Paragraph terminate and filling stuff (Chong)
665(defun wikipedia-terminate-paragraph () ;Version:1.58
666 "In a list, start a new list item. In a paragraph, start a new
667paragraph; if the current paragraph is colon indented, the new
668paragraph will be indented in the same way."
673 (while (cond ((looking-at "^$") nil)
674 ((looking-at "^\\(\\(?: \\|:+\\|[#*]+\\) *\\)")
675 (setq indent-chars (match-string 1)) nil)
676 ((eq (point) (point-min)) nil)
677 ((progn (forward-line -1) t)))
679 (newline) (if (not indent-chars) (newline)
680 (insert indent-chars))))
682(defun wikipedia-terminate-paragraph-and-indent ()
683 "In a list, start a new list item. In a paragraph, start a new
684paragraph but *,# will be ignored; if the current paragraph is colon
685; indented, the new paragraph will be indented in the same way."
690 (while (cond ((looking-at "^$") nil)
691 ((looking-at "^\\(\\(?: \\|:+\\) *\\)")
692 (setq indent-chars (match-string 1)) nil)
693 ((eq (point) (point-min)) nil)
694 ((progn (forward-line -1) t)))
696 (newline) (if (not indent-chars) (newline)
697 (insert indent-chars))))
700(defun wikipedia-link-fill-nobreak-p ()
701 "When filling, don't break the line for preformatted (fixed-width)
702text or inside a Wiki link. See `fill-nobreak-predicate'."
705 (or (eq (char-after (line-beginning-position)) ? )
706 (if (re-search-backward "\\[\\[" (line-beginning-position) t)
707 ;; Break if the link is really really long.
708 ;; You often get this with captioned images.
709 (null (or (> (- pos (point)) fill-column)
710 (re-search-forward "\\]\\]" pos t))))))))
712(defun wikipedia-fill-article ()
713 "Fill the entire article."
716 (fill-region (point-min) (point-max))))
718(defun wikipedia-unfill-article ()
719 "Undo filling, deleting stand-alone newlines (newlines that do not
720end paragraphs, list entries, etc.)"
723 (goto-char (point-min))
724 (while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
725 (replace-match " " nil nil nil 1)))
726 (message "Stand-alone newlines deleted"))
729(defun wikipedia-unfill-paragraph-with-newline (&optional justifyp)
731 (let ((before (point))) ;Version:1.3
734 (or (bolp) (newline 1))
736 (start (progn (backward-paragraph) (point))))
738 (while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
739 (replace-match " " nil nil nil 1))))))
740; (message "Stand-alone newlines IN PARAGRAPH deleted"))
742(defun wikipedia-unfill-region ()
743"Undo filling, deleting stand-alone newlines (newlines that do not end
744paragraphs, list entries, etc.) see also the function
745\\[wikipedia-unfill-paragraph-or-region] and the even simpler function
746\\[wikipedia-unfill-paragraph-simple]."
749 (narrow-to-region (point) (mark))
750 (goto-char (point-min))
751 (while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
752 (replace-match " " nil nil nil 1)))
753 (message "Stand-alone newlines deleted")
758;;{{{ Main function wikipedia mode (using define-derived mode)
761;;{{{ Main function wikipedia-mode
763(define-derived-mode wikipedia-mode text-mode "Wikipedia"
764 "Major mode for editing articles written in the markup language used by
765Wikipedia, the free on-line encyclopedia (http://www.wikipedia.org).
767There are several ways to use wikipedia-mode. One is to copy articles
768between Emacs and your web browser's text box. However for GNU emacs,
769that does not work always smoothly, since copying marked regions into
770other X applications is somehow buggy for GNU emacs. Another way is to
771use MozEx, a Mozilla/Firefox web browser extension that allows you to
772call Emacs from a text box (http://mozex.mozdev.org/). Another way is
773to use the PERL script ee-helper, which allows you to up and download
776Wikipedia articles are usually unfilled: newline characters are not
777used for breaking paragraphs into lines. Unfortunately, Emacs does not
778handle word wrapping yet. As a workaround, wikipedia-mode turns on
779longlines-mode automatically. In case something goes wrong, the
780following commands may come in handy:
782\\[wikipedia-fill-article] fills the buffer.
783\\[wikipedia-unfill-article] unfills the buffer.
784Be warned that function can be dead slow, better use wikipedia-unfill-paragraph-or-region.
785\\[wikipedia-unfill-paragraph-or-region] unfills the paragraph
786\\[wikipedia-unfill-paragraph-simple] doehe same but simpler.
790The following commands put in markup structures.
792\\[wikipedia-insert-strong-emphasis] inserts italics
793\\[wikipedia-insert-bold] inserts bold text
794\\[wikipedia-insert-italics] italics
795\\[wikipedia-insert-header] header
796\\[wikipedia-insert-link] inserts a link
798The following commands are also defined:
799\\[wikipedia-insert-user] inserts user name
800\\[wikipedia-insert-signature] inserts ~~~~
801\\[wikipedia-insert-enumerate] inserts enumerate type structures
802\\[wikipedia-insert-itemize] inserts itemize type structures
803\\[wikipedia-insert-hline] inserts a hline
805The draft functionality
807\\[wikipedia-draft-region]
808\\[wikipedia-draft-view-draft]
809\\[wikipedia-draft-page]
810\\[wikipedia-draft-buffer]
812Replying and sending functionality
813\\[wikipedia-reply-at-point-simple]
814\\[wikipedia-draft-reply]
815\\[wikipedia-send-draft-to-mozex]
818The register functionality
819\\[wikipedia-copy-page-to-register]
820\\[defun wikipedia-insert-page-to-register]
823Some simple editing commands.
824\\[wikipedia-enhance-indent]
825\\[wikipedia-yank-prefix]
826\\[wikipedia-unfill-paragraph-or-region]
830\\[wikipedia-terminate-paragraph] starts a new list item or paragraph in a context-aware manner.
831\\[wikipedia-next-header] moves to the next (sub)section header.
832\\[wikipedia-prev-header] moves to the previous (sub)section header."
834 (set (make-local-variable 'adaptive-fill-regexp) "[ ]*")
835 (set (make-local-variable 'comment-start-skip) "\\(?:<!\\)?-- *")
836 (set (make-local-variable 'comment-end-skip) " *--\\([ \n]*>\\)?")
837 (set (make-local-variable 'comment-start) "<!-- ")
838 (set (make-local-variable 'comment-end) " -->")
839 (set (make-local-variable 'paragraph-start)
840 "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")
841 (set (make-local-variable 'sentence-end-double-space) nil)
842 (set (make-local-variable 'font-lock-multiline) t)
843 (set (make-local-variable 'font-lock-defaults)
844 '(wikipedia-font-lock-keywords t nil nil nil))
845 (set (make-local-variable 'fill-nobreak-predicate)
846 'wikipedia-link-fill-nobreak-p)
847 (set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]")
849 ;; Support for outline-minor-mode. No key conflicts, so we'll use
850 ;; the normal outline-mode prefix.
851 (set (make-local-variable 'outline-regexp) "==+")
852; (set (make-local-variable 'outline-regexp) "=+")
853; (set (make-local-variable 'outline-regexp) ":")
854 (set (make-local-variable 'outline-minor-mode-prefix) "\C-c\C-o")
857 ;; Turn on the Imenu automatically.
859 (set (make-local-variable 'imenu-generic-expression)
860 wikipedia-imenu-generic-expression)
861 (imenu-add-to-menubar "Contents"))
863(modify-syntax-entry ?< "(>" wikipedia-mode-syntax-table)
864(modify-syntax-entry ?> ")<" wikipedia-mode-syntax-table)
872(define-key wikipedia-mode-map "\M-n" 'wikipedia-next-header)
873(define-key wikipedia-mode-map "\C-c\C-n" 'wikipedia-next-long-line)
874(define-key wikipedia-mode-map "\M-p" 'wikipedia-prev-header)
875; (define-key wikipedia-mode-map [(meta down)] 'wikipedia-next-header)
876; (define-key wikipedia-mode-map [(meta up)] 'wikipedia-prev-header)
877(define-key wikipedia-mode-map "\C-j" 'wikipedia-terminate-paragraph)
878; 'wikipedia-terminate-paragraph)
880 (let ((map (make-sparse-keymap "Wikipedia")))
881 (define-key wikipedia-mode-map [menu-bar wikipedia]
882 (cons "Wikipedia" map))
883 (define-key map [unfill-article]
884 '("Unfill article" . wikipedia-unfill-article))
885 (define-key map [fill-article]
886 '("Fill article" . wikipedia-fill-article))
887 (define-key map [separator-fill] '("--"))
888 (define-key map [next-header]
889 '("Next header" . wikipedia-next-header))
890 (define-key map [prev-header]
891 '("Previous header" . wikipedia-prev-header))
892 (define-key map [separator-header] '("--"))
893 (define-key map [outline]
894 '("Toggle Outline Mode..." . outline-minor-mode)))
897(define-key wikipedia-mode-map "\C-c\C-q" 'wikipedia-unfill-article)
898(define-key wikipedia-mode-map "\C-c\M-q" 'wikipedia-fill-article)
899(define-key wikipedia-mode-map "\M-u" 'wikipedia-unfill-paragraph-or-region)
900(define-key wikipedia-mode-map "\C-c\C-u" 'wikipedia-unfill-paragraph-simple)
901(define-key wikipedia-mode-map "\C-c\C-f\C-s" 'wikipedia-insert-strong-emphasis)
902(define-key wikipedia-mode-map "\C-c\C-f\C-b" 'wikipedia-insert-bold) ;Version:1.3
903(define-key wikipedia-mode-map "\C-c\C-f\C-i" 'wikipedia-insert-italics)
904(define-key wikipedia-mode-map "\C-c\C-f\C-h" 'wikipedia-insert-header)
905(define-key wikipedia-mode-map "\C-c\C-f\C-l" 'wikipedia-insert-link)
906(define-key wikipedia-mode-map "\C-c\C-f\C-u" 'wikipedia-insert-user)
907(define-key wikipedia-mode-map "\C-c\C-f\C-q" 'wikipedia-insert-quotation)
908(define-key wikipedia-mode-map "\C-c\C-f\C-v" 'wikipedia-insert-bible-verse-template)
909(define-key wikipedia-mode-map "\C-c\C-w" 'wikipedia-insert-signature)
910(define-key wikipedia-mode-map "\C-c\C-h" 'wikipedia-insert-hline) ;Version:1.30
911(define-key wikipedia-mode-map [(meta f7)] 'wikipedia-draft)
912(define-key wikipedia-mode-map [(meta f8)] 'wikipedia-reply-at-point-simple)
913(define-key wikipedia-mode-map [(meta f9)] 'wikipedia-draft-view-draft)
914(define-key wikipedia-mode-map "\C-c\C-r" 'wikipedia-reply-at-point-simple)
915(define-key wikipedia-mode-map "\C-cr" 'wikipedia-draft-region)
916(define-key wikipedia-mode-map [(meta r)] 'wikipedia-draft-reply)
917(define-key wikipedia-mode-map "\C-c\C-m" 'wikipedia-draft) ;Version:1.25
918(define-key wikipedia-mode-map "\C-c\C-b" 'wikipedia-draft-region)
919(define-key wikipedia-mode-map "\C-c\C-d" 'wikipedia-draft-buffer)
920(define-key wikipedia-mode-map "\C-c\C-k" 'wikipedia-draft-buffer)
921(define-key wikipedia-mode-map "\C-c\C-p" 'wikipedia-draft-copy-page-to-register) ;Version:1.39
922(define-key wikipedia-mode-map "\C-c\C-c" 'wikipedia-draft-send-to-mozex)
923(define-key wikipedia-mode-map "\C-c\C-s" 'wikipedia-draft-yank-page-to-register)
925(define-key wikipedia-mode-map [(control meta prior)] 'wikipedia-enhance-indent)
926(define-key wikipedia-mode-map [(control meta next)] 'wikipedia-yank-prefix)
927(define-key wikipedia-mode-map [(meta return)] 'wikipedia-insert-enumerate)
928(define-key wikipedia-mode-map [(meta control return)] 'wikipedia-insert-enumerate-nonewline)
930(define-key wikipedia-mode-map [(shift return)] 'newline-and-indent) ;Version:1.24
931(define-key wikipedia-mode-map "\C-\\" 'wikipedia-insert-itemize) ;Version:1.28
932(define-key wikipedia-mode-map [(control return)] 'wikipedia-insert-itemize)
933(define-key wikipedia-mode-map "\C-ca" 'auto-capitalize-mode)
934(define-key wikipedia-mode-map "\C-ci" 'set-input-method)
935(define-key wikipedia-mode-map "\C-ct" 'toggle-input-method) ;Version:1.23
940 (make-local-variable 'change-major-mode-hook))
942; wikipedia-mode ends here
947(defun wikipedia-turn-on-longlines () ;Version:1.58
948 "Turn on longlines-mode if it is defined."
949 (if (functionp 'longlines-mode)
951(add-hook 'wikipedia-mode-hook 'wikipedia-turn-on-longlines)
952(set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]")
956;; New formating stuff for inserting simple formating structures such
958;;{{{ Insert makeup and templates
960(defvar wikipedia-enumerate-with-terminate-paragraph nil
961"*Before insert enumerate/itemize do \\[wikipedia-terminate-paragraph].")
963(defun wikipedia-insert-enumerate ()
964"Primitive Function for inserting enumerated items, check the
965variable wikipedia-enumerate-with-terminate-paragraph. Note however
966that the function \\[wikipedia-terminate-paragraph] does not work very
967well will longlines-mode."
969 (when wikipedia-enumerate-with-terminate-paragraph
970 (wikipedia-terminate-paragraph)
972 (when (not wikipedia-enumerate-with-terminate-paragraph)
980(defun wikipedia-insert-itemize ()
981 "Primitive Function for inserting no enumerated items, check the
982variable wikipedia-enumerate-with-terminate-paragraph. Note however
983that the function \\[wikipedia-terminate-paragraph] does not work very
984well will longlines-mode."
986 (when wikipedia-enumerate-with-terminate-paragraph
987 (wikipedia-terminate-paragraph)
989 (when (not wikipedia-enumerate-with-terminate-paragraph )
994(defun wikipedia-insert-strong-emphasis ()
995"Insert strong emphasis italics via four apostrophes (e.g. ''''FOO''''.) When mark is active, surrounds region."
997 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
998 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1004 (insert "'''' ''''")
1008(defun wikipedia-insert-bold ()
1009"Insert bold via three apostrophes (e.g. '''FOO'''.)
1010When mark is active, surrounds region."
1012 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1013 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1023(defun wikipedia-insert-italics ()
1024"Insert bold via TWO apostrophes (e.g. ''FOO''.) When mark is active,
1027 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1028 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1037(defun wikipedia-insert-quotation-with-signature () ;Version:1.60
1038"Insert bold via TWO apostrophes (e.g. ''FOO''.) When mark is active,
1041 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1042 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1045 (insert "{{Quotation|}}")
1047 (insert "{{~~~~}}"))
1048 (insert "{{Quotation| }}{{~~~~}}")
1052(defun wikipedia-insert-quotation () ;Version:1.60
1053"Quotation box of the form {{Quotation}}{{}}. When mark is active,
1056 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1057 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1060 (insert "{{Quotation|}}")
1063 (insert "{{Quotation|}}{{ }}")
1069(defun wikipedia-insert-bible-verse-template ()
1070 "Insert a template for the quotation of bible verses."
1073(let ((name (read-string "Name: ")))
1074 (insert (concat name "|"))
1075(let ((verse (read-string "Verse: ")))
1076 (insert (concat verse "|" name " " verse "}})")))))
1079(defvar wikipedia-english-or-german t
1080"*Variable in order to set the english (t) or german (nil) environment.")
1082(defun wikipedia-insert-user ()
1083 "Inserts, interactively a user name [[User:foo]]"
1085 (when wikipedia-english-or-german
1086 (let ((user (read-string "Name of user: " )))
1087 (insert (concat "[[User:" user "|" user "]]"))))
1088 (when (not wikipedia-english-or-german)
1089 (let ((user (read-string "Name des Benutzers: " )))
1090 (insert (concat "[[Benutzer:" user "|" user "]]")))))
1094(defun wikipedia-insert-reply-prefix () ;Version:1.60
1095"Quotation box of the form {{Quotation}}{{}}. When mark is active,
1098 (beginning-of-line 1)
1099 (search-forward "[[")
1102 (copy-to-register wikipedia-draft-reply-register (region-beginning) (region-end) nil)
1104 (wikipedia-terminate-paragraph)
1105 (beginning-of-line 1)
1111 (insert-register wikipedia-draft-reply-register 1)
1115(defun wikipedia-insert-header ()
1116 "Insert subheader via == (e.g. == FOO ==.)"
1121(defun wikipedia-insert-link ()
1122 "Insert link via [[ (e.g. [[FOO]].) When mark is active, surround region."
1124 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1125 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1134(defun wikipedia-insert-link-www ()
1135 "Insert link via [[ (e.g. [http://FOO].) When mark is active, surround region."
1137 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1138 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1143 (insert "[http://"))
1144 (insert "[http:// ]")
1148(defun wikipedia-insert-image ()
1149 "Insert link image [[ (e.g. [[Image:FOO]].) Check the variable
1150wikipedia-english-or-german. When mark is active, surround region."
1152 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1153 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1158 (when (not wikipedia-english-or-german)
1160 (when wikipedia-english-or-german
1161 (insert "[[Image:")))
1162 (when wikipedia-english-or-german
1163 (insert "[[Image: ]]"))
1164 (when (not wikipedia-english-or-german)
1165 (insert "[[Bild: ]]"))
1168(defun wikipedia-insert-audio ()
1169 "Insert link image [[ (e.g. [[Image:FOO]].) Check the variable
1170wikipedia-english-or-german. When mark is active, surround region."
1172 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1173 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1178 (when (not wikipedia-english-or-german)
1180 (when wikipedia-english-or-german
1181 (insert "[[Media:")))
1182 (when wikipedia-english-or-german
1183 (insert "[[Media: ]]"))
1184 (when (not wikipedia-english-or-german)
1185 (insert "[[Bild: ]]"))
1191(defun wikipedia-turn-on-outline-minor-mode ()
1192 "Turn on outline minor mode."
1194 (outline-minor-mode nil))
1197(defun wikipedia-insert-signature () ;Version:1.4
1206(defun wikipedia-insert-hline () ;Version:1.29
1215;;{{{ filling and longline
1217(defun wikipedia-unfill-paragraph-or-region () ;Version:1.7
1218 "Unfill region, this function does NOT explicitly search for \"soft newlines\"
1219as does wikipedia-unfill-region."
1221 (when use-hard-newlines
1222 ;; (backward-paragraph 1)
1224 (beginning-of-line 1)
1226 (set (make-local-variable 'use-hard-newlines) nil)
1227 (set (make-local-variable 'sentence-end-double-space) t)
1228 (set (make-local-variable 'paragraph-start)
1230 (when (featurep 'xemacs)
1231 (let ((fill-column (point-max)))
1232 (fill-paragraph-or-region nil)))
1233 (unless (featurep 'xemacs)
1234 (let ((fill-column (point-max)))
1235 (fill-paragraph nil)))
1236 (set (make-local-variable 'use-hard-newlines) t)
1237 (set (make-local-variable 'sentence-end-double-space) nil)
1238 (set (make-local-variable 'paragraph-start)
1239 "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$"))
1240 (unless use-hard-newlines
1241 ;; (backward-paragraph 1)
1243 (beginning-of-line 1)
1245 (set (make-local-variable 'sentence-end-double-space) t)
1246 (set (make-local-variable 'paragraph-start)
1248 (when (featurep 'xemacs)
1249 (let ((fill-column (point-max)))
1250 (fill-paragraph-or-region nil)))
1251 (unless (featurep 'xemacs)
1252 (let ((fill-column (point-max)))
1253 (fill-paragraph nil)))
1254 (set (make-local-variable 'sentence-end-double-space) nil)
1255 (set (make-local-variable 'paragraph-start)
1256 "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")))
1261(defun wikipedia-start-paragraph ()
1263 (set (make-local-variable 'paragraph-start)
1264 "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$"))
1267(defun wikipedia-hardlines ()
1268"Set use-hard-newlines to NIL."
1270 (setq use-hard-newlines nil))
1272(defun wikipedia-next-long-line ()
1273 "Move forward to the next long line with column-width greater
1276 TODO: When function reaches end of buffer, save-excursion to
1278 Generalise to make `previous-long-line'."
1280 ;; global-variable: fill-column
1281 (if (= (forward-line) 0)
1286 (if (<= line-length fill-column)
1287 (wikipedia-next-long-line)
1288 (message "Long line found")))
1289 ;; Stop, end of buffer reached.
1290 (error "Long line not found")))
1293(defun wikipedia-unfill-paragraph-simple ()
1294"A very simple function for unfilling a paragraph."
1296 (if (functionp 'filladapt-mode)
1297 (filladapt-mode nil))
1298 (let ((fill-column (point-max)))
1299 (fill-paragraph nil)
1300 (if (functionp 'filladapt-mode)
1301 (filladapt-mode nil))))
1305;;{{{ outline and outline-magic stuff
1307(add-hook 'wikipedia-mode-hook 'wikipedia-turn-on-outline-minor-mode)
1309(defun wikipedia-outline-cycle ()
1311 (if (functionp 'outline-cycle)
1315(add-hook 'outline-minor-mode-hook 'wikipedia-outline-magic-keys)
1317(defun wikipedia-outline-magic-keys ()
1319 (unless (featurep 'xemacs)
1320 (local-set-key [(shift iso-lefttab)] 'wikipedia-outline-cycle))
1321 (local-set-key [iso-left-tab] 'wikipedia-outline-cycle)
1322 (local-set-key [(meta left)] 'outline-promote)
1323 (local-set-key [(meta right)] 'outline-demote)
1324 (local-set-key [(shift return)] 'newline-and-indent)
1325 (local-set-key [(control left)] 'wikipedia-simple-outline-promote)
1326 (local-set-key [(control right)] 'wikipedia-simple-outline-demote)
1327 (local-set-key [(control up)] 'outline-move-subtree-up)
1328 (local-set-key [(control down)] 'outline-move-subtree-down))
1330(defun wikipedia-enhance-indent () ;Version:1.26
1332 (string-rectangle (region-beginning) (region-end) ":"))
1334(defun wikipedia-yank-prefix () ;Version:1.26
1336 (string-rectangle (region-beginning) (region-end) ":"))
1338;; modification for outline-magic
1340(defun wikipedia-simple-outline-promote ()
1341"Function simple deletes \"=\" and the end and the beginning of line,
1342does not promote the whole tree!"
1346 (beginning-of-line 1)
1347 (search-forward "=")
1350 (search-backward "=")
1351 (delete-char 1 nil))))
1353(defun wikipedia-simple-outline-demote ()
1354"Function simple adds \"=\" and the end and the beginning of line,
1355does not promote the whole tree!"
1359 (beginning-of-line 1)
1360 (search-forward "=")
1363 (search-backward "=")
1367(defun wikipedia-rename-buffer () ;Version:1.5
1368 "Make sure that the option UNIQUE is used."
1370 (rename-buffer (read-string "Name of new buffer (unique): " ) 1))
1374;;{{{ wikipedia drafts functionality: `stolen' from remember.el:
1376(defgroup wikipedia-draft nil
1377 "A mode to wikipedia-draft information."
1382(defcustom wikipedia-draft-mode-hook nil
1383 "*Functions run upon entering wikipedia-draft-mode."
1385 :group 'wikipedia-draft)
1387(defcustom wikipedia-draft-register ?R
1388 "The register in which the window configuration is stored."
1390 :group 'wikipedia-draft)
1392(defcustom wikipedia-draft-filter-functions nil
1393 "*Functions run to filter wikipedia-draft data.
1394All functions are run in the wikipedia-draft buffer."
1396 :group 'wikipedia-draft)
1398(defcustom wikipedia-draft-handler-functions '(wikipedia-draft-append-to-file)
1399 "*Functions run to process wikipedia-draft data.
1400Each function is called with the current buffer narrowed to what the
1401user wants wikipedia-drafted.
1402If any function returns non-nil, the data is assumed to have been
1403recorded somewhere by that function. "
1405 :group 'wikipedia-draft)
1407(defcustom wikipedia-draft-data-file "~/Wiki/discussions/draft.wiki"
1408 "*The file in which to store the wikipedia drafts."
1410 :group 'wikipedia-draft)
1412(defcustom wikipedia-draft-reply-register ?M
1413 "The register in which the window configuration is stored."
1415 :group 'wikipedia-draft)
1417(defcustom wikipedia-draft-page ?S ;Version:1.37
1418 "The register in which the a page of the wiki draft file is stored."
1420 :group 'wikipedia-draft)
1423(defcustom wikipedia-draft-leader-text "== "
1424 "*The text used to begin each wikipedia-draft item."
1426 :group 'wikipedia-draft)
1429;;; Internal Variables:
1431(defvar wikipedia-draft-buffer "*Wikipedia-Draft*"
1432 "The name of the wikipedia-draft (temporary) data entry buffer.")
1437(defun wikipedia-draft ()
1438 "Open a temporary buffer in wikipedia mode for editing an wikipedia
1439 draft, which an arbitrary piece of data. After finishing the editing
1440 either use C-c C-k \\[wikipedia-draft-buffer] to send the data into
1441 the wikipedia-draft-data-file, or send the buffer using C-c C-c
1442\\[wikipedia-draft-send-to-mozex] and insert it later into a wikipedia article."
1444 (window-configuration-to-register wikipedia-draft-register)
1445 (let ((buf (get-buffer-create wikipedia-draft-buffer)))
1446 (switch-to-buffer-other-window buf)
1448 (message " C-c C-k sends to draft file, C-c C-c sends to org buffer.")))
1454(defsubst wikipedia-draft-time-to-seconds (time)
1455 "Convert TIME to a floating point number."
1456 (+ (* (car time) 65536.0)
1458 (/ (or (car (cdr (cdr time))) 0) 1000000.0)))
1460(defsubst wikipedia-draft-mail-date (&optional rfc822-p)
1461 "Return a simple date. Nothing fancy."
1463 (format-time-string "%a, %e %b %Y %T %z" (current-time))
1464 (format-time-string "%c" (current-time))))
1466(defun wikipedia-draft-buffer-desc ()
1467 "Using the first line of the current buffer, create a short description."
1468 (buffer-substring (point-min)
1470 (goto-char (point-min))
1472 (if (> (- (point) (point-min)) 60)
1473 (goto-char (+ (point-min) 60)))
1477;; Wikipedia-Drafting to plain files:
1480(defun wikipedia-draft-append-to-file ()
1481 "Add a header together with a subject to the text and add it to the
1482draft file. It might be better if longlines-mode is off."
1483 (let ((text (buffer-string))
1484 (desc (wikipedia-draft-buffer-desc)))
1487 (insert wikipedia-draft-leader-text)
1488 (insert "Draft: ") ;Version:1.39
1489 (insert (read-string "Enter Subject: "))
1491 (insert (current-time-string))
1493 (insert wikipedia-draft-leader-text)
1494 (insert "\n\n") ;Version:1.27
1503 (if (find-buffer-visiting wikipedia-draft-data-file)
1504 (let ((wikipedia-draft-text (buffer-string)))
1505 (set-buffer (get-file-buffer wikipedia-draft-data-file))
1507 (goto-char (point-max))
1509 (insert wikipedia-draft-text)
1512 (append-to-file (point-min) (point-max) wikipedia-draft-data-file)))))
1515(setq wikipedia-draft-handler-functions 'wikipedia-draft-append-to-file)
1518(custom-add-option 'wikipedia-draft-handler-functions 'wikipedia-draft-append-to-file)
1521(defun wikipedia-draft-page () ;Version:1.32
1524 (copy-region-as-kill (region-beginning) (region-end))
1529(defun wikipedia-draft-region (&optional beg end)
1530 "Wikipedia-Draft the data from BEG to END.
1531If called from within the wikipedia-draft buffer, BEG and END are ignored,
1532and the entire buffer will be wikipedia-drafted. If called from any other
1533buffer, that region, plus any context information specific to that
1534region, will be wikipedia-drafted."
1536 (let ((b (or beg (min (point) (or (mark) (point-min)))))
1537 (e (or end (max (point) (or (mark) (point-max))))))
1539 (narrow-to-region b e)
1540 (run-hook-with-args-until-success 'wikipedia-draft-handler-functions)
1541 (when (equal wikipedia-draft-buffer (buffer-name))
1542 (kill-buffer (current-buffer))
1543 (jump-to-register wikipedia-draft-register)))))
1547(defun wikipedia-draft-buffer ()
1548 "Wikipedia-draft-buffer sends the contents of the current (temporary)
1549buffer to the wikipedia-draft-buffer, see the variable
1550wikipedia-draft-data-file."
1552 (wikipedia-draft-region (point-min) (point-max)))
1554(defun wikipedia-draft-clipboard ()
1555 "Wikipedia-Draft the contents of the current clipboard.
1556Most useful for wikipedia-drafting things from Netscape or other X Windows
1560 (insert (x-get-clipboard))
1561 (run-hook-with-args-until-success 'wikipedia-draft-handler-functions)))
1566;;; Internal Functions:
1567(defvar wikipedia-draft-send-archive t ;Version:1.56
1568"*Archive the reply.")
1570(defvar wikipedia-draft-mode-map ())
1571(if wikipedia-draft-mode-map
1573 (setq wikipedia-draft-mode-map (make-sparse-keymap))
1574 (define-key wikipedia-draft-mode-map "\C-c\C-k" 'wikipedia-draft-buffer)
1575 (define-key wikipedia-draft-mode-map "\C-c\C-d" 'wikipedia-draft-buffer))
1577(defun wikipedia-draft-mode ()
1578 "Major mode for output from \\[wikipedia-draft].
1579\\<wikipedia-draft-mode-map> This buffer is used to collect data that
1580you want wikipedia-draft. Just hit \\[wikipedia-draft-region] when
1581you're done entering, and it will go ahead and file the data for
1582latter retrieval, and possible indexing.
1583\\{wikipedia-draft-mode-map}"
1585 (kill-all-local-variables)
1586 (indented-text-mode)
1587 (use-local-map wikipedia-draft-mode-map)
1588 (setq major-mode 'wikipedia-draft-mode
1589 mode-name "Wikipedia-Draft")
1590 (run-hooks 'wikipedia-draft-mode-hook))
1593(defun wikipedia-draft-view-draft ()
1595 "Simple shortcut to visit the file, which contains the wikipedia drafts."
1596 (find-file wikipedia-draft-data-file))
1600;;{{{ functions for marking regions
1602(defun wikipedia-mark-section () ;Version:1.36
1603 "Set mark at end of current logical section, and point at top."
1605 (re-search-forward (concat "== " "[a-z,A-z \t]*"
1607 (re-search-backward "^")
1609 (re-search-backward (concat "== " "[a-z,A-z \t]*"
1611 (wikipedia-activate-region))
1613(defun wikipedia-mark-signature () ;Version:1.36
1614 "Set mark at end of current logical section, and point at top."
1616 (re-search-forward "]]") ;;[[ ]]
1617 (re-search-backward "^")
1619 (re-search-backward "[[")
1620 (wikipedia-activate-region))
1622(when (featurep 'xemacs)
1623 (fset 'wikipedia-activate-region (symbol-function 'zmacs-activate-region)))
1625(unless (featurep 'xemacs)
1626 (defun wikipedia-activate-region ()
1631;;{{{ `reply' and `send' functions
1633(defun wikipedia-draft-copy-page-to-register () ;Version:1.47
1634 "Copy a page via the wikipedia-draft-register."
1637 (narrow-to-page nil)
1638 (copy-to-register wikipedia-draft-page (point-min) (point-max) nil)
1639 (message "draft page copied to wikipedia register wikipedia-draft-page.")
1643(defun wikipedia-draft-yank-page-to-register () ;Version:1.50
1644 "Insert a page via the wikipedia-draft-register."
1646 (insert-register wikipedia-draft-page nil))
1650(defun wikipedia-draft-send-to-mozex (target-buffer) ;Version:1.56
1651 "Copy the current page from the wikipedia draft file to
1652 TARGET-BUFFER, this buffer is named something like mozex.textarea.
1653Check the variable wikipedia-draft-send-archive. If it is t, then
1654additionally the text will be archived in the draft.wiki file. Check
1655longlines-mode, it might be better if it is set off."
1656 (interactive "bTarget buffer: ")
1657 (let ((src-buf (current-buffer)))
1658 (wikipedia-draft-copy-page-to-register)
1659 (switch-to-buffer target-buffer)
1662 (wikipedia-draft-yank-page-to-register)
1663 (message "The page has been sent (copied) to the mozex file!")
1664 (switch-to-buffer "*Wikipedia-Draft*")
1665 (when wikipedia-draft-send-archive ;Version:1.56
1666 (let ((text (buffer-string)) ;Version:1.59
1667 (desc (wikipedia-draft-buffer-desc)))
1670 (insert wikipedia-draft-leader-text)
1671 (insert-register wikipedia-draft-reply-register 1)
1673 (insert (current-time-string))
1675 (insert wikipedia-draft-leader-text)
1685 (if (find-buffer-visiting wikipedia-draft-data-file)
1686 (let ((wikipedia-draft-text (buffer-string)))
1687 (set-buffer (get-file-buffer wikipedia-draft-data-file))
1689 (goto-char (point-max))
1691 (insert wikipedia-draft-text)
1694 (append-to-file (point-min) (point-max) wikipedia-draft-data-file)))))
1695 (when (equal wikipedia-draft-buffer (buffer-name))
1696 (kill-buffer (current-buffer)))
1697 (switch-to-buffer target-buffer)))
1701(defvar wikipedia-reply-with-hline nil
1702"*Whether to use a hline as a header seperator in the reply.")
1704(defvar wikipedia-reply-with-quote nil ;Version:1.60
1705"*Whether to use a quotation tempalate or not.")
1707(defvar wikipedia-user-simplify-signature t
1708 "*Simple varible in order to threat complicated signatures of users, which uses
1709fonts and other makeup.")
1711(defun wikipedia-reply-at-signature () ;Version:1.40
1712"Very simple function to add the reply prefix to the signature,
1713sorrounded by the boldface makeup. You have to set the point BEFORE
1714the signature, then the functions inserts the following
1715:'''Re: [[User:foo]]'''."
1717 (beginning-of-line 1)
1718 (search-forward "[[")
1722(wikipedia-terminate-paragraph)
1732(defun wikipedia-draft-reply () ;Version:1.62
1733 "Open a temporary buffer in wikipedia mode for editing an wikipedia
1734draft, with an arbitrary piece of data. After finishing the editing
1735|]]:either use \"C-c C-k\" \\[wikipedia-draft-buffer] to send the data into
1736the wikipedia-draft-data-file, or send the buffer \"C-c\C-c\",
1737\\[wikipedia-draft-send-to-mozex] to the current wikipedia article via
1738mozex. Check the varibale wikipedia-draft-send-archive."
1740 (wikipedia-reply-at-point-simple)
1741(beginning-of-line 1)
1744 (window-configuration-to-register wikipedia-draft-register)
1745 (let ((buf (get-buffer-create wikipedia-draft-buffer)))
1746 (switch-to-buffer-other-window buf)
1748 (if (functionp 'pabbrev-mode)
1750 (when (not wikipedia-reply-with-quote)
1751 (when wikipedia-reply-with-hline
1756 (when wikipedia-reply-with-quote
1757 (insert "{{Quotation|")
1760 (insert-register wikipedia-draft-reply-register 1)
1761 (insert "''' |~~~~}}")
1763 (message " C-c C-k sends to draft, C-c C-c sends to org buffer."))))
1765(defun wikipedia-reply-at-point-simple () ;Version:1.65
1766 "Very simple function to reply to posts in the discussion forum. You have to set
1767the point around the signature, then the functions inserts the following
1768:'''Re: [[User:foo]]'''."
1770 (beginning-of-line 1)
1771 (when wikipedia-english-or-german
1772 (search-forward "(UTC)")
1773 (search-backward "[[User:") )
1774 (when (not wikipedia-english-or-german)
1775 (search-forward "(CET)")
1776 (search-backward "[[Benutzer:"))
1777 (when (not wikipedia-user-simplify-signature)
1779 (when wikipedia-user-simplify-signature
1781 (copy-to-register wikipedia-draft-reply-register (region-beginning) (region-end) nil)
1783 (wikipedia-terminate-paragraph-and-indent)
1785 (insert-register wikipedia-draft-reply-register 1)
1786 (when wikipedia-user-simplify-signature
1788 (when (not wikipedia-user-simplify-signature)
1793(provide 'wikipedia-mode)
1794;;; wikipedia-mode.el ends here.