/
org-readme.el
1630 lines (1507 loc) · 67.5 KB
/
org-readme.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
;;; org-readme.el --- Integrates Readme.org and Commentary/Change-logs.
;;
;; Filename: org-readme.el
;; Description: Integrate Readme.org and Commentary/Change Logs.
;; Author: Matthew L. Fidler
;; Maintainer: Matthew L. Fidler
;; Created: Fri Aug 3 22:33:41 2012 (-0500)
;; Version: 20121207.1640
;; Package-Requires: ((http-post-simple "1.0") (yaoddmuse "0.1.1")(header2 "21.0") (lib-requires "21.0"))
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500)
;; By: Matthew L. Fidler
;; Update #: 794
;; URL: https://github.com/mlf176f2/org-readme
;; Keywords: Header2, Readme.org, Emacswiki, Git
;; Compatibility: Tested with Emacs 24.1 on Windows.
;;
;; Features that might be required by this library:
;;
;; None
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; * Using org-readme
;; Org readme is used to:
;;
;; - Create/Update a "History" section in the Readme.org based on the changelog
;; section of the Emacs Log.
;; - Create/Update a "Library Information" Section Based on the Emacs lisp header.
;; - Create/Update a "Possible Dependencies" Section Based on the Emacs
;; lisp header.
;; - Create/Update a "Functions" Section based on the functions defined
;; in the single lisp library.
;; - Create/Update a "Variables" Section based on the variables defined
;; in the single lisp library.
;;
;; All other sections of the Readme.org are then put into the
;; "Commentary" section of the readme.org.
;;
;; In addition this library defines `org-readme-sync', a convenience function that:
;;
;; - Asks for a commentary about the library change.
;; - To exit/save press `C-c C-c'
;; - Asks if this is a minor revision
;; - If it is a minor revision, bumps the revision up so the new
;; library will be posted to marmalade-repo.org
;; - The package will attempt to add the readme to the info
;; documentation system within emacs.
;; - Syncs the Readme.org with the lisp file as described above.
;; - Updates emacswiki with the library description and the library
;; itself (requires yaoddmuse).
;; - Updates Marmalade-repo if the library version is different than the
;; version in the server (requires http-post-simple).
;; - Updates the git repository with the differences that you posted.
;; - If you are using github, this library creates a melpa recipie.
;; - If you are using github, this library creates a el-get recipie.
;;
;; When `org-readme-sync' is called in a `Readme.org' file that is not a
;; single lisp file, the function exports the readme in EmacsWiki format
;; and posts it to the EmacsWiki.
;; ** EmacsWiki Page Names
;; EmacsWiki Page names are generated from the file. `org-readme.el'
;; would generate a page of OrgReadme.
;;
;; ** Why each required library is needed
;; There are a few required libraries. This is a list of the require
;; libraries and why they are needed.
;;
;; |------------------+--------------------------------------|
;; | Library | Why it is needed |
;; |------------------+--------------------------------------|
;; | yaoddmuse | Publish to emacswiki |
;; | http-post-simple | Publish to marmalade-repo.org |
;; | header2 | To create header and changelog |
;; | lib-requires | To generate the library dependencies |
;; |------------------+--------------------------------------|
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change Log:
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Trying to post the tar package again.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Bug fix -- Tar package contents to include trailing /, otherwise emacs
;; complains :(
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Bug fix for MELPA versions.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Updated org-readme to use MELPA versions. Therefore when you upload
;; to marmalade-repo and MELPA doesn't pick up your revision, you can
;; download the latest version yourself and try it out.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Added info to melpa recipie.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Attempted to add Readme in info format in the elpa package.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Bug fix for deleting directory.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Remove the directory that was created to make the package tarball
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Attempted to fix the package information file.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Added tar package that includes the info file
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; No longer deletes ilg files.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Bug fix for info generation.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Added mecahism to build info files and dir files for elpa package.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Get description from info file.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; The description should now be picked up.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Attempting to update description.
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Test directory entry
;; 07-Dec-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Added directory entry to texinfo file.
;; 18-Sep-2012
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Bug fix to allow changes that read
;; 12-Sep-2012
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Handle errors with the package gracefully.
;;
;; to include the author name who updated the file.
;;
;; 12-Sep-2012
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Handle errors with the package gracefully.
;; 12-Sep-2012
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Bug fix to eliminate duplicate headers in Readme.org and emacswiki
;; 12-Sep-2012
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Bug fix when org todo faces are not set.
;; 12-Sep-2012
;; Last-Updated: Wed Aug 22 13:11:26 2012 (-0500) #794 (Matthew L. Fidler)
;; Added bug fix when `org-todo-keyword-faces' is undefined.
;; 22-Aug-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:05:14 2012 (-0500) #792 (Matthew L. Fidler)
;; Attempting to upload again
;; 22-Aug-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 22 13:03:44 2012 (-0500) #790 (Matthew L. Fidler)
;; Now will remove variable name and functions from markdown and
;; outputted texinfo.
;; 21-Aug-2012 Matthew L. Fidler
;; Last-Updated: Tue Aug 21 12:57:54 2012 (-0500) #786 (Matthew L. Fidler)
;; Bug fix. When variables/functions are documented with an initial
;; asterisk, change that asterisk to a bulleted item.
;; 21-Aug-2012 Matthew L. Fidler
;; Last-Updated: Tue Aug 21 12:34:00 2012 (-0500) #783 (Matthew L. Fidler)
;; Another documentation update where I document how to change the
;; comment and that org-readme may change the minor revision of the library.
;; 21-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:58:29 2012 (-0500) #781 (Matthew L. Fidler)
;; Updated the documentation for org-readme.
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:56:08 2012 (-0500) #779 (Matthew L. Fidler)
;; Bug fix for variables that don't really transport well to the documentation.
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:43:07 2012 (-0500) #774 (Matthew L. Fidler)
;; Bump minor version for marmalade-repo.org
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:36:02 2012 (-0500) #772 (Matthew L. Fidler)
;; Attempt to fix the History list
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:34:35 2012 (-0500) #770 (Matthew L. Fidler)
;; Added ability to customize which sections are added to the Readme.org
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:26:41 2012 (-0500) #757 (Matthew L. Fidler)
;; Bug fix for creating function readme
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:22:04 2012 (-0500) #754 (Matthew L. Fidler)
;; Will now remove the Functions and Variables sections before putting
;; them in the commentary section.
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:17:03 2012 (-0500) #750 (Matthew L. Fidler)
;; Attempt to remove Readme.md when not needed.
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 22:06:30 2012 (-0500) #744 (Matthew L. Fidler)
;; Added ability to add function documentation and variable documentation
;; to the Readme.org file
;; 20-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 20 09:33:22 2012 (-0500) #684 (Matthew L. Fidler)
;; Added pandoc markdown table support (optional)
;; 13-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 13 21:52:37 2012 (-0500) #679 (Matthew L. Fidler)
;; Another attempt to make texinfo documents.
;; 13-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 13 17:23:40 2012 (-0500) #676 (Matthew L. Fidler)
;; Added texinfo output. Allows native emacs documentation.
;; 13-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 13 16:48:37 2012 (-0500) #670 (Matthew L. Fidler)
;; Tried to post behind firewall. Reattempting.
;; 13-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 13 16:44:23 2012 (-0500) #668 (Matthew L. Fidler)
;; Changed the `org-readme-remove-section' to use `org-cut-subtree'.
;; Hopefully all errors will resolve themselves now.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 23:51:30 2012 (-0500) #665 (Matthew L. Fidler)
;; Reverted. Still buggy.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 17:17:44 2012 (-0500) #662 (Matthew L. Fidler)
;; Another attempt at bug fix to remove section.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 17:13:24 2012 (-0500) #659 (Matthew L. Fidler)
;; Another attempt at a remove-section fix.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 17:07:22 2012 (-0500) #654 (Matthew L. Fidler)
;; Bug fix for org-readme version tagging.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 17:03:26 2012 (-0500) #650 (Matthew L. Fidler)
;; Test the bug where some of the section text is deleted
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 16:46:03 2012 (-0500) #647 (Matthew L. Fidler)
;; Added more documentation
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 16:45:19 2012 (-0500) #645 (Matthew L. Fidler)
;; One last bug fix to the markdown export engine.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 16:42:41 2012 (-0500) #642 (Matthew L. Fidler)
;; Markdown bug fix
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 16:31:18 2012 (-0500) #637 (Matthew L. Fidler)
;; Bug fix for el-get recipe.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 16:28:45 2012 (-0500) #633 (Matthew L. Fidler)
;; Added the ability to create a markdown Readme (Readme.md) as well as
;; adding a el-get recipe.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 11:22:44 2012 (-0500) #529 (Matthew L. Fidler)
;; Bug fix for emacswiki post and melpa bug fix
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 11:20:16 2012 (-0500) #525 (Matthew L. Fidler)
;; Bug fix for adding melpa recipes.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 11:19:36 2012 (-0500) #524 (Matthew L. Fidler)
;; Bug fix for creating melpa recipe.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 11:16:46 2012 (-0500) #521 (Matthew L. Fidler)
;; Added ability to add melpa recipe
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 07:12:35 2012 (-0500) #492 (Matthew L. Fidler)
;; Bug fix for pushing tags to a git repository
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 01:21:02 2012 (-0500) #480 (Matthew L. Fidler)
;; Another fix for git tags.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 01:18:42 2012 (-0500) #477 (Matthew L. Fidler)
;; Found a bug, let see if tagging works now.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 01:17:40 2012 (-0500) #475 (Matthew L. Fidler)
;; Added Git tagging of new versions. Lets see if it works.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 01:08:21 2012 (-0500) #467 (Matthew L. Fidler)
;; Git push worked. Bumping minor version.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 01:07:26 2012 (-0500) #465 (Matthew L. Fidler)
;; Attempted to push repository again.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 01:03:15 2012 (-0500) #461 (Matthew L. Fidler)
;; Attempt to push with git. Something changed.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 01:02:04 2012 (-0500) #457 (Matthew L. Fidler)
;; Added better Package-Requires tag.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:58:56 2012 (-0500) #454 (Matthew L. Fidler)
;; Made request for minor revision earlier, and fixed bug.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:57:29 2012 (-0500) #451 (Matthew L. Fidler)
;; Fixed code typo
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:56:12 2012 (-0500) #449 (Matthew L. Fidler)
;; Bug fix for deleting a section of a Readme.org file.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:55:37 2012 (-0500) #447 (Matthew L. Fidler)
;; Testing bug.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:55:30 2012 (-0500) #446 (Matthew L. Fidler)
;; Minor bug fix.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:53:32 2012 (-0500) #444 (Matthew L. Fidler)
;; Bug fix for comment sync, now Readme.org =file= is translated to lisp
;; `file'. Additionally, asks for version bump.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:44:17 2012 (-0500) #434 (Matthew L. Fidler)
;; Bug fix for syncing readme. Now the returns should not be as prevalent.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:39:23 2012 (-0500) #430 (Matthew L. Fidler)
;; Attempting to post to marmlade again...
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:35:40 2012 (-0500) #426 (Matthew L. Fidler)
;; Attempting to fix org-readme-marmalade-post.
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:26:36 2012 (-0500) #420 (Matthew L. Fidler)
;; Bug fix to upload to emacswiki and upload to marmalade-repo
;; 11-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 11 00:21:27 2012 (-0500) #413 (Matthew L. Fidler)
;; Added marmalade-repo support. Now org-readme should upload to
;; marmalade-repo when the version is different from the latest version.
;; 08-Aug-2012 Matthew L. Fidler
;; Last-Updated: Wed Aug 8 18:44:37 2012 (-0500) #343 (Matthew L. Fidler)
;; Fixed preformatting tags in emacswiki post. Previously they may have
;; been replaced with <PRE></pre> instead of <pre></pre>. This makes the
;; emacswiki page display correctly.
;; 07-Aug-2012 Matthew L. Fidler
;; Last-Updated: Tue Aug 7 19:22:53 2012 (-0500) #333 (Matthew L. Fidler)
;; To use, put (require 'ess-smart-underscore) in your ~/.emacs file
;; 7-Aug-2012 Matthew L. Fidler
;; Last-Updated: Tue Aug 7 19:14:34 2012 (-0500) #331 (Matthew L. Fidler)
;; Added a Comment to EmcsWiki pages that states that the content of the
;; page will likely be overwitten since it is automatically generated by `org-readme'
;; 7-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 6 23:42:02 2012 (-0500) #328 (Matthew L. Fidler)
;; Added more documentation.
;; 06-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 6 23:24:22 2012 (-0500) #326 (Matthew L. Fidler)
;; Added support for uploading Readme.org files to emacswiki without
;; having to have a single associated lisp file.
;; 06-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 6 20:44:55 2012 (-0500) #282 (Matthew L. Fidler)
;; Bug fix for syncing from the single lisp file.
;; 06-Aug-2012 Matthew L. Fidler
;; Last-Updated: Mon Aug 6 20:12:50 2012 (-0500) #274 (Matthew L. Fidler)
;; Added the ability to call `org-readme-sync' from Readme.org
;; 05-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sun Aug 5 12:30:26 2012 (-0500) #250 (Matthew L. Fidler)
;; Added git pushing to org-readme
;; 05-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sun Aug 5 12:21:53 2012 (-0500) #237 (Matthew L. Fidler)
;; Added git support as well as a comment mode. The only thing that
;; should need to be called is `org-readme-sync'
;; 04-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 4 21:40:14 2012 (-0500) #122 (Matthew L. Fidler)
;; Added syncing with emacswiki.
;; 04-Aug-2012 Matthew L. Fidler
;; Last-Updated: Sat Aug 4 00:02:49 2012 (-0500) #20 (Matthew L. Fidler)
;; Initial Release
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program 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 3, or
;; (at your option) any later version.
;;
;; This program 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 this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(require 'yaoddmuse nil t)
(require 'http-post-simple nil t)
(require 'org-html)
(defgroup org-readme nil
"Org-readme is a way to create Readme.org files based on an elisp file.")
(defcustom org-readme-use-melpa-versions t
"Use Melpa-type versions YYYYMMDD.HHMM instead of 0.0.0 versions"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-marmalade-server "http://marmalade-repo.org"
"Marmalade server website. This should start with http: and should notend with a trailing forward slash, just like the default value of http://marmalade-repo.org"
:type 'string
:group 'org-readme)
(defcustom org-readme-marmalade-token nil
"Marmalade token to upload content to the marmalade server."
:type 'string
:group 'org-readme)
(defcustom org-readme-marmalade-user-name nil
"Marmalade user name to upload content to the marmalade server."
:type 'string
:group 'org-readme)
(defcustom org-readme-sync-emacswiki t
"Posts library to the emacswiki. Requires `yaoddmuse'"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-sync-marmalade t
"Posts library to marmalade-repo.org"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-sync-git t
"Posts library to git"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-build-melpa-recipe t
"Builds a melpa recipe based on github information"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-build-el-get-recipe t
"Builds a el-get recipe based on github information"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-build-markdown t
"Builds Readme.md from Readme.org"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-use-pandoc-markdown t
"Uses pandoc's grid tables instead of transferring the tables to html."
:type 'boolean
:group 'org-readme)
(defcustom org-readme-build-texi t
"Builds library-name.texi from Readme.org, using Readme.md and pandoc. Requires `org-readme-build-markdown' to be non-nil as pandoc to be found."
:type 'boolean
:group 'org-readme)
(defcustom org-readme-drop-markdown-after-build-texi t
"Removes Readme.md after texinfo is generated"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-build-info t
"Builds library-name.info from Reade.org using texi. Requires `org-readme-build-texi' to be non-nil, pandoc and makeinfo to be found. This will also create the directory entry using install-info, if it is found."
:type 'boolean
:group 'org-readme)
(defcustom org-readme-drop-texi-after-build-info t
"Removes the texi information after building info files."
:type 'boolean
:group 'org-readme)
(defcustom org-readme-add-functions-to-readme t
"Add a Functions section to Readme.org"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-add-variables-to-readme t
"Add a Variables section to Readme.org"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-add-changelog-to-readme t
"Add a Variables section to Readme.org"
:type 'boolean
:group 'org-readme)
(defcustom org-readme-add-top-header-to-readme t
"Add Top Header information to Readme.org"
:type 'boolean
:group 'org-readme)
(defun org-readme-insert-functions ()
"Extracts function documentation and places it in the Readme.org file."
(save-excursion
(goto-char (point-min))
(let ((lst1 '()) tmp ret1 ret2 ret
(readme (org-readme-find-readme)))
(while (re-search-forward "(defun[*]?[ \t\n]+\\([^ \t\n]+\\)" nil t)
(add-to-list 'lst1 (match-string-no-properties 1)))
(setq lst (sort lst1 'string<))
(flet ((fd (x)
(with-temp-buffer
(insert x)
(goto-char (point-min))
(when (re-search-forward "'[.]" nil t)
(skip-chars-forward " \t\n")
(delete-region (point) (point-min)))
(goto-char (point-min))
(when (re-search-forward "[(]" nil t)
(goto-char (match-beginning 0))
(insert "=")
(forward-list)
(insert "="))
(goto-char (point-min))
(while (re-search-forward "`\\(.*?\\)'" nil t)
(replace-match "=\\1="))
(goto-char (point-min))
(while (re-search-forward "^[ \t]*[*]+[ \t]+" nil t)
(replace-match " - "))
(goto-char (point-max))
(insert "\n")
(buffer-string))))
(setq ret1 "** Interactive Functions\n")
(setq ret2 "** Internal Functions\n")
(mapc
(lambda(x)
(condition-case err
(when (intern x)
(setq tmp (describe-function (intern x)))
(cond
((string-match "Not documented" tmp))
((string-match "interactive" tmp)
(setq ret1 (concat ret1 "\n*** " x "\n" (fd tmp))))
(t
(setq ret2 (concat ret2 "\n*** " x "\n" (fd tmp))))))
(error nil)))
lst)
(setq ret (concat "* Functions\n" ret1 "\n" ret2)))
(with-temp-buffer
(insert-file-contents readme)
(org-readme-remove-section "Functions" ret)
(write-file readme)))))
(defun org-readme-insert-variables ()
"Extracts variable documentation and places it in the Readme.org file."
(interactive)
(condition-case err
(eval-buffer)
(error nil))
(save-excursion
(goto-char (point-min))
(let ((lst1 '()) tmp ret1 ret2 ret
(readme (org-readme-find-readme)))
(while (re-search-forward "(def\\(?:var\\|custom\\)[*]?[ \t\n]+\\([^ \t\n]+\\)" nil t)
(add-to-list 'lst1 (match-string-no-properties 1)))
(setq lst (sort lst1 'string<))
(flet ((fd (x)
(with-temp-buffer
(insert x)
(goto-char (point-min))
(when (re-search-forward "Documentation:" nil t)
(skip-chars-forward " \t\n")
(delete-region (point) (point-min)))
(when (re-search-forward "You can customize this variable" nil t)
(goto-char (match-beginning 0))
(skip-chars-backward " \t\n")
(delete-region (point) (point-max)))
(goto-char (point-min))
(while (re-search-forward "`\\(.*?\\)'" nil t)
(replace-match "=\\1="))
(goto-char (point-min))
(while (re-search-forward "^[ \t]*[*]+[ \t]+" nil t)
(replace-match " - "))
(goto-char (point-max))
(insert "\n")
(buffer-string))))
(setq ret1 "** Customizable Variables\n")
(setq ret2 "** Internal Variables\n")
(mapc
(lambda(x)
(condition-case err
(when (intern x)
(setq tmp (describe-variable (intern x)))
(cond
((string-match "Not documented" tmp))
((string-match "customize" tmp)
(setq ret1 (concat ret1 "\n*** " x "\n" (fd tmp))))
(t
(setq ret2 (concat ret2 "\n*** " x "\n" (fd tmp))))))
(error nil)))
lst)
(setq ret (concat "* Variables\n" ret1 "\n" ret2)))
(with-temp-buffer
(insert-file-contents readme)
(org-readme-remove-section "Variables" ret)
(write-file readme)))))
(defun org-readme-build-el-get ()
"Builds an el-get recipe. This assumes github, though others could be added.
Returns file name if created."
(let ((el-get (expand-file-name
"el-get" (file-name-directory (buffer-file-name))))
(lib-name (file-name-sans-extension
(file-name-nondirectory (buffer-file-name))))
(git-cfg
(expand-file-name
"config"
(expand-file-name
".git" (file-name-directory (buffer-file-name)))))
github tmp
rcp)
(unless (file-exists-p el-get)
(make-directory el-get))
(setq el-get (expand-file-name lib-name el-get))
(when (file-exists-p git-cfg)
(with-temp-buffer
(insert-file-contents git-cfg)
(goto-char (point-min))
(when (re-search-forward "git@github.com:\\(.*?\\)[.]git" nil t)
(setq github (match-string 1))))
(setq rcp
(format "(:name %s\n :description \"%s\"%s\n :website \"%s\"\n :type git\n :url \"%s\")"
lib-name
(save-excursion
(goto-char (point-min))
(if (re-search-forward "^[ \t]*;;;[ \t]*%s[.]el[ \t]*--+[ \t]*\\(.*?\\)[ \t]*$" nil t)
(match-string 1)
lib-name))
;; :depends
(save-excursion
(goto-char (point-min))
(if (re-search-forward "^[ \t]*;+[ \t]*[Pp]ackage-[Rr]equires:[ \t]*\\(.*?\\)[ \t]*$" nil t)
(condition-case err
(progn
(setq tmp (match-string 1))
(with-temp-buffer
(insert (format "(setq tmp '%s)" tmp))
(condition-case err
(eval-buffer)
(error nil)))
(format "\n :depends (%s)"
(mapconcat
(lambda(x)
(symbol-name (car x)))
tmp " ")))
(error (message "Error parsing package-requires: %s" err)
""))
""))
;; Website
(save-excursion
(goto-char (point-min))
(if (re-search-forward "^[ \t]*;+URL:[ \t]*\\(.*\\)[ \t]*$" nil t)
(match-string 1)
(format "https://github.com/%s" github)))
;; Github
(format "https://github.com/%s.git" github)
lib-name))
(when rcp
(with-temp-file el-get
(insert rcp))))
(if (file-exists-p el-get)
(symbol-value 'el-get)
nil)))
(defun org-readme-build-melpa ()
"Builds a melpa recipe. This assumes github, though other could be added.
Returns file name if created."
(let ((melpa (expand-file-name
"melpa" (file-name-directory (buffer-file-name))))
(lib-name (file-name-sans-extension
(file-name-nondirectory (buffer-file-name))))
(git-cfg
(expand-file-name
"config"
(expand-file-name
".git" (file-name-directory (buffer-file-name)))))
rcp)
(unless (file-exists-p melpa)
(make-directory melpa))
(setq melpa (expand-file-name lib-name melpa))
(when (file-exists-p git-cfg)
(with-temp-buffer
(insert-file-contents git-cfg)
(goto-char (point-min))
(when (re-search-forward "git@github.com:\\(.*?\\)[.]git")
(setq rcp
(format "(%s\n :repo \"%s\"\n :fetcher github\n :files (\"%s.el\" \"dir\" \"%s.info\"))"
lib-name
(match-string 1)
lib-name lib-name))))
(when rcp
(with-temp-file melpa
(insert rcp))))
(if (file-exists-p melpa)
(symbol-value 'melpa)
nil)))
(defun org-readme-buffer-version ()
"Gets the version of the current buffer."
(let (ver
(case-fold-search t))
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^ *;+ *Version: *\\(.*?\\) *$" nil t)
(setq ver (match-string-no-properties 1))))
(symbol-value 'ver)))
(defun org-readme-marmalade-post ()
"Posts the current buffer to Marmalade."
(interactive)
(let* ((package (file-name-sans-extension
(file-name-nondirectory (buffer-file-name))))
(m-ver (org-readme-marmalade-version package))
(b-ver (org-readme-buffer-version))
token
resp)
(message "Marmalade %s Version: %s, Buffer Version: %s"
package m-ver b-ver)
(when (or (not m-ver) (not (string= m-ver b-ver)))
(message "Should post %s, the marmalade package is outdated or does not exist."
package)
(setq token (org-readme-token))
(setq resp (http-post-simple-multipart
(format "%s/v1/packages"
org-readme-marmalade-server)
`((name . ,org-readme-marmalade-user-name)
(token . ,token))
`(("package" ,(if (file-exists-p (concat package ".tar"))
(concat (file-name-sans-extension (buffer-file-name)) ".tar")
(buffer-file-name))
"text/x-script.elisp"
,(if (file-exists-p (concat package ".tar"))
(with-temp-buffer
(insert-file-contents (concat package ".tar"))
(buffer-string))
(buffer-string))))))
(when (file-exists-p (concat package ".tar"))
(delete-file (concat package ".tar")))
(message "%s" resp))))
(defun org-readme-marmalade-version (package)
"Gets the marmalade version of the PACKAGE."
(let ((ver-json (url-retrieve-synchronously
(format "%s/v1/packages/%s/latest"
org-readme-marmalade-server
package)))
ver)
(when ver-json
(save-excursion
(set-buffer ver-json)
(goto-char (point-min))
(when (re-search-forward "\"version\"[ \t]*:[ \t]*\"\\(.*?\\)\"" nil t)
(setq ver (match-string 1)))
(kill-buffer (current-buffer))))
(symbol-value 'ver)))
(defun org-readme-token ()
"Gets marmalade-token, if not already saved."
(or org-readme-marmalade-token
(let ((user-name (or org-readme-marmalade-user-name
(read-string "Marmalade username: ")))
(password (read-passwd "Marmalade password: "))
token)
(setq token
(with-temp-buffer
(insert
(format "%s"
(nth 0
(http-post-simple
(format "%s/v1/users/login"
org-readme-marmalade-server)
`((name . ,user-name)
(password . ,password))))))
(goto-char (point-min))
(if (not (re-search-forward "\"token\"[ \t]*:[ \t]*\"\\(.*?\\)\"" nil t))
nil
(match-string 1))))
(when token
(setq org-readme-marmalade-user-name user-name)
(setq org-readme-marmalade-token token)
(customize-save-variable 'org-readme-marmalade-user-name org-readme-marmalade-user-name)
(customize-save-variable 'org-readme-marmalade-token org-readme-marmalade-token))
(symbol-value 'token))))
(defcustom org-readme-remove-sections
'("History" "Possible Dependencies" "Library Information"
"Functions" "Variables")
"List of sections to remove when changing the Readme.org to Commentary."
:group 'org-readme
:type '(repeat (string :tag "Section")))
(defcustom org-readme-remove-sections-from-markdown
'("Functions" "Variables")
"List of sections to remove when changing the Readme.org to Markdown which is an intermediary for texinfo (using pandoc)."
:group 'org-readme
:type '(repeat (string :tag "Section")))
(defvar org-readme-edit-mode-map nil
"Keymap for editing change-logs.")
(unless org-readme-edit-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") 'org-readme-edit-commit)
(define-key map (kbd "C-x C-s") 'org-readme-edit-commit)
(define-key map (kbd "C-c C-k") 'org-readme-edit-cancel)
(setq org-readme-edit-mode-map map)))
(defun org-readme-edit-commit ()
"Changelog for editing."
(interactive)
(let ((comment (buffer-substring (point-min) (point-max)))
mr)
(kill-buffer (get-buffer "*Change Comment*"))
(with-temp-buffer
(insert comment)
(goto-char (point-min))
(end-of-line)
(while (re-search-forward "^" nil t)
(insert ";; "))
(setq mr (buffer-substring (point-min) (point-max))))
(set-buffer org-readme-edit-last-buffer)
(make-revision)
(insert mr)
(save-buffer)
(with-temp-file (org-readme-get-change)
(insert comment))
(org-readme-sync t)))
(defun org-readme-edit-cancel ()
"Cancel the edit log."
(interactive)
(kill-buffer (get-buffer "*Change Comment*"))
(when org-readme-edit-last-window-configuration
(set-window-configuration org-readme-edit-last-window-configuration)))
(defvar org-readme-edit-last-window-configuration nil)
(defvar org-readme-edit-last-buffer nil)
(defun org-readme-edit ()
"Edit change comment for commit."
(interactive)
(unless org-readme-edit-last-window-configuration
(setq org-readme-edit-last-window-configuration (current-window-configuration)))
(switch-to-buffer-other-window (get-buffer-create "*Change Comment*"))
(org-readme-edit-mode))
(define-derived-mode org-readme-edit-mode text-mode "Org-readme Log edit.")
(defun org-readme-convert-to-markdown ()
"Converts Readme.org to markdown Readme.md."
(interactive)
(let ((readme (org-readme-find-readme))
(what "Readme.md")
p1 md tmp tmp2)
(with-temp-buffer
(insert-file-contents readme)
(mapc
(lambda(section)
(org-readme-remove-section section))
org-readme-remove-sections-from-markdown)
(goto-char (point-min))
(while (re-search-forward "#[+]TITLE:" nil t)
(replace-match "+TITLE:"))
(goto-char (point-min))
(while (re-search-forward "#[+]AUTHOR:" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "^[ \t]*#.*" nil t) ;
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "[+]TITLE:" nil t)
(replace-match "# "))
;; Convert Headings
(goto-char (point-min))
(while (re-search-forward "^\\([*]+\\) *!?\\(.*\\)" nil t)
(setq tmp (make-string (+ 1 (length (match-string 1))) ?#))
(replace-match (format "%s %s" tmp (match-string 2)) t t))
;; Convert links [[link][text]] to [text](link)
(goto-char (point-min))
(while (re-search-forward "\\[\\[\\(\\(?:https?\\|ftp\\).*?\\)\\]\\[!?\\(.*?\\)\\]\\]" nil t)
(replace-match "[\\2](\\1)" t))
;; Replace file links.
(goto-char (point-min))
(while (re-search-forward "\\[\\[file:\\(.*?[.]el\\)\\]\\[\\1\\]\\]" nil t)
(replace-match "\\1"))
;; Underline _ul_ to <ul>ul</ul>
(goto-char (point-min))
(while (re-search-forward "_\\(.*+?\\)_" nil t)
(replace-match (format "<ul>%s</ul>" (match-string 1)) t t))
;; Emphasis /emp/ to _emph_
(goto-char (point-min))
(while (re-search-forward "/\\(.*+?\\)/" nil t)
(replace-match (format "_%s_" (match-string 1)) t t))
;; Bold *bold* to __bold__
(goto-char (point-min))
(while (re-search-forward "[*]\\(.*+?\\)[*]" nil t)
(unless (save-match-data (string-match "^[*]+$" (match-string 1)))
(replace-match (format "__%s__" (match-string 1)) t t)))
(goto-char (point-min))
(while (re-search-forward "^[ \t]*[+-] +\\(.*?\\) *::" nil t)
(replace-match (format "- __%s__ -- " (match-string 1))))
;; Code blocks
(goto-char (point-min))
(while (re-search-forward "=\\(.*+?\\) *=" nil t)
(replace-match (format "`%s`" (match-string 1)) t t))
(goto-char (point-min))
(while (re-search-forward "^ *#[+]BEGIN_SRC.*" nil t)
(setq tmp (point))
(when (re-search-forward "^ *#[+]END_SRC" nil t)
(beginning-of-line)
(setq tmp2 (point))
(goto-char tmp)
(while (and (> tmp2 (point))
(re-search-forward "^" tmp2 t))
(replace-match "::::"))))
(goto-char (point-min))
(while (re-search-forward "^: " nil t)
(replace-match "\n::::" t t) ;
(while (progn
(end-of-line)
(re-search-forward "\\=\n: " nil t))
(replace-match "\n:::: "))
(end-of-line))
;; Convert pre-formatted
(goto-char (point-min))
(while (re-search-forward "^::::" nil t)
(replace-match " "))
;; Convert tables to html
(goto-char (point-min))
(while (re-search-forward "^[ \t]*|.*|[ \t]*$" nil t)
(beginning-of-line)
(setq p1 (point))
(end-of-line)
(while (re-search-forward "\\=\n[ \t]*|" nil t)
(end-of-line))
(end-of-line)
(save-restriction
(narrow-to-region p1 (point))
(if org-readme-use-pandoc-markdown
(progn
(goto-char (point-min))
(while (re-search-forward "^\\([ \t]*\\)|\\(-.*?-\\)|\\([ \t]*\\)$" nil t)
(replace-match "\\1+\\2+\\3")))
(org-replace-region-by-html (point-min) (point-max))
(goto-char (point-min))
(while (re-search-forward "class" nil t)
(replace-match "align")))))
;; Lists are the same.
(setq readme (buffer-string)))
(with-temp-file (expand-file-name
"Readme.md"
(file-name-directory (buffer-file-name)))
(insert readme))))
(defun org-readme-convert-to-emacswiki ()
"Converts Readme.org to oddmuse markup and uploads to emacswiki."
(interactive)
(let ((readme (org-readme-find-readme))
(what (file-name-nondirectory (buffer-file-name)))
(wiki (org-readme-get-emacswiki-name))
tmp tmp2)
(with-temp-buffer
(insert-file-contents readme)
;; Take out CamelCase Links
(goto-char (point-min))
(let ((case-fold-search nil))
(while (re-search-forward "\\([A-Z][a-z]+[A-Z][A-Za-z]*\\)" nil t)
(replace-match (format "!%s" (match-string 1)) t t)))
;; Convert Tables.
(goto-char (point-min))
(while (re-search-forward "^[ \t]*|[-+]+|[ \t]*\n" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "^[ \t]*|" nil t)
(replace-match "||")
(while (re-search-forward "|" (point-at-eol) t)
(replace-match "||")))
;; Convert Links
(goto-char (point-min))
(while (re-search-forward "\\[\\[\\(\\(?:https?\\|ftp\\).*?\\)\\]\\[!?\\(.*?\\)\\]\\]" nil t)
(replace-match "[\\1 \\2]" t))