]> gitweb.factorcode.org Git - factor.git/commitdiff
Conflict resolution
authorJose A. Ortega Ruiz <jao@gnu.org>
Thu, 18 Dec 2008 23:24:23 +0000 (00:24 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Thu, 18 Dec 2008 23:24:23 +0000 (00:24 +0100)
13 files changed:
extra/fuel/fuel.factor
misc/fuel/README
misc/fuel/factor-mode.el
misc/fuel/fu.el
misc/fuel/fuel-base.el
misc/fuel/fuel-completion.el
misc/fuel/fuel-connection.el
misc/fuel/fuel-eval.el
misc/fuel/fuel-font-lock.el
misc/fuel/fuel-help.el
misc/fuel/fuel-listener.el
misc/fuel/fuel-mode.el
misc/fuel/fuel-syntax.el

index 58efe2d8ce3c85d1a977b302f2f670e547e6f0d6..a3fa95a6b19f8577577366685203de32bc28396f 100644 (file)
@@ -13,7 +13,7 @@ IN: fuel
 
 ! Evaluation status:
 
-TUPLE: fuel-status in use ds? restarts ;
+TUPLE: fuel-status in use restarts ;
 
 SYMBOL: fuel-status-stack
 V{ } clone fuel-status-stack set-global
@@ -37,7 +37,7 @@ t clone fuel-eval-res-flag set-global
     f fuel-eval-res-flag set-global ; inline
 
 : push-fuel-status ( -- )
-    in get use get clone display-stacks? get restarts get-global clone
+    in get use get clone restarts get-global clone
     fuel-status boa
     fuel-status-stack get push ;
 
@@ -46,7 +46,6 @@ t clone fuel-eval-res-flag set-global
         fuel-status-stack get pop {
             [ in>> in set ]
             [ use>> clone use set ]
-            [ ds?>> display-stacks? swap [ on ] [ off ] if ]
             [
                 restarts>> fuel-eval-restartable? [ drop ] [
                     clone restarts set-global
@@ -112,7 +111,7 @@ M: source-file fuel-pprint path>> fuel-pprint ;
     error get
     fuel-eval-result get-global
     fuel-eval-output get-global
-    3array fuel-pprint flush nl "EOT:" write ;
+    3array fuel-pprint flush nl "<~FUEL~>" write nl flush ;
 
 : fuel-forget-error ( -- ) f error set-global ; inline
 : fuel-forget-result ( -- ) f fuel-eval-result set-global ; inline
@@ -120,14 +119,13 @@ M: source-file fuel-pprint path>> fuel-pprint ;
 
 : (fuel-begin-eval) ( -- )
     push-fuel-status
-    display-stacks? off
     fuel-forget-error
     fuel-forget-result
     fuel-forget-output ;
 
 : (fuel-end-eval) ( quot -- )
-    with-string-writer fuel-eval-output set-global
-    fuel-retort pop-fuel-status ; inline
+    with-string-writer fuel-eval-output set-global fuel-retort
+    pop-fuel-status ; inline
 
 : (fuel-eval) ( lines -- )
     [ [ parse-lines ] with-compilation-unit call ] curry
@@ -160,6 +158,10 @@ M: source-file fuel-pprint path>> fuel-pprint ;
 
 : fuel-end-eval ( -- ) [ ] (fuel-end-eval) ; inline
 
+: fuel-run-file ( path -- ) run-file ; inline
+
+! Edit locations
+
 : fuel-get-edit-location ( defspec -- )
     where [
        first2 [ (normalize-path) ] dip 2array fuel-eval-set-result
@@ -168,12 +170,23 @@ M: source-file fuel-pprint path>> fuel-pprint ;
 : fuel-get-vocab-location ( vocab -- )
     >vocab-link fuel-get-edit-location ; inline
 
+! Completion support
+
+: fuel-filter-prefix ( seq prefix -- seq )
+    [ drop-prefix nip length 0 = ] curry filter prune ; inline
+
 : (fuel-get-vocabs) ( -- seq )
     all-vocabs-seq [ vocab-name ] map ; inline
 
 : fuel-get-vocabs ( -- )
     (fuel-get-vocabs) fuel-eval-set-result ; inline
 
+: fuel-get-vocabs/prefix ( prefix -- )
+    (fuel-get-vocabs) swap fuel-filter-prefix fuel-eval-set-result ; inline
+
+: fuel-vocab-summary ( name -- )
+    >vocab-link summary fuel-eval-set-result ; inline
+
 MEMO: (fuel-vocab-words) ( name -- seq )
     >vocab-link words [ name>> ] map ;
 
@@ -185,12 +198,13 @@ MEMO: (fuel-vocab-words) ( name -- seq )
 
 : (fuel-get-words) ( prefix names/f -- seq )
     [ fuel-vocabs-words ] [ fuel-current-words ] if* natural-sort
-    swap [ drop-prefix nip length 0 = ] curry filter ;
+    swap fuel-filter-prefix ;
 
 : fuel-get-words ( prefix names -- )
     (fuel-get-words) fuel-eval-set-result ; inline
 
-: fuel-run-file ( path -- ) run-file ; inline
+
+! -run=fuel support
 
 : fuel-startup ( -- ) "listener" run-file ; inline
 
index cc938a60ff65861ccaab7fd08e65f87ce9d794ab..5073980dbd7b1322050a2fa52db105c8e4ee8a7c 100644 (file)
@@ -90,5 +90,7 @@ C-cC-eC-r is the same as C-cC-er)).
  - RET : help for word at point
  - f/b : next/previous page
  - SPC/S-SPC : scroll up/down
+ - TAB/S-TAB : next/previous headline
+ - C-cz : switch to listener
  - q: bury buffer
 
index 8cf578f0904820f0c8795410620dd67499a48700..2f6eef4f6584bfba416e893b50acddb4ec452283 100644 (file)
@@ -59,23 +59,6 @@ code in the buffer."
   :type 'hook
   :group 'factor-mode)
 
-\f
-;;; Faces:
-
-(fuel-font-lock--define-faces
- factor-font-lock font-lock factor-mode
- ((comment comment "comments")
-  (constructor type  "constructors (<foo>)")
-  (declaration keyword "declaration words")
-  (parsing-word keyword  "parsing words")
-  (setter-word function-name "setter words (>>foo)")
-  (stack-effect comment "stack effect specifications")
-  (string string "strings")
-  (symbol variable-name "name of symbol being defined")
-  (type-name type "type names")
-  (vocabulary-name constant "vocabulary names")
-  (word function-name "word, generic or method being defined")))
-
 \f
 ;;; Syntax table:
 
index 508d7ef3a47bb4c5054d43c8b63b46f1b2a0f834..ffd88bf144c74dc4cc1fe517b7c844a6db134f3a 100644 (file)
@@ -17,6 +17,9 @@
 (autoload 'run-factor "fuel-listener.el"
   "Start a Factor listener, or switch to a running one." t)
 
+(autoload 'switch-to-factor "fuel-listener.el"
+  "Start a Factor listener, or switch to a running one." t)
+
 (autoload 'fuel-autodoc-mode "fuel-help.el"
   "Minor mode showing in the minibuffer a synopsis of Factor word at point."
   t)
index f60c5f241d826622ec2f57e477e646208aaee66f..1a7cf4fbe6b7b157733e6648234b5eedd0025aa0 100644 (file)
            (when (equal item (ring-ref ring ind))
              (throw 'found ind)))))))
 
+(when (not (fboundp 'completion-table-dynamic))
+  (defun completion-table-dynamic (fun)
+    (lexical-let ((fun fun))
+      (lambda (string pred action)
+        (with-current-buffer (let ((win (minibuffer-selected-window)))
+                               (if (window-live-p win) (window-buffer win)
+                                 (current-buffer)))
+          (complete-with-action action (funcall fun string) string pred))))))
+
 \f
 ;;; Utilities
 
 
 (defsubst empty-string-p (str) (equal str ""))
 
+(defun fuel--string-prefix-p (prefix str)
+  (and (>= (length str) (length prefix))
+       (string= (substring-no-properties 0 (length prefix) str)
+                (substring-no-properties prefix))))
+
 (defun fuel--respecting-message (format &rest format-args)
   "Display TEXT as a message, without hiding any minibuffer contents."
   (let ((text (format " [%s]" (apply #'format format format-args))))
index 8d2d779b318cbcd7a8c8b6ccbff4f97cb2b16621..953a349d2fcbe4a2597122704588ee4db7408307 100644 (file)
              (fuel-eval--send/wait '(:fuel* (fuel-get-vocabs) "fuel" (:array)))))))
   fuel-completion--vocabs)
 
+(defsubst fuel-completion--vocab-list (prefix)
+  (fuel-eval--retort-result
+   (fuel-eval--send/wait `(:fuel* (,prefix fuel-get-vocabs/prefix) t t))))
+
 (defun fuel-completion--words (prefix vocabs)
   (let ((vs (if vocabs (cons :array vocabs) 'f))
         (us (or vocabs 't)))
@@ -55,7 +59,7 @@ performed."))
 If this window is no longer active or displaying the completions
 buffer then we can ignore `fuel-completion--window-cfg'."))
 
-(defun fuel-completion--maybe-save-window-configuration ()
+(defun fuel-completion--save-window-cfg ()
   "Maybe save the current window configuration.
 Return true if the configuration was saved."
   (unless (or fuel-completion--window-cfg
@@ -66,17 +70,17 @@ Return true if the configuration was saved."
 
 (defun fuel-completion--delay-restoration ()
   (add-hook 'pre-command-hook
-            'fuel-completion--maybe-restore-window-configuration
+            'fuel-completion--maybe-restore-window-cfg
             nil t))
 
-(defun fuel-completion--forget-window-configuration ()
+(defun fuel-completion--forget-window-cfg ()
   (setq fuel-completion--window-cfg nil)
   (setq fuel-completion--completions-window nil))
 
-(defun fuel-completion--restore-window-configuration ()
+(defun fuel-completion--restore-window-cfg ()
   "Restore the window config if available."
   (remove-hook 'pre-command-hook
-               'fuel-completion--maybe-restore-window-configuration)
+               'fuel-completion--maybe-restore-window-cfg)
   (when (and fuel-completion--window-cfg
              (fuel-completion--window-active-p))
     (save-excursion
@@ -85,21 +89,21 @@ Return true if the configuration was saved."
     (when (buffer-live-p fuel-completion--comp-buffer)
       (kill-buffer fuel-completion--comp-buffer))))
 
-(defun fuel-completion--maybe-restore-window-configuration ()
+(defun fuel-completion--maybe-restore-window-cfg ()
   "Restore the window configuration, if the following command
 terminates a current completion."
   (remove-hook 'pre-command-hook
-               'fuel-completion--maybe-restore-window-configuration)
+               'fuel-completion--maybe-restore-window-cfg)
   (condition-case err
       (cond ((find last-command-char "()\"'`,# \r\n:")
-             (fuel-completion--restore-window-configuration))
+             (fuel-completion--restore-window-cfg))
             ((not (fuel-completion--window-active-p))
-             (fuel-completion--forget-window-configuration))
+             (fuel-completion--forget-window-cfg))
             (t (fuel-completion--delay-restoration)))
     (error
      ;; Because this is called on the pre-command-hook, we mustn't let
      ;; errors propagate.
-     (message "Error in fuel-completion--restore-window-configuration: %S" err))))
+     (message "Error in fuel-completion--restore-window-cfg: %S" err))))
 
 (defun fuel-completion--window-active-p ()
   "Is the completion window currently active?"
@@ -108,7 +112,7 @@ terminates a current completion."
               fuel-completion--comp-buffer)))
 
 (defun fuel-completion--display-comp-list (completions base)
-  (let ((savedp (fuel-completion--maybe-save-window-configuration)))
+  (let ((savedp (fuel-completion--save-window-cfg)))
     (with-output-to-temp-buffer fuel-completion--comp-buffer
       (display-completion-list completions base)
       (let ((offset (- (point) 1 (length base))))
@@ -152,14 +156,16 @@ terminates a current completion."
 (defvar fuel-completion--all-words-list-func
   (completion-table-dynamic 'fuel-completion--all-words-list))
 
-(defun fuel-completion--complete (prefix)
-  (let* ((words (fuel-completion--word-list prefix))
+(defun fuel-completion--complete (prefix vocabs)
+  (let* ((words (if vocabs
+                    (fuel-completion--vocabs)
+                    (fuel-completion--word-list prefix)))
          (completions (all-completions prefix words))
          (partial (try-completion prefix words))
          (partial (if (eq partial t) prefix partial)))
     (cons completions partial)))
 
-(defsubst fuel-completion--read-word (prompt &optional default history all)
+(defun fuel-completion--read-word (prompt &optional default history all)
   (completing-read prompt
                    (if all fuel-completion--all-words-list-func
                      fuel-completion--word-list-func)
@@ -174,16 +180,16 @@ Perform completion similar to Emacs' complete-symbol."
   (let* ((end (point))
          (beg (fuel-syntax--symbol-start))
          (prefix (buffer-substring-no-properties beg end))
-         (result (fuel-completion--complete prefix))
+         (result (fuel-completion--complete prefix (fuel-syntax--in-using)))
          (completions (car result))
          (partial (cdr result)))
     (cond ((null completions)
            (fuel--respecting-message "Can't find completion for %S" prefix)
-           (fuel-completion--restore-window-configuration))
+           (fuel-completion--restore-window-cfg))
           (t (insert-and-inherit (substring partial (length prefix)))
              (cond ((= (length completions) 1)
                     (fuel--respecting-message "Sole completion")
-                    (fuel-completion--restore-window-configuration))
+                    (fuel-completion--restore-window-cfg))
                    (t (fuel--respecting-message "Complete but not unique")
                       (fuel-completion--display-or-scroll completions
                                                           partial)))))))
index da621b3bebf6fa4d61c688299e66e36d18484fb0..162a1edd02d237b21942ac05667227c56c68c16d 100644 (file)
@@ -46,8 +46,7 @@
         (cons :id (random))
         (cons :string str)
         (cons :continuation cont)
-        (cons :buffer (or sender-buffer (current-buffer)))
-        (cons :output "")))
+        (cons :buffer (or sender-buffer (current-buffer)))))
 
 (defsubst fuel-con--request-p (req)
   (and (listp req) (eq (car req) :fuel-connection-request)))
 (defsubst fuel-con--request-buffer (req)
   (cdr (assoc :buffer req)))
 
-(defun fuel-con--request-output (req &optional suffix)
-  (let ((cell (assoc :output req)))
-    (when suffix (setcdr cell (concat (cdr cell) suffix)))
-    (cdr cell)))
-
 (defsubst fuel-con--request-deactivate (req)
   (setcdr (assoc :continuation req) nil))
 
       (fuel-con--connection-start-timer conn))))
 
 (defconst fuel-con--prompt-regex "( .+ ) ")
-(defconst fuel-con--eot-marker "EOT:")
-(defconst fuel-con--init-stanza (format "USE: fuel %S write" fuel-con--eot-marker))
+(defconst fuel-con--eot-marker "<~FUEL~>")
+(defconst fuel-con--init-stanza "USE: fuel f fuel-eval")
 
 (defconst fuel-con--comint-finished-regex
-  (format "%s%s" fuel-con--eot-marker fuel-con--prompt-regex))
+  (format "^%s$" fuel-con--eot-marker))
 
 (defun fuel-con--setup-comint ()
-  (comint-redirect-cleanup)
+  (set (make-local-variable 'comint-redirect-insert-matching-regexp) t)
   (add-hook 'comint-redirect-filter-functions
-            'fuel-con--comint-redirect-filter t t)
+            'fuel-con--comint-preoutput-filter nil t)
   (add-hook 'comint-redirect-hook
             'fuel-con--comint-redirect-hook nil t))
 
 (defadvice comint-redirect-setup (after fuel-con--advice activate)
   (setq comint-redirect-finished-regexp fuel-con--comint-finished-regex))
 
+(defun fuel-con--comint-preoutput-filter (str)
+  (when (string-match fuel-con--comint-finished-regex str)
+    (setq comint-redirect-finished-regexp fuel-con--prompt-regex))
+  str)
+
 \f
 ;;; Requests handling:
 
+(defsubst fuel-con--comint-buffer ()
+  (get-buffer-create " *fuel connection retort*"))
+
+(defsubst fuel-con--comint-buffer-form ()
+  (with-current-buffer (fuel-con--comint-buffer)
+    (goto-char (point-min))
+    (condition-case nil
+        (read (current-buffer))
+      (error (list 'fuel-con-error (buffer-string))))))
+
 (defun fuel-con--process-next (con)
   (when (not (fuel-con--connection-current-request con))
     (let* ((buffer (fuel-con--connection-buffer con))
            (req (fuel-con--connection-pop-request con))
-           (str (and req (fuel-con--request-string req))))
+           (str (and req (fuel-con--request-string req)))
+           (cbuf (with-current-buffer (fuel-con--comint-buffer)
+                   (erase-buffer)
+                   (current-buffer))))
       (if (not (buffer-live-p buffer))
           (fuel-con--connection-cancel-timer con)
         (when (and buffer req str)
           (set-buffer buffer)
           (fuel-log--info "<%s>: %s" (fuel-con--request-id req) str)
-          (comint-redirect-send-command (format "%s" str)
-                                        (fuel-log--buffer) nil t))))))
+          (comint-redirect-send-command (format "%s" str) cbuf nil t))))))
 
 (defun fuel-con--process-completed-request (req)
-  (let ((str (fuel-con--request-output req))
-        (cont (fuel-con--request-continuation req))
+  (let ((cont (fuel-con--request-continuation req))
         (id (fuel-con--request-id req))
         (rstr (fuel-con--request-string req))
         (buffer (fuel-con--request-buffer req)))
     (if (not cont)
         (fuel-log--warn "<%s> Droping result for request %S (%s)"
-                            id rstr str)
+                            id rstr req)
       (condition-case cerr
           (with-current-buffer (or buffer (current-buffer))
-            (funcall cont str)
-            (fuel-log--info "<%s>: processed\n\t%s" id str))
-        (error (fuel-log--error "<%s>: continuation failed %S \n\t%s"
-                                id rstr cerr))))))
-
-(defvar fuel-con--debug-comint-p nil)
-
-(defun fuel-con--comint-redirect-filter (str)
-  (if (not fuel-con--connection)
-      (fuel-log--error "No connection in buffer (%s)" str)
-    (let ((req (fuel-con--connection-current-request fuel-con--connection)))
-      (if (not req) (fuel-log--error "No current request (%s)" str)
-        (fuel-con--request-output req str)
-        (fuel-log--info "<%s>: in progress" (fuel-con--request-id req)))))
-  (if fuel-con--debug-comint-p (fuel--shorten-str str 256) ""))
+            (funcall cont (fuel-con--comint-buffer-form))
+            (fuel-log--info "<%s>: processed\n\t%s" id req))
+        (error (fuel-log--error
+                "<%s>: continuation failed %S \n\t%s" id rstr cerr))))))
 
 (defun fuel-con--comint-redirect-hook ()
   (if (not fuel-con--connection)
index ca71012ec54777532ee5fbdca6a517ae583c766e..871d8c0ae6ce2ea4137597211c20cb2830c9ff09 100644 (file)
@@ -66,7 +66,8 @@
 
 (defsubst factor--fuel-in (in)
   (cond ((null in) :in)
-        ((eq in t) "fuel-scratchpad")
+        ((eq in 'f) 'f)
+        ((eq in 't) "fuel-scratchpad")
         ((stringp in) in)
         (t (error "Invalid 'in' (%s)" in))))
 
 (defsubst fuel-eval--retort-result (ret) (nth 1 ret))
 (defsubst fuel-eval--retort-output (ret) (nth 2 ret))
 
-(defsubst fuel-eval--retort-p (ret) (listp ret))
+(defsubst fuel-eval--retort-p (ret)
+  (and (listp ret) (= 3 (length ret))))
 
 (defsubst fuel-eval--make-parse-error-retort (str)
   (fuel-eval--retort-make (cons 'fuel-parse-retort-error str) nil))
 
-(defun fuel-eval--parse-retort (str)
-  (save-current-buffer
-    (condition-case nil
-        (let ((ret (car (read-from-string str))))
-          (if (fuel-eval--retort-p ret) ret (error)))
-      (error (fuel-eval--make-parse-error-retort str)))))
+(defun fuel-eval--parse-retort (ret)
+  (if (fuel-eval--retort-p ret) ret
+    (fuel-eval--make-parse-error-retort ret)))
 
 (defsubst fuel-eval--error-name (err) (car err))
 
index ba2a499b4bee3e9c772925d9a6d6004b06e184f2..616bff2defbf72ae42a978d5aa5be4bb260b5c77 100644 (file)
@@ -13,8 +13,8 @@
 
 ;;; Code:
 
-(require 'fuel-base)
 (require 'fuel-syntax)
+(require 'fuel-base)
 
 (require 'font-lock)
 
                      ',faces)))
      (,setup))))
 
+(fuel-font-lock--define-faces
+ factor-font-lock font-lock factor-mode
+ ((comment comment "comments")
+  (constructor type  "constructors (<foo>)")
+  (declaration keyword "declaration words")
+  (parsing-word keyword  "parsing words")
+  (setter-word function-name "setter words (>>foo)")
+  (getter-word function-name "getter words (foo>>)")
+  (stack-effect comment "stack effect specifications")
+  (string string "strings")
+  (symbol variable-name "name of symbol being defined")
+  (type-name type "type names")
+  (vocabulary-name constant "vocabulary names")
+  (word function-name "word, generic or method being defined")))
+
 \f
 ;;; Font lock:
 
@@ -59,7 +74,8 @@
                                            (2 'factor-font-lock-word))
     (,fuel-syntax--parent-type-regex 1 'factor-font-lock-type-name)
     (,fuel-syntax--constructor-regex . 'factor-font-lock-constructor)
-    (,fuel-syntax--setter-regex . 'factor-font-lock-setter-word)
+    (,fuel-syntax--setter-regex 2 'factor-font-lock-setter-word)
+    (,fuel-syntax--getter-regex 2 'factor-font-lock-getter-word)
     (,fuel-syntax--symbol-definition-regex 2 'factor-font-lock-symbol)
     (,fuel-syntax--use-line-regex 1 'factor-font-lock-vocabulary-name))
   "Font lock keywords definition for Factor mode.")
index 1b0890ef9b1e5205ffd3278f9cc483e17b90ad67..2154cbebd63a2e18eb0c10ca9c50d02e62b17d97 100644 (file)
   (let ((word (or word (fuel-syntax-symbol-at-point)))
         (fuel-log--inhibit-p t))
     (when word
-      (let* ((cmd `(:fuel* (((:quote ,word) synopsis :get)) t))
-             (ret (fuel-eval--send/wait cmd 20)))
-        (when (and ret (not (fuel-eval--retort-error ret)))
+      (let* ((cmd (if (fuel-syntax--in-using)
+                      `(:fuel* (,word fuel-vocab-summary) t t)
+                    `(:fuel* (((:quote ,word) synopsis :get)) t)))
+             (ret (fuel-eval--send/wait cmd 20))
+             (res (fuel-eval--retort-result ret)))
+        (when (and ret (not (fuel-eval--retort-error ret)) (stringp res))
           (if fuel-help-minibuffer-font-lock
-              (fuel-help--font-lock-str (fuel-eval--retort-result ret))
-            (fuel-eval--retort-result ret)))))))
+              (fuel-help--font-lock-str res)
+            res))))))
 
 (make-variable-buffer-local
  (defvar fuel-autodoc-mode-string " A"
@@ -152,7 +155,8 @@ displayed in the minibuffer."
                   fuel-help-always-ask))
          (def (if ask (fuel-completion--read-word prompt
                                                   def
-                                                  'fuel-help--prompt-history)
+                                                  'fuel-help--prompt-history
+                                                  t)
                 def))
          (cmd `(:fuel* ((:quote ,def) ,(if see 'see 'help)) t)))
     (message "Looking up '%s' ..." def)
@@ -176,14 +180,41 @@ displayed in the minibuffer."
       (when (re-search-forward (format "^%s" def) nil t)
         (beginning-of-line)
         (kill-region (point-min) (point))
-        (next-line)
-        (open-line 1)
         (fuel-help--history-push (cons def (buffer-string)))))
     (set-buffer-modified-p nil)
     (pop-to-buffer hb)
     (goto-char (point-min))
     (message "%s" def)))
 
+\f
+;;; Help mode font lock:
+
+(defconst fuel-help--headlines
+  (regexp-opt '("Class description"
+                "Definition"
+                "Errors"
+                "Examples"
+                "Generic word contract"
+                "Inputs and outputs"
+                "Methods"
+                "Notes"
+                "Parent topics:"
+                "See also"
+                "Syntax"
+                "Variable description"
+                "Variable value"
+                "Vocabulary"
+                "Warning"
+                "Word description")
+              t))
+
+(defconst fuel-help--headlines-regexp (format "^%s" fuel-help--headlines))
+
+(defconst fuel-help--font-lock-keywords
+  `(,@fuel-font-lock--font-lock-keywords
+    (,fuel-help--headlines-regexp . 'fuel-help-font-lock-headlines)))
+
+
 \f
 ;;; Interactive help commands:
 
@@ -221,8 +252,18 @@ buffer."
       (error "No previous page"))
     (fuel-help--insert-contents (car item) (cdr item) t)))
 
+(defun fuel-help-next-headline (&optional count)
+  (interactive "P")
+  (end-of-line)
+  (when (re-search-forward fuel-help--headlines-regexp nil t (or count 1))
+    (beginning-of-line)))
+
+(defun fuel-help-previous-headline (&optional count)
+  (interactive "P")
+  (re-search-backward fuel-help--headlines-regexp nil t count))
+
 \f
-;;;; Factor help mode:
+;;;; Help mode map:
 
 (defvar fuel-help-mode-map
   (let ((map (make-sparse-keymap)))
@@ -231,35 +272,19 @@ buffer."
     (define-key map "b" 'fuel-help-previous)
     (define-key map "f" 'fuel-help-next)
     (define-key map "l" 'fuel-help-previous)
+    (define-key map "p" 'fuel-help-previous)
     (define-key map "n" 'fuel-help-next)
+    (define-key map (kbd "TAB") 'fuel-help-next-headline)
+    (define-key map (kbd "S-TAB") 'fuel-help-previous-headline)
+    (define-key map [(backtab)] 'fuel-help-previous-headline)
     (define-key map (kbd "SPC")  'scroll-up)
     (define-key map (kbd "S-SPC") 'scroll-down)
+    (define-key map "\C-cz" 'run-factor)
+    (define-key map "\C-c\C-z" 'run-factor)
     map))
 
-(defconst fuel-help--headlines
-  (regexp-opt '("Class description"
-                "Definition"
-                "Errors"
-                "Examples"
-                "Generic word contract"
-                "Inputs and outputs"
-                "Methods"
-                "Notes"
-                "Parent topics:"
-                "See also"
-                "Syntax"
-                "Variable description"
-                "Variable value"
-                "Vocabulary"
-                "Warning"
-                "Word description")
-              t))
-
-(defconst fuel-help--headlines-regexp (format "^%s" fuel-help--headlines))
-
-(defconst fuel-help--font-lock-keywords
-  `(,@fuel-font-lock--font-lock-keywords
-    (,fuel-help--headlines-regexp . 'fuel-help-font-lock-headlines)))
+\f
+;;; Help mode definition:
 
 (defun fuel-help-mode ()
   "Major mode for browsing Factor documentation.
index c1e8d670cf8705920c26cc8aba9fc067bfd65209..a12fc817a3f822b0e9abf8ed8b64568c07a3bac1 100644 (file)
@@ -76,6 +76,7 @@ buffer."
     (make-comint-in-buffer "fuel listener" (current-buffer) factor nil
                            "-run=listener" (format "-i=%s" image))
     (fuel-listener--wait-for-prompt 10000)
+    (fuel-con--setup-connection (current-buffer))
     (fuel-con--send-string/wait (current-buffer)
                                 fuel-con--init-stanza
                                 '(lambda (s) (message "FUEL listener up and running!"))
@@ -130,10 +131,12 @@ buffer."
 \f
 ;;; Fuel listener mode:
 
+;;;###autoload
 (define-derived-mode fuel-listener-mode comint-mode "Fuel Listener"
   "Major mode for interacting with an inferior Factor listener process.
 \\{fuel-listener-mode-map}"
   (set (make-local-variable 'comint-prompt-regexp) fuel-con--prompt-regex)
+  (set (make-local-variable 'comint-use-prompt-regexp) t)
   (set (make-local-variable 'comint-prompt-read-only) t)
   (fuel-listener--setup-completion))
 
index b93160518375dc4138dc4a04fd0de9d332c5c5c8..714b9f01042c944a4700cd2a9262b3aedfb16940 100644 (file)
 
 ;;; Code:
 
-(require 'factor-mode)
-(require 'fuel-base)
-(require 'fuel-syntax)
-(require 'fuel-font-lock)
-(require 'fuel-debug)
-(require 'fuel-help)
-(require 'fuel-eval)
-(require 'fuel-completion)
 (require 'fuel-listener)
+(require 'fuel-completion)
+(require 'fuel-eval)
+(require 'fuel-help)
+(require 'fuel-debug)
+(require 'fuel-font-lock)
+(require 'fuel-syntax)
+(require 'fuel-base)
 
 \f
 ;;; Customization:
 \f
 ;;; User commands
 
-(defun fuel-run-file (&optional arg)
-  "Sends the current file to Factor for compilation.
-With prefix argument, ask for the file to run."
-  (interactive "P")
+(defun fuel-mode--read-file (arg)
   (let* ((file (or (and arg (read-file-name "File: " nil (buffer-file-name) t))
                    (buffer-file-name)))
          (file (expand-file-name file))
          (buffer (find-file-noselect file)))
+    (when (and  buffer
+                (buffer-modified-p buffer)
+                (y-or-n-p "Save file? "))
+      (save-buffer buffer))
+    (cons file buffer)))
+
+(defun fuel-run-file (&optional arg)
+  "Sends the current file to Factor for compilation.
+With prefix argument, ask for the file to run."
+  (interactive "P")
+  (let* ((f/b (fuel-mode--read-file arg))
+         (file (car f/b))
+         (buffer (cdr f/b)))
     (when buffer
       (with-current-buffer buffer
         (message "Compiling %s ..." file)
@@ -61,6 +70,7 @@ With prefix argument, ask for the file to run."
       (message "Compiling %s ... OK!" file)
     (message "")))
 
+
 (defun fuel-eval-region (begin end &optional arg)
   "Sends region to Fuel's listener for evaluation.
 Unless called with a prefix, switchs to the compilation results
@@ -191,9 +201,10 @@ interacting with a factor listener is at your disposal.
   (define-key fuel-mode-map (vector '(control ?c) `(control ,p) k) c)
   (define-key fuel-mode-map (vector '(control ?c) `(control ,p) `(control ,k)) c))
 
-(fuel-mode--key-1 ?z 'run-factor)
 (fuel-mode--key-1 ?k 'fuel-run-file)
+(fuel-mode--key-1 ?l 'fuel-run-file)
 (fuel-mode--key-1 ?r 'fuel-eval-region)
+(fuel-mode--key-1 ?z 'run-factor)
 
 (define-key fuel-mode-map "\C-\M-x" 'fuel-eval-definition)
 (define-key fuel-mode-map "\C-\M-r" 'fuel-eval-extended-region)
@@ -201,6 +212,7 @@ interacting with a factor listener is at your disposal.
 (define-key fuel-mode-map (kbd "M-TAB") 'fuel-completion--complete-symbol)
 
 (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)
 (fuel-mode--key ?e ?v 'fuel-edit-vocabulary)
 (fuel-mode--key ?e ?w 'fuel-edit-word)
index 936bded3a5299e874280a055ee3badfb85405f59..e810772bd011bcc3d9e3a961beaeb2339d21870d 100644 (file)
@@ -64,7 +64,8 @@
   '("flushable" "foldable" "inline" "parsing" "recursive"))
 
 (defconst fuel-syntax--declaration-words-regex
-  (regexp-opt fuel-syntax--declaration-words 'words))
+  (format "%s\\($\\| \\)"
+          (regexp-opt fuel-syntax--declaration-words 'words)))
 
 (defsubst fuel-syntax--second-word-regex (prefixes)
   (format "^%s +\\([^ \r\n]+\\)" (regexp-opt prefixes t)))
@@ -82,7 +83,8 @@
 
 (defconst fuel-syntax--constructor-regex "<[^ >]+>")
 
-(defconst fuel-syntax--setter-regex "\\W>>[^ ]+\\b")
+(defconst fuel-syntax--getter-regex "\\( \\|^\\)\\([^ ]+>>\\)\\( \\|$\\)")
+(defconst fuel-syntax--setter-regex "\\( \\|^\\)\\(>>[^ ]+\\)\\( \\|$\\)")
 
 (defconst fuel-syntax--symbol-definition-regex
   (fuel-syntax--second-word-regex '("SYMBOL:" "VAR:")))
 (defsubst fuel-syntax--at-using ()
   (looking-at fuel-syntax--using-lines-regex))
 
+(defun fuel-syntax--in-using ()
+  (let ((p (point)))
+    (save-excursion
+      (and (re-search-backward "^USING: " nil t)
+           (re-search-forward " ;" nil t)
+           (< p (match-end 0))))))
+
 (defsubst fuel-syntax--beginning-of-defun (&optional times)
   (re-search-backward fuel-syntax--begin-of-def-regex nil t times))