File: navi2ch-articles.el

package info (click to toggle)
navi2ch 2.0.0~git20120331-1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 2,292 kB
  • ctags: 1,838
  • sloc: lisp: 19,818; sh: 3,108; makefile: 90
file content (157 lines) | stat: -rw-r--r-- 4,863 bytes parent folder | download
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
;;; navi2ch-articles.el --- Article List Module for Navi2ch -*- coding: iso-2022-7bit; -*-

;; Copyright (C) 2001, 2002, 2003, 2004, 2008 by Navi2ch Project

;; Author: Taiki SUGAWARA <taiki@users.sourceforge.net>
;; Keywords: 2ch, network

;; 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-articles)
(defconst navi2ch-articles-ident
  "$Id$")

(eval-when-compile (require 'cl))

(require 'navi2ch)

(defvar navi2ch-articles-mode-map nil)
(unless navi2ch-articles-mode-map
  (let ((map (make-sparse-keymap)))
    (set-keymap-parent map navi2ch-bm-mode-map)
    ;; (define-key navi2ch-articles-mode-map "q" 'navi2ch-articles-exit)
    (define-key map "d" 'navi2ch-articles-delete)
    (define-key map "md" 'navi2ch-articles-delete-mark-aritcle)
    (define-key map "R" 'navi2ch-articles-remove-article)
    (define-key map "mR" 'navi2ch-articles-remove-mark-article)
    (define-key map "s" 'navi2ch-articles-sync)
    (setq navi2ch-articles-mode-map map)))

(defvar navi2ch-articles-mode-menu-spec
  (navi2ch-bm-make-menu-spec
   "Articles"
   nil))

(defvar navi2ch-articles-board
  '((name . "$BI=<(%9%l0lMw(B")
    (type . articles)
    (id . "#articles")))

;;; navi2ch-bm callbacks
(defun navi2ch-articles-set-property (begin end item)
  (put-text-property begin end 'buffer item))

(defun navi2ch-articles-get-property (point)
  (get-text-property point 'buffer))

(defun navi2ch-articles-get-article (item)
  (when (and item
	     (buffer-live-p item))
    (with-current-buffer item
      navi2ch-article-current-article)))

(defun navi2ch-articles-get-board (item)
  (when (and item
	     (buffer-live-p item))
    (with-current-buffer item
      navi2ch-article-current-board)))

(defun navi2ch-articles-exit ()
  (run-hooks 'navi2ch-articles-exit-hook))

;; regist board
(navi2ch-bm-regist-board 'articles 'navi2ch-articles
			 navi2ch-articles-board)

;;; navi2ch-articles functions
(defun navi2ch-articles-insert-subjects ()
  (let ((i 1))
    (dolist (x (navi2ch-article-buffer-list))
      (let ((article (navi2ch-articles-get-article x))
            (board (navi2ch-articles-get-board x)))
        (navi2ch-bm-insert-subject
         x i
         (cdr (assq 'subject article))
         (format "[%s]" (cdr (assq 'name board))))
        (setq i (1+ i))))))

(defun navi2ch-articles-delete ()
  "$B$=$N9T$r(B articles $B$+$i:o=|$7$F!"$=$N(B article buffer $B$b>C$9!#(B"
  (interactive)
  (let ((buf (save-excursion (beginning-of-line)
			     (navi2ch-articles-get-property (point)))))
    (if buf
	(let ((buffer-read-only nil))
	  (kill-buffer buf)
	  (delete-region (save-excursion (beginning-of-line) (point))
			 (save-excursion (forward-line) (point)))
	  (and (eobp) (not (bobp))
	       (forward-line -1)))
      (message "Can't select this line!"))))

(defun navi2ch-articles-delete-mark-aritcle ()
  (interactive)
  (navi2ch-bm-exec-subr 'navi2ch-articles-delete))

(defun navi2ch-articles-remove-article ()
  (interactive)
  (navi2ch-bm-remove-article)
  (navi2ch-articles-delete))

(defun navi2ch-articles-remove-mark-article ()
  (interactive)
  (navi2ch-bm-exec-subr 'navi2ch-articles-remove-article))

(defun navi2ch-articles (&rest args)
  "articles $B$rI=<($9$k!#(B"
  (navi2ch-articles-mode)
  (navi2ch-bm-setup 'navi2ch-articles)
  (navi2ch-articles-sync))

(defun navi2ch-articles-sync ()
  (interactive)
  (let ((buffer-read-only nil))
    (erase-buffer)
    (save-excursion
      (navi2ch-articles-insert-subjects))))

(easy-menu-define navi2ch-articles-mode-menu
  navi2ch-articles-mode-map
  "Menu used in navi2ch-articles"
  navi2ch-articles-mode-menu-spec)

(defun navi2ch-articles-setup-menu ()
  (easy-menu-add navi2ch-articles-mode-menu))

(defun navi2ch-articles-mode ()
  "\\{navi2ch-articles-mode-map}"
  (interactive)
  (kill-all-local-variables)
  (setq major-mode 'navi2ch-articles-mode)
  (setq mode-name "Navi2ch Articles")
  (setq buffer-read-only t)
  (buffer-disable-undo)
  (use-local-map navi2ch-articles-mode-map)
  (navi2ch-articles-setup-menu)
  (run-hooks 'navi2ch-bm-mode-hook 'navi2ch-articles-mode-hook))

(run-hooks 'navi2ch-articles-load-hook)
;;; navi2ch-articles.el ends here