sbbs.el

Check-in [9d4d483630]
Login
Overview
Comment:show buffer when created instead of when ready
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 9d4d4836303eedb93fce7f2fbe2c1a11e764abca557f254871a5821d7fe32b83
User & Date: philip@warpmail.net on 2020-02-22 13:16:32
Other Links: branch diff | manifest | tags
Context
2020-02-22
13:26
fixed public inbox link in readme check-in: 10da9b03bc user: philip@warpmail.net tags: master, trunk
13:16
show buffer when created instead of when ready check-in: 9d4d483630 user: philip@warpmail.net tags: master, trunk
09:52
fixed checkdoc complaints check-in: 93975f9b0f user: philip@warpmail.net tags: master, trunk
Changes

Modified sbbs.el from [e250c11b65] to [689d8c2215].

118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







-
+







  "Function to reload an opened thread."
  (when sbbs--thread-id (sbbs-view-open sbbs--thread-id)))

(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.

If LINK is a (board, thread or site) local link, modify opening
245
246
247
248
249
250
251
252

253
254

255
256

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295




296
297
298
299
300
301
302







303
304




305
306
307
308
309
310
311
245
246
247
248
249
250
251

252


253
254

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

275




276
277
278
279
280
281
282
283
284
285
286
287
288


289
290
291
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317







-
+
-
-
+

-
+



















-
+
-
-
-
-













-
-
+
+
+
+






-
+
+
+
+
+
+
+

-
+
+
+
+







                              (number-to-string
                               (cdr (assq 'messages (cdr thread))))
                              (propertize
                               (cdr (assq 'headline (cdr thread)))
                               'face 'variable-pitch)))
                ent))
        (setq-local tabulated-list-entries ent)
        (tabulated-list-print t t)))
        (tabulated-list-print t t)
    (switch-to-buffer buf)
    (hl-line-highlight)))
        (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)
    (message "Error while loading: %s"
             (cdr (plist-get status :error))))
  (prog-mode)
  (forward-paragraph)
  (save-excursion
    (save-match-data
      (while (search-forward "#f" nil t)
        (unless (cadddr (syntax-ppss))
          (replace-match "nil")))))
  (save-excursion
    (save-match-data
      (while (search-forward "#f" nil t)
        (unless (cadddr (syntax-ppss))
          (replace-match "t")))))
  (let ((thread (read (current-buffer)))
  (let ((thread (read (current-buffer))))
        (buf (get-buffer-create
              (format "*reading /%s/%d*"
                      (sbbs--board-name board)
                      id))))
    (kill-buffer)
    (with-current-buffer buf
      (sbbs-read-mode)
      (setq sbbs--board board
            sbbs--thread-id id)
      (let ((buffer-read-only nil))
        (erase-buffer)
        (setq header-line-format
              (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))
    (with-current-buffer (generate-new-buffer "*new thread*")
      (sbbs-compose-mode)
375
376
377
378
379
380
381
382

383
384

385
386



387

388
389
390
391
392
393





394
395
396
397
398
399
400
381
382
383
384
385
386
387

388
389

390
391
392
393
394
395

396






397
398
399
400
401
402
403
404
405
406
407
408







-
+

-
+


+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+







    (catch 'found
      (while (search-backward-regexp "^#" nil t)
        (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)))
    (if (and (get-buffer name) (not reload))
        (progn (switch-to-buffer name)
               (sbbs--reload-board))
    (with-current-buffer (get-buffer-create name)
      (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))))))
        (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

(defvar sbbs-view-mode-map