|
| 1 | +;;; sideline-geiser.el --- Show Geiser result with sideline -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2024 Shen, Jen-Chieh |
| 4 | + |
| 5 | +;; Author: Shen, Jen-Chieh <jcs090218@gmail.com> |
| 6 | +;; Maintainer: Shen, Jen-Chieh <jcs090218@gmail.com> |
| 7 | +;; URL: https://github.com/emacs-sideline/sideline-geiser |
| 8 | +;; Version: 0.1.0 |
| 9 | +;; Package-Requires: ((emacs "28.1") (sideline "0.1.0") (geiser "0.31.1")) |
| 10 | +;; Keywords: convenience |
| 11 | + |
| 12 | +;; This file is not part of GNU Emacs. |
| 13 | + |
| 14 | +;; This program is free software: you can redistribute it and/or modify |
| 15 | +;; it under the terms of the GNU General Public License as published by |
| 16 | +;; the Free Software Foundation, either version 3 of the License, or |
| 17 | +;; (at your option) any later version. |
| 18 | + |
| 19 | +;; This program is distributed in the hope that it will be useful, |
| 20 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +;; GNU General Public License for more details. |
| 23 | + |
| 24 | +;; You should have received a copy of the GNU General Public License |
| 25 | +;; along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 26 | + |
| 27 | +;;; Commentary: |
| 28 | +;; |
| 29 | +;; Show Geiser result with sideline. |
| 30 | +;; |
| 31 | + |
| 32 | +;;; Code: |
| 33 | + |
| 34 | +(require 'sideline) |
| 35 | + |
| 36 | +(eval-when-compile |
| 37 | + (require 'geiser) |
| 38 | + (require 'geiser-mode)) |
| 39 | + |
| 40 | +(defgroup sideline-geiser nil |
| 41 | + "Show Geiser result with sideline." |
| 42 | + :prefix "sideline-geiser-" |
| 43 | + :group 'tool |
| 44 | + :link '(url-link :tag "Repository" "https://github.com/emacs-sideline/sideline-geiser")) |
| 45 | + |
| 46 | +(defface sideline-geiser-result-overlay-face |
| 47 | + '((((class color) (background light)) |
| 48 | + :background "grey90" :box (:line-width -1 :color "yellow")) |
| 49 | + (((class color) (background dark)) |
| 50 | + :background "grey10" :box (:line-width -1 :color "black"))) |
| 51 | + "Face used to display evaluation results." |
| 52 | + :group 'sideline-racket) |
| 53 | + |
| 54 | +(defvar sideline-geiser--buffer nil |
| 55 | + "Record the evaluation buffer.") |
| 56 | + |
| 57 | +(defvar-local sideline-geiser--callback nil |
| 58 | + "Callback to display result.") |
| 59 | + |
| 60 | +;;;###autoload |
| 61 | +(defun sideline-geiser (command) |
| 62 | + "Backend for sideline. |
| 63 | +
|
| 64 | +Argument COMMAND is required in sideline backend." |
| 65 | + (cl-case command |
| 66 | + (`candidates (cons :async |
| 67 | + (lambda (callback &rest _) |
| 68 | + (setq sideline-geiser--callback callback |
| 69 | + sideline-geiser--buffer (current-buffer))))) |
| 70 | + (`face 'sideline-geiser-result-overlay-face))) |
| 71 | + |
| 72 | +;;;###autoload |
| 73 | +(defun sideline-geiser-show (msg is-error &rest _) |
| 74 | + "Display the result MSG." |
| 75 | + (when (and msg |
| 76 | + sideline-geiser--buffer) |
| 77 | + (with-current-buffer sideline-geiser--buffer |
| 78 | + (funcall sideline-geiser--callback |
| 79 | + (list (format "%s%s" |
| 80 | + (if is-error "ERROR" "") |
| 81 | + msg)))))) |
| 82 | + |
| 83 | +(provide 'sideline-geiser) |
| 84 | +;;; sideline-geiser.el ends here |
0 commit comments