-
Notifications
You must be signed in to change notification settings - Fork 8
/
dime-browse.el
94 lines (75 loc) · 2.79 KB
/
dime-browse.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;;; dime-browse.el --- Dylan interaction mode -*- lexical-binding: t -*-
;; Lineage: SLIME, Open Dylan
;; Copyright (C) 20?? Rui Patrocínio (SLIME)
;; Copyright (C) 2011, 2012 Hannes Mehnert
;; Copyright (C) 2013 Erik Charlebois
;; Copyright (C) 2021 Lassi Kortela
;; SPDX-License-Identifier: GPL-2.0-or-later
;; URL: https://opendylan.org/
;; Package-Requires: ((emacs "25.1"))
;;; Commentary:
;; Dylan class browser for Dime.
;;; Code:
;; Originally adapted from `slime-xref-browser.el'.
(require 'cl-lib)
(require 'tree-widget)
(require 'dime)
(defun dime-browse--expand-node (expander swank widget)
"Helper to expand a node in WIDGET using EXPANDER and SWANK command."
(or (widget-get widget :args)
(let ((name (widget-get widget :tag)))
(cl-loop for kid in (dime-eval `(,swank ,name))
collect `(tree-widget
:tag ,kid
:expander ',expander
:has-children t)))))
(defun dime-browse--expand-subclass-node (widget)
"Helper to expand a subclass node in WIDGET."
(dime-browse--expand-node
'dime-browse--expand-subclass-node
'swank:dylan-subclasses
widget))
(defun dime-browse--expand-superclass-node (widget)
"Helper to expand a superclass node in WIDGET."
(dime-browse--expand-node
'dime-browse--expand-superclass-node
'swank:dylan-superclasses
widget))
(defvar dime-browse-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map widget-keymap)
(define-key map "q" 'bury-buffer)
map)
"Keymap for the Dime class browser.")
(defun dime-browse--with-expander (name expander)
"Internal function to browse class NAME using EXPANDER."
(let ((project (dime-current-project))
(module dylan-buffer-module))
(switch-to-buffer "*Dime class browser*")
(kill-all-local-variables)
(setq dime-buffer-project project)
(setq dylan-buffer-module module)
(let ((inhibit-read-only t))
(erase-buffer)
(widget-insert "Class Browser" "\n\n")
(save-excursion
(widget-create 'tree-widget
:tag name
:expander expander
:has-echildren t)))
(lisp-mode-variables t)
(dime-mode t)
(use-local-map dime-browse-map)
(widget-setup)))
;;;###autoload
(defun dime-browse-subclasses (name)
"Read the NAME of a class and show its subclasses."
(interactive (list (dime-read-symbol-name "Class Name: ")))
(dime-browse--with-expander name 'dime-browse--expand-subclass-node))
;;;###autoload
(defun dime-browse-superclasses (name)
"Read the NAME of a class and show its superclasses."
(interactive (list (dime-read-symbol-name "Class Name: ")))
(dime-browse--with-expander name 'dime-browse--expand-superclass-node))
(provide 'dime-browse)
;;; dime-browse.el ends here