emacs-ipython-notebook/ein-pager.el

89 lines
2.4 KiB
EmacsLisp
Raw Normal View History

2012-05-07 14:41:15 +02:00
;;; ein-pager.el --- Pager module
;; Copyright (C) 2012- Takafumi Arakaki
;; Author: Takafumi Arakaki
;; This file is NOT part of GNU Emacs.
;; ein-pager.el 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.
;; ein-pager.el 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 ein-pager.el. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'ansi-color)
2012-05-14 03:06:55 +02:00
(require 'ein-utils)
2012-05-22 20:14:10 +02:00
(require 'ein-events)
2012-05-07 14:41:15 +02:00
2012-05-22 20:14:10 +02:00
(defun ein:pager-new (name events)
;; currently pager = name.
(ein:pager-bind-events name events)
2012-05-14 03:08:32 +02:00
name)
2012-05-22 20:14:10 +02:00
(defun ein:pager-bind-events (pager events)
"Bind events related to PAGER to the event handler EVENTS."
(ein:events-on events
'(open_with_text . Pager)
#'ein:pager--open-with-text
pager))
(defun ein:pager--open-with-text (pager data)
(let ((text (plist-get :text data)))
(unless (equal (ein:trim text) "")
(ein:pager-clear pager)
(ein:pager-expand pager)
(ein:pager-append-text pager text))))
2012-05-07 14:41:15 +02:00
(defun ein:pager-clear (pager)
2012-05-14 03:08:32 +02:00
(ein:with-read-only-buffer (get-buffer-create pager)
(erase-buffer)))
2012-05-07 14:41:15 +02:00
(defun ein:pager-expand (pager)
2012-05-14 03:08:32 +02:00
(pop-to-buffer (get-buffer-create pager))
2012-05-15 04:51:19 +02:00
(goto-char (point-min)))
2012-05-07 14:41:15 +02:00
(defun ein:pager-append-text (pager text)
2012-05-14 03:08:32 +02:00
(ein:with-read-only-buffer (get-buffer-create pager)
2012-05-15 04:51:19 +02:00
(insert (ansi-color-apply text))
2012-05-15 05:34:37 +02:00
(ein:pager-mode)))
2012-05-15 05:55:52 +02:00
;; FIXME: this should be automatically called when opening pager.
(defun ein:pager-goto-docstring-bset-loc ()
"Goto the best location of the documentation."
(interactive)
(goto-char (point-min))
(search-forward-regexp "^Docstring:")
(beginning-of-line 0)
(recenter 0))
2012-05-15 05:34:37 +02:00
(define-derived-mode ein:pager-mode fundamental-mode "ein:pager"
"IPython notebook pager mode."
(view-mode)
(font-lock-mode))
2012-05-07 14:41:15 +02:00
2012-05-15 05:55:52 +02:00
(setq
ein:pager-mode-map
(let ((map (copy-keymap widget-keymap)))
(define-key map "\C-c\C-b" 'ein:pager-goto-docstring-bset-loc)
map))
2012-05-07 14:41:15 +02:00
(provide 'ein-pager)
;;; ein-pager.el ends here