FUEL: New command: fuel-show-file-words.
							parent
							
								
									3b44c824ee
								
							
						
					
					
						commit
						c5f55dc36d
					
				| 
						 | 
				
			
			@ -201,6 +201,9 @@ SYMBOL: :uses
 | 
			
		|||
: fuel-apropos-xref ( str -- )
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
: fuel-filter-prefix ( seq prefix -- seq )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -70,6 +70,7 @@ beast.
 | 
			
		|||
    - C-cC-ds : short help word at point
 | 
			
		||||
    - 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-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 callees of word at point
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -132,37 +132,6 @@ With prefix argument, ask for the file name."
 | 
			
		|||
  (let ((file (car (fuel-mode--read-file arg))))
 | 
			
		||||
    (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:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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-callers)
 | 
			
		||||
(fuel-mode--key ?d ?v 'fuel-show-file-words)
 | 
			
		||||
(fuel-mode--key ?d ?a 'fuel-autodoc-mode)
 | 
			
		||||
(fuel-mode--key ?d ?p 'fuel-apropos)
 | 
			
		||||
(fuel-mode--key ?d ?d 'fuel-help)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -312,6 +312,12 @@
 | 
			
		|||
(defsubst fuel-syntax--usings ()
 | 
			
		||||
  (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)
 | 
			
		||||
  (save-excursion
 | 
			
		||||
    (let ((usings))
 | 
			
		||||
| 
						 | 
				
			
			@ -319,10 +325,7 @@
 | 
			
		|||
      (while (re-search-backward fuel-syntax--using-lines-regex nil t)
 | 
			
		||||
        (dolist (u (split-string (match-string-no-properties 1) nil t))
 | 
			
		||||
          (push u usings)))
 | 
			
		||||
      (goto-char (point-min))
 | 
			
		||||
      (when (and (not no-private)
 | 
			
		||||
                 (re-search-forward "\\_<<PRIVATE\\_>" nil t)
 | 
			
		||||
                 (re-search-forward "\\_<PRIVATE>\\_>" nil t))
 | 
			
		||||
      (when (and (not no-private) (fuel-syntax--file-has-private))
 | 
			
		||||
        (goto-char (point-max))
 | 
			
		||||
        (push (concat (fuel-syntax--find-in) ".private") usings))
 | 
			
		||||
      usings)))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,8 @@
 | 
			
		|||
 | 
			
		||||
;;; Code:
 | 
			
		||||
 | 
			
		||||
(require 'fuel-edit)
 | 
			
		||||
(require 'fuel-completion)
 | 
			
		||||
(require 'fuel-help)
 | 
			
		||||
(require 'fuel-eval)
 | 
			
		||||
(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))
 | 
			
		||||
        (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))
 | 
			
		||||
             (stringp (third ref))
 | 
			
		||||
             (numberp (fourth ref)))
 | 
			
		||||
| 
						 | 
				
			
			@ -94,29 +96,28 @@ cursor at the first ocurrence of the used word."
 | 
			
		|||
                                           (fourth ref))
 | 
			
		||||
                        'file (third ref)
 | 
			
		||||
                        'line (fourth ref))
 | 
			
		||||
    (when (stringp (second ref))
 | 
			
		||||
    (when (and (not no-vocab) (stringp (second ref)))
 | 
			
		||||
      (insert (format " (in %s)" (second ref))))
 | 
			
		||||
    (newline)
 | 
			
		||||
    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)
 | 
			
		||||
        (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))
 | 
			
		||||
      (insert (fuel-xref--title word cc count) "\n\n")
 | 
			
		||||
      (when (> count 0)
 | 
			
		||||
        (setq fuel-xref--word (and cc word))
 | 
			
		||||
        (goto-char (point-max))
 | 
			
		||||
        (insert "\n" fuel-xref--help-string "\n"))
 | 
			
		||||
      (goto-char (point-min))
 | 
			
		||||
      count)))
 | 
			
		||||
      (let ((start (if app (goto-char (point-max))
 | 
			
		||||
                     (erase-buffer)
 | 
			
		||||
                     (point-min))))
 | 
			
		||||
        (dolist (ref refs)
 | 
			
		||||
          (when (fuel-xref--insert-ref ref no-vocab) (setq count (1+ count))))
 | 
			
		||||
        (newline)
 | 
			
		||||
        (goto-char start)
 | 
			
		||||
        (save-excursion
 | 
			
		||||
          (insert (fuel-xref--title word cc count) "\n\n"))
 | 
			
		||||
        count))))
 | 
			
		||||
 | 
			
		||||
(defun fuel-xref--fill-and-display (word cc refs)
 | 
			
		||||
  (let ((count (fuel-xref--fill-buffer word cc refs)))
 | 
			
		||||
(defun fuel-xref--fill-and-display (word cc refs &optional no-vocab)
 | 
			
		||||
  (let ((count (fuel-xref--fill-buffer word cc refs no-vocab)))
 | 
			
		||||
    (if (zerop count)
 | 
			
		||||
        (error (fuel-xref--title word cc 0))
 | 
			
		||||
      (message "")
 | 
			
		||||
| 
						 | 
				
			
			@ -137,6 +138,65 @@ cursor at the first ocurrence of the used word."
 | 
			
		|||
         (res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
 | 
			
		||||
    (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:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -159,6 +219,7 @@ cursor at the first ocurrence of the used word."
 | 
			
		|||
  (kill-all-local-variables)
 | 
			
		||||
  (buffer-disable-undo)
 | 
			
		||||
  (use-local-map fuel-xref-mode-map)
 | 
			
		||||
  (set-syntax-table fuel-syntax--syntax-table)
 | 
			
		||||
  (setq mode-name "FUEL Xref")
 | 
			
		||||
  (setq major-mode 'fuel-xref-mode)
 | 
			
		||||
  (font-lock-add-keywords nil '(("(in \\(.+\\))" 1 'fuel-font-lock-xref-vocab)))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue