Differences From
Artifact [689d8c2215]:
226 226 ;; URL.EL CALLBACKS
227 227
228 228 (defun sbbs--board-loader (status buf)
229 229 "Callback function for `url-retrieve' when loading board.
230 230
231 231 Load results into buffer BUF. STATUS is used to check for
232 232 errors."
233 - (when (plist-get status :error)
234 - (message "Error while loading: %s"
233 + (when (buffer-live-p buf)
234 + (when (plist-get status :error)
235 + (error "Error while loading: %s"
235 236 (cdr (plist-get status :error))))
236 - (forward-paragraph)
237 - (let ((list (read (current-buffer))))
238 - (kill-buffer)
239 - (with-current-buffer buf
240 - (let (ent)
241 - (dolist (thread list)
242 - (push (list (car thread)
243 - (vector (substring (cdr (assq 'date (cdr thread)))
244 - 0 16)
245 - (number-to-string
246 - (cdr (assq 'messages (cdr thread))))
247 - (propertize
248 - (cdr (assq 'headline (cdr thread)))
249 - 'face 'variable-pitch)))
250 - ent))
251 - (setq-local tabulated-list-entries ent)
252 - (tabulated-list-print t t)
253 - (hl-line-highlight)))))
237 + (forward-paragraph)
238 + (let ((list (read (current-buffer))))
239 + (kill-buffer)
240 + (with-current-buffer buf
241 + (let (ent)
242 + (dolist (thread list)
243 + (push (list (car thread)
244 + (vector (substring (cdr (assq 'date (cdr thread)))
245 + 0 16)
246 + (number-to-string
247 + (cdr (assq 'messages (cdr thread))))
248 + (propertize
249 + (cdr (assq 'headline (cdr thread)))
250 + 'face 'variable-pitch)))
251 + ent))
252 + (setq-local tabulated-list-entries ent)
253 + (tabulated-list-print t t)
254 + (hl-line-highlight))))))
254 255
255 256 (defun sbbs--thread-loader (status board id buf)
256 257 "Callback function for `url-retrieve' when loading thread.
257 258
258 259 The attribute ID determines what thread from board BOARD to
259 260 load. STATUS is used to check for errors."
260 - (when (plist-get status :error)
261 - (message "Error while loading: %s"
261 + (when (buffer-live-p buf)
262 + (when (plist-get status :error)
263 + (error "Error while loading: %s"
262 264 (cdr (plist-get status :error))))
263 - (prog-mode)
264 - (forward-paragraph)
265 - (save-excursion
266 - (save-match-data
267 - (while (search-forward "#f" nil t)
268 - (unless (cadddr (syntax-ppss))
269 - (replace-match "nil")))))
270 - (save-excursion
271 - (save-match-data
272 - (while (search-forward "#f" nil t)
273 - (unless (cadddr (syntax-ppss))
274 - (replace-match "t")))))
275 - (let ((thread (read (current-buffer))))
276 - (kill-buffer)
277 - (with-current-buffer buf
278 - (sbbs-read-mode)
279 - (setq sbbs--board board
280 - sbbs--thread-id id)
281 - (let ((buffer-read-only nil))
282 - (erase-buffer)
283 - (setq header-line-format
284 - (format "Thread %d: %s" id
285 - (cdr (assq 'headline thread))))
286 - (dolist (post (cadr (assq 'posts thread)))
287 - (sbbs--thread-insert-post post))
288 - (delete-blank-lines)
289 - (goto-char (point-min)))
290 - (rename-buffer (format "*reading /%s/%d*"
291 - (sbbs--board-name board)
292 - id)))))
265 + (prog-mode)
266 + (forward-paragraph)
267 + (save-excursion
268 + (save-match-data
269 + (while (search-forward "#f" nil t)
270 + (unless (cadddr (syntax-ppss))
271 + (replace-match "nil")))))
272 + (save-excursion
273 + (save-match-data
274 + (while (search-forward "#f" nil t)
275 + (unless (cadddr (syntax-ppss))
276 + (replace-match "t")))))
277 + (let ((thread (read (current-buffer))))
278 + (kill-buffer)
279 + (with-current-buffer buf
280 + (sbbs-read-mode)
281 + (setq sbbs--board board
282 + sbbs--thread-id id)
283 + (let ((buffer-read-only nil))
284 + (erase-buffer)
285 + (setq header-line-format
286 + (format "Thread %d: %s" id
287 + (cdr (assq 'headline thread))))
288 + (dolist (post (cadr (assq 'posts thread)))
289 + (sbbs--thread-insert-post post))
290 + (delete-blank-lines)
291 + (goto-char (point-min)))
292 + (rename-buffer (format "*reading /%s/%d*"
293 + (sbbs--board-name board)
294 + id))))))
293 295
294 296 ;; INTERACTIVE FUNCTIONS
295 297
296 298 (defun sbbs-view-open (id)
297 299 "Open thread ID in new buffer."
298 300 (interactive (list (tabulated-list-get-id)))
299 301 (let ((url (sbbs--board-url (format "/%d" id) t))