Index: sbbs.el ================================================================== --- sbbs.el +++ sbbs.el @@ -120,11 +120,11 @@ (defun sbbs--reload-board () "Function to regenerate thread index. Called by `tabulated-list-mode' hooks." - (when sbbs--board (sbbs-browse sbbs--board))) + (when sbbs--board (sbbs-browse sbbs--board t))) ;; UI GENERATOR (defun sbbs--insert-link (text link) "Insert link to LINK as TEXT into buffer. @@ -247,15 +247,14 @@ (propertize (cdr (assq 'headline (cdr thread))) 'face 'variable-pitch))) ent)) (setq-local tabulated-list-entries ent) - (tabulated-list-print t t))) - (switch-to-buffer buf) - (hl-line-highlight))) + (tabulated-list-print t t) + (hl-line-highlight))))) -(defun sbbs--thread-loader (status board id) +(defun sbbs--thread-loader (status board id buf) "Callback function for `url-retrieve' when loading thread. The attribute ID determines what thread from board BOARD to load. STATUS is used to check for errors." (when (plist-get status :error) @@ -271,15 +270,11 @@ (save-excursion (save-match-data (while (search-forward "#f" nil t) (unless (cadddr (syntax-ppss)) (replace-match "t"))))) - (let ((thread (read (current-buffer))) - (buf (get-buffer-create - (format "*reading /%s/%d*" - (sbbs--board-name board) - id)))) + (let ((thread (read (current-buffer)))) (kill-buffer) (with-current-buffer buf (sbbs-read-mode) (setq sbbs--board board sbbs--thread-id id) @@ -289,21 +284,32 @@ (format "Thread %d: %s" id (cdr (assq 'headline thread)))) (dolist (post (cadr (assq 'posts thread))) (sbbs--thread-insert-post post)) (delete-blank-lines) - (goto-char (point-min)))) - (switch-to-buffer buf))) + (goto-char (point-min))) + (rename-buffer (format "*reading /%s/%d*" + (sbbs--board-name board) + id))))) ;; INTERACTIVE FUNCTIONS (defun sbbs-view-open (id) "Open thread ID in new buffer." (interactive (list (tabulated-list-get-id))) - (let ((url (sbbs--board-url (format "/%d" id) t))) + (let ((url (sbbs--board-url (format "/%d" id) t)) + (headline (substring-no-properties + (aref (tabulated-list-get-entry ) 2))) + (buf (get-buffer-create + (format "*loading /%s/%d*" + (sbbs--board-name sbbs--board) + id)))) (url-retrieve url #'sbbs--thread-loader - (list sbbs--board id)))) + (list sbbs--board id buf)) + (with-current-buffer buf + (setq header-line-format (format "Thread %d: %s" id headline))) + (switch-to-buffer buf))) (defun sbbs-view-compose () "Create buffer to start a new thread." (interactive) (let ((board sbbs--board)) @@ -377,22 +383,24 @@ (when (eq 'highlight (get-text-property (point) 'face)) (throw 'found t))))) (beginning-of-line)) ;;;###autoload -(defun sbbs-browse (board) +(defun sbbs-browse (board reload) "Open thread overview for BOARD." - (interactive (list (sbbs-read-board))) + (interactive (list (sbbs-read-board) nil)) (let* ((name (format "*browsing /%s/*" (sbbs--board-name board))) (url (sbbs--board-url "list" t board))) - (with-current-buffer (get-buffer-create name) - (let ((buffer-read-only nil)) - (erase-buffer)) - (sbbs-view-mode) - (setq sbbs--board board) - (url-retrieve url #'sbbs--board-loader - (list (current-buffer)))))) + (if (and (get-buffer name) (not reload)) + (progn (switch-to-buffer name) + (sbbs--reload-board)) + (with-current-buffer (get-buffer-create name) + (sbbs-view-mode) + (setq sbbs--board board) + (url-retrieve url #'sbbs--board-loader + (list (current-buffer))) + (switch-to-buffer (current-buffer)))))) ;;;###autoload (defalias 'sbbs #'sbbs-browse) ;; MAJOR MODES