Browse Source

Try a chat-like interface for commenting

master
Damien Cassou 10 months ago
parent
commit
65ec85fa41
Signed by: DamienCassou <damien@cassou.me> GPG Key ID: B68746238E59B548
2 changed files with 101 additions and 0 deletions
  1. +92
    -0
      bcel-chat.el
  2. +9
    -0
      bcel.el

+ 92
- 0
bcel-chat.el View File

@@ -0,0 +1,92 @@
;;; bcel-chat.el --- Comment on anything using a chat-like interface -*- lexical-binding: t; -*-

;; Copyright (C) 2019 Damien Cassou

;; Author: Damien Cassou <damien@cassou.me>
;; Url: https://gitea.petton.fr/bcel/bcel
;; Package-requires: ((emacs "26.1") (libbcel "0.4.0"))
;; Version: 0.1.0

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Let the user comment on anything commentable using a chat-like interface.

;;; Code:
(require 'lui)
(require 'navigel)
(require 'libbcel)

(defun bcel-chat--buffer-name (entity)
"Return a buffer name to chat on ENTITY's comments."
(format "*bcel-chat-%s (%s)*"
(libbcel-entity-name entity)
(libbcel-entity-id entity)))

(define-derived-mode bcel-chat-mode lui-mode "bcel chat"
"Chat interface to discuss on an ENTITY's comments.")

(defun bcel-chat--insert-html (html)
"Insert a propertized text representing HTML in current buffer."
(shr-insert-document
(with-temp-buffer
(insert html)
(libxml-parse-html-region (point-min) (point-max)))))

(defun bcel-chat--insert-header (comment)
"Insert a line with meta information about COMMENT."
(let ((author (libbcel-comment-creator comment)))
(insert (libbcel-person-name author))
(insert "\n")))

(defun bcel-chat--prepare-comment-text (comment)
"Return a propertized string representing COMMENT."
(with-temp-buffer
(bcel-chat--insert-header comment)
(bcel-chat--insert-html (libbcel-comment-content comment))
(buffer-substring (point-min) (point-max))))

(defun bcel-chat--insert-comment (comment buffer)
"Insert COMMENT into lui BUFFER."
(let ((lui-time-stamp-time (date-to-time (libbcel-comment-created-at comment)))
(lui-message-id (libbcel-entity-id comment)))
(with-current-buffer buffer
(lui-insert
(bcel-chat--prepare-comment-text comment)))))

(defun bcel-chat--insert-comments (entity buffer)
"Insert ENTITY's comments into lui BUFFER."
(libbcel-nav-comments
entity
(lambda (comments)
(dolist (comment comments)
(bcel-chat--insert-comment comment buffer)))))

(defun bcel-chat-open (entity)
"Create and display a chat buffer for ENTITY's comments."
(with-current-buffer (get-buffer-create (bcel-chat--buffer-name entity))
(let ((inhibit-read-only t))
(erase-buffer))
(bcel-chat-mode)
(setq-local navigel-entity entity)
(lui-set-prompt "Comment> ")
(setq-local lui-input-function
(lambda (new-comment)
(message "saving new comment: %s" new-comment)))
(bcel-chat--insert-comments entity (current-buffer))
(switch-to-buffer (current-buffer))))

(provide 'bcel-chat)
;;; bcel-chat.el ends here

+ 9
- 0
bcel.el View File

@@ -28,6 +28,7 @@

(require 'navigel)
(require 'libbcel)
(require 'bcel-chat)

;;;###autoload
(defun bcel-list-projects ()
@@ -57,6 +58,8 @@
(define-derived-mode bcel-tablist-mode navigel-tablist-mode "bcel Tablist")

(define-key bcel-tablist-mode-map (kbd "C-c C-o") #'bcel-browse)
(define-key bcel-tablist-mode-map (kbd "c") #'bcel-chat)

(define-derived-mode bcel-todolist-tablist-mode bcel-tablist-mode "bcel todos")

(define-key bcel-todolist-tablist-mode-map (kbd "C-c C-c") #'bcel-todo-toggle)
@@ -192,5 +195,11 @@ Interactively, use ENTITY at point."
(interactive (list (navigel-entity-at-point)))
(browse-url (libbcel-entity-app-url entity)))

(defun bcel-chat (entity)
"Open a chat-like interface to comment on ENTITY.
Interactively, use ENTITY at point."
(interactive (list (navigel-entity-at-point)))
(bcel-chat-open entity))

(provide 'bcel)
;;; bcel.el ends here

Loading…
Cancel
Save