1 ;;; fuel-edit.el -- utilities for file editing
3 ;; Copyright (C) 2009 Jose Antonio Ortega Ruiz
4 ;; See http://factorcode.org/license.txt for BSD license.
6 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
7 ;; Keywords: languages, fuel, factor
8 ;; Start date: Mon Jan 05, 2009 21:16
12 ;; Locating and opening factor source and documentation files.
16 (require 'fuel-completion)
21 ;;; Auxiliar functions:
23 (defun fuel-edit--try-edit (ret)
24 (let* ((err (fuel-eval--retort-error ret))
25 (loc (fuel-eval--retort-result ret)))
26 (when (or err (not loc) (not (listp loc)) (not (stringp (car loc))))
27 (error "Couldn't find edit location"))
28 (unless (file-readable-p (car loc))
29 (error "Couldn't open '%s' for read" (car loc)))
30 (find-file-other-window (car loc))
31 (goto-line (if (numberp (cadr loc)) (cadr loc) 1))))
33 (defun fuel-edit--read-vocabulary-name (refresh)
34 (let* ((vocabs (fuel-completion--vocabs refresh))
35 (prompt "Vocabulary name: "))
37 (completing-read prompt vocabs nil nil nil fuel-edit--vocab-history)
38 (read-string prompt nil fuel-edit--vocab-history))))
40 (defun fuel-edit--edit-article (name)
41 (let ((cmd `(:fuel* (,name fuel-get-article-location) "fuel" t)))
42 (fuel-edit--try-edit (fuel-eval--send/wait cmd))))
47 (defvar fuel-edit--word-history nil)
48 (defvar fuel-edit--vocab-history nil)
50 (defun fuel-edit-vocabulary (&optional refresh vocab)
51 "Visits vocabulary file in Emacs.
52 When called interactively, asks for vocabulary with completion.
53 With prefix argument, refreshes cached vocabulary list."
55 (let* ((vocab (or vocab (fuel-edit--read-vocabulary-name refresh)))
56 (cmd `(:fuel* (,vocab fuel-get-vocab-location) "fuel" t)))
57 (fuel-edit--try-edit (fuel-eval--send/wait cmd))))
59 (defun fuel-edit-word (&optional arg)
60 "Asks for a word to edit, with completion.
61 With prefix, only words visible in the current vocabulary are
64 (let* ((word (fuel-completion--read-word "Edit word: "
66 fuel-edit--word-history
68 (cmd `(:fuel* ((:quote ,word) fuel-get-edit-location))))
69 (fuel-edit--try-edit (fuel-eval--send/wait cmd))))
71 (defun fuel-edit-word-at-point (&optional arg)
72 "Opens a new window visiting the definition of the word at point.
73 With prefix, asks for the word to edit."
75 (let* ((word (or (and (not arg) (fuel-syntax-symbol-at-point))
76 (fuel-completion--read-word "Edit word: ")))
77 (cmd `(:fuel* ((:quote ,word) fuel-get-edit-location))))
79 (fuel-edit--try-edit (fuel-eval--send/wait cmd))
80 (error (fuel-edit-vocabulary nil word)))))
82 (defun fuel-edit-word-doc-at-point (&optional arg word)
83 "Opens a new window visiting the documentation file for the word at point.
84 With prefix, asks for the word to edit."
87 (and (not arg) (fuel-syntax-symbol-at-point))
88 (fuel-completion--read-word "Edit word: ")))
89 (cmd `(:fuel* ((:quote ,word) fuel-get-doc-location))))
91 (fuel-edit--try-edit (fuel-eval--send/wait cmd))
93 (message "Documentation for '%s' not found" word)
94 (when (and (eq major-mode 'factor-mode)
95 (y-or-n-p (concat "No documentation found. "
96 "Do you want to open the vocab's "
98 (find-file-other-window
99 (format "%s-docs.factor"
100 (file-name-sans-extension (buffer-file-name)))))))))
104 ;;; fuel-edit.el ends here