changelog shortlog tags changeset files revisions annotate raw

wikipedia-mode.el

changeset 66: 5b737eefe5ea
author: kim.vanwyk
date: Wed Nov 10 15:19:03 2010 +0200 (18 months ago)
permissions: -rw-r--r--
description: Adding CSharp Mode and Google Weather
1;;; wikipedia-mode.el --- Mode for editing Wikipedia articles off-line
2;; Copyright (C) 2003, 2004, 2006 Chong Yidong, Uwe Brauer
3
4;; Author: Chong Yidong <cyd at stupidchicken com>
5;; Maintainer: Uwe Brauer <oub at mat.ucm.es>
6;; Version: 0.5
7;; Keywords: wiki
8;; $Id: wikipedia-mode.el,v 1.5 2006/05/30 15:16:45 oub Exp oub $
9
10
11;; This file is not part of GNU Emacs.
12
13;;{{{ GPL2
14
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.
19
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.
24
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,
28;; MA 02111-1307 USA
29
30;;}}}
31
32;;; Commentary:
33
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.
38
39;; wikipedia mode can be found also at:
40;; http://en.wikipedia.org/wiki/Wikipedia:Wikipedia-mode.el
41
42;;{{{ INSTALLING WIKIPEDIA-MODE
43
44;; Installing wikipedia-mode
45;; =========================
46;;
47;; Save wikipedia-mode.el in a convenient directory, preferably in
48;; your `load-path'. Add the following to your `user-init-file':
49;;
50;; (autoload 'wikipedia-mode
51;; "wikipedia-mode.el"
52;; "Major mode for editing documents in Wikipedia markup." t)
53;;
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.:
57;;
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)
61;;
62;; If you want to associate filenames ending in ".wiki" with
63;; wikipedia-mode, add the following to your init file:
64;;
65;; (setq auto-mode-alist
66;; (cons '("\\.wiki\\'" . wikipedia-mode) auto-mode-alist))
67
68;;}}}
69
70;;{{{ REQUIREMENTS
71
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.
75;; It can be found at
76;; http://www.astro.uva.nl/~dominik/Tools/outline-magic.el
77
78
79
80
81;;}}}
82
83;;{{{ RECOMMENDATIONS INSTALLING LONGLINES-MODE
84
85;; Installing longlines-mode
86;; =========================
87;;
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.
92;;
93;; Download longlines.el, saving into your `load-path':
94;;
95;; http://www.emacswiki.org/elisp/longlines.el
96;;
97;; Add the following to your `user-init-file':
98;;
99;; (autoload 'longlines-mode "longlines.el"
100;; "Minor mode for editing long lines." t)
101;;
102;;
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!
106
107;;}}}
108
109;;{{{ RECOMMENDATIONS INSTALLING PABBREV-MODE
110
111;; Installing longlines-mode
112;; =========================
113;;
114;; You may find pabbrev.el useful, which can be found at
115;; http://www.russet.org.uk/download/emacs/pabbrev.el
116
117
118;;}}}
119
120;;{{{ Xemacs or (GNU) Emacs
121
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.
141
142
143;;}}}
144
145;;{{{ INSTALLING EE-HELPER or MOZEX
146
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
151;;
152;; (1) EE-HELPER: This is perl script which will communicate with
153;; the wikipedia server. However that sometimes be slow.
154
155;; PROS: if the editor supports UTF8, then ee-helper will
156;; pass the coding flawlessly.
157;;
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.
162
163;; (2) MozEx: this is a Java-script which allows to communicate
164;; Mozilla (or Firefox) directly with Emacs.
165
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.
169;;
170;; CONTRA: the official version does not support UTF8,
171;; however there is now a new semi official version which
172;; does support UTF8.
173
174
175;;
176;; Installing ee-helper
177;; ====================
178;;
179;; Download the perl script from
180;;
181;; http://meta.wikimedia.org/wiki/Help:External_editors
182;;
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.
186
187;; Installing MozEx
188;; ================
189;;
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:
192;;
193;; http://mozex.mozdev.org/development.html
194;;
195;; See also
196;;
197;; http://www.emacswiki.org/cgi-bin/wiki/FireFox
198;;
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':
202;;
203;; (add-to-list 'auto-mode-alist '("mozex.\\.*" . wikipedia-mode))
204
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
210;; typing.
211
212;;}}}
213
214;;{{{ NEWS
215
216
217;; NEWS
218;; ==================================
219;; (1) Font setting has changed.
220;; (2) Some makeup formats have been added: italics, bold, strong
221;; emphasise, links.
222;; (3) outline-cycle from Carsten Dominiks outline-magic has been
223;; added.
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
232;; for doing that:
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.
243;;
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)
251;;
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!
257;;
258;;
259;; 2. You want to reply in a discussion page to a specific
260;; contribution, you can use either the function
261;;
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.
268;;
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
275;;
276
277;;}}}
278
279;;{{{ NEW FUNCTIONS AND VARIABLES
280
281
282;; VERSION 0.4
283;;==================
284;; NEW FUNCTIONS
285;; ------------------
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
307;; wikipedia-draft
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
325
326;; NEW VARIABLES
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
340
341
342;; VERSION 0.5
343;;====================================
344;; NEW FUNCTIONS
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
357
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
365
366;;}}}
367
368;;{{{ TODO
369
370;; Todo
371;; ----
372
373
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!
378
379;;}}}
380
381
382
383;;; Code:
384
385(require 'derived)
386(require 'font-lock)
387
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 $
390
391Report bugs to: Uwe Brauer oub at mat.ucm.es")
392
393
394;;{{{ TAGS
395
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.")
401
402(defvar wikipedia-complex-tags
403 '("a" "div" "font" "table" "td" "th" "tr")
404 "Tags that accept arguments.")
405
406(defvar wikipedia-url-protocols
407 '("ftp" "gopher" "http" "https" "mailto" "news")
408 "Valid protocols for URLs in Wikipedia articles.")
409
410;;}}}
411
412;;{{{ FACES
413
414(defvar font-wikipedia-sedate-face 'font-wikipedia-sedate-face
415 "Face to use for Wikipedia minor keywords.")
416
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.")
427
428
429
430
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))
434 (t '(:bold t)))))
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))
443 (t (,@font))))
444 "Face used to highlight text to be typeset in bold."
445 :group 'font-wikipedia-highlighting-faces)
446
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))
450 (t '(:italic t)))))
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))
459 (t (,@font))))
460 "Face used to highlight text to be typeset in italic."
461 :group 'font-wikipedia-highlighting-faces)
462
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"))
475 (t (,@font))))
476 "Face used to highlight math."
477 :group 'font-wikipedia-highlighting-faces)
478
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))
485 )
486 "Face used to highlight sedate stuff."
487 :group 'font-wikipedia-highlighting-faces)
488
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))
492 (t '(:italic t)))))
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"))
503 (t (,@font))))
504 "Face used to highlight strings."
505 :group 'font-wikipedia-highlighting-faces)
506
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))
510 (t '(:bold t)))))
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))
519 (t (,@font))))
520 "Face for important keywords."
521 :group 'font-wikipedia-highlighting-faces)
522
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))
538 (t (,@font))))
539 "Face used to highlight TeX verbatim environments."
540 :group 'font-wikipedia-highlighting-faces)
541
542
543 (defvar wikipedia-font-lock-keywords
544 (list
545
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)
554
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)
562
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)
568
569 ;; Colon indentation, lists, definitions, and tables
570 (cons "^\\(:+\\|[*#]+\\||[}-]?\\|{|\\)" 'font-lock-builtin-face)
571
572 (list "^\\(;\\)\\([^:\n]*\\)\\(:?\\)"
573 '(1 font-lock-builtin-face)
574 '(2 font-lock-keyword-face)
575 '(3 font-lock-builtin-face))
576
577
578
579 ;; Tags and comments
580
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))
595
596
597
598 ;; External Links
599
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))
607
608
609
610
611 ;; Wiki links
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))
618
619 ;; Wiki variables
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))
624
625 ;; Character entity references
626 (cons "&#?[a-zA-Z0-9]+;" '(0 font-lock-type-face t t))
627
628 ;; Preformatted text
629 (cons "^ .*$" '(0 font-lock-constant-face t t))
630
631 ;; Math environment (uniform highlight only, no TeX markup)
632 (list "<math>\\(\\(\n?.\\)*\\)</math>"
633 '(1 font-lock-keyword-face t t))))
634
635; )
636
637;;}}}
638
639;;{{{ Menu and header stuff
640
641(defvar wikipedia-imenu-generic-expression
642 (list '(nil "^==+ *\\(.*[^\n=]\\)==+" 1))
643 "Imenu expression for `wikipedia-mode'. See `imenu-generic-expression'.")
644
645(defun wikipedia-next-header ()
646 "Move point to the end of the next section header."
647 (interactive)
648 (let ((oldpoint (point)))
649 (end-of-line)
650 (if (re-search-forward "\\(^==+\\).*\\1" (point-max) t)
651 (beginning-of-line)
652 (goto-char oldpoint)
653 (message "No section headers after point."))))
654
655(defun wikipedia-prev-header ()
656 "Move point to the start of the previous section header."
657 (interactive)
658 (unless (re-search-backward "\\(^==+\\).*\\1" (point-min) t)
659 (message "No section headers before point.")))
660
661;;}}}
662
663;;{{{ Paragraph terminate and filling stuff (Chong)
664
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."
669 (interactive)
670 (let (indent-chars)
671 (save-excursion
672 (beginning-of-line)
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)))
678 t))
679 (newline) (if (not indent-chars) (newline)
680 (insert indent-chars))))
681
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."
686 (interactive)
687 (let (indent-chars)
688 (save-excursion
689 (beginning-of-line)
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)))
695 t))
696 (newline) (if (not indent-chars) (newline)
697 (insert indent-chars))))
698
699
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'."
703 (save-excursion
704 (let ((pos (point)))
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))))))))
711
712(defun wikipedia-fill-article ()
713 "Fill the entire article."
714 (interactive)
715 (save-excursion
716 (fill-region (point-min) (point-max))))
717
718(defun wikipedia-unfill-article ()
719 "Undo filling, deleting stand-alone newlines (newlines that do not
720end paragraphs, list entries, etc.)"
721 (interactive)
722 (save-excursion
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"))
727
728
729(defun wikipedia-unfill-paragraph-with-newline (&optional justifyp)
730 (interactive "P")
731 (let ((before (point))) ;Version:1.3
732 (save-excursion
733 (forward-paragraph)
734 (or (bolp) (newline 1))
735 (let ((end (point))
736 (start (progn (backward-paragraph) (point))))
737 (goto-char before)
738 (while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
739 (replace-match " " nil nil nil 1))))))
740; (message "Stand-alone newlines IN PARAGRAPH deleted"))
741
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]."
747 (interactive)
748 (save-excursion
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")
754 (widen))
755
756;;}}}
757
758;;{{{ Main function wikipedia mode (using define-derived mode)
759
760;;;###autoload
761;;{{{ Main function wikipedia-mode
762
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).
766
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
774wiki texts.
775
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:
781
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.
787
788
789
790The following commands put in markup structures.
791
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
797
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
804
805The draft functionality
806\\[wikipedia-draft]
807\\[wikipedia-draft-region]
808\\[wikipedia-draft-view-draft]
809\\[wikipedia-draft-page]
810\\[wikipedia-draft-buffer]
811
812Replying and sending functionality
813\\[wikipedia-reply-at-point-simple]
814\\[wikipedia-draft-reply]
815\\[wikipedia-send-draft-to-mozex]
816
817
818The register functionality
819\\[wikipedia-copy-page-to-register]
820\\[defun wikipedia-insert-page-to-register]
821
822
823Some simple editing commands.
824\\[wikipedia-enhance-indent]
825\\[wikipedia-yank-prefix]
826\\[wikipedia-unfill-paragraph-or-region]
827
828
829
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."
833
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) "^[ *#:|;]")
848
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")
855
856
857 ;; Turn on the Imenu automatically.
858(when menu-bar-mode
859 (set (make-local-variable 'imenu-generic-expression)
860 wikipedia-imenu-generic-expression)
861 (imenu-add-to-menubar "Contents"))
862
863(modify-syntax-entry ?< "(>" wikipedia-mode-syntax-table)
864(modify-syntax-entry ?> ")<" wikipedia-mode-syntax-table)
865
866;;}}}
867
868;; KEY SETTING
869
870;;{{{ KEY SETTING
871
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)
879
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)))
895
896
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)
924
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)
929;; private setting
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
936
937;;}}}
938
939
940 (make-local-variable 'change-major-mode-hook))
941
942; wikipedia-mode ends here
943;;}}}
944
945 ;;{{{ longlines-mode
946
947(defun wikipedia-turn-on-longlines () ;Version:1.58
948 "Turn on longlines-mode if it is defined."
949 (if (functionp 'longlines-mode)
950 (longlines-mode 1)))
951(add-hook 'wikipedia-mode-hook 'wikipedia-turn-on-longlines)
952(set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]")
953
954;;}}}
955
956;; New formating stuff for inserting simple formating structures such
957
958;;{{{ Insert makeup and templates
959
960(defvar wikipedia-enumerate-with-terminate-paragraph nil
961"*Before insert enumerate/itemize do \\[wikipedia-terminate-paragraph].")
962
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."
968 (interactive)
969 (when wikipedia-enumerate-with-terminate-paragraph
970 (wikipedia-terminate-paragraph)
971 (insert "#"))
972 (when (not wikipedia-enumerate-with-terminate-paragraph)
973 (newline nil)
974 (insert ":#")))
975
976
977
978
979
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."
985 (interactive)
986 (when wikipedia-enumerate-with-terminate-paragraph
987 (wikipedia-terminate-paragraph)
988 (insert "*"))
989 (when (not wikipedia-enumerate-with-terminate-paragraph )
990 (newline nil)
991 (insert ":*")))
992
993
994(defun wikipedia-insert-strong-emphasis ()
995"Insert strong emphasis italics via four apostrophes (e.g. ''''FOO''''.) When mark is active, surrounds region."
996 (interactive)
997 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
998 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
999 (save-excursion
1000 (goto-char (point))
1001 (insert "''''")
1002 (goto-char (mark))
1003 (insert "''''"))
1004 (insert "'''' ''''")
1005 (backward-char 5)))
1006
1007
1008(defun wikipedia-insert-bold ()
1009"Insert bold via three apostrophes (e.g. '''FOO'''.)
1010When mark is active, surrounds region."
1011 (interactive)
1012 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1013 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1014 (save-excursion
1015 (goto-char (point))
1016 (insert "'''")
1017 (goto-char (mark))
1018 (insert "'''"))
1019 (insert "''' '''")
1020 (backward-char 4)))
1021
1022
1023(defun wikipedia-insert-italics ()
1024"Insert bold via TWO apostrophes (e.g. ''FOO''.) When mark is active,
1025surrounds region."
1026 (interactive)
1027 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1028 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1029 (save-excursion
1030 (goto-char (point))
1031 (insert "''")
1032 (goto-char (mark))
1033 (insert "''"))
1034 (insert "'' ''")
1035 (backward-char 3)))
1036
1037(defun wikipedia-insert-quotation-with-signature () ;Version:1.60
1038"Insert bold via TWO apostrophes (e.g. ''FOO''.) When mark is active,
1039surrounds region."
1040 (interactive)
1041 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1042 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1043 (save-excursion
1044 (goto-char (point))
1045 (insert "{{Quotation|}}")
1046 (goto-char (mark))
1047 (insert "{{~~~~}}"))
1048 (insert "{{Quotation| }}{{~~~~}}")
1049 (backward-sexp 1)
1050 (backward-char 3)))
1051
1052(defun wikipedia-insert-quotation () ;Version:1.60
1053"Quotation box of the form {{Quotation}}{{}}. When mark is active,
1054surrounds region."
1055 (interactive)
1056 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1057 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1058 (save-excursion
1059 (goto-char (point))
1060 (insert "{{Quotation|}}")
1061 (goto-char (mark))
1062 (insert "{{}}"))
1063 (insert "{{Quotation|}}{{ }}")
1064 (backward-char 3)))
1065
1066
1067
1068
1069(defun wikipedia-insert-bible-verse-template ()
1070 "Insert a template for the quotation of bible verses."
1071 (interactive)
1072 (insert "({{niv|")
1073(let ((name (read-string "Name: ")))
1074 (insert (concat name "|"))
1075(let ((verse (read-string "Verse: ")))
1076 (insert (concat verse "|" name " " verse "}})")))))
1077
1078
1079(defvar wikipedia-english-or-german t
1080"*Variable in order to set the english (t) or german (nil) environment.")
1081
1082(defun wikipedia-insert-user ()
1083 "Inserts, interactively a user name [[User:foo]]"
1084 (interactive)
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 "]]")))))
1091
1092
1093
1094(defun wikipedia-insert-reply-prefix () ;Version:1.60
1095"Quotation box of the form {{Quotation}}{{}}. When mark is active,
1096surrounds region."
1097 (interactive)
1098 (beginning-of-line 1)
1099 (search-forward "[[")
1100 (backward-char 2)
1101 (mark-sexp 1)
1102 (copy-to-register wikipedia-draft-reply-register (region-beginning) (region-end) nil)
1103 (end-of-line 1)
1104 (wikipedia-terminate-paragraph)
1105 (beginning-of-line 1)
1106 (kill-line nil)
1107 (insert "----")
1108 (newline 1)
1109 (yank)
1110 (insert ":'''Re: ")
1111 (insert-register wikipedia-draft-reply-register 1)
1112 (insert "''' ")
1113 (end-of-line 1))
1114
1115(defun wikipedia-insert-header ()
1116 "Insert subheader via == (e.g. == FOO ==.)"
1117 (interactive)
1118 (insert "== ==")
1119 (backward-char 4))
1120
1121(defun wikipedia-insert-link ()
1122 "Insert link via [[ (e.g. [[FOO]].) When mark is active, surround region."
1123 (interactive)
1124 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1125 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1126 (save-excursion
1127 (goto-char (point))
1128 (insert "]]")
1129 (goto-char (mark))
1130 (insert "[["))
1131 (insert "[[ ]]")
1132 (backward-char 3)))
1133
1134(defun wikipedia-insert-link-www ()
1135 "Insert link via [[ (e.g. [http://FOO].) When mark is active, surround region."
1136 (interactive)
1137 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1138 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1139 (save-excursion
1140 (goto-char (point))
1141 (insert "]")
1142 (goto-char (mark))
1143 (insert "[http://"))
1144 (insert "[http:// ]")
1145 (backward-char 2)))
1146
1147
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."
1151 (interactive)
1152 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1153 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1154 (save-excursion
1155 (goto-char (point))
1156 (insert "]]")
1157 (goto-char (mark))
1158 (when (not wikipedia-english-or-german)
1159 (insert "[[Bild:"))
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: ]]"))
1166 (backward-char 3)))
1167
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."
1171 (interactive)
1172 (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1173 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
1174 (save-excursion
1175 (goto-char (point))
1176 (insert "]]")
1177 (goto-char (mark))
1178 (when (not wikipedia-english-or-german)
1179 (insert "[[Bild:"))
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: ]]"))
1186 (backward-char 3)))
1187
1188
1189
1190
1191(defun wikipedia-turn-on-outline-minor-mode ()
1192 "Turn on outline minor mode."
1193 (interactive)
1194 (outline-minor-mode nil))
1195
1196
1197(defun wikipedia-insert-signature () ;Version:1.4
1198 "Insert \"~~~~:\" "
1199 (interactive)
1200 (insert "~~~~: "))
1201
1202
1203
1204
1205
1206(defun wikipedia-insert-hline () ;Version:1.29
1207 "Insert \"----\" "
1208 (interactive)
1209 (insert "\n")
1210 (insert "----")
1211 (insert "\n"))
1212
1213;;}}}
1214
1215;;{{{ filling and longline
1216
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."
1220 (interactive)
1221 (when use-hard-newlines
1222 ;; (backward-paragraph 1)
1223 ;; (next-line 1)
1224 (beginning-of-line 1)
1225 (set-fill-prefix)
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)
1229 "[   \n ]")
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)
1242 ;; (next-line 1)
1243 (beginning-of-line 1)
1244 (set-fill-prefix)
1245 (set (make-local-variable 'sentence-end-double-space) t)
1246 (set (make-local-variable 'paragraph-start)
1247 "[   \n ]")
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 "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")))
1257
1258
1259
1260
1261(defun wikipedia-start-paragraph ()
1262 (interactive)
1263 (set (make-local-variable 'paragraph-start)
1264 "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$"))
1265
1266
1267(defun wikipedia-hardlines ()
1268"Set use-hard-newlines to NIL."
1269 (interactive)
1270 (setq use-hard-newlines nil))
1271;; from emacs wiki
1272(defun wikipedia-next-long-line ()
1273 "Move forward to the next long line with column-width greater
1274 than `fill-column'.
1275
1276 TODO: When function reaches end of buffer, save-excursion to
1277 starting point.
1278 Generalise to make `previous-long-line'."
1279 (interactive)
1280 ;; global-variable: fill-column
1281 (if (= (forward-line) 0)
1282 (let ((line-length
1283 (save-excursion
1284 (end-of-line)
1285 (current-column))))
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")))
1291
1292
1293(defun wikipedia-unfill-paragraph-simple ()
1294"A very simple function for unfilling a paragraph."
1295 (interactive)
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))))
1302
1303;;}}}
1304
1305;;{{{ outline and outline-magic stuff
1306
1307(add-hook 'wikipedia-mode-hook 'wikipedia-turn-on-outline-minor-mode)
1308
1309(defun wikipedia-outline-cycle ()
1310 (interactive)
1311 (if (functionp 'outline-cycle)
1312 (outline-cycle)))
1313
1314
1315(add-hook 'outline-minor-mode-hook 'wikipedia-outline-magic-keys)
1316
1317(defun wikipedia-outline-magic-keys ()
1318 (interactive)
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))
1329
1330(defun wikipedia-enhance-indent () ;Version:1.26
1331 (interactive)
1332 (string-rectangle (region-beginning) (region-end) ":"))
1333
1334(defun wikipedia-yank-prefix () ;Version:1.26
1335 (interactive)
1336 (string-rectangle (region-beginning) (region-end) ":"))
1337
1338;; modification for outline-magic
1339
1340(defun wikipedia-simple-outline-promote ()
1341"Function simple deletes \"=\" and the end and the beginning of line,
1342does not promote the whole tree!"
1343 (interactive)
1344 (save-excursion
1345 (progn
1346 (beginning-of-line 1)
1347 (search-forward "=")
1348 (delete-char 1 nil)
1349 (end-of-line 1)
1350 (search-backward "=")
1351 (delete-char 1 nil))))
1352
1353(defun wikipedia-simple-outline-demote ()
1354"Function simple adds \"=\" and the end and the beginning of line,
1355does not promote the whole tree!"
1356 (interactive)
1357 (save-excursion
1358 (progn
1359 (beginning-of-line 1)
1360 (search-forward "=")
1361 (insert "=")
1362 (end-of-line 1)
1363 (search-backward "=")
1364 (insert "="))))
1365
1366
1367(defun wikipedia-rename-buffer () ;Version:1.5
1368 "Make sure that the option UNIQUE is used."
1369 (interactive)
1370 (rename-buffer (read-string "Name of new buffer (unique): " ) 1))
1371
1372;;}}}
1373
1374;;{{{ wikipedia drafts functionality: `stolen' from remember.el:
1375
1376(defgroup wikipedia-draft nil
1377 "A mode to wikipedia-draft information."
1378 :group 'data)
1379
1380;;; User Variables:
1381
1382(defcustom wikipedia-draft-mode-hook nil
1383 "*Functions run upon entering wikipedia-draft-mode."
1384 :type 'hook
1385 :group 'wikipedia-draft)
1386
1387(defcustom wikipedia-draft-register ?R
1388 "The register in which the window configuration is stored."
1389 :type 'character
1390 :group 'wikipedia-draft)
1391
1392(defcustom wikipedia-draft-filter-functions nil
1393 "*Functions run to filter wikipedia-draft data.
1394All functions are run in the wikipedia-draft buffer."
1395 :type 'hook
1396 :group 'wikipedia-draft)
1397
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. "
1404 :type 'hook
1405 :group 'wikipedia-draft)
1406
1407(defcustom wikipedia-draft-data-file "~/Wiki/discussions/draft.wiki"
1408 "*The file in which to store the wikipedia drafts."
1409 :type 'file
1410 :group 'wikipedia-draft)
1411
1412(defcustom wikipedia-draft-reply-register ?M
1413 "The register in which the window configuration is stored."
1414 :type 'character
1415 :group 'wikipedia-draft)
1416
1417(defcustom wikipedia-draft-page ?S ;Version:1.37
1418 "The register in which the a page of the wiki draft file is stored."
1419 :type 'character
1420 :group 'wikipedia-draft)
1421
1422
1423(defcustom wikipedia-draft-leader-text "== "
1424 "*The text used to begin each wikipedia-draft item."
1425 :type 'string
1426 :group 'wikipedia-draft)
1427
1428
1429;;; Internal Variables:
1430
1431(defvar wikipedia-draft-buffer "*Wikipedia-Draft*"
1432 "The name of the wikipedia-draft (temporary) data entry buffer.")
1433
1434;;; User Functions:
1435
1436;;;###autoload
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."
1443 (interactive)
1444 (window-configuration-to-register wikipedia-draft-register)
1445 (let ((buf (get-buffer-create wikipedia-draft-buffer)))
1446 (switch-to-buffer-other-window buf)
1447 (wikipedia-mode)
1448 (message " C-c C-k sends to draft file, C-c C-c sends to org buffer.")))
1449
1450
1451
1452
1453
1454(defsubst wikipedia-draft-time-to-seconds (time)
1455 "Convert TIME to a floating point number."
1456 (+ (* (car time) 65536.0)
1457 (cadr time)
1458 (/ (or (car (cdr (cdr time))) 0) 1000000.0)))
1459
1460(defsubst wikipedia-draft-mail-date (&optional rfc822-p)
1461 "Return a simple date. Nothing fancy."
1462 (if rfc822-p
1463 (format-time-string "%a, %e %b %Y %T %z" (current-time))
1464 (format-time-string "%c" (current-time))))
1465
1466(defun wikipedia-draft-buffer-desc ()
1467 "Using the first line of the current buffer, create a short description."
1468 (buffer-substring (point-min)
1469 (save-excursion
1470 (goto-char (point-min))
1471 (end-of-line)
1472 (if (> (- (point) (point-min)) 60)
1473 (goto-char (+ (point-min) 60)))
1474 (point))))
1475
1476
1477;; Wikipedia-Drafting to plain files:
1478
1479
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)))
1485 (with-temp-buffer
1486 (insert "\n\n")
1487 (insert wikipedia-draft-leader-text)
1488 (insert "Draft: ") ;Version:1.39
1489 (insert (read-string "Enter Subject: "))
1490 (insert " ")
1491 (insert (current-time-string))
1492 (insert " ")
1493 (insert wikipedia-draft-leader-text)
1494 (insert "\n\n") ;Version:1.27
1495 (insert " ")
1496 (insert "\n\n")
1497 (insert text)
1498 (insert "\n")
1499 (insert " ")
1500 (insert "\n")
1501 (if (not (bolp))
1502 (insert "\n\n"))
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))
1506 (save-excursion
1507 (goto-char (point-max))
1508 (insert "\n")
1509 (insert wikipedia-draft-text)
1510 (insert "\n")
1511 (save-buffer)))
1512 (append-to-file (point-min) (point-max) wikipedia-draft-data-file)))))
1513
1514
1515(setq wikipedia-draft-handler-functions 'wikipedia-draft-append-to-file)
1516
1517
1518(custom-add-option 'wikipedia-draft-handler-functions 'wikipedia-draft-append-to-file)
1519
1520;;;###autoload
1521(defun wikipedia-draft-page () ;Version:1.32
1522 (interactive)
1523 (mark-page)
1524 (copy-region-as-kill (region-beginning) (region-end))
1525 (wikipedia-draft)
1526 (yank nil))
1527
1528
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."
1535 (interactive)
1536 (let ((b (or beg (min (point) (or (mark) (point-min)))))
1537 (e (or end (max (point) (or (mark) (point-max))))))
1538 (save-restriction
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)))))
1544
1545;;
1546;;;###autoload
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."
1551 (interactive)
1552 (wikipedia-draft-region (point-min) (point-max)))
1553
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
1557application."
1558 (interactive)
1559 (with-temp-buffer
1560 (insert (x-get-clipboard))
1561 (run-hook-with-args-until-success 'wikipedia-draft-handler-functions)))
1562
1563;;;###autoload
1564
1565
1566;;; Internal Functions:
1567(defvar wikipedia-draft-send-archive t ;Version:1.56
1568"*Archive the reply.")
1569
1570(defvar wikipedia-draft-mode-map ())
1571(if wikipedia-draft-mode-map
1572 ()
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))
1576
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}"
1584 (interactive)
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))
1591
1592
1593(defun wikipedia-draft-view-draft ()
1594 (interactive)
1595 "Simple shortcut to visit the file, which contains the wikipedia drafts."
1596 (find-file wikipedia-draft-data-file))
1597
1598;;}}}
1599
1600;;{{{ functions for marking regions
1601
1602(defun wikipedia-mark-section () ;Version:1.36
1603 "Set mark at end of current logical section, and point at top."
1604 (interactive)
1605 (re-search-forward (concat "== " "[a-z,A-z \t]*"
1606 " =="))
1607 (re-search-backward "^")
1608 (set-mark (point))
1609 (re-search-backward (concat "== " "[a-z,A-z \t]*"
1610 " "))
1611 (wikipedia-activate-region))
1612
1613(defun wikipedia-mark-signature () ;Version:1.36
1614 "Set mark at end of current logical section, and point at top."
1615 (interactive)
1616 (re-search-forward "]]") ;;[[ ]]
1617 (re-search-backward "^")
1618 (set-mark (point))
1619 (re-search-backward "[[")
1620 (wikipedia-activate-region))
1621
1622(when (featurep 'xemacs)
1623 (fset 'wikipedia-activate-region (symbol-function 'zmacs-activate-region)))
1624
1625(unless (featurep 'xemacs)
1626 (defun wikipedia-activate-region ()
1627 nil))
1628
1629;;}}}
1630
1631;;{{{ `reply' and `send' functions
1632
1633(defun wikipedia-draft-copy-page-to-register () ;Version:1.47
1634 "Copy a page via the wikipedia-draft-register."
1635 (interactive)
1636 (save-excursion
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.")
1640 (widen)))
1641
1642;aux function
1643(defun wikipedia-draft-yank-page-to-register () ;Version:1.50
1644 "Insert a page via the wikipedia-draft-register."
1645 (interactive)
1646 (insert-register wikipedia-draft-page nil))
1647
1648
1649
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)
1660 (end-of-line 1)
1661 (newline 1)
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)))
1668 (with-temp-buffer
1669 (insert "\n\n")
1670 (insert wikipedia-draft-leader-text)
1671 (insert-register wikipedia-draft-reply-register 1)
1672 (insert " ")
1673 (insert (current-time-string))
1674 (insert " ")
1675 (insert wikipedia-draft-leader-text)
1676 (insert "\n\n")
1677 (insert " ")
1678 (insert "\n\n")
1679 (insert text)
1680 (insert "\n")
1681 (insert " ")
1682 (insert "\n")
1683 (if (not (bolp))
1684 (insert "\n\n"))
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))
1688 (save-excursion
1689 (goto-char (point-max))
1690 (insert "\n")
1691 (insert wikipedia-draft-text)
1692 (insert "\n")
1693 (save-buffer)))
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)))
1698
1699
1700;;Apr_22_2006
1701(defvar wikipedia-reply-with-hline nil
1702"*Whether to use a hline as a header seperator in the reply.")
1703
1704(defvar wikipedia-reply-with-quote nil ;Version:1.60
1705"*Whether to use a quotation tempalate or not.")
1706
1707(defvar wikipedia-user-simplify-signature t
1708 "*Simple varible in order to threat complicated signatures of users, which uses
1709fonts and other makeup.")
1710
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]]'''."
1716 (interactive)
1717 (beginning-of-line 1)
1718 (search-forward "[[")
1719 (mark-word 3)
1720 (yank)
1721 (end-of-line 1)
1722(wikipedia-terminate-paragraph)
1723 (insert ":'''Re: ")
1724 (insert "[[")
1725 (yank)
1726 (insert "]]")
1727 (insert "'''"))
1728
1729
1730
1731
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."
1739 (interactive)
1740 (wikipedia-reply-at-point-simple)
1741(beginning-of-line 1)
1742(kill-line nil)
1743 (save-excursion
1744 (window-configuration-to-register wikipedia-draft-register)
1745 (let ((buf (get-buffer-create wikipedia-draft-buffer)))
1746 (switch-to-buffer-other-window buf)
1747 (wikipedia-mode)
1748 (if (functionp 'pabbrev-mode)
1749 (pabbrev-mode))
1750 (when (not wikipedia-reply-with-quote)
1751 (when wikipedia-reply-with-hline
1752 (insert "----")
1753 (newline 1))
1754 (yank)
1755 (end-of-line 1))
1756 (when wikipedia-reply-with-quote
1757 (insert "{{Quotation|")
1758 (yank)
1759 (insert "'''Re: ")
1760 (insert-register wikipedia-draft-reply-register 1)
1761 (insert "''' |~~~~}}")
1762 (backward-char 7))
1763 (message " C-c C-k sends to draft, C-c C-c sends to org buffer."))))
1764
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]]'''."
1769 (interactive)
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)
1778 (mark-word 3))
1779 (when wikipedia-user-simplify-signature
1780 (mark-word 2))
1781 (copy-to-register wikipedia-draft-reply-register (region-beginning) (region-end) nil)
1782 (end-of-line 1)
1783 (wikipedia-terminate-paragraph-and-indent)
1784 (insert ":'''Re: ")
1785 (insert-register wikipedia-draft-reply-register 1)
1786 (when wikipedia-user-simplify-signature
1787 (insert "|]]''' "))
1788 (when (not wikipedia-user-simplify-signature)
1789 (insert "]]''' ")))
1790
1791;;}}}
1792
1793(provide 'wikipedia-mode)
1794;;; wikipedia-mode.el ends here.
1795
1796