Differences From
Artifact [e250c11b65]:
118 118 "Function to reload an opened thread."
119 119 (when sbbs--thread-id (sbbs-view-open sbbs--thread-id)))
120 120
121 121 (defun sbbs--reload-board ()
122 122 "Function to regenerate thread index.
123 123
124 124 Called by `tabulated-list-mode' hooks."
125 - (when sbbs--board (sbbs-browse sbbs--board)))
125 + (when sbbs--board (sbbs-browse sbbs--board t)))
126 126
127 127 ;; UI GENERATOR
128 128
129 129 (defun sbbs--insert-link (text link)
130 130 "Insert link to LINK as TEXT into buffer.
131 131
132 132 If LINK is a (board, thread or site) local link, modify opening
................................................................................
245 245 (number-to-string
246 246 (cdr (assq 'messages (cdr thread))))
247 247 (propertize
248 248 (cdr (assq 'headline (cdr thread)))
249 249 'face 'variable-pitch)))
250 250 ent))
251 251 (setq-local tabulated-list-entries ent)
252 - (tabulated-list-print t t)))
253 - (switch-to-buffer buf)
254 - (hl-line-highlight)))
252 + (tabulated-list-print t t)
253 + (hl-line-highlight)))))
255 254
256 -(defun sbbs--thread-loader (status board id)
255 +(defun sbbs--thread-loader (status board id buf)
257 256 "Callback function for `url-retrieve' when loading thread.
258 257
259 258 The attribute ID determines what thread from board BOARD to
260 259 load. STATUS is used to check for errors."
261 260 (when (plist-get status :error)
262 261 (message "Error while loading: %s"
263 262 (cdr (plist-get status :error))))
................................................................................
269 268 (unless (cadddr (syntax-ppss))
270 269 (replace-match "nil")))))
271 270 (save-excursion
272 271 (save-match-data
273 272 (while (search-forward "#f" nil t)
274 273 (unless (cadddr (syntax-ppss))
275 274 (replace-match "t")))))
276 - (let ((thread (read (current-buffer)))
277 - (buf (get-buffer-create
278 - (format "*reading /%s/%d*"
279 - (sbbs--board-name board)
280 - id))))
275 + (let ((thread (read (current-buffer))))
281 276 (kill-buffer)
282 277 (with-current-buffer buf
283 278 (sbbs-read-mode)
284 279 (setq sbbs--board board
285 280 sbbs--thread-id id)
286 281 (let ((buffer-read-only nil))
287 282 (erase-buffer)
288 283 (setq header-line-format
289 284 (format "Thread %d: %s" id
290 285 (cdr (assq 'headline thread))))
291 286 (dolist (post (cadr (assq 'posts thread)))
292 287 (sbbs--thread-insert-post post))
293 288 (delete-blank-lines)
294 - (goto-char (point-min))))
295 - (switch-to-buffer buf)))
289 + (goto-char (point-min)))
290 + (rename-buffer (format "*reading /%s/%d*"
291 + (sbbs--board-name board)
292 + id)))))
296 293
297 294 ;; INTERACTIVE FUNCTIONS
298 295
299 296 (defun sbbs-view-open (id)
300 297 "Open thread ID in new buffer."
301 298 (interactive (list (tabulated-list-get-id)))
302 - (let ((url (sbbs--board-url (format "/%d" id) t)))
299 + (let ((url (sbbs--board-url (format "/%d" id) t))
300 + (headline (substring-no-properties
301 + (aref (tabulated-list-get-entry ) 2)))
302 + (buf (get-buffer-create
303 + (format "*loading /%s/%d*"
304 + (sbbs--board-name sbbs--board)
305 + id))))
303 306 (url-retrieve url #'sbbs--thread-loader
304 - (list sbbs--board id))))
307 + (list sbbs--board id buf))
308 + (with-current-buffer buf
309 + (setq header-line-format (format "Thread %d: %s" id headline)))
310 + (switch-to-buffer buf)))
305 311
306 312 (defun sbbs-view-compose ()
307 313 "Create buffer to start a new thread."
308 314 (interactive)
309 315 (let ((board sbbs--board))
310 316 (with-current-buffer (generate-new-buffer "*new thread*")
311 317 (sbbs-compose-mode)
................................................................................
375 381 (catch 'found
376 382 (while (search-backward-regexp "^#" nil t)
377 383 (when (eq 'highlight (get-text-property (point) 'face))
378 384 (throw 'found t)))))
379 385 (beginning-of-line))
380 386
381 387 ;;;###autoload
382 -(defun sbbs-browse (board)
388 +(defun sbbs-browse (board reload)
383 389 "Open thread overview for BOARD."
384 - (interactive (list (sbbs-read-board)))
390 + (interactive (list (sbbs-read-board) nil))
385 391 (let* ((name (format "*browsing /%s/*" (sbbs--board-name board)))
386 392 (url (sbbs--board-url "list" t board)))
387 - (with-current-buffer (get-buffer-create name)
388 - (let ((buffer-read-only nil))
389 - (erase-buffer))
390 - (sbbs-view-mode)
391 - (setq sbbs--board board)
392 - (url-retrieve url #'sbbs--board-loader
393 - (list (current-buffer))))))
393 + (if (and (get-buffer name) (not reload))
394 + (progn (switch-to-buffer name)
395 + (sbbs--reload-board))
396 + (with-current-buffer (get-buffer-create name)
397 + (sbbs-view-mode)
398 + (setq sbbs--board board)
399 + (url-retrieve url #'sbbs--board-loader
400 + (list (current-buffer)))
401 + (switch-to-buffer (current-buffer))))))
394 402
395 403 ;;;###autoload
396 404 (defalias 'sbbs #'sbbs-browse)
397 405
398 406 ;; MAJOR MODES
399 407
400 408 (defvar sbbs-view-mode-map