-
Notifications
You must be signed in to change notification settings - Fork 2
/
wikipedia-mode.el
1796 lines (1490 loc) · 59.5 KB
/
wikipedia-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; wikipedia-mode.el --- Mode for editing Wikipedia articles off-line
;; Copyright (C) 2003, 2004, 2006 Chong Yidong, Uwe Brauer
;; Author: Chong Yidong <cyd at stupidchicken com>
;; Maintainer: Uwe Brauer <oub at mat.ucm.es>
;; Version: 0.5
;; Keywords: wiki
;; $Id: wikipedia-mode.el,v 1.5 2006/05/30 15:16:45 oub Exp oub $
;; This file is not part of GNU Emacs.
;;{{{ GPL2
;; This file is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;; This file is distributed in the hope that it will be
;; useful, but WITHOUT ANY WARRANTY; without even the implied
;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;; PURPOSE. See the GNU General Public License for more details.
;; You should have received a copy of the GNU General Public
;; License along with GNU Emacs; if not, write to the Free
;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
;; MA 02111-1307 USA
;;}}}
;;; Commentary:
;; This is `wikipedia-mode', a major mode for editing articles written
;; in the markup language used by Wikipedia, the free on-line
;; encyclopedia (http://www.wikipedia.org). It is intended to work
;; with GNU Emacs 21.x, and Xemacs 21.4.x. See below for details.
;; wikipedia mode can be found also at:
;; http://en.wikipedia.org/wiki/Wikipedia:Wikipedia-mode.el
;;{{{ INSTALLING WIKIPEDIA-MODE
;; Installing wikipedia-mode
;; =========================
;;
;; Save wikipedia-mode.el in a convenient directory, preferably in
;; your `load-path'. Add the following to your `user-init-file':
;;
;; (autoload 'wikipedia-mode
;; "wikipedia-mode.el"
;; "Major mode for editing documents in Wikipedia markup." t)
;;
;; If you did not save wikipedia-mode.el in your `load-path', you must
;; use the full pathname. On MS Windows, use forward slashes (/)
;; rather than back slashes (\) to indicate the directory, e.g.:
;;
;; (autoload 'wikipedia-mode
;; "C:/Documents and Settings/USERNAME/.emacs.d/Wikipedia-mode.el"
;; "Major mode for editing documents in Wikipedia markup." t)
;;
;; If you want to associate filenames ending in ".wiki" with
;; wikipedia-mode, add the following to your init file:
;;
;; (setq auto-mode-alist
;; (cons '("\\.wiki\\'" . wikipedia-mode) auto-mode-alist))
;;}}}
;;{{{ REQUIREMENTS
;; This is not a real requirements but I highly recommend to use
;; outline-magic written by Carsten Dominik. If you don't want to use it
;; you have to comment out the relevant reference to outline magic.
;; It can be found at
;; http://www.astro.uva.nl/~dominik/Tools/outline-magic.el
;;}}}
;;{{{ RECOMMENDATIONS INSTALLING LONGLINES-MODE
;; Installing longlines-mode
;; =========================
;;
;; Wikipedia articles don't use newline characters to break paragraphs
;; into lines, so each paragraph looks like a super-long line to
;; Emacs. To let Emacs handle "soft word wrapping", you need to
;; download a third-party package, longlines-mode.
;;
;; Download longlines.el, saving into your `load-path':
;;
;; http://www.emacswiki.org/elisp/longlines.el
;;
;; Add the following to your `user-init-file':
;;
;; (autoload 'longlines-mode "longlines.el"
;; "Minor mode for editing long lines." t)
;;
;;
;; WARNING: if you insert text from one file in wikipedia-mode to
;; another file in wikipedia-mode I strongly recommend, to turn
;; longlines-mode off, before the copying!
;;}}}
;;{{{ RECOMMENDATIONS INSTALLING PABBREV-MODE
;; Installing longlines-mode
;; =========================
;;
;; You may find pabbrev.el useful, which can be found at
;; http://www.russet.org.uk/download/emacs/pabbrev.el
;;}}}
;;{{{ Xemacs or (GNU) Emacs
;; Xemacs or (GNU) Emacs
;; =====================
;; Usually that is a question of taste. However almost all wikipedia
;; articles nowadays use UTF8 coding, so the question which of the
;; Macsen to use, boils down to which degree UTF8 support is
;; implemented (no mule Xemacs is ruled out). While Xemacs has the
;; better font support, the UTF8 support still is not complete and
;; hence at the time being it is sad for the maintainer (a long time
;; Xemacs user) to recommend NOT to use Xemacs, even not 21.5.x, which
;; has a much better implemented UTF8 coding engine. That might
;; however change in the foreseeable future....
;; WARNING: at least for me in Debian testing/unstable Emacs does not
;; ship all fonts necessary for a flawless editing of UTF8 files. For
;; example you can chose Greek input, write Greek text, but then when
;; you close and open the file again, the Greek symbol are not
;; displayed but you see empty blocks. The reason seems that emacs
;; chooses for the input fonts other fonts as for the display (don't
;; ask me). However for installing the (ugly) UTF8 compatible fonts
;; from ..... solved that problem.
;;}}}
;;{{{ INSTALLING EE-HELPER or MOZEX
;; Installing the helper programs.
;; =========================
;; Helper Programs: MozEx and EE-HELPER. There are two possibilities
;; in order to use Emacs as an external editor
;;
;; (1) EE-HELPER: This is perl script which will communicate with
;; the wikipedia server. However that sometimes be slow.
;; PROS: if the editor supports UTF8, then ee-helper will
;; pass the coding flawlessly.
;;
;; CONTRA: the problem with this script is that it directly
;; communicates with the wikipedia site and does not
;; warn you about simultaneous editing. Use it with
;; care!!! Moreover section editing is not implemented.
;; (2) MozEx: this is a Java-script which allows to communicate
;; Mozilla (or Firefox) directly with Emacs.
;; PROS: After finishing editing you use the wikipedia
;; software to submit your changes and not the script,
;; so you are warned about possible conflicting editing.
;;
;; CONTRA: the official version does not support UTF8,
;; however there is now a new semi official version which
;; does support UTF8.
;;
;; Installing ee-helper
;; ====================
;;
;; Download the perl script from
;;
;; http://meta.wikimedia.org/wiki/Help:External_editors
;;
;; and follow the instructions. configure the .ee-ini file. chance in
;; your personal wikipedia-mode-map account setting the editing
;; functions: activate the `external editor' option.
;; Installing MozEx
;; ================
;;
;; If your web browser is Mozilla or Firefox, take a look at the MozEx
;; extension, which allows you to call Emacs for editing text boxes:
;;
;; http://mozex.mozdev.org/development.html
;;
;; See also
;;
;; http://www.emacswiki.org/cgi-bin/wiki/FireFox
;;
;; If you mostly use MozEx to edit Wikipedia articles, it might be
;; worthwhile to tell Emacs to enter wikipedia-mode whenever it is
;; called by MozEx. Just add this to your `user-init-file':
;;
;; (add-to-list 'auto-mode-alist '("mozex.\\.*" . wikipedia-mode))
;; Recall: you have to click on edit (either edit article or edit
;; section), then use mouse3 (or shift f10), then select
;; mozex, then edit textarea: Edit-->mouse3-->mozex-->Edit
;; Textarea. After editing, you have to _click_ on the
;; text in the browser otherwise Mozilla will ignore your
;; typing.
;;}}}
;;{{{ NEWS
;; NEWS
;; ==================================
;; (1) Font setting has changed.
;; (2) Some makeup formats have been added: italics, bold, strong
;; emphasise, links.
;; (3) outline-cycle from Carsten Dominiks outline-magic has been
;; added.
;; (4) "Draft", "send" and "reply" (for discussion pages)
;; abilities `based' on ideas of John Wigleys remember.el: see
;; the functions wikipedia-draft-*
;; RATIONALE: This comes handy in 2 situations
;; 1. You are editing articles which various authors (this I
;; think is the usual case), you then want not to submit
;; your edit immediately but want to copy it somewhere and
;; to continue later. You can use the following functions
;; for doing that:
;; wikipedia-draft-buffer \C-c\C-b
;; wikipedia-draft-region \C-c\C-r
;; then the buffer/region will be appended to the
;; wikipedia-draft-data-file (default is
;; "~/Wiki/discussions/draft.wiki", which you can visit via
;; wikipedia-draft-view-draft) and it will be
;; surrounded by the ^L marks in order to set a page.
;; moreover on top on that a section header == will be
;; inserted, which consists of the Word Draft, a subject
;; you are asked for and a date stamp.
;;
;; Another possibility consists in using the function
;; wikipedia-draft, bound to \C-c \C-m then a new buffer
;; will opened already in wikipedia mode. You edit and then
;; either can send the content of the buffer to the
;; wikipedia-draft-data-file in the same manner as
;; described above using the function
;; wikipedia-draft-buffer (bound to \C-c\C-k)
;;
;; BACK: In order to copy/send the content of temporary
;; buffer or of a page in the wikipedia-draft-data-file
;; back in to your wikipedia file, use the function
;; wikipedia-send-draft-to-mozex bound to "\C-c\C-c". You
;; will be asked to which buffer to copy your text!
;;
;;
;; 2. You want to reply in a discussion page to a specific
;; contribution, you can use either the function
;;
;; \\[wikipedia-reply-at-point-simple] bound to [(meta shift r)]
;; which inserts a newline, a hline, and the signature of
;; the author. Or can use
;; \\[wikipedia-draft-reply] bound [(meta r)]
;; which does the same as wikipedia-reply-at-point-simple
;; but in a temporary draft buffer.
;;
;; BACK: In order to copy/send the content of that buffer
;; back in to your wikipedia file, use the function
;; \\[wikipedia-send-draft-to-mozex] bound to "\C-c\C-c". You
;; will be asked to which buffer to copy your text! If
;; you want a copy to be send to your draft file, use
;; the variable wikipedia-draft-send-archive
;;
;;}}}
;;{{{ NEW FUNCTIONS AND VARIABLES
;; VERSION 0.4
;;==================
;; NEW FUNCTIONS
;; ------------------
;; wikipedia-insert-enumerate
;; wikipedia-insert-itemize
;; wikipedia-insert-strong-emphasis
;; wikipedia-insert-bold
;; wikipedia-insert-italics
;; wikipedia-insert-header
;; wikipedia-insert-link
;; wikipedia-turn-on-outline-minor-mode
;; wikipedia-insert-signature
;; wikipedia-insert-hline
;; wikipedia-unfill-paragraph-or-region
;; wikipedia-start-paragraph
;; wikipedia-hardlines
;; wikipedia-outline-magic-keys
;; wikipedia-enhance-indent
;; wikipedia-yank-prefix
;; wikipedia-simple-outline-promote
;; wikipedia-simple-outline-demote
;; wikipedia-next-long-line
;; wikipedia-unfill-paragraph
;; wikipedia-rename-buffer
;; wikipedia-draft
;; wikipedia-draft-buffer-desc
;; wikipedia-draft-append-to-file
;; wikipedia-draft-page
;; wikipedia-draft-region (&optional beg end)
;; wikipedia-draft-buffer
;; wikipedia-draft-clipboard
;; wikipedia-draft-mode
;; wikipedia-draft-view-draft
;; wikipedia-mark-section
;; wikipedia-activate-region
;; wikipedia-copy-page-to-register
;; wikipedia-insert-page-to-register
;; wikipedia-send-draft-to-mozex (target-buffer)
;; wikipedia-reply-at-point-simple
;; wikipedia-draft-reply
;; wikipedia-insert-quotation-with-signature
;; wikipedia-insert-quotation
;; NEW VARIABLES
;;---------------------
;; wikipedia-enumerate-with-terminate-paragraph
;; wikipedia-draft-buffer "*Wikipedia-Draft*"
;; wikipedia-draft-mode-map
;; wikipedia-draft-mode-hook
;; wikipedia-draft-register ?R
;; wikipedia-draft-filter-functions
;; wikipedia-draft-handler-functions '(wikipedia-draft-append-to-file)
;; wikipedia-draft-data-file "~/Wiki/discussions/draft.wiki"
;; wikipedia-draft-leader-text "== "
;; wikipedia-draft-page ?S
;; wikipedia-draft-send-archive
;; wikipedia-reply-with-quote
;; VERSION 0.5
;;====================================
;; NEW FUNCTIONS
;; ------------------------------------
;; wikipedia-insert-audio
;; wikipedia-insert-bible-verse-template
;; wikipedia-insert-bible-verse-template-old
;; wikipedia-insert-image
;; wikipedia-insert-link-www
;; wikipedia-insert-user
;; wikipedia-mark-signature
;; wikipedia-outline-cycle
;; wikipedia-reply-at-signature
;; wikipedia-terminate-paragraph-and-indent
;; wikipedia-yank-prefix
;; NEW VARIABLES (defvar, defcustom, defconst)
;; ----------------------
;; wikipedia-reply-with-hline
;; wikipedia-user-simplify-signature
;; wikipedia-english-or-german
;; wikipedia-draft-reply-register ?M
;; wikipedia-mode-version
;;}}}
;;{{{ TODO
;; Todo
;; ----
;; * Implement TeX highlighting in <math> environment
;; * Implement (La)TeX input syntax, following the ideas of CDlatex.el
;; * Make outline-cycle work correctly
;; * wikipedia-reply-at-point-simple should use regexp!
;;}}}
;;; Code:
(require 'derived)
(require 'font-lock)
(defconst wikipedia-mode-version (concat "0." (substring "$Revision: 1.5 $" 13 14))
"$Id: wikipedia-mode.el,v 1.5 2006/05/30 15:16:45 oub Exp oub $
Report bugs to: Uwe Brauer oub at mat.ucm.es")
;;{{{ TAGS
(defvar wikipedia-simple-tags
'("b" "big" "blockquote" "br" "caption" "code" "center" "cite" "del"
"dfn" "dl" "em" "i" "ins" "kbd" "math" "nowiki" "ol" "pre" "samp"
"small" "strike" "strong" "sub" "sup" "tt" "u" "ul" "var")
"Tags that do not accept arguments.")
(defvar wikipedia-complex-tags
'("a" "div" "font" "table" "td" "th" "tr")
"Tags that accept arguments.")
(defvar wikipedia-url-protocols
'("ftp" "gopher" "http" "https" "mailto" "news")
"Valid protocols for URLs in Wikipedia articles.")
;;}}}
;;{{{ FACES
(defvar font-wikipedia-sedate-face 'font-wikipedia-sedate-face
"Face to use for Wikipedia minor keywords.")
(defvar font-wikipedia-italic-face 'font-wikipedia-italic-face
"Face to use for Wikipedia italics.")
(defvar font-wikipedia-bold-face 'font-wikipedia-bold-face
"Face to use for Wikipedia bolds.")
(defvar font-wikipedia-math-face 'font-wikipedia-math-face
"Face to use for Wikipedia math environments.")
(defvar font-wikipedia-string-face 'font-wikipedia-string-face
"Face to use for strings. This is set by Font Wikipedia.")
(defvar font-wikipedia-verbatim-face 'font-wikipedia-verbatim-face
"Face to use for text in verbatim macros or environments.")
(defface font-wikipedia-bold-face
(let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit bold))
((assq :weight custom-face-attributes) '(:weight bold))
(t '(:bold t)))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "DarkOliveGreen" ,@font))
(((class color) (background dark))
(:foreground "OliveDrab" ,@font))
(t (,@font))))
"Face used to highlight text to be typeset in bold."
:group 'font-wikipedia-highlighting-faces)
(defface font-wikipedia-italic-face
(let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit italic))
((assq :slant custom-face-attributes) '(:slant italic))
(t '(:italic t)))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "DarkOliveGreen" ,@font))
(((class color) (background dark))
(:foreground "OliveDrab" ,@font))
(t (,@font))))
"Face used to highlight text to be typeset in italic."
:group 'font-wikipedia-highlighting-faces)
(defface font-wikipedia-math-face
(let ((font (cond ((assq :inherit custom-face-attributes)
'(:inherit underline))
(t '(:underline t)))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "SaddleBrown"))
(((class color) (background dark))
(:foreground "burlywood"))
(t (,@font))))
"Face used to highlight math."
:group 'font-wikipedia-highlighting-faces)
(defface font-wikipedia-sedate-face
'((((class grayscale) (background light)) (:foreground "DimGray"))
(((class grayscale) (background dark)) (:foreground "LightGray"))
(((class color) (background light)) (:foreground "DimGray"))
(((class color) (background dark)) (:foreground "LightGray"))
;;;(t (:underline t))
)
"Face used to highlight sedate stuff."
:group 'font-wikipedia-highlighting-faces)
(defface font-wikipedia-string-face
(let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit italic))
((assq :slant custom-face-attributes) '(:slant italic))
(t '(:italic t)))))
`((((type tty) (class color))
(:foreground "green"))
(((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "RosyBrown"))
(((class color) (background dark))
(:foreground "LightSalmon"))
(t (,@font))))
"Face used to highlight strings."
:group 'font-wikipedia-highlighting-faces)
(defface font-wikipedia-warning-face
(let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit bold))
((assq :weight custom-face-attributes) '(:weight bold))
(t '(:bold t)))))
`((((class grayscale)(background light))
(:foreground "DimGray" ,@font))
(((class grayscale)(background dark))
(:foreground "LightGray" ,@font))
(((class color)(background light))
(:foreground "red" ,@font))
(((class color)(background dark))
(:foreground "red" ,@font))
(t (,@font))))
"Face for important keywords."
:group 'font-wikipedia-highlighting-faces)
(defface font-wikipedia-verbatim-face
(let ((font (if (and (assq :inherit custom-face-attributes)
(if (featurep 'xemacs)
(find-face 'fixed-pitch)
(facep 'fixed-pitch)))
'(:inherit fixed-pitch)
'(:family "courier"))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "SaddleBrown" ,@font))
(((class color) (background dark))
(:foreground "burlywood" ,@font))
(t (,@font))))
"Face used to highlight TeX verbatim environments."
:group 'font-wikipedia-highlighting-faces)
(defvar wikipedia-font-lock-keywords
(list
;; Apostrophe-style text markup
(cons "''''\\([^']\\|[^']'\\)*?\\(''''\\|\n\n\\)"
'font-lock-builtin-face)
(cons "'''\\([^']\\|[^']'\\)*?\\('''\\|\n\n\\)"
; 'font-lock-builtin-face)
'font-wikipedia-bold-face)
(cons "''\\([^']\\|[^']'\\)*?\\(''\\|\n\n\\)"
'font-wikipedia-italic-face)
;; Headers and dividers
(list "^\\(==+\\)\\(.*\\)\\(\\1\\)"
'(1 font-lock-builtin-face)
; '(2 wikipedia-header-face)
'(2 font-wikipedia-sedate-face)
'(3 font-lock-builtin-face))
(cons "^-----*" 'font-lock-builtin-face)
;; Bare URLs and ISBNs
(cons (concat "\\(^\\| \\)" (regexp-opt wikipedia-url-protocols t)
"://[-A-Za-z0-9._\/~%+&#?!=()@]+")
'font-lock-variable-name-face)
(cons "\\(^\\| \\)ISBN [-0-9A-Z]+" 'font-lock-variable-name-face)
;; Colon indentation, lists, definitions, and tables
(cons "^\\(:+\\|[*#]+\\||[}-]?\\|{|\\)" 'font-lock-builtin-face)
(list "^\\(;\\)\\([^:\n]*\\)\\(:?\\)"
'(1 font-lock-builtin-face)
'(2 font-lock-keyword-face)
'(3 font-lock-builtin-face))
;; Tags and comments
(list (concat "\\(</?\\)"
(regexp-opt wikipedia-simple-tags t) "\\(>\\)")
'(1 font-lock-builtin-face t t)
'(2 font-lock-function-name-face t t)
'(3 font-lock-builtin-face t t))
(list (concat "\\(</?\\)"
(regexp-opt wikipedia-complex-tags t)
"\\(\\(?: \\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?\\)\\(>\\)")
'(1 font-lock-builtin-face t t)
'(2 font-lock-function-name-face t t)
'(3 font-lock-keyword-face t t)
'(4 font-lock-builtin-face t t))
(cons (concat "<!-- \\([^->]\\|>\\|-\\([^-]\\|-[^>]\\)\\)*-->")
'(0 font-lock-comment-face t t))
;; External Links
(list (concat "\\(\\[\\)\\(\\(?:"
(regexp-opt wikipedia-url-protocols)
"\\)://[-A-Za-z0-9._\/~%-+&#?!=()@]+\\)\\(\\(?: [^]\n]*\\)?\\)\\(\\]\\)")
'(1 font-lock-builtin-face t t)
'(2 font-lock-variable-name-face t t)
'(3 font-lock-keyword-face t t)
'(4 font-lock-builtin-face t t))
;; Wiki links
'("\\(\\[\\[\\)\\([^]\n|]*\\)\\(|?\\)\\([^]\n]*\\)\\(\\]\\]\\)"
(1 font-lock-builtin-face t t)
(2 font-lock-variable-name-face t t)
(3 font-lock-builtin-face t t)
(4 font-lock-keyword-face t t)
(5 font-lock-builtin-face t t))
;; Wiki variables
'("\\({{\\)\\(.+?\\)\\(}}\\)"
(1 font-lock-builtin-face t t)
(2 font-lock-variable-name-face t t)
(3 font-lock-builtin-face t t))
;; Character entity references
(cons "&#?[a-zA-Z0-9]+;" '(0 font-lock-type-face t t))
;; Preformatted text
(cons "^ .*$" '(0 font-lock-constant-face t t))
;; Math environment (uniform highlight only, no TeX markup)
(list "<math>\\(\\(\n?.\\)*\\)</math>"
'(1 font-lock-keyword-face t t))))
; )
;;}}}
;;{{{ Menu and header stuff
(defvar wikipedia-imenu-generic-expression
(list '(nil "^==+ *\\(.*[^\n=]\\)==+" 1))
"Imenu expression for `wikipedia-mode'. See `imenu-generic-expression'.")
(defun wikipedia-next-header ()
"Move point to the end of the next section header."
(interactive)
(let ((oldpoint (point)))
(end-of-line)
(if (re-search-forward "\\(^==+\\).*\\1" (point-max) t)
(beginning-of-line)
(goto-char oldpoint)
(message "No section headers after point."))))
(defun wikipedia-prev-header ()
"Move point to the start of the previous section header."
(interactive)
(unless (re-search-backward "\\(^==+\\).*\\1" (point-min) t)
(message "No section headers before point.")))
;;}}}
;;{{{ Paragraph terminate and filling stuff (Chong)
(defun wikipedia-terminate-paragraph () ;Version:1.58
"In a list, start a new list item. In a paragraph, start a new
paragraph; if the current paragraph is colon indented, the new
paragraph will be indented in the same way."
(interactive)
(let (indent-chars)
(save-excursion
(beginning-of-line)
(while (cond ((looking-at "^$") nil)
((looking-at "^\\(\\(?: \\|:+\\|[#*]+\\) *\\)")
(setq indent-chars (match-string 1)) nil)
((eq (point) (point-min)) nil)
((progn (forward-line -1) t)))
t))
(newline) (if (not indent-chars) (newline)
(insert indent-chars))))
(defun wikipedia-terminate-paragraph-and-indent ()
"In a list, start a new list item. In a paragraph, start a new
paragraph but *,# will be ignored; if the current paragraph is colon
; indented, the new paragraph will be indented in the same way."
(interactive)
(let (indent-chars)
(save-excursion
(beginning-of-line)
(while (cond ((looking-at "^$") nil)
((looking-at "^\\(\\(?: \\|:+\\) *\\)")
(setq indent-chars (match-string 1)) nil)
((eq (point) (point-min)) nil)
((progn (forward-line -1) t)))
t))
(newline) (if (not indent-chars) (newline)
(insert indent-chars))))
(defun wikipedia-link-fill-nobreak-p ()
"When filling, don't break the line for preformatted (fixed-width)
text or inside a Wiki link. See `fill-nobreak-predicate'."
(save-excursion
(let ((pos (point)))
(or (eq (char-after (line-beginning-position)) ? )
(if (re-search-backward "\\[\\[" (line-beginning-position) t)
;; Break if the link is really really long.
;; You often get this with captioned images.
(null (or (> (- pos (point)) fill-column)
(re-search-forward "\\]\\]" pos t))))))))
(defun wikipedia-fill-article ()
"Fill the entire article."
(interactive)
(save-excursion
(fill-region (point-min) (point-max))))
(defun wikipedia-unfill-article ()
"Undo filling, deleting stand-alone newlines (newlines that do not
end paragraphs, list entries, etc.)"
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
(replace-match " " nil nil nil 1)))
(message "Stand-alone newlines deleted"))
(defun wikipedia-unfill-paragraph-with-newline (&optional justifyp)
(interactive "P")
(let ((before (point))) ;Version:1.3
(save-excursion
(forward-paragraph)
(or (bolp) (newline 1))
(let ((end (point))
(start (progn (backward-paragraph) (point))))
(goto-char before)
(while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
(replace-match " " nil nil nil 1))))))
; (message "Stand-alone newlines IN PARAGRAPH deleted"))
(defun wikipedia-unfill-region ()
"Undo filling, deleting stand-alone newlines (newlines that do not end
paragraphs, list entries, etc.) see also the function
\\[wikipedia-unfill-paragraph-or-region] and the even simpler function
\\[wikipedia-unfill-paragraph-simple]."
(interactive)
(save-excursion
(narrow-to-region (point) (mark))
(goto-char (point-min))
(while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
(replace-match " " nil nil nil 1)))
(message "Stand-alone newlines deleted")
(widen))
;;}}}
;;{{{ Main function wikipedia mode (using define-derived mode)
;;;###autoload
;;{{{ Main function wikipedia-mode
(define-derived-mode wikipedia-mode text-mode "Wikipedia"
"Major mode for editing articles written in the markup language used by
Wikipedia, the free on-line encyclopedia (http://www.wikipedia.org).
There are several ways to use wikipedia-mode. One is to copy articles
between Emacs and your web browser's text box. However for GNU emacs,
that does not work always smoothly, since copying marked regions into
other X applications is somehow buggy for GNU emacs. Another way is to
use MozEx, a Mozilla/Firefox web browser extension that allows you to
call Emacs from a text box (http://mozex.mozdev.org/). Another way is
to use the PERL script ee-helper, which allows you to up and download
wiki texts.
Wikipedia articles are usually unfilled: newline characters are not
used for breaking paragraphs into lines. Unfortunately, Emacs does not
handle word wrapping yet. As a workaround, wikipedia-mode turns on
longlines-mode automatically. In case something goes wrong, the
following commands may come in handy:
\\[wikipedia-fill-article] fills the buffer.
\\[wikipedia-unfill-article] unfills the buffer.
Be warned that function can be dead slow, better use wikipedia-unfill-paragraph-or-region.
\\[wikipedia-unfill-paragraph-or-region] unfills the paragraph
\\[wikipedia-unfill-paragraph-simple] doehe same but simpler.
The following commands put in markup structures.
\\[wikipedia-insert-strong-emphasis] inserts italics
\\[wikipedia-insert-bold] inserts bold text
\\[wikipedia-insert-italics] italics
\\[wikipedia-insert-header] header
\\[wikipedia-insert-link] inserts a link
The following commands are also defined:
\\[wikipedia-insert-user] inserts user name
\\[wikipedia-insert-signature] inserts ~~~~
\\[wikipedia-insert-enumerate] inserts enumerate type structures
\\[wikipedia-insert-itemize] inserts itemize type structures
\\[wikipedia-insert-hline] inserts a hline
The draft functionality
\\[wikipedia-draft]
\\[wikipedia-draft-region]
\\[wikipedia-draft-view-draft]
\\[wikipedia-draft-page]
\\[wikipedia-draft-buffer]
Replying and sending functionality
\\[wikipedia-reply-at-point-simple]
\\[wikipedia-draft-reply]
\\[wikipedia-send-draft-to-mozex]
The register functionality
\\[wikipedia-copy-page-to-register]
\\[defun wikipedia-insert-page-to-register]
Some simple editing commands.
\\[wikipedia-enhance-indent]
\\[wikipedia-yank-prefix]
\\[wikipedia-unfill-paragraph-or-region]
\\[wikipedia-terminate-paragraph] starts a new list item or paragraph in a context-aware manner.
\\[wikipedia-next-header] moves to the next (sub)section header.
\\[wikipedia-prev-header] moves to the previous (sub)section header."
(set (make-local-variable 'adaptive-fill-regexp) "[ ]*")
(set (make-local-variable 'comment-start-skip) "\\(?:<!\\)?-- *")
(set (make-local-variable 'comment-end-skip) " *--\\([ \n]*>\\)?")
(set (make-local-variable 'comment-start) "<!-- ")
(set (make-local-variable 'comment-end) " -->")
(set (make-local-variable 'paragraph-start)
"\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")
(set (make-local-variable 'sentence-end-double-space) nil)
(set (make-local-variable 'font-lock-multiline) t)
(set (make-local-variable 'font-lock-defaults)
'(wikipedia-font-lock-keywords t nil nil nil))
(set (make-local-variable 'fill-nobreak-predicate)
'wikipedia-link-fill-nobreak-p)
(set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]")
;; Support for outline-minor-mode. No key conflicts, so we'll use
;; the normal outline-mode prefix.
(set (make-local-variable 'outline-regexp) "==+")
; (set (make-local-variable 'outline-regexp) "=+")
; (set (make-local-variable 'outline-regexp) ":")
(set (make-local-variable 'outline-minor-mode-prefix) "\C-c\C-o")
;; Turn on the Imenu automatically.
(when menu-bar-mode
(set (make-local-variable 'imenu-generic-expression)
wikipedia-imenu-generic-expression)
(imenu-add-to-menubar "Contents"))
(modify-syntax-entry ?< "(>" wikipedia-mode-syntax-table)
(modify-syntax-entry ?> ")<" wikipedia-mode-syntax-table)
;;}}}
;; KEY SETTING
;;{{{ KEY SETTING
(define-key wikipedia-mode-map "\M-n" 'wikipedia-next-header)
(define-key wikipedia-mode-map "\C-c\C-n" 'wikipedia-next-long-line)
(define-key wikipedia-mode-map "\M-p" 'wikipedia-prev-header)
; (define-key wikipedia-mode-map [(meta down)] 'wikipedia-next-header)
; (define-key wikipedia-mode-map [(meta up)] 'wikipedia-prev-header)
(define-key wikipedia-mode-map "\C-j" 'wikipedia-terminate-paragraph)
; 'wikipedia-terminate-paragraph)
(let ((map (make-sparse-keymap "Wikipedia")))
(define-key wikipedia-mode-map [menu-bar wikipedia]
(cons "Wikipedia" map))
(define-key map [unfill-article]
'("Unfill article" . wikipedia-unfill-article))
(define-key map [fill-article]
'("Fill article" . wikipedia-fill-article))
(define-key map [separator-fill] '("--"))
(define-key map [next-header]
'("Next header" . wikipedia-next-header))
(define-key map [prev-header]
'("Previous header" . wikipedia-prev-header))
(define-key map [separator-header] '("--"))
(define-key map [outline]
'("Toggle Outline Mode..." . outline-minor-mode)))
(define-key wikipedia-mode-map "\C-c\C-q" 'wikipedia-unfill-article)
(define-key wikipedia-mode-map "\C-c\M-q" 'wikipedia-fill-article)
(define-key wikipedia-mode-map "\M-u" 'wikipedia-unfill-paragraph-or-region)
(define-key wikipedia-mode-map "\C-c\C-u" 'wikipedia-unfill-paragraph-simple)
(define-key wikipedia-mode-map "\C-c\C-f\C-s" 'wikipedia-insert-strong-emphasis)
(define-key wikipedia-mode-map "\C-c\C-f\C-b" 'wikipedia-insert-bold) ;Version:1.3
(define-key wikipedia-mode-map "\C-c\C-f\C-i" 'wikipedia-insert-italics)
(define-key wikipedia-mode-map "\C-c\C-f\C-h" 'wikipedia-insert-header)
(define-key wikipedia-mode-map "\C-c\C-f\C-l" 'wikipedia-insert-link)
(define-key wikipedia-mode-map "\C-c\C-f\C-u" 'wikipedia-insert-user)
(define-key wikipedia-mode-map "\C-c\C-f\C-q" 'wikipedia-insert-quotation)
(define-key wikipedia-mode-map "\C-c\C-f\C-v" 'wikipedia-insert-bible-verse-template)
(define-key wikipedia-mode-map "\C-c\C-w" 'wikipedia-insert-signature)
(define-key wikipedia-mode-map "\C-c\C-h" 'wikipedia-insert-hline) ;Version:1.30
(define-key wikipedia-mode-map [(meta f7)] 'wikipedia-draft)
(define-key wikipedia-mode-map [(meta f8)] 'wikipedia-reply-at-point-simple)
(define-key wikipedia-mode-map [(meta f9)] 'wikipedia-draft-view-draft)
(define-key wikipedia-mode-map "\C-c\C-r" 'wikipedia-reply-at-point-simple)
(define-key wikipedia-mode-map "\C-cr" 'wikipedia-draft-region)
(define-key wikipedia-mode-map [(meta r)] 'wikipedia-draft-reply)
(define-key wikipedia-mode-map "\C-c\C-m" 'wikipedia-draft) ;Version:1.25
(define-key wikipedia-mode-map "\C-c\C-b" 'wikipedia-draft-region)
(define-key wikipedia-mode-map "\C-c\C-d" 'wikipedia-draft-buffer)
(define-key wikipedia-mode-map "\C-c\C-k" 'wikipedia-draft-buffer)
(define-key wikipedia-mode-map "\C-c\C-p" 'wikipedia-draft-copy-page-to-register) ;Version:1.39
(define-key wikipedia-mode-map "\C-c\C-c" 'wikipedia-draft-send-to-mozex)
(define-key wikipedia-mode-map "\C-c\C-s" 'wikipedia-draft-yank-page-to-register)
(define-key wikipedia-mode-map [(control meta prior)] 'wikipedia-enhance-indent)
(define-key wikipedia-mode-map [(control meta next)] 'wikipedia-yank-prefix)
(define-key wikipedia-mode-map [(meta return)] 'wikipedia-insert-enumerate)
(define-key wikipedia-mode-map [(meta control return)] 'wikipedia-insert-enumerate-nonewline)
;; private setting
(define-key wikipedia-mode-map [(shift return)] 'newline-and-indent) ;Version:1.24
(define-key wikipedia-mode-map "\C-\\" 'wikipedia-insert-itemize) ;Version:1.28
(define-key wikipedia-mode-map [(control return)] 'wikipedia-insert-itemize)
(define-key wikipedia-mode-map "\C-ca" 'auto-capitalize-mode)
(define-key wikipedia-mode-map "\C-ci" 'set-input-method)
(define-key wikipedia-mode-map "\C-ct" 'toggle-input-method) ;Version:1.23
;;}}}
(make-local-variable 'change-major-mode-hook))
; wikipedia-mode ends here
;;}}}
;;{{{ longlines-mode
(defun wikipedia-turn-on-longlines () ;Version:1.58
"Turn on longlines-mode if it is defined."
(if (functionp 'longlines-mode)
(longlines-mode 1)))
(add-hook 'wikipedia-mode-hook 'wikipedia-turn-on-longlines)
(set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]")
;;}}}
;; New formating stuff for inserting simple formating structures such
;;{{{ Insert makeup and templates
(defvar wikipedia-enumerate-with-terminate-paragraph nil
"*Before insert enumerate/itemize do \\[wikipedia-terminate-paragraph].")
(defun wikipedia-insert-enumerate ()
"Primitive Function for inserting enumerated items, check the
variable wikipedia-enumerate-with-terminate-paragraph. Note however
that the function \\[wikipedia-terminate-paragraph] does not work very
well will longlines-mode."
(interactive)
(when wikipedia-enumerate-with-terminate-paragraph
(wikipedia-terminate-paragraph)
(insert "#"))
(when (not wikipedia-enumerate-with-terminate-paragraph)
(newline nil)
(insert ":#")))
(defun wikipedia-insert-itemize ()
"Primitive Function for inserting no enumerated items, check the
variable wikipedia-enumerate-with-terminate-paragraph. Note however
that the function \\[wikipedia-terminate-paragraph] does not work very
well will longlines-mode."
(interactive)
(when wikipedia-enumerate-with-terminate-paragraph
(wikipedia-terminate-paragraph)
(insert "*"))
(when (not wikipedia-enumerate-with-terminate-paragraph )
(newline nil)
(insert ":*")))
(defun wikipedia-insert-strong-emphasis ()
"Insert strong emphasis italics via four apostrophes (e.g. ''''FOO''''.) When mark is active, surrounds region."
(interactive)
(if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p)
(and (boundp 'transient-mark-mode) transient-mark-mode mark-active))
(save-excursion
(goto-char (point))