Emacs user interface to navigate Basecamp 3.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

93 lines
3.2 KiB

  1. ;;; bcel-chat.el --- Comment on anything using a chat-like interface -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2019 Damien Cassou
  3. ;; Author: Damien Cassou <damien@cassou.me>
  4. ;; Url: https://gitea.petton.fr/bcel/bcel
  5. ;; Package-requires: ((emacs "26.1") (libbcel "0.4.0"))
  6. ;; Version: 0.1.0
  7. ;; This program is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Let the user comment on anything commentable using a chat-like interface.
  19. ;;; Code:
  20. (require 'lui)
  21. (require 'navigel)
  22. (require 'libbcel)
  23. (defun bcel-chat--buffer-name (entity)
  24. "Return a buffer name to chat on ENTITY's comments."
  25. (format "*bcel-chat-%s (%s)*"
  26. (libbcel-entity-name entity)
  27. (libbcel-entity-id entity)))
  28. (define-derived-mode bcel-chat-mode lui-mode "bcel chat"
  29. "Chat interface to discuss on an ENTITY's comments.")
  30. (defun bcel-chat--insert-html (html)
  31. "Insert a propertized text representing HTML in current buffer."
  32. (shr-insert-document
  33. (with-temp-buffer
  34. (insert html)
  35. (libxml-parse-html-region (point-min) (point-max)))))
  36. (defun bcel-chat--insert-header (comment)
  37. "Insert a line with meta information about COMMENT."
  38. (let ((author (libbcel-comment-creator comment)))
  39. (insert (libbcel-person-name author))
  40. (insert "\n")))
  41. (defun bcel-chat--prepare-comment-text (comment)
  42. "Return a propertized string representing COMMENT."
  43. (with-temp-buffer
  44. (bcel-chat--insert-header comment)
  45. (bcel-chat--insert-html (libbcel-comment-content comment))
  46. (buffer-substring (point-min) (point-max))))
  47. (defun bcel-chat--insert-comment (comment buffer)
  48. "Insert COMMENT into lui BUFFER."
  49. (let ((lui-time-stamp-time (date-to-time (libbcel-comment-created-at comment)))
  50. (lui-message-id (libbcel-entity-id comment)))
  51. (with-current-buffer buffer
  52. (lui-insert
  53. (bcel-chat--prepare-comment-text comment)))))
  54. (defun bcel-chat--insert-comments (entity buffer)
  55. "Insert ENTITY's comments into lui BUFFER."
  56. (libbcel-nav-comments
  57. entity
  58. (lambda (comments)
  59. (dolist (comment comments)
  60. (bcel-chat--insert-comment comment buffer)))))
  61. (defun bcel-chat-open (entity)
  62. "Create and display a chat buffer for ENTITY's comments."
  63. (with-current-buffer (get-buffer-create (bcel-chat--buffer-name entity))
  64. (let ((inhibit-read-only t))
  65. (erase-buffer))
  66. (bcel-chat-mode)
  67. (setq-local navigel-entity entity)
  68. (lui-set-prompt "Comment> ")
  69. (setq-local lui-input-function
  70. (lambda (new-comment)
  71. (message "saving new comment: %s" new-comment)))
  72. (bcel-chat--insert-comments entity (current-buffer))
  73. (switch-to-buffer (current-buffer))))
  74. (provide 'bcel-chat)
  75. ;;; bcel-chat.el ends here