Browse Source

New major mode for listing scripts (fix #103)

* indium-list-scripts.el: New file.  This major mode lists all parsed scripts
  using a tabulated list.
* indium.el: Load indium-list-scripts.
workspaces
Nicolas Petton 5 years ago
parent
commit
af6de70fd3
3 changed files with 113 additions and 0 deletions
  1. +66
    -0
      indium-list-scripts.el
  2. +1
    -0
      indium.el
  3. +46
    -0
      test/unit/indium-list-scripts-test.el

+ 66
- 0
indium-list-scripts.el View File

@ -0,0 +1,66 @@
;;; indium-list-scripts.el --- List parsed scripts -*- lexical-binding: t; -*-
;; Copyright (C) 2017 Nicolas Petton
;; Author: Nicolas Petton <nicolas@petton.fr>
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'indium-script)
(require 'indium-structs)
(require 'map)
(require 'tabulated-list)
(defun indium-list-scripts ()
"Display a list of parsed scripts."
(interactive)
(unless-indium-connected
(user-error "Connect Indium to a runtime first"))
(let ((buf (get-buffer-create "*Indium scripts*")))
(with-current-buffer buf
(indium-list-scripts-mode)
(indium-list-scripts--refresh)
(tabulated-list-print))
(display-buffer buf)))
(define-derived-mode indium-list-scripts-mode tabulated-list-mode "Indium list scripts"
"Major mode for listing parsed JavaScript scripts."
(setq tabulated-list-format [("Script source" 0 t)])
(add-hook 'tabulated-list-revert-hook 'indium-list-scripts--refresh nil t)
(tabulated-list-init-header))
(defun indium-list-scripts--refresh ()
"Refresh the list of parsed scripts."
(setq tabulated-list-entries
(map-apply (lambda (_ script)
(indium-list-scripts--make-entry script))
(indium-current-connection-scripts))))
(defun indium-list-scripts--make-entry (script)
"Return a tabulated list entry for SCRIPT."
(list (indium-script-id script)
(make-vector 1 (if-let ((file (indium-script-get-file script)))
(cons (indium-script-url script)
(list 'action (lambda (&rest _)
(find-file file))))
(indium-script-url script)))))
(provide 'indium-list-scripts)
;;; indium-list-scripts.el ends here

+ 1
- 0
indium.el View File

@ -35,6 +35,7 @@
(require 'indium-chrome)
(require 'indium-nodejs)
(require 'indium-scratch)
(require 'indium-list-scripts)
(provide 'indium)
;;; indium.el ends here

+ 46
- 0
test/unit/indium-list-scripts-test.el View File

@ -0,0 +1,46 @@
;;; indium-list-scripts-test.el --- Tests for indium-list-scripts.el -*- lexical-binding: t; -*-
;; Copyright (C) 2017 Nicolas Petton
;; Author: Nicolas Petton <nicolas@foretagsplatsen.se>
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'buttercup)
(require 'indium-list-scripts)
(describe "Listing entries"
(it "Should signal an error when there is no connection"
(let ((indium-current-connection nil))
(expect (indium-list-scripts) :to-throw 'user-error))))
(describe "Making tabulated list entries"
(it "Should be able to make entries"
(spy-on 'indium-script-get-file :and-return-value nil)
(let* ((script (make-indium-script :id "1" :url "foo.html"))
(entry (indium-list-scripts--make-entry script)))
(expect entry :to-equal '("1" ["foo.html"]))))
(it "Should make an entry with a button when there is a local file"
(spy-on 'indium-script-get-file :and-return-value "bar.html")
(let* ((script (make-indium-script :id "1" :url "foo.html"))
(entry (indium-list-scripts--make-entry script)))
(expect (cadr (elt (cadr entry) 0)) :to-equal 'action))))
(provide 'indium-list-scripts-test)
;;; indium-list-scripts-test.el ends here

Loading…
Cancel
Save