-
Notifications
You must be signed in to change notification settings - Fork 0
/
avandu-extended.el
139 lines (128 loc) · 4.8 KB
/
avandu-extended.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
;;; avandu-extended.el extension of avandu
;;; this code adds a new mode for avandu ttrss reader
(require 'avandu)
(defvar article-id nil)
(defun print-current-line-id ()
(interactive)
(message (concat "current line ID is: " (tabulated-list-get-id))))
(defun avandu2-open-next-article-in-table ()
(interactive)
(avandu2-open-relative-article-in-table "n"))
(defun avandu2-open-previous-article-in-table ()
(interactive)
(avandu2-open-relative-article-in-table "p"))
(defun avandu2-open-relative-article-in-table (direction)
(interactive)
"find next article in overviews table and open it if direction is 'n' else previous"
(let ((buffer (get-buffer-create "*avandu-table-overview*")))
(with-current-buffer buffer
;;;(make-local-variable 'article-id)
(goto-char (point-min))
(while (not (equal (tabulated-list-get-id) article-id))
;;;focus next line
(next-line))
;;;focus next line
(if (equal direction "n") (next-line) (previous-line))
;;;open article with that id
(avandu2-view-article (tabulated-list-get-id)))))
;;; Since the original avandu-view-article function runs an UI function
;;; that does not work with my ui I had to copy the whole function excluding
;;; that call
(defun avandu2-view-article (id)
"Show a single article identified by ID in a new buffer."
(interactive "nArticle id: ")
(setq article-id id)
(let* ((data (avandu-get-article id))
(buffer (get-buffer-create "*avandu-article*"))
(inhibit-read-only t)
content-start
content-end)
(with-current-buffer buffer
(erase-buffer)
(mapc #'(lambda (item)
(insert
(propertize (avu-prop item title)
'face 'avandu-article-title))
(insert "\n")
(insert
(propertize (concat "by: " (avu-prop item author))
'face 'avandu-article-author))
(insert " (")
(insert-button
"Browse original"
'url (avu-prop item link)
'action #'(lambda (button)
(browse-url (button-get button 'url))))
(insert ")")
(insert "\n")(insert "\n")
(setq content-start (point))
(insert (avu-prop item content))
(setq content-end (point))
(insert "\n")(insert "\n"))
data)
(setq buffer-read-only t)
(goto-char (point-min))
(avandu-article-mode))
(avandu-mark-article-read id)
(switch-to-buffer buffer)
(when avandu-article-render-function
(funcall
avandu-article-render-function content-start
(min content-end (point-max))))
(goto-char (point-min))))
(defun avandu2-open-article ()
(interactive)
"Get id of article in focused line and pass it to avandu-view-article"
(avandu2-view-article (tabulated-list-get-id)))
(defun avandu2-table-overview ()
"Request the headlines of unread articles and list them.
The list is grouped and sorted by feed ID. Sorting by feed ID is
meaningless, but it's easy."
(interactive)
(avandu--check-login)
(let ((buffer (get-buffer-create "*avandu-table-overview*"))
(result (sort (cl-coerce (avandu-headlines -4 :show-excerpt t
:view-mode "unread")
'list)
#'avandu--order-feed))
feed-id )
(with-current-buffer buffer
(setq buffer-read-only nil)
(erase-buffer)
(goto-char (point-min))
(setq tabulated-list-entries '())
(mapc #'(lambda (elt)
(unless (equal feed-id (assq 'feed_id elt))
(add-to-list 'tabulated-list-entries
(list (avu-prop elt id) (vector
(avu-prop elt title)
(avu-prop elt feed_title)
(format-time-string "%a %D %R" (avu-prop elt updated))
)))))
result)
(setq buffer-read-only t)
(goto-char (point-min))
(avandu2-mode)
(tabulated-list-print t))
(switch-to-buffer buffer)))
(defvar avandu2-overview-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map special-mode-map)
(define-key map "o" 'avandu2-open-article)
(define-key map "q" 'bury-buffer)
map)
"Keymap for `avandu2-mode'.")
(define-derived-mode avandu2-mode tabulated-list-mode "Avandu2"
"Major mode for ttrss displaying headlines in tabulated list.
\\{avandu2-mode-map}"
(use-local-map avandu2-overview-map)
(setq tabulated-list-format [("Headline" 64 t)
("Kategorie" 40 t)
("Updated" 40 t)])
(setq tabulated-list-padding 2)
(setq tabulated-list-sort-key (cons "Updated" t))
(tabulated-list-init-header))
(eval-after-load 'avandu
'(define-key avandu-article-mode-map "n" 'avandu2-open-next-article-in-table))
(eval-after-load 'avandu
'(define-key avandu-article-mode-map "p" 'avandu2-open-previous-article-in-table))