-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnavi2ch-article.el
4128 lines (3875 loc) · 150 KB
/
navi2ch-article.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
;;; navi2ch-article.el --- article view module for navi2ch -*- coding: iso-2022-7bit; -*-
;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
;; 2009 by Navi2ch Project
;; Author: Taiki SUGAWARA <taiki@users.sourceforge.net>
;; Keywords: network, 2ch
;; 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, 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; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;;; Code:
(provide 'navi2ch-article)
(defconst navi2ch-article-ident
"$Id$")
(eval-when-compile
(require 'cl)
(defvar navi2ch-board-buffer-name)
(defvar navi2ch-board-current-board)
(defvar navi2ch-board-subject-list)
(defvar navi2ch-board-last-seen-alist)
(defvar navi2ch-popup-article-current-board)
(defvar navi2ch-popup-article-current-article)
(require 'wid-edit))
(require 'base64)
(require 'widget)
(require 'navi2ch)
(defvar navi2ch-article-mode-map nil)
(unless navi2ch-article-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map navi2ch-global-view-map)
(define-key map "q" 'navi2ch-article-exit)
(define-key map "Q" 'navi2ch-article-goto-current-board)
(define-key map "s" 'navi2ch-article-sync)
(define-key map "S" 'navi2ch-article-sync-disable-diff)
(define-key map "r" 'navi2ch-article-redraw-range)
(define-key map "j" 'navi2ch-article-few-scroll-up)
(define-key map "k" 'navi2ch-article-few-scroll-down)
(define-key map " " 'navi2ch-article-scroll-up)
(navi2ch-define-delete-keys map 'navi2ch-article-scroll-down)
(define-key map "w" 'navi2ch-article-write-message)
(define-key map "W" 'navi2ch-article-write-sage-message)
(define-key map "\r" 'navi2ch-article-select-current-link)
(unless (featurep 'xemacs)
(define-key map [follow-link] 'mouse-face))
(navi2ch-define-mouse-key map 2 'navi2ch-article-mouse-select)
(define-key map "g" 'navi2ch-article-goto-number-or-board)
;; (define-key map "g" 'navi2ch-article-goto-number)
(define-key map "l" 'navi2ch-article-pop-point)
(define-key map "L" 'navi2ch-article-pop-poped-point)
(define-key map "m" 'navi2ch-article-push-point)
(define-key map "R" 'navi2ch-article-rotate-point)
(define-key map "U" 'navi2ch-article-show-url)
(define-key map "." 'navi2ch-article-redisplay-current-message)
(define-key map "p" 'navi2ch-article-previous-message)
(define-key map "n" 'navi2ch-article-next-message)
(define-key map "P" 'navi2ch-article-through-previous)
(define-key map "N" 'navi2ch-article-through-next)
(define-key map [(shift tab)] 'navi2ch-article-previous-link)
(define-key map [(iso-left-tab)] 'navi2ch-article-previous-link)
(define-key map [(shift iso-lefttab)] 'navi2ch-article-previous-link)
(define-key map "\e\C-i" 'navi2ch-article-previous-link)
(define-key map "\C-\i" 'navi2ch-article-next-link)
(define-key map "i" 'navi2ch-article-fetch-link)
(define-key map ">" 'navi2ch-article-goto-last-message)
(define-key map "<" 'navi2ch-article-goto-first-message)
(define-key map "\ed" 'navi2ch-article-decode-message)
(define-key map "\ei" 'navi2ch-article-auto-decode-toggle-text)
(define-key map "v" 'navi2ch-article-view-aa)
(define-key map "f" 'navi2ch-article-forward-buffer)
(define-key map "b" 'navi2ch-article-backward-buffer)
(define-key map "d" 'navi2ch-article-hide-message)
(define-key map "a" 'navi2ch-article-add-important-message)
(define-key map "h" 'navi2ch-article-toggle-hide)
(define-key map "$" 'navi2ch-article-toggle-important)
(define-key map "A" 'navi2ch-article-add-global-bookmark)
(define-key map "\C-c\C-m" 'navi2ch-message-pop-message-buffer)
(define-key map "G" 'navi2ch-article-goto-board)
(define-key map "e" 'navi2ch-article-textize-article)
(define-key map "?" 'navi2ch-article-search)
(define-key map "\C-o" 'navi2ch-article-save-dat-file)
(define-key map "F" 'navi2ch-article-toggle-message-filter)
(define-key map "x" 'undefined)
(define-key map "!" 'navi2ch-article-add-message-filter-cus)
(define-key map "\C-c\C-r" 'navi2ch-article-remove-article)
(navi2ch-ifxemacs
(define-key map "\C-c\C- " 'navi2ch-article-toggle-sticky)
(define-key map [(control c) (control ? )] 'navi2ch-article-toggle-sticky))
(define-key map "u" 'navi2ch-show-url-at-point)
(define-key map "\C-c\C-y" 'navi2ch-article-write-cite-message)
(define-key map "," 'navi2ch-thumbnail-select-current-link)
(define-key map "V" 'navi2ch-thumbnail-save-content)
(define-key map "\e\r" 'navi2ch-article-select-current-link)
(define-key map "\C-c\C-d" 'navi2ch-thumbnail-image-delete-cache)
(define-key map "T" 'navi2ch-thumbnail-all-show)
(setq navi2ch-article-mode-map map)))
(defvar navi2ch-article-mode-menu-spec
'("Article"
["Toggle offline" navi2ch-toggle-offline]
["Sync" navi2ch-article-sync]
["Sync (no diff)" navi2ch-article-sync-disable-diff]
["Exit" navi2ch-article-exit]
["Write message" navi2ch-article-write-message]
["Write message (sage)" navi2ch-article-write-sage-message]
["Select Range" navi2ch-article-redraw-range]))
(defvar navi2ch-article-view-range nil
"$BI=<($9$k%9%l%C%I$NHO0O!#(B
$B=q<0$O(B '(first . last) $B$G!"(B
first $B$,:G=i$+$i$$$/$DI=<($9$k$+!"(B
last $B$,:G8e$+$i$$$/$DI=<($9$k$+!#(B
$BNc$($P!"(B(10 . 50) $B$G!":G=i$N(B10$B$H:G8e$N(B50$B$rI=<((B")
(defvar navi2ch-article-buffer-name-prefix "*navi2ch article ")
(defvar navi2ch-article-current-article nil)
(defvar navi2ch-article-current-board nil)
(defvar navi2ch-article-message-list nil)
(defvar navi2ch-article-point-stack nil "$B0LCV$r3P$($H$/(B stack")
(defvar navi2ch-article-poped-point-stack nil)
(defvar navi2ch-article-hide-mode nil)
(defvar navi2ch-article-through-next-function 'navi2ch-article-through-next)
(defvar navi2ch-article-through-previous-function 'navi2ch-article-through-previous)
(defvar navi2ch-article-through-forward-line-function 'navi2ch-bm-forward-line
"$BA08e$N%9%l$K0\F0$9$k$?$a$K<B9T$5$l$k4X?t!#(B
$B0l$D$N@0?t$r0z?t$K$H$j!"$=$N?t$@$18e$m(B($B0z?t$,Ii$N$H$-$OA0(B)$B$N%9%l$K0\F0$7!"(B
$B0\F0$G$-$?$i(B 0$B!"$G$-$J$1$l$P(B 0 $B0J30$N@0?t$rJV$94X?t$G$"$k$3$H!#(B")
(defvar navi2ch-article-save-info-keys
'(number name time hide important unfilter mail kako response down compressed))
(defvar navi2ch-article-insert-message-separator-function
(if (and window-system
(eq emacs-major-version 20)
(not (featurep 'xemacs)))
'navi2ch-article-insert-message-separator-by-face
'navi2ch-article-insert-message-separator-by-char)
"$B%;%Q%l!<%?$rA^F~$9$k4X?t!#(B")
(defvar navi2ch-article-summary-file-name "article-summary")
(defvar navi2ch-article-local-dat-regexp "[0-9]+\\.dat\\(?:.gz\\)?\\'"
"$B%m!<%+%k$K$"$k(B dat $B%U%!%$%k$rI=$o$9@55,I=8=!#(B
$B%5!<%P$K$"$k(B dat $B%U%!%$%k$K$O$3$NJQ?t$r;H$C$F$O$$$1$J$$!#(B")
(defvar navi2ch-article-link-internal nil)
(defconst navi2ch-article-separator " *<> *")
;; important mode
(defvar navi2ch-article-important-mode nil)
(defvar navi2ch-article-important-mode-map nil)
(unless navi2ch-article-important-mode-map
(setq navi2ch-article-important-mode-map (make-sparse-keymap))
(define-key navi2ch-article-important-mode-map "d" 'navi2ch-article-delete-important-message)
(define-key navi2ch-article-important-mode-map "a" 'undefined))
;; hide mode
(defvar navi2ch-article-hide-mode nil)
(defvar navi2ch-article-hide-mode-map nil)
(unless navi2ch-article-hide-mode-map
(setq navi2ch-article-hide-mode-map (make-sparse-keymap))
(define-key navi2ch-article-hide-mode-map "d" 'navi2ch-article-cancel-hide-message)
(define-key navi2ch-article-hide-mode-map "a" 'undefined))
;; filter mode
(defvar navi2ch-article-message-filter-mode nil)
(defvar navi2ch-article-message-filter-mode-map nil)
(unless navi2ch-article-message-filter-mode-map
(setq navi2ch-article-message-filter-mode-map (make-sparse-keymap))
(define-key navi2ch-article-message-filter-mode-map "x" 'navi2ch-article-toggle-replace-message))
(defvar navi2ch-article-message-filter-cache nil)
(defvar navi2ch-article-save-message-filter-cache-keys
'(cache replace hide important))
;; sticky mode
(defvar navi2ch-article-sticky-mode nil)
(make-variable-buffer-local 'navi2ch-article-sticky-mode)
(add-to-list 'minor-mode-alist '(navi2ch-article-sticky-mode " Sticky"))
(defvar navi2ch-article-message-filter-default-rule-alist
'((?n
:var navi2ch-article-message-filter-by-name-alist
:string navi2ch-article-get-current-name)
(?m
:var navi2ch-article-message-filter-by-mail-alist
:string navi2ch-article-get-current-mail)
(?i
:var navi2ch-article-message-filter-by-id-alist
:string navi2ch-article-get-current-id
:scope board-local
:date t)
(?h
:var navi2ch-article-message-filter-by-hostname-alist
:string navi2ch-article-get-current-hostname)
(?b
:var navi2ch-article-message-filter-by-message-alist
:string (lambda ()
(or (navi2ch-article-get-current-word-in-body)
"")))
(?s
:var navi2ch-article-message-filter-by-subject-alist
:string navi2ch-article-get-current-subject)
(t :match-method "s")))
(defvar navi2ch-article-message-filter-wid-string)
(defvar navi2ch-article-message-filter-wid-rule)
(defvar navi2ch-article-message-filter-wid-method)
(defvar navi2ch-article-message-filter-wid-case)
(defvar navi2ch-article-message-filter-wid-invert)
(defvar navi2ch-article-message-filter-wid-scope)
(defvar navi2ch-article-message-filter-wid-float)
(defvar navi2ch-article-message-filter-wid-var)
(defvar navi2ch-article-message-filter-wid-date)
(defvar navi2ch-article-message-filter-wid-window-configuration)
;; JIT
(defvar navi2ch-article-jit-interval 0.1)
(defvar navi2ch-article-jit-timer nil)
(defvar navi2ch-article-use-jit nil)
(defvar navi2ch-article-jit-buffers nil)
(defvar navi2ch-article-jit-need-insert nil)
;; local variables
(make-variable-buffer-local 'navi2ch-article-current-article)
(make-variable-buffer-local 'navi2ch-article-current-board)
(make-variable-buffer-local 'navi2ch-article-message-list)
(make-variable-buffer-local 'navi2ch-article-message-filter-cache)
(make-variable-buffer-local 'navi2ch-article-point-stack)
(make-variable-buffer-local 'navi2ch-article-poped-point-stack)
(make-variable-buffer-local 'navi2ch-article-view-range)
(make-variable-buffer-local 'navi2ch-article-through-next-function)
(make-variable-buffer-local 'navi2ch-article-through-previous-function)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-string)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-rule)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-method)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-case)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-invert)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-scope)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-float)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-var)
(make-variable-buffer-local 'navi2ch-article-message-filter-wid-date)
(make-variable-buffer-local 'navi2ch-article-jit-need-insert)
;; add hook
(defun navi2ch-article-kill-emacs-hook ()
(navi2ch-article-expunge-buffers -1))
(add-hook 'navi2ch-kill-emacs-hook 'navi2ch-article-kill-emacs-hook)
;;; navi2ch-article functions
(defun navi2ch-article-get-url (board article &optional no-kako)
(let ((artid (cdr (assq 'artid article)))
(url (navi2ch-board-get-uri board)))
(if (and (not no-kako)
(cdr (assq 'kako article)))
(navi2ch-article-get-kako-url board article)
(concat url "dat/" artid ".dat"))))
(defun navi2ch-article-get-kako-url (board article)
(let* ((artid (cdr (assq 'artid article)))
(url (navi2ch-board-get-uri board))
(length (length artid)))
(cond
((= length 9)
(concat url "kako/"
(substring artid 0 3)
"/" artid ".dat.gz"))
((= length 10)
(concat url "kako/"
(substring artid 0 4) "/" (substring artid 0 5)
"/" artid ".dat.gz"))
(t
nil))))
(defsubst navi2ch-article-get-file-name (board article)
(navi2ch-board-get-file-name board
(concat (cdr (assq 'artid article))
(if (cdr (or (assq 'compressed article)
(assq 'compressed
(navi2ch-article-load-info
board
article))))
".dat.gz"
".dat"))))
(defsubst navi2ch-article-get-info-file-name (board article)
(navi2ch-board-get-file-name board
(concat "info/" (cdr (assq 'artid article)))))
(defsubst navi2ch-article-file-name-to-artid (filename)
"*FILENAME $B$r%9%l(BID$B$KJQ49$9$k!#(B"
(file-name-sans-extension (file-name-sans-extension
(file-name-nondirectory filename))))
(defsubst navi2ch-article-inside-range-p (num range len)
"NUM $B$,(B RANGE $B$G<($9HO0O$KF~$C$F$k$+!#(B
LEN $B$O(B RANGE $B$GHO0O$r;XDj$5$l$k(B list $B$ND9$5!#(B"
(or (not range)
(<= num (car range))
(> num (- len (cdr range)))))
(defsubst navi2ch-article-get-buffer-name (board article)
(concat navi2ch-article-buffer-name-prefix
(navi2ch-article-get-url board article 'no-kako)))
(defsubst navi2ch-article-check-cached (board article)
"BOARD $B$H(B ARTICLE $B$G;XDj$5$l$k%9%l%C%I$,%-%c%C%7%e$5$l$F$k$+!#(B"
(cond ((get-buffer (navi2ch-article-get-buffer-name board article))
'view)
((file-exists-p (navi2ch-article-get-file-name board article))
;; ((member (concat (cdr (assq 'artid article)) ".dat") list)
'cache)))
(defmacro navi2ch-article-summary-element-seen (element)
`(plist-get ,element :seen))
(defmacro navi2ch-article-summary-element-access-time (element)
`(plist-get ,element :access-time))
(defmacro navi2ch-article-summary-element-set-seen (element seen)
`(setq ,element (plist-put ,element :seen ,seen)))
(defmacro navi2ch-article-summary-element-set-access-time (element time)
`(setq ,element (plist-put ,element :access-time ,time)))
(defmacro navi2ch-article-save-view (&rest body)
"BODY $BFb$G8=:_I=<($7$F$$$k%9%l$rI=<($7$J$*$9$H$-$K!"(B
$B%&%#%s%I%&Fb$N%+!<%=%k$N0LCV$r$G$-$k$@$10];}$9$k!#(B"
(let ((num (make-symbol "num"))
(buf (make-symbol "buf"))
(win (make-symbol "win"))
(bol (make-symbol "bol"))
(col (make-symbol "col"))
(win-lin (make-symbol "win-lin"))
(msg-lin (make-symbol "msg-lin"))
(visible (make-symbol "visible")))
`(let* ((,num (navi2ch-article-get-current-number))
(,buf (current-buffer))
(,win (if (eq (window-buffer) ,buf)
(selected-window)
(get-buffer-window ,buf)))
(,bol (navi2ch-line-beginning-position))
(,col (current-column))
,win-lin ,msg-lin ,visible)
(save-excursion
(goto-char (window-start ,win))
(setq ,win-lin (count-lines (navi2ch-line-beginning-position) ,bol))
(if (null ,num)
(setq ,msg-lin ,win-lin)
(navi2ch-article-goto-number ,num)
(setq ,msg-lin
(count-lines (navi2ch-line-beginning-position) ,bol))))
(prog1 (progn ,@body)
(with-current-buffer ,buf
(when ,num
(setq ,visible (navi2ch-article-get-visible-numbers))
(while (and (cdr ,visible)
(< (car ,visible) ,num))
(setq ,visible (cdr ,visible))))
(navi2ch-article-goto-number (or (car ,visible) 1))
(forward-line ,msg-lin)
(move-to-column ,col)
(set-window-start ,win
(navi2ch-line-beginning-position (- 1 ,win-lin)))
(unless (eq (navi2ch-article-get-current-number) (car ,visible))
(navi2ch-article-goto-number (or (car ,visible) 1))))))))
(put 'navi2ch-article-save-view 'lisp-indent-function 0)
(defun navi2ch-article-url-to-article (url)
"URL $B$+$i(B article $B$KJQ49!#(B"
(navi2ch-multibbs-url-to-article url))
(defun navi2ch-article-to-url (board article &optional start end nofirst)
"BOARD, ARTICLE $B$+$i(B url $B$KJQ49!#(B
START, END, NOFIRST $B$GHO0O$r;XDj$9$k(B"
(navi2ch-multibbs-article-to-url board article start end nofirst))
(defun navi2ch-article-cleanup-message ()
(let (re)
(when navi2ch-article-cleanup-trailing-newline ; $B%l%9KvHx$N6uGr$r<h$j=|$/(B
(goto-char (point-min))
(when (re-search-forward "\\(<br> *\\)+<>" nil t)
(replace-match "<>")))
(when navi2ch-article-cleanup-white-space-after-old-br
(goto-char (point-min))
(unless (re-search-forward "<br>[^ ]" nil t)
(setq re "<br> ")))
(when navi2ch-article-cleanup-trailing-whitespace
(setq re (concat " *" (or re "<br>"))))
(unless (or (not re)
(string= re "<br>"))
(goto-char (point-min))
(while (re-search-forward re nil t)
(replace-match "<br>"))))) ; "\n" $B$G$b$$$$$+$b!#(B
(defun navi2ch-article-parse-message (str)
(unless (string= str "")
(let ((board navi2ch-article-current-board)
(article navi2ch-article-current-article))
(with-temp-buffer
(let ((syms '(name mail date data subject))
alist max)
(insert str)
(navi2ch-article-cleanup-message)
(setq max (point-max-marker))
(goto-char (point-min))
(setq alist (mapcar
(lambda (sym)
(cons sym
(cons (point-marker)
(if (re-search-forward navi2ch-article-separator nil t)
(copy-marker (match-beginning 0))
(goto-char max)
max))))
syms))
(let ((start (car (cdr (assq 'name alist))))
(end (cdr (cdr (assq 'name alist)))))
(when (and start end)
(goto-char start)
(while (re-search-forward "\\(</b>[^<]+<b>\\)\\|\\(<font[^>]+>[^<]+</font>\\)" end t)
;; fusianasan $B$d%H%j%C%W$J$I(B
(replace-match (navi2ch-propertize (match-string 0)
'navi2ch-fusianasan-flag t)
t t))))
(navi2ch-replace-html-tag-with-buffer)
(dolist (x alist)
(setcdr x (buffer-substring (cadr x) (cddr x))))
alist)))))
(defun navi2ch-article-get-separator ()
(save-excursion
(let ((string (buffer-substring (navi2ch-line-beginning-position)
(navi2ch-line-end-position))))
(if (or (string-match "<>.*<>.*<>" string)
(not (string-match ",.*,.*," string)))
" *<> *"
" *, *"))))
(defun navi2ch-article-get-first-message ()
"current-buffer $B$N(B article $B$N:G=i$N(B message $B$rJV$9!#(B"
(goto-char (point-min))
(navi2ch-article-parse-message
(buffer-substring-no-properties (point)
(progn (forward-line 1)
(1- (point))))))
(defun navi2ch-article-get-first-message-from-file (file &optional board)
"FILE $B$G;XDj$5$l$?(B article $B$N:G=i$N(B message $B$rJV$9!#(B
BOARD non-nil $B$J$i$P!"$=$NHD$N(B coding-system $B$r;H$&!#(B"
(with-temp-buffer
(navi2ch-board-insert-file-contents board file)
(navi2ch-apply-filters board navi2ch-article-filter-list)
(navi2ch-article-get-first-message)))
(defun navi2ch-article-get-message-list (file &optional begin end)
"FILE $B$N(B BEGIN $B$+$i(B END $B$^$G$NHO0O$+$i%9%l$N(B list $B$r:n$k!#(B
$B6u9T$O(B nil$B!#(B"
(when (file-exists-p file)
(let ((board navi2ch-article-current-board)
message-list)
(with-temp-buffer
(navi2ch-board-insert-file-contents board file begin end)
(run-hooks 'navi2ch-article-get-message-list-hook)
(let ((i 1))
(navi2ch-apply-filters board navi2ch-article-filter-list)
(message "Splitting current messages...")
(goto-char (point-min))
(while (not (eobp))
(setq message-list
(cons (cons i
(let ((str (buffer-substring-no-properties
(point)
(progn (forward-line 1)
(1- (point))))))
(unless (string= str "") str)))
message-list))
(setq i (1+ i)))
(message "Splitting current messages...done")))
(nreverse message-list))))
(defun navi2ch-article-append-message-list (list1 list2)
(let ((num (length list1)))
(append list1
(mapcar
(lambda (x)
(setq num (1+ num))
(cons num (cdr x)))
list2))))
(defun navi2ch-article-update-previous-message-separator ()
"$B8=:_0LCV$ND>A0$N%l%96h@Z$r99?7$9$k!#(B"
(let ((old-pos (point-marker)))
(set-marker-insertion-type old-pos t)
(save-excursion
(let ((buffer-read-only nil)
end beg)
(if (= (point) (point-max))
(setq end (point))
(setq end (previous-single-property-change (point) 'message-separator)))
(when end
(if (get-text-property (max (1- end) (point-min)) 'message-separator)
(setq beg (previous-single-property-change end 'message-separator))
(setq beg end)
(setq end (next-single-property-change beg 'message-separator))))
(when (and beg end)
(let ((number (get-text-property beg 'message-separator)))
(goto-char beg)
(delete-region beg end)
(navi2ch-article-insert-message-separator number)))))
(goto-char old-pos)))
(defun navi2ch-article-insert-message-separator (number)
"$B%l%96h@Z$rA^F~$9$k!#(B"
(let ((p (point)))
(funcall navi2ch-article-insert-message-separator-function)
(when (and navi2ch-article-message-separator-insert-hide-number-p
(navi2ch-article-insert-hide-number-following number))
(funcall navi2ch-article-insert-message-separator-function))
(when navi2ch-article-message-separator-insert-trailing-newline-p
(insert "\n"))
(put-text-property p (point) 'message-separator number)))
(defun navi2ch-article-insert-hide-number-following (number)
"$B%l%9HV9f(B NUMBER $B$N8e$KB3$/(B hide $B$5$l$?%l%9?t$rA^F~$9$k!#(B
$BA^F~$7$?>l9g$O(B non-nil $B$rJV$9!#(B"
(unless (or navi2ch-article-hide-mode navi2ch-article-important-mode)
(let (hide beg end cnt)
;; hide $B>pJs$O(B filter mode $B$+$I$&$+$GJQ$o$C$F$/$k(B
(setq hide
(funcall
(if navi2ch-article-message-filter-mode
'navi2ch-union
'navi2ch-set-difference)
(cdr (assq 'hide navi2ch-article-current-article))
(cdr (assq 'hide navi2ch-article-message-filter-cache))))
(setq beg (car (memq (1+ number) hide)))
(when beg
(setq end beg)
(while (memq (1+ end) hide)
(setq end (1+ end)))
(setq cnt (1+ (- end beg)))
(let ((number-str (if (= cnt 1)
(format "%d" beg)
(format "%d-%d" beg end))))
(insert (format "[%d hidden message(s) (" cnt))
(let ((pos (point)))
(insert ">>" number-str)
(navi2ch-article-set-link-property-subr pos (point)
'number number-str)
(insert ")]")))
'found))))
(defun navi2ch-article-insert-message-separator-by-face ()
(let ((p (point)))
(insert "\n")
(put-text-property p (point) 'face 'underline)))
(defun navi2ch-article-insert-message-separator-by-char ()
(let ((pos (point)))
(insert (make-string (max 0
(- (eval navi2ch-article-message-separator-width)
(current-column)))
navi2ch-article-message-separator))
(put-text-property pos (point) 'face 'navi2ch-article-message-separator-face)
(insert "\n")))
(defun navi2ch-article-set-link-property-subr (start end type value
&optional object)
(let ((face (cond ((eq type 'number) 'navi2ch-article-link-face)
((eq type 'url) 'navi2ch-article-url-face))))
(add-text-properties start end
(list 'face face
'help-echo #'navi2ch-article-help-echo
'navi2ch-link-type type
'navi2ch-link value
'mouse-face navi2ch-article-mouse-face)
object)))
(defun navi2ch-article-link-regexp-alist-to-internal ()
(navi2ch-regexp-alist-to-internal
(append
navi2ch-article-link-regexp-alist
(list (cons (concat navi2ch-article-number-prefix-regexp
navi2ch-article-number-number-regexp)
(lambda (match)
(navi2ch-article-set-link-property-subr
(match-beginning 0) (match-end 0)
'number (navi2ch-match-string-no-properties 1))
(while (looking-at (concat
navi2ch-article-number-separator-regexp
navi2ch-article-number-number-regexp))
(navi2ch-article-set-link-property-subr
(match-beginning 1) (match-end 1)
'number (navi2ch-match-string-no-properties 1))
(goto-char (max (1+ (match-beginning 0))
(match-end 0))))))
(cons navi2ch-article-url-regexp
(lambda (url)
(if (string-match "\\`\\(h?t?tp\\)\\(s?:\\)" url)
(replace-match "http\\2" nil nil url)
url)))))))
(defun navi2ch-article-set-link-property ()
">>1 $B$H$+(B http:// $B$K(B property $B$rIU$1$k!#(B"
(goto-char (point-min))
(let* ((reg-internal (or navi2ch-article-link-internal
(navi2ch-article-link-regexp-alist-to-internal)))
match rep literal)
(while (setq match (navi2ch-re-search-forward-regexp-alist reg-internal nil t))
(setq rep (cdr match)
literal nil)
(when (functionp rep)
(save-match-data
(setq rep (funcall rep (navi2ch-match-string-no-properties 0))
literal t)))
(when (stringp rep)
(let ((start (match-beginning 0))
(end (match-end 0))
(url (navi2ch-match-string-no-properties 0)))
(when (string-match (concat "\\`" (car match) "\\'") url)
(setq url (replace-match rep nil literal url))
(navi2ch-article-set-link-property-subr
start end 'url url))
(goto-char (max (1+ start) end)))))))
(defun navi2ch-article-put-cite-face ()
(goto-char (point-min))
(while (re-search-forward navi2ch-article-citation-regexp nil t)
(put-text-property (match-beginning 0)
(match-end 0)
'face 'navi2ch-article-citation-face)))
(defun navi2ch-article-arrange-message ()
(goto-char (point-min))
(let ((id (cdr (assq 'id navi2ch-article-current-board))))
(when (or (member id navi2ch-article-enable-fill-list)
(and (not (member id navi2ch-article-disable-fill-list))
navi2ch-article-enable-fill))
(set-hard-newline-properties (point-min) (point-max))
(let ((fill-column (- (window-width) 5))
(use-hard-newlines t))
(fill-region (point-min) (point-max)))))
(run-hooks 'navi2ch-article-arrange-message-hook))
(defun navi2ch-article-insert-message (num alist)
(let ((p (point)))
(insert (funcall navi2ch-article-header-format-function
num
(cdr (assq 'name alist))
(cdr (assq 'mail alist))
(cdr (assq 'date alist))))
(put-text-property p (1+ p) 'current-number num)
(setq p (point))
(insert (cdr (assq 'data alist)) "\n")
(save-excursion
(save-restriction
(narrow-to-region p (point))
;; (navi2ch-article-cleanup-message) ; $B$d$C$QCY$$(B
(put-text-property (point-min) (point-max) 'face
'navi2ch-article-face)
(navi2ch-article-put-cite-face)
(navi2ch-article-set-link-property)
(if navi2ch-article-auto-decode-p
(navi2ch-article-auto-decode-encoded-section))
(navi2ch-article-arrange-message)
;; $B%5%`%M%$%k2hA|$N%-%c%C%7%e$,$"$C$?$iI=<((B
(navi2ch-thumbnail-insert-image-reload))))
(navi2ch-article-insert-message-separator num))
(defun navi2ch-article-insert-messages (list range)
"LIST $B$r@07A$7$FA^F~$9$k!#(B"
(let ((msg (if navi2ch-article-message-filter-mode
"Filtering and inserting current messages..."
"Inserting current messages..."))
(len (length list))
(hide (cdr (assq 'hide navi2ch-article-current-article)))
(imp (cdr (assq 'important navi2ch-article-current-article)))
(unfilter (cdr (assq 'unfilter navi2ch-article-current-article)))
(cache (cdr (assq 'cache navi2ch-article-message-filter-cache)))
(rep (cdr (assq 'replace navi2ch-article-message-filter-cache)))
(orig (cdr (assq 'original navi2ch-article-message-filter-cache)))
(progress 0)
(percent 0)
(navi2ch-article-link-internal (navi2ch-article-link-regexp-alist-to-internal)))
(unless navi2ch-article-use-jit (message msg))
(let ((func (if navi2ch-article-message-filter-mode
#'navi2ch-union
#'navi2ch-set-difference)))
(setq hide (funcall func
hide
(cdr (assq 'hide
navi2ch-article-message-filter-cache))))
(setq imp (funcall func
imp
(cdr (assq 'important
navi2ch-article-message-filter-cache)))))
(setq navi2ch-article-current-article
(navi2ch-put-alist 'hide hide navi2ch-article-current-article))
(setq navi2ch-article-current-article
(navi2ch-put-alist 'important imp navi2ch-article-current-article))
(dolist (x list)
(let* ((num (car x))
(alist (cdr x))
(rep-alist (cdr (assq num rep)))
(orig-alist (cdr (assq num orig)))
suppress)
(when (and alist
(cond (navi2ch-article-hide-mode
(memq num hide))
(navi2ch-article-important-mode
(memq num imp))
(t
(and (navi2ch-article-inside-range-p num range len)
(not (memq num hide))))))
(if (stringp alist)
(progn
(setq alist (navi2ch-article-parse-message alist))
(cond
((and (string= "$B$"$\!<$s(B" (cdr (assq 'date alist)))
(memq num cache))
;; $B?7$7$/!V$"$\!<$s!W$5$l$?%l%9$O%-%c%C%7%e$r%/%j%"(B
(setq unfilter (delq num unfilter))
(setq navi2ch-article-current-article
(navi2ch-put-alist
'unfilter
unfilter
navi2ch-article-current-article))
(setq cache (delq num cache))
(setq navi2ch-article-message-filter-cache
(navi2ch-put-alist
'cache
cache
navi2ch-article-message-filter-cache)))
(rep-alist
;; $BCV498e$N%-%c%C%7%e$,$"$k>l9g$OCV49A0$N%l%9$rB`Hr(B
(setq orig-alist (mapcar
(lambda (x)
(cons (car x)
(cdr (assq (car x) alist))))
rep-alist))
(setq orig (navi2ch-put-alist num orig-alist orig))
(setq navi2ch-article-message-filter-cache
(navi2ch-put-alist
'original
orig
navi2ch-article-message-filter-cache)))))
(dolist (slot alist)
(when (stringp (cdr slot))
(set-text-properties 0 (length (cdr slot)) nil (cdr slot)))))
(if (and navi2ch-article-message-filter-mode
(not (memq num unfilter)))
(if (and navi2ch-article-use-message-filter-cache
(memq num cache))
;; $BCV498e$N%l%9$r%-%c%C%7%e$+$iCj=P(B
(dolist (slot rep-alist)
(when (cdr slot)
(navi2ch-put-alist (car slot) (cdr slot) alist)))
;; $B%U%#%k%?=hM}$NK\BN(B
(let ((result (navi2ch-article-apply-message-filters
(navi2ch-put-alist 'number num alist))))
(when (and (eq result 'hide)
(not navi2ch-article-hide-mode))
(setq suppress t))))
;; $BCV49A0$N%l%9$r%-%c%C%7%e$+$iI|85(B
(dolist (slot orig-alist)
(when (cdr slot)
(navi2ch-put-alist (car slot) (cdr slot) alist))))
(setq alist (navi2ch-put-alist 'point (point-marker) alist))
(setcdr x alist)
;; (setcdr x (navi2ch-put-alist 'point (point) alist))
(if suppress
(navi2ch-article-update-previous-message-separator)
(navi2ch-article-insert-message num alist)
(set-marker-insertion-type (cdr (assq 'point alist)) t)))
;; $B?JD=I=<((B
(unless navi2ch-article-use-jit
(and (> (setq progress (+ progress 100)) 10000)
(/= (/ progress len) percent)
(navi2ch-no-logging-message
"%s%d%%" msg (setq percent (/ progress len)))))))
(unless navi2ch-article-use-jit (message "%sdone" msg))))
(defsubst navi2ch-article-get-message (num)
"NUM $BHVL\$N%l%9$rF@$k!#(B"
(cdr (assq num navi2ch-article-message-list)))
(defun navi2ch-article-reinsert-partial-messages (start &optional end)
"START $BHVL\$+$i!":G8e$^$?$O(B END $BHVL\$^$G$N%l%9$rA^F~$7$J$*$9!#(B"
(let* ((nums (mapcar #'car navi2ch-article-message-list))
(len (length nums))
(last (car (last nums)))
list visible start-point end-point)
(when (minusp start)
(setq start (+ start last 1)))
(if (null end)
(setq end last)
(when (minusp end)
(setq end (+ end last 1)))
(when (> start end)
(setq start (prog1 end
(setq end start)))))
(catch 'loop
(dolist (num (nreverse nums))
(cond
((< num start)
(throw 'loop nil))
((and (<= num end)
(or navi2ch-article-hide-mode
navi2ch-article-important-mode
(navi2ch-article-inside-range-p num
navi2ch-article-view-range
len)))
(let ((slot (assq num navi2ch-article-message-list)))
(when slot
(setq list (cons slot list))))))))
(setq visible (navi2ch-article-get-visible-numbers))
(while (and visible
(< (car visible) start))
(setq visible (cdr visible)))
(when visible
(setq start-point
(cdr (assq 'point (navi2ch-article-get-message (car visible))))))
(while (and visible
(<= (car visible) end))
(setq visible (cdr visible)))
(when visible
(setq end-point
(cdr (assq 'point (navi2ch-article-get-message (car visible))))))
(if (null start-point)
(goto-char (point-max))
(goto-char start-point)
(delete-region start-point (or end-point (point-max))))
(navi2ch-article-insert-messages list nil)))
(defun navi2ch-article-apply-message-filters (alist)
(let* ((num (cdr (assq 'number alist)))
(orig (cdr (assq 'original navi2ch-article-message-filter-cache))))
;; $BCV49A0$N%l%9$r%-%c%C%7%e$+$iI|85(B
(dolist (slot (cdr (assq num orig)))
(when (cdr slot)
(navi2ch-put-alist (car slot) (cdr slot) alist)))
(let ((old-alist (copy-alist alist))
score result)
(catch 'loop
(dolist (filter navi2ch-article-message-filter-list)
(setq result (funcall filter alist))
(cond ((numberp result)
(setq score (+ (or score 0) result)))
(result
(throw 'loop nil)))))
(when score
(cond
((and navi2ch-article-message-add-important-above
(> score navi2ch-article-message-add-important-above))
(setq result 'important))
((and navi2ch-article-message-replace-below
navi2ch-article-message-hide-below
(< score (car navi2ch-article-message-replace-below))
(< score navi2ch-article-message-hide-below))
;; `navi2ch-article-message-replace-below' $B$H(B
;; `navi2ch-article-message-hide-below' $B$,N>J}$H$b(B
;; $BE,MQ$5$l$&$k>l9g!"$7$-$$CM$NDc$$J}$rM%@h(B
(if (< navi2ch-article-message-hide-below
(car navi2ch-article-message-replace-below))
(setq result 'hide)
(setq result (cdr navi2ch-article-message-replace-below))))
((and navi2ch-article-message-replace-below
(< score (car navi2ch-article-message-replace-below)))
(setq result (cdr navi2ch-article-message-replace-below)))
((and navi2ch-article-message-hide-below
(< score navi2ch-article-message-hide-below))
(setq result 'hide))))
(cond
((stringp result)
(let ((case-fold-search nil))
(navi2ch-put-alist 'name result alist)
(navi2ch-put-alist 'data result alist)
(navi2ch-put-alist 'mail
(if (string-match "sage"
(cdr (assq 'mail alist)))
"sage"
"")
alist)
(navi2ch-put-alist 'date
(navi2ch-replace-string " ID:.*"
""
(cdr (assq 'date alist)))
alist)))
((memq result '(hide important unfilter))
(let ((nums (cdr (assq result navi2ch-article-current-article))))
(unless (memq num nums)
(setq navi2ch-article-current-article
(navi2ch-put-alist result
(cons num nums)
navi2ch-article-current-article))))))
(unless (equal old-alist alist)
(setq navi2ch-article-message-filter-cache
(navi2ch-put-alist
'original
(navi2ch-put-alist
num
(navi2ch-set-difference old-alist alist)
orig)
navi2ch-article-message-filter-cache)))
(when navi2ch-article-use-message-filter-cache
(unless (equal alist old-alist)
(setq navi2ch-article-message-filter-cache
(navi2ch-put-alist
'replace
(navi2ch-put-alist
num
(copy-alist (navi2ch-set-difference alist old-alist))
(cdr (assq 'replace navi2ch-article-message-filter-cache)))
navi2ch-article-message-filter-cache)))
(unless (or (memq result '(nil cache replace original unfilter))
(stringp result))
(setq navi2ch-article-message-filter-cache
(navi2ch-put-alist
result
(cons num
(cdr (assq result navi2ch-article-message-filter-cache)))
navi2ch-article-message-filter-cache)))
(setq navi2ch-article-message-filter-cache
(navi2ch-put-alist
'cache
(cons num
(cdr (assq 'cache navi2ch-article-message-filter-cache)))
navi2ch-article-message-filter-cache)))
result)))
(defun navi2ch-article-extract-date (str)
(cond
((not (stringp str))
nil)
((string-match "^[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]" str)
(match-string 0 str))
((string-match "^[0-9][0-9]/[0-9][0-9]/[0-9][0-9]" str)
(concat "20" (match-string 0 str)))
(t nil)))
(defun navi2ch-article-message-filter-by-name (alist)
(when navi2ch-article-message-filter-by-name-alist
(navi2ch-article-message-filter-subr
navi2ch-article-message-filter-by-name-alist
(cdr (assq 'name alist))
(navi2ch-article-extract-date (cdr (assq 'date alist))))))
(defun navi2ch-article-message-filter-by-message (alist)
(when navi2ch-article-message-filter-by-message-alist
(navi2ch-article-message-filter-subr
navi2ch-article-message-filter-by-message-alist
(cdr (assq 'data alist))
(navi2ch-article-extract-date (cdr (assq 'date alist))))))
(defun navi2ch-article-message-filter-by-id (alist)
(let ((case-fold-search nil))
(when (and navi2ch-article-message-filter-by-id-alist
(string-match " ID:\\([^ ]+\\)"
(cdr (assq 'date alist))))
(navi2ch-article-message-filter-subr
navi2ch-article-message-filter-by-id-alist
(match-string 1 (cdr (assq 'date alist)))
(navi2ch-article-extract-date (cdr (assq 'date alist)))))))
(defun navi2ch-article-message-filter-by-mail (alist)
(when navi2ch-article-message-filter-by-mail-alist
(navi2ch-article-message-filter-subr
navi2ch-article-message-filter-by-mail-alist
(cdr (assq 'mail alist))
(navi2ch-article-extract-date (cdr (assq 'date alist))))))
(defun navi2ch-article-message-filter-by-subject (alist)
(when navi2ch-article-message-filter-by-subject-alist
(navi2ch-article-message-filter-subr
navi2ch-article-message-filter-by-subject-alist