FUEL: Small improvements to xref mode.

db4
Jose A. Ortega Ruiz 2008-12-21 18:39:59 +01:00
parent 3630933b09
commit 3721086424
6 changed files with 61 additions and 42 deletions

View File

@ -147,16 +147,6 @@ M: source-file fuel-pprint path>> fuel-pprint ;
(fuel-eval) (fuel-eval)
] (fuel-end-eval) ; ] (fuel-end-eval) ;
: fuel-begin-eval ( in -- )
(fuel-begin-eval)
(fuel-eval-in)
fuel-retort ;
: fuel-eval ( lines -- )
(fuel-begin-eval) [ (fuel-eval) ] (fuel-end-eval) ; inline
: fuel-end-eval ( -- ) [ ] (fuel-end-eval) ; inline
: fuel-run-file ( path -- ) run-file ; inline : fuel-run-file ( path -- ) run-file ; inline
! Edit locations ! Edit locations

View File

@ -134,7 +134,7 @@
(defconst fuel-con--prompt-regex "( .+ ) ") (defconst fuel-con--prompt-regex "( .+ ) ")
(defconst fuel-con--eot-marker "<~FUEL~>") (defconst fuel-con--eot-marker "<~FUEL~>")
(defconst fuel-con--init-stanza "USE: fuel f fuel-eval") (defconst fuel-con--init-stanza "USE: fuel fuel-retort")
(defconst fuel-con--comint-finished-regex (defconst fuel-con--comint-finished-regex
(format "^%s$" fuel-con--eot-marker)) (format "^%s$" fuel-con--eot-marker))

View File

@ -183,8 +183,7 @@ With prefix argument, ask for word."
(fuel-syntax-symbol-at-point)))) (fuel-syntax-symbol-at-point))))
(when word (when word
(message "Looking up %s's callers ..." word) (message "Looking up %s's callers ..." word)
(fuel-xref--show-callers word) (fuel-xref--show-callers word))))
(message ""))))
(defun fuel-show-callees (&optional arg) (defun fuel-show-callees (&optional arg)
"Show a list of callers of word at point. "Show a list of callers of word at point.
@ -196,8 +195,7 @@ With prefix argument, ask for word."
(fuel-syntax-symbol-at-point)))) (fuel-syntax-symbol-at-point))))
(when word (when word
(message "Looking up %s's callees ..." word) (message "Looking up %s's callees ..." word)
(fuel-xref--show-callees word) (fuel-xref--show-callees word))))
(message ""))))
;;; Minor mode definition: ;;; Minor mode definition:

View File

@ -20,7 +20,8 @@
(make-variable-buffer-local (make-variable-buffer-local
(defvar fuel-popup--selected-window nil)) (defvar fuel-popup--selected-window nil))
(defun fuel-popup--display () (defun fuel-popup--display (&optional buffer)
(when buffer (set-buffer buffer))
(let ((selected-window (selected-window)) (let ((selected-window (selected-window))
(buffer (current-buffer))) (buffer (current-buffer)))
(unless (eq selected-window (get-buffer-window buffer)) (unless (eq selected-window (get-buffer-window buffer))

View File

@ -277,6 +277,11 @@
(defsubst fuel-syntax--end-of-defun () (defsubst fuel-syntax--end-of-defun ()
(re-search-forward fuel-syntax--end-of-def-regex nil t)) (re-search-forward fuel-syntax--end-of-def-regex nil t))
(defsubst fuel-syntax--end-of-defun-pos ()
(save-excursion
(re-search-forward fuel-syntax--end-of-def-regex nil t)
(point)))
(defconst fuel-syntax--defun-signature-regex (defconst fuel-syntax--defun-signature-regex
(format "\\(%s\\|%s\\)" (format "\\(%s\\|%s\\)"
(format ":[^ ]* [^ ]+\\(%s\\)*" fuel-syntax--stack-effect-regex) (format ":[^ ]* [^ ]+\\(%s\\)*" fuel-syntax--stack-effect-regex)

View File

@ -14,6 +14,7 @@
;;; Code: ;;; Code:
(require 'fuel-eval) (require 'fuel-eval)
(require 'fuel-syntax)
(require 'fuel-popup) (require 'fuel-popup)
(require 'fuel-font-lock) (require 'fuel-font-lock)
(require 'fuel-base) (require 'fuel-base)
@ -27,6 +28,12 @@
"FUEL's cross-referencing engine." "FUEL's cross-referencing engine."
:group 'fuel) :group 'fuel)
(defcustom fuel-xref-follow-link-to-word-p t
"Whether, when following a link to a caller, we position the
cursor at the first ocurrence of the used word."
:group 'fuel-xref
:type 'boolean)
(fuel-font-lock--defface fuel-font-lock-xref-link (fuel-font-lock--defface fuel-font-lock-xref-link
'link fuel-xref "highlighting links in cross-reference buffers") 'link fuel-xref "highlighting links in cross-reference buffers")
@ -48,8 +55,14 @@
(error "No file for this ref")) (error "No file for this ref"))
(when (not (file-readable-p file)) (when (not (file-readable-p file))
(error "File '%s' is not readable" file)) (error "File '%s' is not readable" file))
(let ((word fuel-xref--word))
(find-file-other-window file) (find-file-other-window file)
(when (numberp line) (goto-line line)))) (when (numberp line) (goto-line line))
(when (and word fuel-xref-follow-link-to-word-p)
(and (search-forward word
(fuel-syntax--end-of-defun-pos)
t)
(goto-char (match-beginning 0)))))))
;;; The xref buffer: ;;; The xref buffer:
@ -57,19 +70,17 @@
(fuel-popup--define fuel-xref--buffer (fuel-popup--define fuel-xref--buffer
"*fuel xref*" 'fuel-xref-mode) "*fuel xref*" 'fuel-xref-mode)
(make-local-variable (defvar fuel-xref--word nil))
(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--title (word cc count) (defun fuel-xref--title (word cc count)
(cond ((zerop count) (format "No known words %s '%s'." cc word)) (let ((cc (if cc "using" "used by")))
(cond ((zerop count) (format "No known words %s '%s'" cc word))
((= 1 count) (format "1 word %s '%s':" cc word)) ((= 1 count) (format "1 word %s '%s':" cc word))
(t (format "%s words %s '%s':" count cc word)))) (t (format "%s words %s '%s':" count cc word)))))
(defun fuel-xref--fill-buffer (word cc refs) (defun fuel-xref--insert-ref (ref)
(let ((inhibit-read-only t)
(count 0))
(with-current-buffer (fuel-xref--buffer)
(erase-buffer)
(dolist (ref refs)
(when (and (stringp (first ref)) (when (and (stringp (first ref))
(stringp (third ref)) (stringp (third ref))
(numberp (fourth ref))) (numberp (fourth ref)))
@ -77,33 +88,47 @@
(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) (third ref)
(third ref)) (fourth ref))
'file (third ref) 'file (third ref)
'line (fourth ref)) 'line (fourth ref))
(when (stringp (second ref)) (when (stringp (second ref))
(insert (format " (in %s)" (second ref)))) (insert (format " (in %s)" (second ref))))
(setq count (1+ count)) (newline)
(newline))) t))
(defun fuel-xref--fill-buffer (word cc refs)
(let ((inhibit-read-only t)
(count 0))
(with-current-buffer (fuel-xref--buffer)
(erase-buffer)
(dolist (ref refs)
(when (fuel-xref--insert-ref ref) (setq count (1+ count))))
(goto-char (point-min)) (goto-char (point-min))
(insert (fuel-xref--title word (if cc "using" "used by") count) "\n\n") (insert (fuel-xref--title word cc count) "\n\n")
(when (> count 0) (when (> count 0)
(setq fuel-xref--word (and cc word))
(goto-char (point-max)) (goto-char (point-max))
(insert "\n" fuel-xref--help-string "\n")) (insert "\n" fuel-xref--help-string "\n"))
(goto-char (point-min)) (goto-char (point-min))
(current-buffer)))) count)))
(defun fuel-xref--fill-and-display (word cc refs)
(let ((count (fuel-xref--fill-buffer word cc refs)))
(if (zerop count)
(error (fuel-xref--title word cc 0))
(message "")
(fuel-popup--display (fuel-xref--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))))
(set-buffer (fuel-xref--fill-buffer word t res)) (fuel-xref--fill-and-display word t res)))
(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))))
(set-buffer (fuel-xref--fill-buffer word nil res)) (fuel-xref--fill-and-display word nil res)))
(fuel-popup--display)))
;;; Xref mode: ;;; Xref mode: