FUEL: New command: fuel-show-file-words.

db4
Jose A. Ortega Ruiz 2009-01-08 18:47:17 +01:00
parent 3b44c824ee
commit c5f55dc36d
5 changed files with 89 additions and 51 deletions

View File

@ -201,6 +201,9 @@ SYMBOL: :uses
: fuel-apropos-xref ( str -- ) : fuel-apropos-xref ( str -- )
words-matching fuel-format-xrefs fuel-eval-set-result ; inline words-matching fuel-format-xrefs fuel-eval-set-result ; inline
: fuel-vocab-xref ( vocab -- )
words fuel-format-xrefs fuel-eval-set-result ; inline
! Completion support ! Completion support
: fuel-filter-prefix ( seq prefix -- seq ) : fuel-filter-prefix ( seq prefix -- seq )

View File

@ -70,6 +70,7 @@ beast.
- C-cC-ds : short help word at point - C-cC-ds : short help word at point
- C-cC-de : show stack effect of current sexp (with prefix, region) - C-cC-de : show stack effect of current sexp (with prefix, region)
- C-cC-dp : find words containing given substring (M-x fuel-apropos) - C-cC-dp : find words containing given substring (M-x fuel-apropos)
- C-cC-dv : show words in current file (with prefix, ask for vocab)
- C-cM-<, C-cC-d< : show callers of word at point - C-cM-<, C-cC-d< : show callers of word at point
- C-cM->, C-cC-d> : show callees of word at point - C-cM->, C-cC-d> : show callees of word at point

View File

@ -132,37 +132,6 @@ With prefix argument, ask for the file name."
(let ((file (car (fuel-mode--read-file arg)))) (let ((file (car (fuel-mode--read-file arg))))
(when file (fuel-debug--uses-for-file file)))) (when file (fuel-debug--uses-for-file file))))
(defvar fuel-mode--word-history nil)
(defun fuel-show-callers (&optional arg)
"Show a list of callers of word at point.
With prefix argument, ask for word."
(interactive "P")
(let ((word (if arg (fuel-completion--read-word "Find callers for: "
(fuel-syntax-symbol-at-point)
fuel-mode--word-history)
(fuel-syntax-symbol-at-point))))
(when word
(message "Looking up %s's callers ..." word)
(fuel-xref--show-callers word))))
(defun fuel-show-callees (&optional arg)
"Show a list of callers of word at point.
With prefix argument, ask for word."
(interactive "P")
(let ((word (if arg (fuel-completion--read-word "Find callees for: "
(fuel-syntax-symbol-at-point)
fuel-mode--word-history)
(fuel-syntax-symbol-at-point))))
(when word
(message "Looking up %s's callees ..." word)
(fuel-xref--show-callees word))))
(defun fuel-apropos (str)
"Show a list of words containing the given substring."
(interactive "MFind words containing: ")
(message "Looking up %s's references ..." str)
(fuel-xref--apropos str))
;;; Minor mode definition: ;;; Minor mode definition:
@ -230,6 +199,7 @@ interacting with a factor listener is at your disposal.
(fuel-mode--key ?d ?> 'fuel-show-callees) (fuel-mode--key ?d ?> 'fuel-show-callees)
(fuel-mode--key ?d ?< 'fuel-show-callers) (fuel-mode--key ?d ?< 'fuel-show-callers)
(fuel-mode--key ?d ?v 'fuel-show-file-words)
(fuel-mode--key ?d ?a 'fuel-autodoc-mode) (fuel-mode--key ?d ?a 'fuel-autodoc-mode)
(fuel-mode--key ?d ?p 'fuel-apropos) (fuel-mode--key ?d ?p 'fuel-apropos)
(fuel-mode--key ?d ?d 'fuel-help) (fuel-mode--key ?d ?d 'fuel-help)

View File

@ -312,6 +312,12 @@
(defsubst fuel-syntax--usings () (defsubst fuel-syntax--usings ()
(funcall fuel-syntax--usings-function)) (funcall fuel-syntax--usings-function))
(defun fuel-syntax--file-has-private ()
(save-excursion
(goto-char (point-min))
(and (re-search-forward "\\_<<PRIVATE\\_>" nil t)
(re-search-forward "\\_<PRIVATE>\\_>" nil t))))
(defun fuel-syntax--find-usings (&optional no-private) (defun fuel-syntax--find-usings (&optional no-private)
(save-excursion (save-excursion
(let ((usings)) (let ((usings))
@ -319,10 +325,7 @@
(while (re-search-backward fuel-syntax--using-lines-regex nil t) (while (re-search-backward fuel-syntax--using-lines-regex nil t)
(dolist (u (split-string (match-string-no-properties 1) nil t)) (dolist (u (split-string (match-string-no-properties 1) nil t))
(push u usings))) (push u usings)))
(goto-char (point-min)) (when (and (not no-private) (fuel-syntax--file-has-private))
(when (and (not no-private)
(re-search-forward "\\_<<PRIVATE\\_>" nil t)
(re-search-forward "\\_<PRIVATE>\\_>" nil t))
(goto-char (point-max)) (goto-char (point-max))
(push (concat (fuel-syntax--find-in) ".private") usings)) (push (concat (fuel-syntax--find-in) ".private") usings))
usings))) usings)))

View File

@ -13,6 +13,8 @@
;;; Code: ;;; Code:
(require 'fuel-edit)
(require 'fuel-completion)
(require 'fuel-help) (require 'fuel-help)
(require 'fuel-eval) (require 'fuel-eval)
(require 'fuel-syntax) (require 'fuel-syntax)
@ -82,7 +84,7 @@ cursor at the first ocurrence of the used 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--insert-ref (ref) (defun fuel-xref--insert-ref (ref &optional no-vocab)
(when (and (stringp (first ref)) (when (and (stringp (first ref))
(stringp (third ref)) (stringp (third ref))
(numberp (fourth ref))) (numberp (fourth ref)))
@ -94,29 +96,28 @@ cursor at the first ocurrence of the used word."
(fourth ref)) (fourth ref))
'file (third ref) 'file (third ref)
'line (fourth ref)) 'line (fourth ref))
(when (stringp (second ref)) (when (and (not no-vocab) (stringp (second ref)))
(insert (format " (in %s)" (second ref)))) (insert (format " (in %s)" (second ref))))
(newline) (newline)
t)) t))
(defun fuel-xref--fill-buffer (word cc refs) (defun fuel-xref--fill-buffer (word cc refs &optional no-vocab app)
(let ((inhibit-read-only t) (let ((inhibit-read-only t)
(count 0)) (count 0))
(with-current-buffer (fuel-xref--buffer) (with-current-buffer (fuel-xref--buffer)
(let ((start (if app (goto-char (point-max))
(erase-buffer) (erase-buffer)
(point-min))))
(dolist (ref refs) (dolist (ref refs)
(when (fuel-xref--insert-ref ref) (setq count (1+ count)))) (when (fuel-xref--insert-ref ref no-vocab) (setq count (1+ count))))
(goto-char (point-min)) (newline)
(insert (fuel-xref--title word cc count) "\n\n") (goto-char start)
(when (> count 0) (save-excursion
(setq fuel-xref--word (and cc word)) (insert (fuel-xref--title word cc count) "\n\n"))
(goto-char (point-max)) count))))
(insert "\n" fuel-xref--help-string "\n"))
(goto-char (point-min))
count)))
(defun fuel-xref--fill-and-display (word cc refs) (defun fuel-xref--fill-and-display (word cc refs &optional no-vocab)
(let ((count (fuel-xref--fill-buffer word cc refs))) (let ((count (fuel-xref--fill-buffer word cc refs no-vocab)))
(if (zerop count) (if (zerop count)
(error (fuel-xref--title word cc 0)) (error (fuel-xref--title word cc 0))
(message "") (message "")
@ -137,6 +138,65 @@ cursor at the first ocurrence of the used word."
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd)))) (res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
(fuel-xref--fill-and-display str "containing" res))) (fuel-xref--fill-and-display str "containing" res)))
(defun fuel-xref--show-vocab (vocab &optional app)
(let* ((cmd `(:fuel* ((,vocab fuel-vocab-xref)) ,vocab))
(res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
(fuel-xref--fill-buffer vocab "in vocabulary" res t app)))
(defun fuel-xref--show-vocab-words (vocab &optional private)
(fuel-xref--show-vocab vocab)
(when private
(fuel-xref--show-vocab (format "%s.private" (substring-no-properties vocab))
t))
(fuel-popup--display (fuel-xref--buffer))
(goto-char (point-min)))
;;; User commands:
(defvar fuel-xref--word-history nil)
(defun fuel-show-callers (&optional arg)
"Show a list of callers of word at point.
With prefix argument, ask for word."
(interactive "P")
(let ((word (if arg (fuel-completion--read-word "Find callers for: "
(fuel-syntax-symbol-at-point)
fuel-xref--word-history)
(fuel-syntax-symbol-at-point))))
(when word
(message "Looking up %s's callers ..." word)
(fuel-xref--show-callers word))))
(defun fuel-show-callees (&optional arg)
"Show a list of callers of word at point.
With prefix argument, ask for word."
(interactive "P")
(let ((word (if arg (fuel-completion--read-word "Find callees for: "
(fuel-syntax-symbol-at-point)
fuel-xref--word-history)
(fuel-syntax-symbol-at-point))))
(when word
(message "Looking up %s's callees ..." word)
(fuel-xref--show-callees word))))
(defun fuel-apropos (str)
"Show a list of words containing the given substring."
(interactive "MFind words containing: ")
(message "Looking up %s's references ..." str)
(fuel-xref--apropos str))
(defun fuel-show-file-words (&optional arg)
"Show a list of words in current file.
With prefix argument, ask for the vocab."
(interactive "P")
(let ((vocab (or (and (not arg) (fuel-syntax--current-vocab))
(fuel-edit--read-vocabulary-name))))
(when vocab
(fuel-xref--show-vocab-words vocab
(fuel-syntax--file-has-private)))))
;;; Xref mode: ;;; Xref mode:
@ -159,6 +219,7 @@ cursor at the first ocurrence of the used word."
(kill-all-local-variables) (kill-all-local-variables)
(buffer-disable-undo) (buffer-disable-undo)
(use-local-map fuel-xref-mode-map) (use-local-map fuel-xref-mode-map)
(set-syntax-table fuel-syntax--syntax-table)
(setq mode-name "FUEL Xref") (setq mode-name "FUEL Xref")
(setq major-mode 'fuel-xref-mode) (setq major-mode 'fuel-xref-mode)
(font-lock-add-keywords nil '(("(in \\(.+\\))" 1 'fuel-font-lock-xref-vocab))) (font-lock-add-keywords nil '(("(in \\(.+\\))" 1 'fuel-font-lock-xref-vocab)))