]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: Bug fixes and compatibility with Emacs 22.
authorJose A. Ortega Ruiz <jao@gnu.org>
Wed, 17 Dec 2008 22:50:48 +0000 (23:50 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Wed, 17 Dec 2008 22:50:48 +0000 (23:50 +0100)
extra/fuel/fuel.factor
misc/fuel/fuel-base.el
misc/fuel/fuel-completion.el
misc/fuel/fuel-eval.el
misc/fuel/fuel-help.el
misc/fuel/fuel-mode.el

index 4535ac7fd6612e1b02f22dc0f20ef28f1e203f2a..15b9adf87015b95353f508eb54188e5b95eeb77b 100644 (file)
@@ -168,12 +168,20 @@ 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 ; 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
+
 MEMO: (fuel-vocab-words) ( name -- seq )
     >vocab-link words [ name>> ] map ;
 
@@ -185,7 +193,7 @@ 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
index aa9614da0aea2c9d78073ff21c8a709105b14927..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
 
index a2b617672f7dc585c1e43938447627661004a6ed..a4f467fd98939a86177af74dcb724255d1c0f654 100644 (file)
              (fuel-eval--send/wait '(:fuel* (fuel-get-vocabs) "fuel" (:array)))))))
   fuel-completion--vocabs)
 
-(defvar fuel-completion--words-last (cons nil nil))
-
-(defsubst fuel-completion--forget-words ()
-  (setq fuel-completion--words-last (cons nil nil)))
-
 (defun fuel-completion--words (prefix vocabs)
   (let ((vs (if vocabs (cons :array vocabs) 'f))
         (us (or vocabs 't)))
-    (if (and (car fuel-completion--words-last)
-             (cdr fuel-completion--words-last)
-             (equal (caar fuel-completion--words-last) vs)
-             (fuel--string-prefix-p (cdar fuel-completion--words-last) prefix))
-        (cdr fuel-completion--words-last)
-      (setcar fuel-completion--words-last (cons vocabs prefix))
-      (setcdr fuel-completion--words-last
-              (fuel-eval--retort-result
-               (fuel-eval--send/wait
-                `(:fuel* (,prefix ,vs fuel-get-words) t ,us)))))))
+    (fuel-eval--retort-result
+     (fuel-eval--send/wait `(:fuel* (,prefix ,vs fuel-get-words) t ,us)))))
 
 \f
 ;;; Completions window handling, heavily inspired in slime's:
@@ -173,7 +160,6 @@ terminates a current completion."
     (cons completions partial)))
 
 (defun fuel-completion--read-word (prompt &optional default history all)
-  (fuel-completion--forget-words)
   (completing-read prompt
                    (if all fuel-completion--all-words-list-func
                      fuel-completion--word-list-func)
@@ -185,7 +171,6 @@ terminates a current completion."
   "Complete the symbol at point.
 Perform completion similar to Emacs' complete-symbol."
   (interactive)
-  (fuel-completion--forget-words)
   (let* ((end (point))
          (beg (fuel-syntax--symbol-start))
          (prefix (buffer-substring-no-properties beg end))
index a77de0ba2ed3e22eb321c7b94dba3bd613f5a069..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))))
 
index f0e02df4f1d5e611179b7f4c8223623cc9103be2..e618fd130a961fa15518e6150f59a569be8203ff 100644 (file)
@@ -152,7 +152,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)
@@ -229,6 +230,7 @@ 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 "SPC")  'scroll-up)
     (define-key map (kbd "S-SPC") 'scroll-down)
index b93160518375dc4138dc4a04fd0de9d332c5c5c8..265cfde0a22b2580d060840471889db8a7aa08c1 100644 (file)
 \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 +71,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 +202,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 +213,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)