FUEL: Nicer xref buffers.
parent
ad728652d8
commit
3630933b09
|
@ -166,14 +166,11 @@ M: source-file fuel-pprint path>> fuel-pprint ;
|
||||||
first2 [ (normalize-path) ] dip 2array fuel-eval-set-result
|
first2 [ (normalize-path) ] dip 2array fuel-eval-set-result
|
||||||
] when* ; inline
|
] when* ; inline
|
||||||
|
|
||||||
: fuel-xref-desc ( word -- str )
|
|
||||||
[ name>> ]
|
|
||||||
[ vocabulary>> [ " (" prepend ")" append ] [ "" ] if* ] bi append ; inline
|
|
||||||
|
|
||||||
: fuel-format-xrefs ( seq -- seq )
|
: fuel-format-xrefs ( seq -- seq )
|
||||||
[ word? ] filter [
|
[ word? ] filter [
|
||||||
[ fuel-xref-desc ]
|
[ name>> ]
|
||||||
[ where [ first2 [ (normalize-path) ] dip ] [ f f ] if* ] bi 3array
|
[ vocabulary>> ]
|
||||||
|
[ where [ first2 [ (normalize-path) ] dip ] [ f f ] if* ] tri 4array
|
||||||
] map [ [ first ] dip first <=> ] sort ; inline
|
] map [ [ first ] dip first <=> ] sort ; inline
|
||||||
|
|
||||||
: fuel-callers-xref ( word -- )
|
: fuel-callers-xref ( word -- )
|
||||||
|
|
|
@ -98,3 +98,8 @@ C-cC-eC-r is the same as C-cC-er)).
|
||||||
- C-cz : switch to listener
|
- C-cz : switch to listener
|
||||||
- q : bury buffer
|
- q : bury buffer
|
||||||
|
|
||||||
|
* In crossref buffers
|
||||||
|
|
||||||
|
- TAB/BACKTAB : navigate links
|
||||||
|
- RET/mouse click : follow link
|
||||||
|
- q : bury buffer
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'fuel-eval)
|
||||||
|
(require 'fuel-popup)
|
||||||
|
(require 'fuel-font-lock)
|
||||||
(require 'fuel-base)
|
(require 'fuel-base)
|
||||||
|
|
||||||
(require 'button)
|
(require 'button)
|
||||||
|
@ -24,13 +27,19 @@
|
||||||
"FUEL's cross-referencing engine."
|
"FUEL's cross-referencing engine."
|
||||||
:group 'fuel)
|
:group 'fuel)
|
||||||
|
|
||||||
|
(fuel-font-lock--defface fuel-font-lock-xref-link
|
||||||
|
'link fuel-xref "highlighting links in cross-reference buffers")
|
||||||
|
|
||||||
|
(fuel-font-lock--defface fuel-font-lock-xref-vocab
|
||||||
|
'italic fuel-xref "vocabulary names in cross-reference buffers")
|
||||||
|
|
||||||
|
|
||||||
;;; Buttons:
|
;;; Buttons:
|
||||||
|
|
||||||
(define-button-type 'fuel-xref--button-type
|
(define-button-type 'fuel-xref--button-type
|
||||||
'action 'fuel-xref--follow-link
|
'action 'fuel-xref--follow-link
|
||||||
'follow-link t
|
'follow-link t
|
||||||
'face 'default)
|
'face 'fuel-font-lock-xref-link)
|
||||||
|
|
||||||
(defun fuel-xref--follow-link (button)
|
(defun fuel-xref--follow-link (button)
|
||||||
(let ((file (button-get button 'file))
|
(let ((file (button-get button 'file))
|
||||||
|
@ -50,43 +59,50 @@
|
||||||
|
|
||||||
(defvar fuel-xref--help-string "(Press RET or click to follow crossrefs)")
|
(defvar fuel-xref--help-string "(Press RET or click to follow crossrefs)")
|
||||||
|
|
||||||
(defun fuel-xref--fill-buffer (title refs)
|
(defun fuel-xref--title (word cc count)
|
||||||
(let ((inhibit-read-only t))
|
(cond ((zerop count) (format "No known words %s '%s'." cc word))
|
||||||
|
((= 1 count) (format "1 word %s '%s':" cc word))
|
||||||
|
(t (format "%s words %s '%s':" count cc word))))
|
||||||
|
|
||||||
|
(defun fuel-xref--fill-buffer (word cc refs)
|
||||||
|
(let ((inhibit-read-only t)
|
||||||
|
(count 0))
|
||||||
(with-current-buffer (fuel-xref--buffer)
|
(with-current-buffer (fuel-xref--buffer)
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(insert title "\n\n")
|
|
||||||
(dolist (ref refs)
|
(dolist (ref refs)
|
||||||
(when (and (first ref) (second ref) (numberp (third ref)))
|
(when (and (stringp (first ref))
|
||||||
|
(stringp (third ref))
|
||||||
|
(numberp (fourth ref)))
|
||||||
(insert " ")
|
(insert " ")
|
||||||
(insert-text-button (first ref)
|
(insert-text-button (first ref)
|
||||||
:type 'fuel-xref--button-type
|
:type 'fuel-xref--button-type
|
||||||
'help-echo (format "File: %s (%s)"
|
'help-echo (format "File: %s (%s)"
|
||||||
(second ref)
|
(second ref)
|
||||||
(third ref))
|
(third ref))
|
||||||
'file (second ref)
|
'file (third ref)
|
||||||
'line (third ref))
|
'line (fourth ref))
|
||||||
|
(when (stringp (second ref))
|
||||||
|
(insert (format " (in %s)" (second ref))))
|
||||||
|
(setq count (1+ count))
|
||||||
(newline)))
|
(newline)))
|
||||||
(when refs
|
(goto-char (point-min))
|
||||||
(insert "\n\n" fuel-xref--help-string "\n"))
|
(insert (fuel-xref--title word (if cc "using" "used by") count) "\n\n")
|
||||||
|
(when (> count 0)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(insert "\n" fuel-xref--help-string "\n"))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(current-buffer))))
|
(current-buffer))))
|
||||||
|
|
||||||
(defun fuel-xref--show-callers (word)
|
(defun fuel-xref--show-callers (word)
|
||||||
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref))))
|
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref))))
|
||||||
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))
|
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
|
||||||
(title (format (if res "Callers of '%s':"
|
(set-buffer (fuel-xref--fill-buffer word t res))
|
||||||
"No callers found for '%s'")
|
|
||||||
word)))
|
|
||||||
(set-buffer (fuel-xref--fill-buffer title res))
|
|
||||||
(fuel-popup--display)))
|
(fuel-popup--display)))
|
||||||
|
|
||||||
(defun fuel-xref--show-callees (word)
|
(defun fuel-xref--show-callees (word)
|
||||||
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref))))
|
(let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref))))
|
||||||
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))
|
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
|
||||||
(title (format (if res "Words called by '%s':"
|
(set-buffer (fuel-xref--fill-buffer word nil res))
|
||||||
"No callees found for '%s'")
|
|
||||||
word)))
|
|
||||||
(set-buffer (fuel-xref--fill-buffer title res))
|
|
||||||
(fuel-popup--display)))
|
(fuel-popup--display)))
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,7 +124,7 @@
|
||||||
(use-local-map fuel-xref-mode-map)
|
(use-local-map fuel-xref-mode-map)
|
||||||
(setq mode-name "FUEL Xref")
|
(setq mode-name "FUEL Xref")
|
||||||
(setq major-mode 'fuel-xref-mode)
|
(setq major-mode 'fuel-xref-mode)
|
||||||
(fuel-font-lock--font-lock-setup)
|
(font-lock-add-keywords nil '(("(in \\(.+\\))" 1 'fuel-font-lock-xref-vocab)))
|
||||||
(setq buffer-read-only t))
|
(setq buffer-read-only t))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue