show-comments.pl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 3 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, see <http://www.gnu.org/licenses/>.
  16. # Includes comment pages in journal collections.
  17. use strict;
  18. use v5.10;
  19. AddModuleDescription('show-comments.pl', 'Comment Pages');
  20. our (%Page, $OpenPageName, $CommentsPrefix, $CollectingJournal);
  21. *OldPrintJournal = \&PrintJournal;
  22. *PrintJournal = \&NewPrintJournal;
  23. sub NewPrintJournal {
  24. my ($num, $regexp, $mode) = @_;
  25. if (!$CollectingJournal) {
  26. $CollectingJournal = 1;
  27. $regexp = '^\d\d\d\d-\d\d-\d\d' unless $regexp;
  28. $num = 10 unless $num;
  29. my @pages = (grep(/$regexp/, AllPagesList()));
  30. if (defined &JournalSort) {
  31. @pages = sort JournalSort @pages;
  32. } else {
  33. # Begin modifications to PrintJournal
  34. if ($mode eq 'reverse') {
  35. @pages = sort {
  36. my ($A, $B) = ($a, $b);
  37. $A .= 'z' unless $A =~ s/^$CommentsPrefix//;
  38. $B .= 'z' unless $B =~ s/^$CommentsPrefix//;
  39. $B cmp $A;
  40. } @pages;
  41. } else {
  42. @pages = sort {
  43. my ($A, $B) = ($a, $b);
  44. $A .= 'z' unless $A =~ s/^$CommentsPrefix//;
  45. $B .= 'z' unless $B =~ s/^$CommentsPrefix//;
  46. $B cmp $A;
  47. } @pages;
  48. }
  49. # End modifications to PrintJournal
  50. }
  51. if ($mode eq 'reverse') {
  52. @pages = reverse @pages;
  53. }
  54. @pages = @pages[0 .. $num - 1] if $#pages >= $num;
  55. if (@pages) {
  56. # Now save information required for saving the cache of the current page.
  57. local %Page;
  58. local $OpenPageName='';
  59. print '<div class="journal">';
  60. PrintAllPages(1, 1, undef, undef, @pages);
  61. print '</div>';
  62. }
  63. $CollectingJournal = 0;
  64. }
  65. }