show-comments.pl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
  2. # Sebastian Blatt <sblatt@havens.de>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the
  16. # Free Software Foundation, Inc.
  17. # 59 Temple Place, Suite 330
  18. # Boston, MA 02111-1307 USA
  19. # Includes comment pages in journal collections.
  20. use strict;
  21. use v5.10;
  22. AddModuleDescription('show-comments.pl', 'Comment Pages');
  23. our (%Page, $OpenPageName, $CommentsPrefix, $CollectingJournal);
  24. *OldPrintJournal = \&PrintJournal;
  25. *PrintJournal = \&NewPrintJournal;
  26. sub NewPrintJournal {
  27. my ($num, $regexp, $mode) = @_;
  28. if (!$CollectingJournal) {
  29. $CollectingJournal = 1;
  30. $regexp = '^\d\d\d\d-\d\d-\d\d' unless $regexp;
  31. $num = 10 unless $num;
  32. my @pages = (grep(/$regexp/, AllPagesList()));
  33. if (defined &JournalSort) {
  34. @pages = sort JournalSort @pages;
  35. } else {
  36. # Begin modifications to PrintJournal
  37. if ($mode eq 'reverse') {
  38. @pages = sort {
  39. my ($A, $B) = ($a, $b);
  40. $A .= 'z' unless $A =~ s/^$CommentsPrefix//;
  41. $B .= 'z' unless $B =~ s/^$CommentsPrefix//;
  42. $B cmp $A;
  43. } @pages;
  44. } else {
  45. @pages = sort {
  46. my ($A, $B) = ($a, $b);
  47. $A .= 'z' unless $A =~ s/^$CommentsPrefix//;
  48. $B .= 'z' unless $B =~ s/^$CommentsPrefix//;
  49. $B cmp $A;
  50. } @pages;
  51. }
  52. # End modifications to PrintJournal
  53. }
  54. if ($mode eq 'reverse') {
  55. @pages = reverse @pages;
  56. }
  57. @pages = @pages[0 .. $num - 1] if $#pages >= $num;
  58. if (@pages) {
  59. # Now save information required for saving the cache of the current page.
  60. local %Page;
  61. local $OpenPageName='';
  62. print '<div class="journal">';
  63. PrintAllPages(1, 1, undef, undef, @pages);
  64. print '</div>';
  65. }
  66. $CollectingJournal = 0;
  67. }
  68. }