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
51 ;; "wikipedia-mode.el"
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 ;; If you are using Emacs 22 or later longlines-mode is included so
89 ;; please skip this section!
91 ;; Wikipedia articles don't use newline characters to break paragraphs
92 ;; into lines, so each paragraph looks like a super-long line to
93 ;; Emacs. To let Emacs handle "soft word wrapping", you need to
94 ;; download a third-party package, longlines-mode.
96 ;; Download longlines.el, saving into your `load-path':
98 ;; http://www.emacswiki.org/elisp/longlines.el
100 ;; Add the following to your `user-init-file':
102 ;; (autoload 'longlines-mode "longlines.el"
103 ;; "Minor mode for editing long lines." t)
106 ;; WARNING: if you insert text from one file in wikipedia-mode to
107 ;; another file in wikipedia-mode I strongly recommend, to turn
108 ;; longlines-mode off, before the copying!
112 ;;{{{ RECOMMENDATIONS INSTALLING PABBREV-MODE
114 ;; Installing pabbrev-mode
115 ;; =========================
117 ;; You may find pabbrev.el useful, which can be found at
118 ;; http://www.russet.org.uk/download/emacs/pabbrev.el
123 ;;{{{ Xemacs or (GNU) Emacs
125 ;; Xemacs or (GNU) Emacs
126 ;; =====================
127 ;; Usually that is a question of taste. However almost all wikipedia
128 ;; articles nowadays use UTF8 coding, so the question which of the
129 ;; Macsen to use, boils down to which degree UTF8 support is
130 ;; implemented (no mule Xemacs is ruled out). While Xemacs has the
131 ;; better font support, the UTF8 support still is not complete and
132 ;; hence at the time being it is sad for the maintainer (a long time
133 ;; Xemacs user) to recommend NOT to use Xemacs, even not 21.5.x, which
134 ;; has a much better implemented UTF8 coding engine. That might
135 ;; however change in the foreseeable future....
136 ;; WARNING: at least for me in Debian testing/unstable Emacs does not
137 ;; ship all fonts necessary for a flawless editing of UTF8 files. For
138 ;; example you can chose Greek input, write Greek text, but then when
139 ;; you close and open the file again, the Greek symbol are not
140 ;; displayed but you see empty blocks. The reason seems that emacs
141 ;; chooses for the input fonts other fonts as for the display (don't
142 ;; ask me). However for installing the (ugly) UTF8 compatible fonts
143 ;; from ..... solved that problem.
148 ;;{{{ INSTALLING EE-HELPER or MOZEX
150 ;; Installing the helper programs.
151 ;; =========================
152 ;; Helper Programs: MozEx and EE-HELPER. There are three possibilities
153 ;; in order to use Emacs as an external editor
155 ;; (1) Firefox add-on It's All Text: Recommended. The elisp
156 ;; library its-all-text.el makes it easier to use this.
158 ;; PROS: Easy to intall, supported. (You need to add Emacs
159 ;; client as the editor.) Can be used for editing other
160 ;; text fields with Emacs too.
162 ;; (2) EE-HELPER: This is perl script which will communicate with
163 ;; the wikipedia server. However that sometimes be slow.
165 ;; PROS: if the editor supports UTF8, then ee-helper will
166 ;; pass the coding flawlessly.
168 ;; CONTRA: the problem with this script is that it directly
169 ;; communicates with the wikipedia site and does not
170 ;; warn you about simultaneous editing. Use it with
171 ;; care!!! Moreover section editing is not implemented.
173 ;; (3) MozEx: this is a Java-script which allows to communicate
174 ;; Mozilla (or Firefox) directly with Emacs.
176 ;; PROS: After finishing editing you use the wikipedia
177 ;; software to submit your changes and not the script,
178 ;; so you are warned about possible conflicting editing.
180 ;; CONTRA: the official version does not support UTF8,
181 ;; however there is now a new semi official version which
182 ;; does support UTF8.
184 ;; Installing It's All Text
185 ;; ========================
187 ;; Go to the home page and follow the instructions there:
189 ;; https://addons.mozilla.org/en-US/firefox/addon/4125
191 ;; Then open It's All Text preferences from the Firefox Add-ons page
192 ;; and choose emacsclient as your editor (emacsclientw.exe on
195 ;; Installing ee-helper
196 ;; ====================
198 ;; Download the perl script from
200 ;; http://meta.wikimedia.org/wiki/Help:External_editors
202 ;; and follow the instructions. configure the .ee-ini file. chance in
203 ;; your personal wikipedia-mode-map account setting the editing
204 ;; functions: activate the `external editor' option.
209 ;; If your web browser is Mozilla or Firefox, take a look at the MozEx
210 ;; extension, which allows you to call Emacs for editing text boxes:
212 ;; http://mozex.mozdev.org/development.html
216 ;; http://www.emacswiki.org/cgi-bin/wiki/FireFox
218 ;; If you mostly use MozEx to edit Wikipedia articles, it might be
219 ;; worthwhile to tell Emacs to enter wikipedia-mode whenever it is
220 ;; called by MozEx. Just add this to your `user-init-file':
222 ;; (add-to-list 'auto-mode-alist '("mozex.\\.*" . wikipedia-mode))
224 ;; Recall: you have to click on edit (either edit article or edit
225 ;; section), then use mouse3 (or shift f10), then select
226 ;; mozex, then edit textarea: Edit-->mouse3-->mozex-->Edit
227 ;; Textarea. After editing, you have to _click_ on the
228 ;; text in the browser otherwise Mozilla will ignore your
237 ;; ==================================
238 ;; (1) Font setting has changed.
239 ;; (2) Some makeup formats have been added: italics, bold, strong
241 ;; (3) outline-cycle from Carsten Dominiks outline-magic has been
243 ;; (4) "Draft", "send" and "reply" (for discussion pages)
244 ;; abilities 'based' on ideas of John Wigleys remember.el: see
245 ;; the functions wikipedia-draft-*
246 ;; RATIONALE: This comes handy in 2 situations
247 ;; 1. You are editing articles which various authors (this I
248 ;; think is the usual case), you then want not to submit
249 ;; your edit immediately but want to copy it somewhere and
250 ;; to continue later. You can use the following functions
252 ;; wikipedia-draft-buffer \C-c\C-b
253 ;; wikipedia-draft-region \C-c\C-r
254 ;; then the buffer/region will be appended to the
255 ;; wikipedia-draft-data-file (default is
256 ;; "~/Wiki/discussions/draft.wiki", which you can visit via
257 ;; wikipedia-draft-view-draft) and it will be
258 ;; surrounded by the ^L marks in order to set a page.
259 ;; moreover on top on that a section header == will be
260 ;; inserted, which consists of the Word Draft, a subject
261 ;; you are asked for and a date stamp.
263 ;; Another possibility consists in using the function
264 ;; wikipedia-draft, bound to \C-c \C-m then a new buffer
265 ;; will opened already in wikipedia mode. You edit and then
266 ;; either can send the content of the buffer to the
267 ;; wikipedia-draft-data-file in the same manner as
268 ;; described above using the function
269 ;; wikipedia-draft-buffer (bound to \C-c\C-k)
271 ;; BACK: In order to copy/send the content of temporary
272 ;; buffer or of a page in the wikipedia-draft-data-file
273 ;; back in to your wikipedia file, use the function
274 ;; `wikipedia-send-to-mozex'. You
275 ;; will be asked to which buffer to copy your text!
278 ;; 2. You want to reply in a discussion page to a specific
279 ;; contribution, you can use either the function
281 ;; \\[wikipedia-reply-at-point-simple] bound to [(meta shift r)]
282 ;; which inserts a newline, a hline, and the signature of
283 ;; the author. Or can use
284 ;; \\[wikipedia-draft-reply] bound [(meta r)]
285 ;; which does the same as wikipedia-reply-at-point-simple
286 ;; but in a temporary draft buffer.
288 ;; BACK: In order to copy/send the content of that buffer
289 ;; back in to your wikipedia file, use the function
290 ;; \\[wikipedia-send-to-mozex] bound to "\C-c\C-c". You
291 ;; will be asked to which buffer to copy your text! If
292 ;; you want a copy to be send to your draft file, use
293 ;; the variable wikipedia-draft-send-archive
298 ;;{{{ NEW FUNCTIONS AND VARIABLES
304 ;; ------------------
305 ;; wikipedia-insert-enumerate
306 ;; wikipedia-insert-itemize
307 ;; wikipedia-insert-strong-emphasis (renamed to wikipedia-insert-bold-italic)
308 ;; wikipedia-insert-bold
309 ;; wikipedia-insert-italics
310 ;; wikipedia-insert-header
311 ;; wikipedia-insert-link-wiki
312 ;; wikipedia-turn-on-outline-minor-mode
313 ;; wikipedia-insert-signature
314 ;; wikipedia-insert-hline
315 ;; wikipedia-unfill-paragraph-or-region
316 ;; wikipedia-start-paragraph
317 ;; wikipedia-hardlines
318 ;; wikipedia-outline-magic-keys
319 ;; wikipedia-enhance-indent
320 ;; wikipedia-yank-prefix
321 ;; wikipedia-simple-outline-promote
322 ;; wikipedia-simple-outline-demote
323 ;; wikipedia-next-long-line
324 ;; wikipedia-unfill-paragraph
325 ;; wikipedia-rename-buffer
327 ;; wikipedia-draft-buffer-desc
328 ;; wikipedia-draft-append-to-file
329 ;; wikipedia-draft-page
330 ;; wikipedia-draft-region (&optional beg end)
331 ;; wikipedia-draft-buffer
332 ;; wikipedia-draft-clipboard
333 ;; wikipedia-draft-mode
334 ;; wikipedia-draft-view-draft
335 ;; wikipedia-mark-section
336 ;; wikipedia-activate-region
337 ;; wikipedia-copy-page-to-register
338 ;; wikipedia-insert-page-to-register
339 ;; wikipedia-send-to-mozex (target-buffer)
340 ;; wikipedia-reply-at-point-simple
341 ;; wikipedia-draft-reply
342 ;; wikipedia-insert-quotation-with-signature
343 ;; wikipedia-insert-quotation
346 ;;---------------------
347 ;; wikipedia-enumerate-with-terminate-paragraph
348 ;; wikipedia-draft-buffer "*Wikipedia-Draft*"
349 ;; wikipedia-draft-mode-map
350 ;; wikipedia-draft-mode-hook
351 ;; wikipedia-draft-register ?R
352 ;; wikipedia-draft-filter-functions
353 ;; wikipedia-draft-handler-functions '(wikipedia-draft-append-to-file)
354 ;; wikipedia-draft-data-file "~/Wiki/discussions/draft.wiki"
355 ;; wikipedia-draft-leader-text "== "
356 ;; wikipedia-draft-page ?S
357 ;; wikipedia-draft-send-archive
358 ;; wikipedia-reply-with-quote
362 ;;====================================
364 ;; ------------------------------------
365 ;; wikipedia-insert-audio
366 ;; wikipedia-insert-image
367 ;; wikipedia-insert-link-www (renamed to wikipedia-insert-link-external)
368 ;; wikipedia-insert-user
369 ;; wikipedia-mark-signature
370 ;; wikipedia-outline-cycle
371 ;; wikipedia-reply-at-signature
372 ;; wikipedia-terminate-paragraph-and-indent
373 ;; wikipedia-yank-prefix
375 ;; NEW VARIABLES (defvar, defcustom, defconst)
376 ;; ----------------------
377 ;; wikipedia-reply-with-hline
378 ;; wikipedia-user-simplify-signature
379 ;; wikipedia-english-or-german
380 ;; wikipedia-draft-reply-register ?M
381 ;; wikipedia-mode-version
384 ;;====================================
386 ;; - Now requires Emacs 22 or higher.
387 ;; - Cleaned the code in various ways.
388 ;; - Removed wikipedia-english-or-german
389 ;; - Removed some private stuff
390 ;; - Simplified some key bindings.
391 ;; - Changed some key bindings to those used in org-mode.
392 ;; - Added wikipedia-lang etc
393 ;; - Added support for templates
394 ;; - Adjusted header end after inserting heading/promoting/demoting
395 ;; - Removed some functions that are already supported by outline.el
396 ;; - Changed wikipedia-mode menus
397 ;; - Added support for bullets and numbering
407 ;; * Implement TeX highlighting in <math> environment
408 ;; * Implement (La)TeX input syntax, following the ideas of CDlatex.el
409 ;; * Make outline-cycle work correctly
410 ;; * wikipedia-reply-at-point-simple should use regexp!
420 (defconst wikipedia-mode-version (concat "0." (substring "$Revision: 1.5 $" 13 14))
421 "$Id: wikipedia-mode.el,v 1.5 2006/05/30 15:16:45 oub Exp oub $
423 Report bugs to: Uwe Brauer oub at mat.ucm.es")
427 ;; (defvar wikipedia-english-or-german t
428 ;; "*Variable in order to set the english (t) or german (nil) environment.")
430 (require 'tutorial) ;; for lang strings
432 (defvar wikipedia-lang "English")
434 (defvar wikipedia-langs-added nil)
435 ;;(defconst xlang-strings nil)
437 (unless wikipedia-langs-added
438 (defun add-lang-strings (lang new-strings)
439 (let ((lang-rec (assoc lang lang-strings)))
441 (dolist (str new-strings)
442 (nconc (cdr lang-rec) (list str)))
443 (setq lang-rec (cons lang new-strings))
444 (add-to-list 'lang-strings lang-rec))))
446 (add-lang-strings "English"
448 (wikip-username-prompt . "Name of user: ")
449 (wikip-image-mark . "[[Image:")
450 (wikip-media-mark . "[[Media:")
451 (wikip-utc . "(UTC)")
452 (wikip-user-mark . "[[User:")
454 (add-lang-strings "Deutsch"
456 (wikip-username-prompt . "Name des Benutzers: ")
457 (wikip-image-mark . "[[Bild:")
458 (wikip-media-mark . "[[Bild:")
459 (wikip-utc . "(CET)")
460 (wikip-user-mark . "[[Benutzer:")
462 (setq wikipedia-langs-added t))
468 (defvar wikipedia-simple-tags
469 '("b" "big" "blockquote" "br" "caption" "code" "center" "cite" "del"
470 "dfn" "dl" "em" "i" "ins" "kbd" "math" "nowiki" "ol" "pre" "samp"
471 "small" "strike" "strong" "sub" "sup" "tt" "u" "ul" "var")
472 "Tags that do not accept arguments.")
474 (defvar wikipedia-complex-tags
475 '("a" "div" "font" "table" "td" "th" "tr")
476 "Tags that accept arguments.")
478 (defvar wikipedia-url-protocols
479 '("ftp" "gopher" "http" "https" "mailto" "news")
480 "Valid protocols for URLs in Wikipedia articles.")
486 (defvar font-wikipedia-sedate-face 'font-wikipedia-sedate-face
487 "Face to use for Wikipedia minor keywords.")
489 (defvar font-wikipedia-italic-face 'font-wikipedia-italic-face
490 "Face to use for Wikipedia italics.")
491 (defvar font-wikipedia-bold-face 'font-wikipedia-bold-face
492 "Face to use for Wikipedia bolds.")
493 (defvar font-wikipedia-math-face 'font-wikipedia-math-face
494 "Face to use for Wikipedia math environments.")
495 (defvar font-wikipedia-string-face 'font-wikipedia-string-face
496 "Face to use for strings. This is set by Font Wikipedia.")
497 (defvar font-wikipedia-verbatim-face 'font-wikipedia-verbatim-face
498 "Face to use for text in verbatim macros or environments.")
503 (defface font-wikipedia-bold-face
504 (let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit bold))
505 ((assq :weight custom-face-attributes) '(:weight bold))
507 `((((class grayscale) (background light))
508 (:foreground "DimGray" ,@font))
509 (((class grayscale) (background dark))
510 (:foreground "LightGray" ,@font))
511 (((class color) (background light))
512 (:foreground "DarkOliveGreen" ,@font))
513 (((class color) (background dark))
514 (:foreground "OliveDrab" ,@font))
516 "Face used to highlight text to be typeset in bold."
517 :group 'font-wikipedia-highlighting-faces)
519 (defface font-wikipedia-italic-face
520 (let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit italic))
521 ((assq :slant custom-face-attributes) '(:slant italic))
523 `((((class grayscale) (background light))
524 (:foreground "DimGray" ,@font))
525 (((class grayscale) (background dark))
526 (:foreground "LightGray" ,@font))
527 (((class color) (background light))
528 (:foreground "DarkOliveGreen" ,@font))
529 (((class color) (background dark))
530 (:foreground "OliveDrab" ,@font))
532 "Face used to highlight text to be typeset in italic."
533 :group 'font-wikipedia-highlighting-faces)
535 (defface font-wikipedia-math-face
536 (let ((font (cond ((assq :inherit custom-face-attributes)
537 '(:inherit underline))
538 (t '(:underline t)))))
539 `((((class grayscale) (background light))
540 (:foreground "DimGray" ,@font))
541 (((class grayscale) (background dark))
542 (:foreground "LightGray" ,@font))
543 (((class color) (background light))
544 (:foreground "SaddleBrown"))
545 (((class color) (background dark))
546 (:foreground "burlywood"))
548 "Face used to highlight math."
549 :group 'font-wikipedia-highlighting-faces)
551 (defface font-wikipedia-sedate-face
552 '((((class grayscale) (background light)) (:foreground "DimGray"))
553 (((class grayscale) (background dark)) (:foreground "LightGray"))
554 (((class color) (background light)) (:foreground "DimGray"))
555 (((class color) (background dark)) (:foreground "LightGray"))
556 ;;;(t (:underline t))
558 "Face used to highlight sedate stuff."
559 :group 'font-wikipedia-highlighting-faces)
561 (defface font-wikipedia-string-face
562 (let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit italic))
563 ((assq :slant custom-face-attributes) '(:slant italic))
565 `((((type tty) (class color))
566 (:foreground "green"))
567 (((class grayscale) (background light))
568 (:foreground "DimGray" ,@font))
569 (((class grayscale) (background dark))
570 (:foreground "LightGray" ,@font))
571 (((class color) (background light))
572 (:foreground "RosyBrown"))
573 (((class color) (background dark))
574 (:foreground "LightSalmon"))
576 "Face used to highlight strings."
577 :group 'font-wikipedia-highlighting-faces)
579 (defface font-wikipedia-warning-face
580 (let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit bold))
581 ((assq :weight custom-face-attributes) '(:weight bold))
583 `((((class grayscale)(background light))
584 (:foreground "DimGray" ,@font))
585 (((class grayscale)(background dark))
586 (:foreground "LightGray" ,@font))
587 (((class color)(background light))
588 (:foreground "red" ,@font))
589 (((class color)(background dark))
590 (:foreground "red" ,@font))
592 "Face for important keywords."
593 :group 'font-wikipedia-highlighting-faces)
595 (defface font-wikipedia-verbatim-face
596 (let ((font (if (and (assq :inherit custom-face-attributes)
597 (if (featurep 'xemacs)
598 (find-face 'fixed-pitch)
599 (facep 'fixed-pitch)))
600 '(:inherit fixed-pitch)
601 '(:family "courier"))))
602 `((((class grayscale) (background light))
603 (:foreground "DimGray" ,@font))
604 (((class grayscale) (background dark))
605 (:foreground "LightGray" ,@font))
606 (((class color) (background light))
607 (:foreground "SaddleBrown" ,@font))
608 (((class color) (background dark))
609 (:foreground "burlywood" ,@font))
611 "Face used to highlight TeX verbatim environments."
612 :group 'font-wikipedia-highlighting-faces)
615 (defvar wikipedia-font-lock-keywords
618 ;; Apostrophe-style text markup
619 (cons "''''\\([^']\\|[^']'\\)*?\\(''''\\|\n\n\\)"
620 'font-lock-builtin-face)
621 (cons "'''\\([^']\\|[^']'\\)*?\\('''\\|\n\n\\)"
622 ; 'font-lock-builtin-face)
623 'font-wikipedia-bold-face)
624 (cons "''\\([^']\\|[^']'\\)*?\\(''\\|\n\n\\)"
625 'font-wikipedia-italic-face)
627 ;; Headers and dividers
628 (list "^\\(==+\\)\\(.*\\)\\(\\1\\)"
629 '(1 font-lock-builtin-face)
630 ; '(2 wikipedia-header-face)
631 '(2 font-wikipedia-sedate-face)
632 '(3 font-lock-builtin-face))
633 (cons "^-----*" 'font-lock-builtin-face)
635 ;; Bare URLs and ISBNs
636 (cons (concat "\\(^\\| \\)" (regexp-opt wikipedia-url-protocols t)
637 "://[-A-Za-z0-9._\/~%+&#?!=()@]+")
638 'font-lock-variable-name-face)
639 (cons "\\(^\\| \\)ISBN [-0-9A-Z]+" 'font-lock-variable-name-face)
641 ;; Colon indentation, lists, definitions, and tables
642 (cons "^\\(:+\\|[*#]+\\||[}-]?\\|{|\\)" 'font-lock-builtin-face)
644 (list "^\\(;\\)\\([^:\n]*\\)\\(:?\\)"
645 '(1 font-lock-builtin-face)
646 '(2 font-lock-keyword-face)
647 '(3 font-lock-builtin-face))
653 (list (concat "\\(</?\\)"
654 (regexp-opt wikipedia-simple-tags t) "\\(>\\)")
655 '(1 font-lock-builtin-face t t)
656 '(2 font-lock-function-name-face t t)
657 '(3 font-lock-builtin-face t t))
658 (list (concat "\\(</?\\)"
659 (regexp-opt wikipedia-complex-tags t)
660 "\\(\\(?: \\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?\\)\\(>\\)")
661 '(1 font-lock-builtin-face t t)
662 '(2 font-lock-function-name-face t t)
663 '(3 font-lock-keyword-face t t)
664 '(4 font-lock-builtin-face t t))
665 (cons (concat "<!-- \\([^->]\\|>\\|-\\([^-]\\|-[^>]\\)\\)*-->")
666 '(0 font-lock-comment-face t t))
672 (list (concat "\\(\\[\\)\\(\\(?:"
673 (regexp-opt wikipedia-url-protocols)
674 "\\)://[-A-Za-z0-9._\/~%-+&#?!=()@]+\\)\\(\\(?: [^]\n]*\\)?\\)\\(\\]\\)")
675 '(1 font-lock-builtin-face t t)
676 '(2 font-lock-variable-name-face t t)
677 '(3 font-lock-keyword-face t t)
678 '(4 font-lock-builtin-face t t))
684 '("\\(\\[\\[\\)\\([^]\n|]*\\)\\(|?\\)\\([^]\n]*\\)\\(\\]\\]\\)"
685 (1 font-lock-builtin-face t t)
686 (2 font-lock-variable-name-face t t)
687 (3 font-lock-builtin-face t t)
688 (4 font-lock-keyword-face t t)
689 (5 font-lock-builtin-face t t))
692 '("\\({{\\)\\(.+?\\)\\(}}\\)"
693 (1 font-lock-builtin-face t t)
694 (2 font-lock-variable-name-face t t)
695 (3 font-lock-builtin-face t t))
697 ;; Character entity references
698 (cons "&#?[a-zA-Z0-9]+;" '(0 font-lock-type-face t t))
701 (cons "^ .*$" '(0 font-lock-constant-face t t))
703 ;; Math environment (uniform highlight only, no TeX markup)
704 (list "<math>\\(\\(\n?.\\)*\\)</math>"
705 '(1 font-lock-keyword-face t t))))
711 ;;{{{ Menu and header stuff
713 (defvar wikipedia-imenu-generic-expression
714 ;;(list '(nil "^==+ *\\(.*[^\n=]\\)==+" 1))
715 (list '(nil "^=+ *\\(.*[^\n=]\\)=+" 1))
716 "Imenu expression for `wikipedia-mode'. See `imenu-generic-expression'.")
718 ;; (defun wikipedia-next-header ()
719 ;; "Move point to the end of the next section header."
721 ;; (let ((oldpoint (point)))
723 ;; (if (re-search-forward "\\(^==+\\).*\\1" (point-max) t)
724 ;; (beginning-of-line)
725 ;; (goto-char oldpoint)
726 ;; (message "No section headers after point."))))
728 ;; (defun wikipedia-prev-header ()
729 ;; "Move point to the start of the previous section header."
731 ;; (unless (re-search-backward "\\(^==+\\).*\\1" (point-min) t)
732 ;; (message "No section headers before point.")))
736 ;;{{{ Paragraph terminate and filling stuff (Chong)
738 (defun wikipedia-terminate-paragraph () ;Version:1.58
739 "New list item or paragraph.
740 In a list, start a new list item. In a paragraph, start a new
743 If the current paragraph is colon indented, the new paragraph
744 will be indented in the same way."
749 (while (cond ((looking-at "^$") nil)
750 ((looking-at "^\\(\\(?: \\|:+\\|[#*]+\\) *\\)")
751 (setq indent-chars (match-string 1)) nil)
752 ((eq (point) (point-min)) nil)
753 ((progn (forward-line -1) t)))
755 (newline) (if (not indent-chars) (newline)
756 (insert indent-chars))))
758 (defun wikipedia-terminate-paragraph-and-indent ()
759 "New list item or paragraph, ignore *,#.
760 In a list, start a new list item. In a paragraph, start a new
761 paragraph but *,# will be ignored.
763 If the current paragraph is colon ; indented, the new paragraph
764 will be indented in the same way."
769 (while (cond ((looking-at "^$") nil)
770 ((looking-at "^\\(\\(?: \\|:+\\) *\\)")
771 (setq indent-chars (match-string 1)) nil)
772 ((eq (point) (point-min)) nil)
773 ((progn (forward-line -1) t)))
775 (newline) (if (not indent-chars) (newline)
776 (insert indent-chars))))
779 (defun wikipedia-link-fill-nobreak-p ()
780 "Function for `fill-nobreak-predicate'.
781 When filling, don't break the line for preformatted (fixed-width)
782 text or inside a Wiki link."
785 (or (eq (char-after (line-beginning-position)) ? )
786 (if (re-search-backward "\\[\\[" (line-beginning-position) t)
787 ;; Break if the link is really really long.
788 ;; You often get this with captioned images.
789 (null (or (> (- pos (point)) fill-column)
790 (re-search-forward "\\]\\]" pos t))))))))
792 (defun wikipedia-fill-article ()
793 "Fill the entire article."
796 (fill-region (point-min) (point-max))))
798 (defun wikipedia-unfill-article ()
800 Undo filling, deleting stand-alone newlines (newlines that do not
801 end paragraphs, list entries, etc.)"
804 (goto-char (point-min))
805 (while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
806 (replace-match " " nil nil nil 1)))
807 (message "Stand-alone newlines deleted"))
810 (defun wikipedia-unfill-paragraph-with-newline (&optional justifyp)
812 (let ((before (point))) ;Version:1.3
815 (or (bolp) (newline 1))
817 (start (progn (backward-paragraph) (point))))
819 (while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
820 (replace-match " " nil nil nil 1))))))
821 ; (message "Stand-alone newlines IN PARAGRAPH deleted"))
823 (defun wikipedia-unfill-region ()
825 Undo filling, deleting stand-alone newlines (newlines that do not
826 end paragraphs, list entries, etc.) see also the function
827 \\[wikipedia-unfill-paragraph-or-region] and the even simpler
828 function \\[wikipedia-unfill-paragraph-simple]."
831 (narrow-to-region (point) (mark))
832 (goto-char (point-min))
833 (while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
834 (replace-match " " nil nil nil 1)))
835 (message "Stand-alone newlines deleted")
840 ;;{{{ Main function wikipedia mode (using define-derived mode)
843 ;; (defvar wikipedia-outline-map
844 ;; (let ((map (make-sparse-keymap)))
845 ;; (define-key map [(down)] 'outline-next-visible-heading)
846 ;; (define-key map [(up)] 'outline-previous-visible-heading)
847 ;; (define-key map "n" 'outline-next-visible-heading)
848 ;; (define-key map "p" 'outline-previous-visible-heading)
849 ;; (define-key map "f" 'outline-forward-same-level)
850 ;; (define-key map "b" 'outline-backward-same-level)
851 ;; (define-key map "u" 'outline-up-heading)
852 ;; (define-key map "/" 'org-occur)
853 ;; (define-key map "\C-c\C-n" 'outline-next-visible-heading)
854 ;; (define-key map "\C-c\C-p" 'outline-previous-visible-heading)
855 ;; (define-key map "\C-c\C-f" 'outline-forward-same-level)
856 ;; (define-key map "\C-c\C-b" 'outline-backward-same-level)
857 ;; (define-key map "\C-c\C-u" 'outline-up-heading)
861 (defvar wikipedia-mode-map
862 (let ((map (make-sparse-keymap)))
863 ;;(define-key map "\M-n" 'wikipedia-next-header)
864 (define-key map "\C-c\C-n" 'wikipedia-next-long-line)
865 ;; (define-key map "\M-p" 'wikipedia-prev-header)
866 ;; (define-key map [(meta down)] 'wikipedia-next-header)
867 ;; (define-key map [(meta up)] 'wikipedia-prev-header)
868 (define-key map "\C-j" 'wikipedia-terminate-paragraph)
869 ;;(define-key map "RET" 'wikipedia-newline)
870 (define-key map [(shift return)] 'wikipedia-newline)
872 ;;(define-key mm [separator-format] '("--"))
873 ;; (define-key mm [outline]
874 ;; '("Toggle Outline Mode..." . outline-minor-mode))
875 ;;(define-key mm [separator-edit-structure] '("--"))
879 ;;(define-key map "\C-c\C-q" 'wikipedia-unfill-article)
880 (define-key map "\C-c\M-qua" 'wikipedia-unfill-article)
881 ;;(define-key map "\C-c\M-q" 'wikipedia-fill-article)
882 (define-key map "\C-c\M-qfa" 'wikipedia-fill-article)
883 ;;(define-key map "\M-u" 'wikipedia-unfill-paragraph-or-region)
884 (define-key map "\C-c\M-qur" 'wikipedia-unfill-paragraph-or-region)
885 ;;(define-key map "\C-c\C-u" 'wikipedia-unfill-paragraph-simple)
886 (define-key map "\C-c\M-qup" 'wikipedia-unfill-paragraph-simple)
888 (define-key map "\C-c\C-fs" 'wikipedia-insert-bold-italic)
889 (define-key map "\C-c\C-fb" 'wikipedia-insert-bold) ;Version:1.3
890 (define-key map "\C-c\C-fi" 'wikipedia-insert-italics)
891 (define-key map "\C-c\C-fn" 'wikipedia-insert-nowiki)
893 (define-key map "\C-c\C-ts" 'wikipedia-insert-signature)
894 (define-key map "\C-c\C-tt" 'wikipedia-insert-template)
895 (define-key map "\C-c\C-tu" 'wikipedia-insert-user)
896 ;;(define-key map "\C-c\C-fq" 'wikipedia-insert-quotation)
897 ;;(define-key map "\C-c\C-fh" 'wikipedia-insert-header)
898 (define-key map "\C-c\C-fr" 'wikipedia-insert-hline) ;Version:1.30
899 (define-key map "\C-c\C-li" 'wikipedia-insert-link-wiki)
900 (define-key map "\C-c\C-le" 'wikipedia-insert-link-external)
902 ;; Breaks key binding conventions:
903 ;;(define-key map [(meta f7)] 'wikipedia-draft)
904 ;;(define-key map [(meta f8)] 'wikipedia-reply-at-point-simple)
905 ;;(define-key map [(meta f9)] 'wikipedia-draft-view-draft)
907 (define-key map "\C-c\C-r" 'wikipedia-reply-at-point-simple)
909 ;; Breaks key binding conventions:
910 ;;(define-key map "\C-cr" 'wikipedia-draft-region)
912 (define-key map [(meta r)] 'wikipedia-draft-reply)
913 (define-key map "\C-c\C-m" 'wikipedia-draft) ;Version:1.25
914 (define-key map "\C-c\C-b" 'wikipedia-draft-region)
915 (define-key map "\C-c\C-d" 'wikipedia-draft-buffer)
916 (define-key map "\C-c\C-k" 'wikipedia-draft-buffer)
917 (define-key map "\C-c\C-p" 'wikipedia-draft-copy-page-to-register) ;Version:1.39
918 ;; (define-key map "\C-c\C-c" 'wikipedia-draft-send-to-mozex)
919 (define-key map "\C-c\C-s" 'wikipedia-draft-yank-page-to-register)
921 (define-key map [(control meta prior)] 'wikipedia-enhance-indent)
922 (define-key map [(control meta next)] 'wikipedia-yank-prefix)
923 (define-key map [(meta return)] 'wikipedia-insert-enumerate)
924 (define-key map [(meta control return)] 'wikipedia-insert-enumerate-nonewline)
926 ;; This is bound to C-j by default:
927 ;;(define-key map [(shift return)] 'newline-and-indent) ;Version:1.24
928 (define-key map "\C-\\" 'wikipedia-insert-itemize) ;Version:1.28
929 (define-key map [(control return)] 'wikipedia-insert-itemize)
931 ;; The next three breaks Emacs key binding conventions, are they really necessary?
932 ;;(define-key map "\C-ca" 'auto-capitalize-mode)
933 ;;(define-key map "\C-ci" 'set-input-method)
934 ;;(define-key map "\C-ct" 'toggle-input-method) ;Version:1.23
936 (define-key map [(shift tab)] 'org-shifttab)
937 (define-key map [backtab] 'org-shifttab)
938 (define-key map [tab] 'org-cycle)
942 (defvar wikipedia-org-menu nil)
944 (easy-menu-define wikipedia-org-menu wikipedia-mode-map "Wikipedia menu"
947 ["Cycle Visibility" org-cycle (or (bobp) (outline-on-heading-p))]
948 ["Cycle Global Visibility" org-shifttab]
949 ["Sparse Tree" org-occur t]
950 ["Reveal Context" org-reveal t]
951 ["Show All" show-all t]
953 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
955 ["New Heading" outline-insert-heading t]
957 ["Up" outline-up-heading t]
958 ["Next" outline-next-visible-heading t]
959 ["Previous" outline-previous-visible-heading t]
960 ["Next Same Level" outline-forward-same-level t]
961 ["Previous Same Level" outline-backward-same-level t]
965 ["Move Subtree Up" outline-move-subtree-up]
966 ["Move Subtree Down" outline-move-subtree-down]
968 ["Copy Subtree" org-copy-special]
969 ["Cut Subtree" org-cut-special]
970 ["Paste Subtree" org-paste-special]
972 ["Promote Heading" wikipedia-simple-outline-promote]
973 ["Promote Subtree" outline-promote]
974 ["Demote Heading" wikipedia-simple-outline-demote]
975 ["Demote Subtree" outline-demote])
977 ["Unfill article" wikipedia-unfill-article]
978 ["Fill article" wikipedia-fill-article])
981 ["Horizontal line" wikipedia-insert-hline]
983 ["Indent Paragraph" wikipedia-indent-paragraph]
984 ["Deindent Paragraph" wikipedia-deindent-paragraph]
986 ["Insert No Wiki Formatting" wikipedia-insert-nowiki]
987 ["Bold-Italic" wikipedia-insert-bold-italic]
988 ["Italic" wikipedia-insert-italics]
989 ["Bold" wikipedia-insert-bold]
993 ["Site Specific Template" wikipedia-insert-template]
994 ["Signature" wikipedia-insert-signature]
997 ["External Link" wikipedia-insert-link-external]
998 ["Internal Wiki Link" wikipedia-insert-link-wiki]
1000 ("Bullets and numbering"
1001 ["Bullet" wikipedia-insert-bullet]
1002 ["Numbering" wikipedia-insert-numbering]
1010 ;;{{{ Main function wikipedia-mode
1012 (define-derived-mode wikipedia-mode outline-mode "Wikipedia"
1013 "Major mode for editing wikimedia style wikis.
1014 Major mode for editing articles written in the markup language
1015 used by Wikipedia, the free on-line
1016 encyclopedia (see URL `http://www.wikipedia.org').
1018 There are several ways to use wikipedia-mode:
1020 - You can simply cut and paste articles between Emacs and your
1021 web browser's text box.
1022 - If you are using Firefox you can use the It's All Text add-on
1024 - You can use MozEx, a Mozilla/Firefox web browser extension that
1025 allows you to call Emacs from a text
1026 box (see URL `http://mozex.mozdev.org/').
1027 - Another way is to use the PERL script ee-helper, which allows
1028 you to up and download wiki texts.
1030 Wikipedia articles are usually unfilled: newline characters are not
1031 used for breaking paragraphs into lines. Unfortunately, Emacs does not
1032 handle word wrapping yet. As a workaround, wikipedia-mode turns on
1033 longlines-mode automatically. In case something goes wrong, the
1034 following commands may come in handy:
1036 \\[wikipedia-fill-article] fills the buffer.
1037 \\[wikipedia-unfill-article] unfills the buffer.
1038 Be warned that function can be dead slow, better use wikipedia-unfill-paragraph-or-region.
1039 \\[wikipedia-unfill-paragraph-or-region] unfills the paragraph
1040 \\[wikipedia-unfill-paragraph-simple] doehe same but simpler.
1044 The following commands put in markup structures.
1046 \\[wikipedia-insert-bold-italic] bold+italic
1047 \\[wikipedia-insert-bold] bold text
1048 \\[wikipedia-insert-italics] italics
1049 \\[wikipedia-insert-nowiki] no wiki markup
1050 \\[wikipedia-insert-link-wiki] inserts a link
1052 The following commands are also defined:
1053 \\[wikipedia-insert-user] inserts user name
1054 \\[wikipedia-insert-signature] inserts ~~~~
1055 \\[wikipedia-insert-enumerate] inserts enumerate type structures
1056 \\[wikipedia-insert-itemize] inserts itemize type structures
1057 \\[wikipedia-insert-hline] inserts a hline
1059 The draft functionality
1061 \\[wikipedia-draft-region]
1062 \\[wikipedia-draft-view-draft]
1063 \\[wikipedia-draft-page]
1064 \\[wikipedia-draft-buffer]
1066 Replying and sending functionality
1067 \\[wikipedia-reply-at-point-simple]
1068 \\[wikipedia-draft-reply]
1071 The register functionality
1072 \\[wikipedia-copy-page-to-register]
1073 \\[defun wikipedia-insert-page-to-register]
1076 Some simple editing commands.
1077 \\[wikipedia-enhance-indent]
1078 \\[wikipedia-yank-prefix]
1079 \\[wikipedia-unfill-paragraph-or-region]
1083 \\[wikipedia-terminate-paragraph] starts a new list item or paragraph in a context-aware manner."
1085 (set (make-local-variable 'adaptive-fill-regexp) "[ ]*")
1086 (set (make-local-variable 'comment-start-skip) "\\(?:<!\\)?-- *")
1087 (set (make-local-variable 'comment-end-skip) " *--\\([ \n]*>\\)?")
1088 (set (make-local-variable 'comment-start) "<!-- ")
1089 (set (make-local-variable 'comment-end) " -->")
1090 (set (make-local-variable 'paragraph-start)
1091 "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")
1092 (set (make-local-variable 'sentence-end-double-space) nil)
1093 (set (make-local-variable 'font-lock-multiline) t)
1094 (set (make-local-variable 'font-lock-defaults)
1095 '(wikipedia-font-lock-keywords t nil nil nil))
1096 (set (make-local-variable 'fill-nobreak-predicate)
1097 'wikipedia-link-fill-nobreak-p)
1098 (set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]")
1100 ;; Support for outline-minor-mode. No key conflicts, so we'll use
1101 ;; the normal outline-mode prefix.
1102 ;;(set (make-local-variable 'outline-regexp) "==+")
1103 (set (make-local-variable 'outline-regexp) "=+")
1104 ;;(set (make-local-variable 'outline-heading-end-regexp) "=+") ;; For betting fixing
1105 ;; (set (make-local-variable 'outline-regexp) "=+")
1106 ;; (set (make-local-variable 'outline-regexp) ":")
1108 ;; Fix-me: Why change this?? Should not the user do this globally instead?
1109 ;;(set (make-local-variable 'outline-minor-mode-prefix) "\C-c\C-o")
1111 ;; Fix-mde For longlines-mode??:
1112 (set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]")
1115 ;; Get rid of Outline menus, they are not needed
1116 ;; Need to do this here because define-derived-mode sets up
1117 ;; the keymap so late. Still, it is a waste to call this each time
1118 ;; we switch another buffer into org-mode.
1119 (if (featurep 'xemacs)
1120 (when (boundp 'outline-mode-menu-heading)
1121 ;; Assume this is Greg's port, it used easymenu
1122 (easy-menu-remove outline-mode-menu-heading)
1123 (easy-menu-remove outline-mode-menu-show)
1124 (easy-menu-remove outline-mode-menu-hide))
1125 (define-key wikipedia-mode-map [menu-bar headings] 'undefined)
1126 (define-key wikipedia-mode-map [menu-bar hide] 'undefined)
1127 (define-key wikipedia-mode-map [menu-bar show] 'undefined))
1129 (easy-menu-add wikipedia-org-menu)
1131 ;; Turn on the Imenu automatically.
1132 ;; (when menu-bar-mode
1133 ;; (set (make-local-variable 'imenu-generic-expression)
1134 ;; wikipedia-imenu-generic-expression)
1135 ;; (imenu-add-to-menubar "TOC"))
1137 (modify-syntax-entry ?< "(>" wikipedia-mode-syntax-table)
1138 (modify-syntax-entry ?> ")<" wikipedia-mode-syntax-table)
1142 ;;; This is the wrong way to do it, see add-hook:
1143 ;; (make-local-variable 'change-major-mode-hook)
1145 ;; Check if our version of outline.el has the new header hooks:
1147 (when (boundp 'outline-demote-hook)
1148 (add-hook 'outline-demote-hook 'wikipedia-outline-insert-heading-f nil t)
1149 (add-hook 'outline-promote-hook 'wikipedia-outline-insert-heading-f nil t)
1150 (add-hook 'outline-insert-heading-hook 'wikipedia-outline-insert-heading-f nil t)
1154 (defun wikipedia-outline-insert-heading-f ()
1157 (wikipedia-adjust-header-end))
1159 ;; wikipedia-mode ends here
1162 ;;{{{ longlines-mode
1164 (defun wikipedia-turn-on-longlines () ;Version:1.58
1165 "Turn on longlines-mode if it is defined."
1166 (if (functionp 'longlines-mode)
1167 (longlines-mode 1)))
1169 (defcustom wikipedia-use-longlines-mode nil
1170 "Turn on longlines-mode' if non-nil.
1171 Unfortunately there are some bugs in `longlines-mode' so turning
1172 it on is an option currently."
1174 :set (lambda (sym val)
1175 (set-default sym val)
1177 (add-hook 'wikipedia-mode-hook 'wikipedia-turn-on-longlines)
1178 (remove-hook 'wikipedia-mode-hook 'wikipedia-turn-on-longlines)))
1183 ;; New formating stuff for inserting simple formating structures such
1185 ;;{{{ Insert makeup and templates
1187 (defvar wikipedia-enumerate-with-terminate-paragraph nil
1188 "*Before insert enumerate/itemize do \\[wikipedia-terminate-paragraph].")
1190 (defun wikipedia-region-active-p ()
1191 (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
1192 (and (boundp 'transient-mark-mode) transient-mark-mode mark-active)))
1194 (defun wikipedia-insert-around-region (before after)
1195 (if (wikipedia-region-active-p)
1197 (let ((beginning (region-beginning))
1199 (check (= (string-to-char before) ?')))
1200 ;; When we are inserting ' do not mix them:
1203 (append (buffer-substring-no-properties
1204 beginning end) nil))))
1208 (goto-char beginning)
1210 (message "Sorry, the region already contains the char '.")
1214 (backward-char (length after))))
1216 (defun wikipedia-insert-enumerate ()
1217 "Insert enumerated items.
1218 Format depends on `wikipedia-enumerate-with-terminate-paragraph'.
1219 Note however that `wikipedia-terminate-paragraph' does not work
1220 very well will longlines-mode."
1222 (if wikipedia-enumerate-with-terminate-paragraph
1224 (wikipedia-terminate-paragraph)
1233 (defun wikipedia-insert-itemize ()
1234 "Insert not enumerated items.
1235 Format depends on `wikipedia-enumerate-with-terminate-paragraph'.
1236 Note however that the `wikipedia-terminate-paragraph' does not
1237 work very well will longlines-mode."
1239 (if wikipedia-enumerate-with-terminate-paragraph
1241 (wikipedia-terminate-paragraph)
1247 (defun wikipedia-insert-bold-italic ()
1248 "Insert strong emphasis.
1249 Uses four apostrophes (e.g. ''''FOO''''.) When mark is active, surrounds region."
1251 (wikipedia-insert-around-region "''''" "''''"))
1254 (defun wikipedia-insert-bold ()
1256 Uses three apostrophes (e.g. '''FOO'''.) When mark is active,
1259 (wikipedia-insert-around-region "'''" "'''"))
1262 (defun wikipedia-insert-italics ()
1264 Uses two apostrophes (e.g. ''FOO''.) When mark is active,
1267 (wikipedia-insert-around-region "''" "''"))
1269 (defun wikipedia-indent-paragraph ()
1271 (backward-paragraph)
1273 (defun wikipedia-deindent-paragraph ()
1279 ;; http://en.wikipedia.org/wiki/Template:Quotation
1280 ;; http://en.wikipedia.org/wiki/Help:A_quick_guide_to_templates
1281 (defvar wikipedia-site nil)
1282 (make-variable-buffer-local 'wikipedia-site)
1283 (defvar wikipedia-site-history nil)
1285 (defcustom wikipedia-templates nil
1286 "Templates for different wikis."
1287 :type '(repeat (list
1288 (string :tag "Wiki site")
1291 (string :tag "Template name")
1292 (string :tag "Template code")))))
1295 (defun wikipedia-insert-template ()
1296 "Prompts for a template and inserts it."
1298 (let* ((t-name-code (wikipedia-get-template))
1299 (t-name (car t-name-code))
1300 ;; Ask how to insert:
1301 (choices '("Evaluate when page is created"
1302 "Substitute when saving this source page"
1303 "Show template when page is fetched"
1304 "Insert template itself"))
1305 (hist (copy-sequence choices))
1306 (default (car choices))
1307 (choice (completing-read
1308 "How do you want to insert the template? "
1314 ;; (lwarn 't :warning "t-name=%s" t-name)
1315 ;; (lwarn 't :warning "choice=%s" choice)
1316 ;; (lwarn 't :warning "0=%s" (nth 0 choices))
1317 ;; (lwarn 't :warning "1=%s" (nth 1 choices))
1318 ;; (lwarn 't :warning "2=%s" (nth 2 choices))
1320 ((string= choice (nth 0 choices))
1321 ;;(lwarn 't :warning "evaluate=>%s" (concat "{{" t-name "}}"))
1322 (insert "{{" t-name "}}")
1324 ((string= choice (nth 1 choices))
1325 ;;(lwarn 't :warning "subst=>%s" (concat "{{subst:" t-name "}}"))
1326 (insert "{{subst:" t-name "}}")
1328 ((string= choice (nth 2 choices))
1329 ;;(lwarn 't :warning "raw=>%s" (concat "{{msgnw:" t-name "}}"))
1330 (insert "{{msgnw:" t-name "}}")
1332 ((string= choice (nth 3 choices))
1333 (insert (cdr t-name-code))
1336 (defun wikipedia-get-template ()
1337 (let* ((sites (mapcar (lambda (t-sites)
1339 wikipedia-templates))
1340 (hist (copy-sequence sites))
1341 (default-site wikipedia-site)
1342 (histpos (if (not default-site)
1348 (when (string= default-site elt)
1349 (throw 'pos n)))))))
1350 (site (if (= 1 (length sites))
1352 (completing-read "Wiki site: "
1357 (cons 'hist histpos))))
1358 (s-t (assoc site wikipedia-templates))
1359 (templates (car (cdr s-t)))
1360 (t-names (mapcar (lambda (t-for-site)
1361 ;;(lwarn 't :warning "t-for-site=%s" t-for-site)
1364 (t-name (wikipedia-get-template-name site templates))
1365 (code (car (cdr (assoc t-name templates))))
1367 (setq wikipedia-site site)
1368 ;; (lwarn 't :warning "site=%s" site)
1369 ;; (lwarn 't :warning "s-t=%s" s-t)
1370 ;; (lwarn 't :warning "templates=%s" templates)
1371 ;; (lwarn 't :warning "t-names=%s" t-names)
1372 ;; (lwarn 't :warning "t-name=%s" t-name)
1373 ;; (lwarn 't :warning "code=%s" code)
1374 (cons t-name code)))
1376 (defun wikipedia-get-template-name (site templates)
1378 (let* ((prompt "Template: ")
1379 (minibuffer-local-must-match-map (copy-keymap minibuffer-local-must-match-map))
1380 (hist (mapcar (lambda (elt)
1383 (desc-fun (lambda ()
1384 (let ((s (minibuffer-contents-no-properties)))
1385 (when (< 0 (length s))
1386 (wikipedia-describe-template s site templates)))))
1387 (up-fun (lambda () (interactive)
1388 (previous-history-element 1)
1389 (funcall desc-fun)))
1390 (down-fun (lambda () (interactive)
1391 (next-history-element 1)
1392 (funcall desc-fun)))
1394 (histpos (if (not default) 1))
1395 (default-name (if default
1397 (car (nth (1- histpos) templates))))
1400 (define-key minibuffer-local-must-match-map [up] up-fun)
1401 (define-key minibuffer-local-must-match-map [down] down-fun)
1402 (save-window-excursion
1403 (wikipedia-describe-template default-name site templates)
1404 (setq tpl-name (completing-read prompt
1408 default-name ;; initial-input
1409 (cons 'hist histpos) ;; hist
1411 (when (= 0 (length tpl-name))
1412 (error "No template name given"))
1413 (let ((tpl (assoc tpl-name templates)))
1415 (error "There is no template named %s for site %s" tpl-name site))
1416 ;;(lwarn 't :warning "tpl=%s" tpl)
1420 (defun wikipedia-describe-template (name site templates)
1421 (let ((tpl-rec (assoc name templates)))
1422 (with-output-to-temp-buffer (help-buffer)
1423 (with-current-buffer (help-buffer)
1424 (help-setup-xref (list #'wikipedia-describe-template name site templates) (interactive-p))
1425 (let ((inhibit-read-only t)
1428 (tpl (assoc name templates)))
1429 ;;(insert (format "%S\n\n" family))
1430 (insert (format "%s - a wiki template for site %s" name site))
1432 (setq start (point))
1435 (with-no-warnings (print-help-return-message))
1436 ;;(put-text-property start end 'face 'highlight)
1439 (while (re-search-forward "\\(?:<onlyinclude>\\|</onlyinclude>\\|<noinclude>.*</noinclude>\\)" end t)
1440 (put-text-property here (match-beginning 0) 'face 'highlight)
1443 (put-text-property (point) end 'face 'highlight)
1446 (defun wikipedia-insert-nowiki ()
1447 "Mark the region as 'nowiki'.
1448 When mark is active, surrounds region."
1450 (wikipedia-insert-around-region "<nowiki>" "</nowiki>"))
1454 (defun wikipedia-insert-user ()
1455 "Prompt for a user name, insert [[User:foo]]"
1457 (let ((user (read-string (get-lang-string wikipedia-lang 'wikip-username-prompt)))
1458 (user-mark (get-lang-string wikipedia-lang 'wikip-user-mark)))
1459 (insert (concat user-mark user "|" user "]]"))))
1461 (defun wikipedia-insert-signature () ;Version:1.4
1463 This will be shown as your user identity when showing the page."
1469 (defun wikipedia-insert-reply-prefix () ;Version:1.60
1470 "Quotation box of the form {{Quotation}}{{}}. When mark is active,
1473 (beginning-of-line 1)
1474 (search-forward "[[")
1477 (copy-to-register wikipedia-draft-reply-register (region-beginning) (region-end) nil)
1479 (wikipedia-terminate-paragraph)
1480 (beginning-of-line 1)
1486 (insert-register wikipedia-draft-reply-register 1)
1490 ;; (defun wikipedia-insert-header ()
1491 ;; "Insert subheader via == (e.g. == FOO ==.)"
1494 ;; (beginning-of-line))
1498 ;; (backward-char 3))
1500 (defvar wikipedia-link-wiki-history nil)
1502 (defun wikipedia-insert-link-wiki ()
1503 "Insert link via [[ (e.g. [[FOO]].) When mark is active, surround region."
1505 (if (wikipedia-region-active-p)
1506 (wikipedia-insert-around-region "[[" "]]")
1507 (let* ((link (read-string "Wiki link: " nil wikipedia-link-wiki-history))
1508 (name (read-string "Name (optional): ")))
1510 (when (< 0 (length name))
1514 (defun wikipedia-insert-link-external ()
1515 "Insert link via [[ (e.g. [http://FOO].) When mark is active, surround region."
1517 (if (wikipedia-region-active-p)
1518 (wikipedia-insert-around-region "[" "]")
1519 (let* ((choices '("Plain" "Footnote" "Named"))
1520 (hist (copy-sequence choices))
1521 (style (completing-read
1522 "Link style: " ; prompt
1523 choices ; collection
1526 "Plain" ; initial-input
1527 (cons 'hist 1) ; hist
1529 (url (read-string "URL: "))
1531 ;;(lwarn 't :warning "style=%s" style)
1533 ((string= style "Plain")
1535 ((string= style "Footnote")
1536 (insert "[" url "]"))
1537 ((string= style "Named")
1538 (let ((name (read-string "Link name: ")))
1540 (when (< 0 (length name))
1544 (error "Internal error, bad style=%s" style))))))
1547 (defun wikipedia-insert-image ()
1548 "Insert link image, e.g. [[Image:FOO]].
1549 When mark is active, surround region."
1551 (let ((img-mark (get-lang-string wikipedia-lang 'wikip-image-mark)))
1552 (wikipedia-insert-around-region img-mark "]]")))
1554 (defun wikipedia-insert-audio ()
1555 "Insert audio link, e.g. [[Media:FOO]].
1556 When mark is active, surround region."
1558 (let ((aud-mark (get-lang-string wikipedia-lang 'wikip-audio-mark)))
1559 (wikipedia-insert-around-region aud-mark "]]")))
1564 ;; (defun wikipedia-turn-on-outline-minor-mode ()
1565 ;; "Turn on outline minor mode."
1567 ;; (outline-minor-mode nil))
1574 (defun wikipedia-insert-hline () ;Version:1.29
1578 (insert hard-newline "----" hard-newline))
1580 (defun wikipedia-newline (&optional arg)
1581 "Insert newline and check for bullets and numbering."
1583 (let ((here (point))
1586 (when (eq ?* (char-after))
1587 (setq line-type 'bullet))
1588 (when (eq ?# (char-after))
1589 (setq line-type 'numbered))
1591 (looking-at ".\\s-*$"))
1593 (delete-region (match-beginning 0) (match-end 0))
1598 ((eq line-type 'bullet)
1600 ((eq line-type 'numbered)
1605 ;;{{{ bullets and numbering
1607 ;; Fix-me: Seems like this and my newline stuff already was there ... ;-)
1608 (defun wikipedia-insert-bullet ()
1615 (defun wikipedia-insert-numbering ()
1624 ;;{{{ filling and longline
1626 (defun wikipedia-unfill-paragraph-or-region () ;Version:1.7
1628 This function does NOT explicitly search for \"soft newlines\" as
1629 does wikipedia-unfill-region."
1631 (when use-hard-newlines
1632 ;; (backward-paragraph 1)
1634 (beginning-of-line 1)
1636 ;; Fix-me: The use of make-local-variable here looks incorrect,
1637 ;; use lexical binding instead:
1638 ;; (set (make-local-variable 'use-hard-newlines) nil)
1639 ;; (set (make-local-variable 'sentence-end-double-space) t)
1640 ;; (set (make-local-variable 'paragraph-start) "[   \n
\f]")
1641 (let ((use-hard-newlines nil)
1642 (sentence-end-double-space t)
1643 (paragraph-start nil))
1644 (when (featurep 'xemacs)
1645 (let ((fill-column (point-max)))
1646 (fill-paragraph-or-region nil)))
1647 (unless (featurep 'xemacs)
1648 (let ((fill-column (point-max)))
1649 (fill-paragraph nil)))))
1650 ;; (set (make-local-variable 'use-hard-newlines) t)
1651 ;; (set (make-local-variable 'sentence-end-double-space) nil)
1652 ;; (set (make-local-variable 'paragraph-start) "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$"))
1653 (unless use-hard-newlines
1654 ;; (backward-paragraph 1)
1656 (beginning-of-line 1)
1658 ;; (set (make-local-variable 'sentence-end-double-space) t)
1659 ;; (set (make-local-variable 'paragraph-start)
1660 (let ((sentence-end-double-space t)
1661 (paragraph-start nil))
1662 (when (featurep 'xemacs)
1663 (let ((fill-column (point-max)))
1664 (fill-paragraph-or-region nil)))
1665 (unless (featurep 'xemacs)
1666 (let ((fill-column (point-max)))
1667 (fill-paragraph nil))))
1668 ;; (set (make-local-variable 'sentence-end-double-space) nil)
1669 ;; (set (make-local-variable 'paragraph-start) "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")
1675 ;; (defun wikipedia-start-paragraph ()
1677 ;; (set (make-local-variable 'paragraph-start)
1678 ;; "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$"))
1680 ;; Use function use-hard-newlines instead:
1681 ;; (defun wikipedia-hardlines ()
1682 ;; "Set use-hard-newlines to NIL."
1684 ;; (setq use-hard-newlines nil))
1687 (defun wikipedia-next-long-line ()
1688 "Move forward to the next long line with column-width greater
1691 TODO: When function reaches end of buffer, save-excursion to
1693 Generalise to make `previous-long-line'."
1695 ;; global-variable: fill-column
1696 (if (= (forward-line) 0)
1701 (if (<= line-length fill-column)
1702 (wikipedia-next-long-line)
1703 (message "Long line found")))
1704 ;; Stop, end of buffer reached.
1705 (error "Long line not found")))
1708 (defun wikipedia-unfill-paragraph-simple ()
1709 "A very simple function for unfilling a paragraph."
1711 (if (functionp 'filladapt-mode)
1712 (filladapt-mode nil))
1713 (let ((fill-column (point-max)))
1714 (fill-paragraph nil)
1715 (if (functionp 'filladapt-mode)
1716 (filladapt-mode nil))))
1720 ;;{{{ outline and outline-magic stuff
1722 ;;(add-hook 'wikipedia-mode-hook 'wikipedia-turn-on-outline-minor-mode)
1723 ;;(remove-hook 'wikipedia-mode-hook 'wikipedia-turn-on-outline-minor-mode)
1725 (defun wikipedia-outline-cycle ()
1727 (if (functionp 'outline-cycle)
1730 ;; Fix-me: Unfortunately outline maybe does not take care of the
1731 ;; heading endings when promoting and demoting (I have submitted a bug
1732 ;; report for this and hooks will be added). To work around this we
1733 ;; defadvice outline-demote/promote:
1736 (unless (boundp 'outline-demote-hook)
1738 (defadvice outline-demote (after wikipedia-outline-demote-advice
1740 "Adjust heading after demote."
1742 (wikipedia-adjust-header-end)))
1744 (defadvice outline-promote (after wikipedia-outline-promote-advice
1746 "Adjust heading after promote."
1748 (wikipedia-adjust-header-end)))
1750 (defadvice outline-insert-heading (after wikipedia-outline-insert-heading-advice
1752 "Adjust heading after insert new heading."
1753 (wikipedia-adjust-header-end))
1757 (defun wikipedia-adjust-header-end ()
1758 (when (eq major-mode 'wikipedia-mode)
1759 (let ((here (point))
1760 (end-pos (line-end-position))
1767 (when (looking-at outline-regexp)
1768 (setq bgn-mark (match-string-no-properties 0))
1769 (setq bgn-len (length bgn-mark))
1771 (if (looking-back outline-regexp nil t)
1773 (setq end-mark (match-string-no-properties 0))
1774 (setq end-len (length end-mark))
1775 (/= end-len bgn-len))
1776 (replace-match bgn-mark))
1778 ;;(lwarn 't :warning "bgn-len=%s, end-len=%s" bgn-len end-len)
1783 ;;(add-hook 'outline-minor-mode-hook 'wikipedia-outline-magic-keys)
1784 (add-hook 'wikipedia-mode-hook 'wikipedia-outline-magic-keys)
1786 (defun wikipedia-outline-magic-keys ()
1788 (unless (featurep 'xemacs)
1789 (local-set-key [(shift iso-lefttab)] 'wikipedia-outline-cycle))
1790 (local-set-key [iso-left-tab] 'wikipedia-outline-cycle)
1791 ;;(local-set-key [(meta left)] 'outline-promote)
1792 (local-set-key [(meta shift left)] 'outline-promote)
1793 ;;(local-set-key [(meta right)] 'outline-demote)
1794 (local-set-key [(meta shift right)] 'outline-demote)
1795 ;;(local-set-key [(control left)] 'wikipedia-simple-outline-promote)
1796 (local-set-key [(meta left)] 'wikipedia-simple-outline-promote)
1797 ;;(local-set-key [(control right)] 'wikipedia-simple-outline-demote)
1798 (local-set-key [(meta right)] 'wikipedia-simple-outline-demote)
1799 (local-set-key [(shift return)] 'newline-and-indent)
1800 ;;(local-set-key [(control up)] 'outline-move-subtree-up)
1801 (local-set-key [(meta shift up)] 'outline-move-subtree-up)
1802 ;;(local-set-key [(control down)] 'outline-move-subtree-down))
1803 (local-set-key [(meta shift down)] 'outline-move-subtree-down))
1805 (defun wikipedia-enhance-indent () ;Version:1.26
1807 (string-rectangle (region-beginning) (region-end) ":"))
1809 (defun wikipedia-yank-prefix () ;Version:1.26
1811 (string-rectangle (region-beginning) (region-end) ":"))
1813 ;; modification for outline-magic
1815 (defun wikipedia-simple-outline-promote ()
1816 "Function simple deletes \"=\" and the end and the beginning of line,
1817 does not promote the whole tree!"
1821 (beginning-of-line 1)
1822 (search-forward "=")
1825 (search-backward "=")
1826 (delete-char 1 nil))))
1828 (defun wikipedia-simple-outline-demote ()
1829 "Function simple adds \"=\" and the end and the beginning of line,
1830 does not promote the whole tree!"
1834 (beginning-of-line 1)
1835 (search-forward "=")
1838 (search-backward "=")
1842 (defun wikipedia-rename-buffer () ;Version:1.5
1843 "Make sure that the option UNIQUE is used."
1845 (rename-buffer (read-string "Name of new buffer (unique): " ) 1))
1849 ;;{{{ wikipedia drafts functionality: `stolen' from remember.el:
1851 (defgroup wikipedia-draft nil
1852 "A mode to wikipedia-draft information."
1857 (defcustom wikipedia-draft-mode-hook nil
1858 "*Functions run upon entering wikipedia-draft-mode."
1860 :group 'wikipedia-draft)
1862 (defcustom wikipedia-draft-register ?R
1863 "The register in which the window configuration is stored."
1865 :group 'wikipedia-draft)
1867 (defcustom wikipedia-draft-filter-functions nil
1868 "*Functions run to filter wikipedia-draft data.
1869 All functions are run in the wikipedia-draft buffer."
1871 :group 'wikipedia-draft)
1873 (defcustom wikipedia-draft-handler-functions '(wikipedia-draft-append-to-file)
1874 "*Functions run to process wikipedia-draft data.
1875 Each function is called with the current buffer narrowed to what the
1876 user wants wikipedia-drafted.
1877 If any function returns non-nil, the data is assumed to have been
1878 recorded somewhere by that function. "
1880 :group 'wikipedia-draft)
1882 (defcustom wikipedia-draft-data-file "~/Wiki/discussions/draft.wiki"
1883 "*The file in which to store the wikipedia drafts."
1885 :group 'wikipedia-draft)
1887 (defcustom wikipedia-draft-reply-register ?M
1888 "The register in which the window configuration is stored."
1890 :group 'wikipedia-draft)
1892 (defcustom wikipedia-draft-page ?S ;Version:1.37
1893 "The register in which the a page of the wiki draft file is stored."
1895 :group 'wikipedia-draft)
1898 (defcustom wikipedia-draft-leader-text "== "
1899 "*The text used to begin each wikipedia-draft item."
1901 :group 'wikipedia-draft)
1904 ;;; Internal Variables:
1906 (defvar wikipedia-draft-buffer "*Wikipedia-Draft*"
1907 "The name of the wikipedia-draft (temporary) data entry buffer.")
1912 (defun wikipedia-draft ()
1913 "Open a temporary buffer in wikipedia mode for editing an
1914 wikipedia draft, which an arbitrary piece of data. After
1915 finishing the editing either use \\[wikipedia-draft-buffer] to
1916 send the data into the wikipedia-draft-data-file, or send the
1917 buffer using `wikipedia-draft-send-to-mozex' and insert it later
1918 into a wikipedia article."
1920 (window-configuration-to-register wikipedia-draft-register)
1921 (let ((buf (get-buffer-create wikipedia-draft-buffer)))
1922 (switch-to-buffer-other-window buf)
1924 (message " C-c C-k sends to draft file, C-c C-c sends to org buffer.")))
1930 (defsubst wikipedia-draft-time-to-seconds (time)
1931 "Convert TIME to a floating point number."
1932 (+ (* (car time) 65536.0)
1934 (/ (or (car (cdr (cdr time))) 0) 1000000.0)))
1936 (defsubst wikipedia-draft-mail-date (&optional rfc822-p)
1937 "Return a simple date. Nothing fancy."
1939 (format-time-string "%a, %e %b %Y %T %z" (current-time))
1940 (format-time-string "%c" (current-time))))
1942 (defun wikipedia-draft-buffer-desc ()
1943 "Using the first line of the current buffer, create a short description."
1944 (buffer-substring (point-min)
1946 (goto-char (point-min))
1948 (if (> (- (point) (point-min)) 60)
1949 (goto-char (+ (point-min) 60)))
1953 ;; Wikipedia-Drafting to plain files:
1956 (defun wikipedia-draft-append-to-file ()
1957 "Add a header together with a subject to the text and add it to the
1958 draft file. It might be better if longlines-mode is off."
1959 (let ((text (buffer-string))
1960 (desc (wikipedia-draft-buffer-desc)))
1963 (insert wikipedia-draft-leader-text)
1964 (insert "Draft: ") ;Version:1.39
1965 (insert (read-string "Enter Subject: "))
1967 (insert (current-time-string))
1969 (insert wikipedia-draft-leader-text)
1970 (insert "\n\n") ;Version:1.27
1979 (if (find-buffer-visiting wikipedia-draft-data-file)
1980 (let ((wikipedia-draft-text (buffer-string)))
1981 (set-buffer (get-file-buffer wikipedia-draft-data-file))
1983 (goto-char (point-max))
1985 (insert wikipedia-draft-text)
1988 (append-to-file (point-min) (point-max) wikipedia-draft-data-file)))))
1991 (setq wikipedia-draft-handler-functions 'wikipedia-draft-append-to-file)
1994 (custom-add-option 'wikipedia-draft-handler-functions 'wikipedia-draft-append-to-file)
1997 (defun wikipedia-draft-page () ;Version:1.32
2000 (copy-region-as-kill (region-beginning) (region-end))
2005 (defun wikipedia-draft-region (&optional beg end)
2006 "Wikipedia-Draft the data from BEG to END.
2007 If called from within the wikipedia-draft buffer, BEG and END are ignored,
2008 and the entire buffer will be wikipedia-drafted. If called from any other
2009 buffer, that region, plus any context information specific to that
2010 region, will be wikipedia-drafted."
2012 (let ((b (or beg (min (point) (or (mark) (point-min)))))
2013 (e (or end (max (point) (or (mark) (point-max))))))
2015 (narrow-to-region b e)
2016 (run-hook-with-args-until-success 'wikipedia-draft-handler-functions)
2017 (when (equal wikipedia-draft-buffer (buffer-name))
2018 (kill-buffer (current-buffer))
2019 (jump-to-register wikipedia-draft-register)))))
2023 (defun wikipedia-draft-buffer ()
2024 "Wikipedia-draft-buffer sends the contents of the current (temporary)
2025 buffer to the wikipedia-draft-buffer, see the variable
2026 wikipedia-draft-data-file."
2028 (wikipedia-draft-region (point-min) (point-max)))
2030 (defun wikipedia-draft-clipboard ()
2031 "Wikipedia-Draft the contents of the current clipboard.
2032 Most useful for wikipedia-drafting things from Netscape or other X Windows
2036 (insert (x-get-clipboard))
2037 (run-hook-with-args-until-success 'wikipedia-draft-handler-functions)))
2042 ;;; Internal Functions:
2043 (defvar wikipedia-draft-send-archive t ;Version:1.56
2044 "*Archive the reply.")
2046 (defvar wikipedia-draft-mode-map
2047 (let ((m (make-sparse-keymap)))
2048 (define-key m "\C-c\C-k" 'wikipedia-draft-buffer)
2049 (define-key m "\C-c\C-d" 'wikipedia-draft-buffer)
2052 (defun wikipedia-draft-mode ()
2053 "Major mode for output from \\[wikipedia-draft].
2054 \\<wikipedia-draft-mode-map> This buffer is used to collect data that
2055 you want wikipedia-draft. Just hit \\[wikipedia-draft-region] when
2056 you're done entering, and it will go ahead and file the data for
2057 latter retrieval, and possible indexing.
2058 \\{wikipedia-draft-mode-map}"
2060 (kill-all-local-variables)
2061 (indented-text-mode)
2062 (use-local-map wikipedia-draft-mode-map)
2063 (setq major-mode 'wikipedia-draft-mode
2064 mode-name "Wikipedia-Draft")
2065 (run-hooks 'wikipedia-draft-mode-hook))
2068 (defun wikipedia-draft-view-draft ()
2070 "Simple shortcut to visit the file, which contains the wikipedia drafts."
2071 (find-file wikipedia-draft-data-file))
2075 ;;{{{ functions for marking regions
2077 (defun wikipedia-mark-section () ;Version:1.36
2078 "Set mark at end of current logical section, and point at top."
2080 (re-search-forward (concat "== " "[a-z,A-z \t]*"
2082 (re-search-backward "^")
2084 (re-search-backward (concat "== " "[a-z,A-z \t]*"
2086 (wikipedia-activate-region))
2088 (defun wikipedia-mark-signature () ;Version:1.36
2089 "Set mark at end of current logical section, and point at top."
2091 (re-search-forward "]]") ;;[[ ]]
2092 (re-search-backward "^")
2094 (re-search-backward "[[")
2095 (wikipedia-activate-region))
2097 (when (featurep 'xemacs)
2098 (fset 'wikipedia-activate-region (symbol-function 'zmacs-activate-region)))
2100 (unless (featurep 'xemacs)
2101 (defun wikipedia-activate-region ()
2106 ;;{{{ `reply' and `send' functions
2108 (defun wikipedia-draft-copy-page-to-register () ;Version:1.47
2109 "Copy a page via the wikipedia-draft-register."
2112 (narrow-to-page nil)
2113 (copy-to-register wikipedia-draft-page (point-min) (point-max) nil)
2114 (message "draft page copied to wikipedia register wikipedia-draft-page.")
2118 (defun wikipedia-draft-yank-page-to-register () ;Version:1.50
2119 "Insert a page via the wikipedia-draft-register."
2121 (insert-register wikipedia-draft-page nil))
2125 (defun wikipedia-draft-send-to-mozex (target-buffer) ;Version:1.56
2126 "Copy the current page from the wikipedia draft file to
2127 TARGET-BUFFER, this buffer is named something like mozex.textarea.
2128 Check the variable wikipedia-draft-send-archive. If it is t, then
2129 additionally the text will be archived in the draft.wiki file. Check
2130 longlines-mode, it might be better if it is set off."
2131 (interactive "bTarget buffer: ")
2132 (let ((src-buf (current-buffer)))
2133 (wikipedia-draft-copy-page-to-register)
2134 (switch-to-buffer target-buffer)
2137 (wikipedia-draft-yank-page-to-register)
2138 (message "The page has been sent (copied) to the mozex file!")
2139 (switch-to-buffer "*Wikipedia-Draft*")
2140 (when wikipedia-draft-send-archive ;Version:1.56
2141 (let ((text (buffer-string)) ;Version:1.59
2142 (desc (wikipedia-draft-buffer-desc)))
2145 (insert wikipedia-draft-leader-text)
2146 (insert-register wikipedia-draft-reply-register 1)
2148 (insert (current-time-string))
2150 (insert wikipedia-draft-leader-text)
2160 (if (find-buffer-visiting wikipedia-draft-data-file)
2161 (let ((wikipedia-draft-text (buffer-string)))
2162 (set-buffer (get-file-buffer wikipedia-draft-data-file))
2164 (goto-char (point-max))
2166 (insert wikipedia-draft-text)
2169 (append-to-file (point-min) (point-max) wikipedia-draft-data-file)))))
2170 (when (equal wikipedia-draft-buffer (buffer-name))
2171 (kill-buffer (current-buffer)))
2172 (switch-to-buffer target-buffer)))
2176 (defvar wikipedia-reply-with-hline nil
2177 "*Whether to use a hline as a header seperator in the reply.")
2179 (defvar wikipedia-reply-with-quote nil ;Version:1.60
2180 "*Whether to use a quotation tempalate or not.")
2182 (defvar wikipedia-user-simplify-signature t
2183 "*Simple varible in order to threat complicated signatures of users, which uses
2184 fonts and other makeup.")
2186 (defun wikipedia-reply-at-signature () ;Version:1.40
2187 "Very simple function to add the reply prefix to the signature,
2188 sorrounded by the boldface makeup. You have to set the point BEFORE
2189 the signature, then the functions inserts the following
2190 :'''Re: [[User:foo]]'''."
2192 (beginning-of-line 1)
2193 (search-forward "[[")
2197 (wikipedia-terminate-paragraph)
2207 (defun wikipedia-draft-reply () ;Version:1.62
2208 "Open a temporary buffer in wikipedia mode for editing an wikipedia
2209 draft, with an arbitrary piece of data. After finishing the editing
2210 |]]:either use \"C-c C-k\" \\[wikipedia-draft-buffer] to send the data into
2211 the wikipedia-draft-data-file, or send the buffer \"C-c\C-c\",
2212 \\[wikipedia-draft-send-to-mozex] to the current wikipedia article via
2213 mozex. Check the varibale wikipedia-draft-send-archive."
2215 (wikipedia-reply-at-point-simple)
2216 (beginning-of-line 1)
2219 (window-configuration-to-register wikipedia-draft-register)
2220 (let ((buf (get-buffer-create wikipedia-draft-buffer)))
2221 (switch-to-buffer-other-window buf)
2223 (if (functionp 'pabbrev-mode)
2225 (when (not wikipedia-reply-with-quote)
2226 (when wikipedia-reply-with-hline
2231 (when wikipedia-reply-with-quote
2232 (insert "{{Quotation|")
2235 (insert-register wikipedia-draft-reply-register 1)
2236 (insert "''' |~~~~}}")
2238 (message " C-c C-k sends to draft, C-c C-c sends to org buffer."))))
2240 (defun wikipedia-reply-at-point-simple () ;Version:1.65
2241 "Reply to posts in discussion forums.
2242 You have to put the region around the signature, then the
2243 functions inserts the following
2244 :'''Re: [[User:foo]]'''."
2246 (beginning-of-line 1)
2247 (search-forward (get-lang-string wikipedia-lang 'wikip-utc))
2248 (search-backward (get-lang-string wikipedia-lang 'wikip-user-mark))
2249 (when (not wikipedia-user-simplify-signature)
2251 (when wikipedia-user-simplify-signature
2253 (copy-to-register wikipedia-draft-reply-register (region-beginning) (region-end) nil)
2255 (wikipedia-terminate-paragraph-and-indent)
2257 (insert-register wikipedia-draft-reply-register 1)
2258 (when wikipedia-user-simplify-signature
2260 (when (not wikipedia-user-simplify-signature)
2265 ;;{{{ Optional private stuff:
2267 ;; (defun wikipedia-insert-quotation-with-signature () ;Version:1.60
2268 ;; "Insert quotation with signature.
2269 ;; When mark is active, surrounds region."
2271 ;; (wikipedia-insert-around-region "{{Quotation|" "}}{{~~~~}}"))
2273 ;; (defun wikipedia-insert-quotation () ;Version:1.60
2274 ;; "Insert quotation box.
2275 ;; When mark is active, surrounds region."
2277 ;; ;; Fix-me: This uses a template, is that really always available???
2278 ;; (wikipedia-insert-around-region "{{Quotation|" "}}"))
2280 ;; (define-key wikipedia-mode-map "\C-c\C-fv" 'wikipedia-insert-bible-verse-template)
2282 ;; (defun wikipedia-insert-bible-verse-template ()
2283 ;; "Insert a template for the quotation of bible verses."
2285 ;; (insert "({{niv|")
2286 ;; (let ((name (read-string "Name: ")))
2287 ;; (insert (concat name "|"))
2288 ;; (let ((verse (read-string "Verse: ")))
2289 ;; (insert (concat verse "|" name " " verse "}})")))))
2293 (provide 'wikipedia-mode)
2294 ;;; wikipedia-mode.el ends here.