! Edit locations
+: fuel-normalize-loc ( seq -- path line )
+ dup length 1 > [ first2 [ (normalize-path) ] dip ] [ f ] if ; inline
+
: fuel-get-edit-location ( defspec -- )
- where [
- first2 [ (normalize-path) ] dip 2array fuel-eval-set-result
- ] when* ; inline
+ where fuel-normalize-loc 2array fuel-eval-set-result ; inline
+
+: fuel-get-doc-location ( defspec -- )
+ props>> "help-loc" swap at
+ fuel-normalize-loc 2array fuel-eval-set-result ;
: fuel-format-xrefs ( seq -- seq )
[ word? ] filter [
[ name>> ]
[ vocabulary>> ]
- [ where [ first2 [ (normalize-path) ] dip ] [ f f ] if* ] tri 4array
+ [ where fuel-normalize-loc ] tri 4array
] map [ [ first ] dip first <=> ] sort ; inline
: fuel-callers-xref ( word -- )
- M-. : edit word at point in Emacs
- M-TAB : complete word at point
- C-cC-ev : edit vocabulary (M-x fuel-edit-vocabulary)
- - C-cC-ew : edit word (M-x fuel-edit-word)
+ - C-cC-ew : edit word (M-x fuel-edit-word-at-point)
+ - C-cC-ed : edit word's doc (M-x fuel-edit-word-at-point)
- C-cr, C-cC-er : eval region
- C-M-r, C-cC-ee : eval region, extending it to definition boundaries
With prefix, asks for the word to edit."
(interactive "P")
(let* ((word (or (and (not arg) (fuel-syntax-symbol-at-point))
- (fuel-completion--read-word "Edit word: ")))
- (cmd `(:fuel ((:quote ,word) fuel-get-edit-location))))
+ (fuel-completion--read-word "Edit word: ")))
+ (cmd `(:fuel* ((:quote ,word) fuel-get-edit-location))))
(condition-case nil
(fuel--try-edit (fuel-eval--send/wait cmd))
(error (fuel-edit-vocabulary nil word)))))
+(defun fuel-edit-word-doc-at-point (&optional arg)
+ "Opens a new window visiting the documentation file for the word at point.
+With prefix, asks for the word to edit."
+ (interactive "P")
+ (let* ((word (or (and (not arg) (fuel-syntax-symbol-at-point))
+ (fuel-completion--read-word "Edit word: ")))
+ (cmd `(:fuel* ((:quote ,word) fuel-get-doc-location))))
+ (condition-case nil
+ (fuel--try-edit (fuel-eval--send/wait cmd))
+ (error (when (y-or-n-p (concat "No documentation found. "
+ "Do you want to open the vocab's "
+ "doc file? "))
+ (find-file-other-window
+ (format "%s-docs.factor"
+ (file-name-sans-extension (buffer-file-name)))))))))
+
(defvar fuel-mode--word-history nil)
(defun fuel-edit-word (&optional arg)
nil
fuel-mode--word-history
arg))
- (cmd `(:fuel ((:quote ,word) fuel-get-edit-location))))
+ (cmd `(:fuel* ((:quote ,word) fuel-get-edit-location))))
(fuel--try-edit (fuel-eval--send/wait cmd))))
(defvar fuel--vocabs-prompt-history nil)
(define-key fuel-mode-map "\C-c\M->" 'fuel-show-callees)
(define-key fuel-mode-map (kbd "M-TAB") 'fuel-completion--complete-symbol)
+(fuel-mode--key ?e ?d 'fuel-edit-word-doc-at-point)
(fuel-mode--key ?e ?e 'fuel-eval-extended-region)
(fuel-mode--key ?e ?l 'fuel-run-file)
(fuel-mode--key ?e ?r 'fuel-eval-region)