factor/libs/factor.el

169 lines
4.8 KiB
EmacsLisp
Raw Normal View History

2006-08-17 20:41:56 -04:00
;; Eduardo Cavazos - wayo.cavazos@gmail.com
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2006-08-17 20:41:56 -04:00
;; Add these lines to your .emacs file:
;; (load-file "/scratch/repos/Factor/contrib/factor.el")
;; (setq factor-binary "/scratch/repos/Factor/f")
;; (setq factor-image "/scratch/repos/Factor/factor.image")
;; Of course, you'll have to edit the directory paths for your system
;; accordingly.
;; That's all you have to do to "install" factor.el on your
;; system. Whenever you edit a factor file, Emacs will know to switch
;; to Factor mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2006-08-17 20:41:56 -04:00
;; M-x run-factor === Start a Factor listener inside Emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2006-08-17 20:41:56 -04:00
;; BUG: A double quote character on a commented line will break the
;; syntax highlighting for that line.
(defgroup factor nil
"Factor mode"
:group 'languages)
(defvar factor-mode-syntax-table nil
"Syntax table used while in Factor mode.")
(if factor-mode-syntax-table
()
(let ((i 0))
(setq factor-mode-syntax-table (make-syntax-table))
;; Default is atom-constituent
(while (< i 256)
(modify-syntax-entry i "_ ")
(setq i (1+ i)))
;; Word components.
(setq i ?0)
(while (<= i ?9)
(modify-syntax-entry i "w ")
(setq i (1+ i)))
(setq i ?A)
(while (<= i ?Z)
(modify-syntax-entry i "w ")
(setq i (1+ i)))
(setq i ?a)
(while (<= i ?z)
(modify-syntax-entry i "w ")
(setq i (1+ i)))
;; Whitespace
(modify-syntax-entry ?\t " ")
(modify-syntax-entry ?\n ">")
(modify-syntax-entry ?\f " ")
(modify-syntax-entry ?\r " ")
(modify-syntax-entry ? " ")
(modify-syntax-entry ?\[ "(] ")
(modify-syntax-entry ?\] ")[ ")
(modify-syntax-entry ?{ "(} ")
(modify-syntax-entry ?} "){ ")
(modify-syntax-entry ?\( "()")
(modify-syntax-entry ?\) ")(")
(modify-syntax-entry ?\" "\" ")))
(defvar factor-mode-map (make-sparse-keymap))
(defcustom factor-mode-hook nil
"Hook run when entering Factor mode."
:type 'hook
:group 'factor)
(defconst factor-font-lock-keywords
'(("#!.*$" . font-lock-comment-face)
("!.*$" . font-lock-comment-face)
("( .* )" . font-lock-comment-face)
"IN:" "USING:" "TUPLE:" "^C:" "^M:" "USE:" "REQUIRE:" "PROVIDE:"
2006-10-04 00:11:59 -04:00
"REQUIRES:"
"GENERIC:" "SYMBOL:" "PREDICATE:" "VAR:" "VARS:"))
(defun factor-mode ()
"A mode for editing programs written in the Factor programming language."
(interactive)
(kill-all-local-variables)
(use-local-map factor-mode-map)
(setq major-mode 'factor-mode)
(setq mode-name "Factor")
(make-local-variable 'comment-start)
(setq comment-start "! ")
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
'(factor-font-lock-keywords nil nil nil nil))
(set-syntax-table factor-mode-syntax-table)
(run-hooks 'factor-mode-hooks))
(add-to-list 'auto-mode-alist '("\\.factor\\'" . factor-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2006-05-24 07:18:51 -04:00
(require 'comint)
(defvar factor-binary "/scratch/repos/Factor/f")
(defvar factor-image "-i=/scratch/repos/Factor/factor.image")
(defun run-factor ()
(interactive)
(switch-to-buffer
(make-comint-in-buffer
"factor" nil factor-binary nil factor-image "-shell=tty")))
2006-05-24 07:18:51 -04:00
(defun factor-telnet-to-port (port)
(interactive "nPort: ")
(switch-to-buffer
(make-comint-in-buffer "factor-telnet" nil (cons "localhost" port))))
2006-05-24 07:18:51 -04:00
(defun factor-telnet ()
2006-05-24 20:24:11 -04:00
(interactive)
(factor-telnet-to-port 9000))
(defun factor-telnet-factory ()
2006-05-24 20:24:11 -04:00
(interactive)
(factor-telnet-to-port 9010))
(defun factor-run-file ()
2006-05-24 07:18:51 -04:00
(interactive)
(comint-send-string "*factor*" (format "\"%s\"" (buffer-file-name)))
(comint-send-string "*factor*" " run-file\n"))
2006-05-24 07:18:51 -04:00
(defun factor-send-region (start end)
(interactive "r")
(comint-send-region "*factor*" start end)
(comint-send-string "*factor*" "\n"))
2006-05-24 07:18:51 -04:00
(defun factor-see ()
2006-05-24 20:24:11 -04:00
(interactive)
(comint-send-string "*factor*" "\\ ")
(comint-send-string "*factor*" (thing-at-point 'sexp))
(comint-send-string "*factor*" " see\n"))
2006-05-24 07:18:51 -04:00
(defun factor-help ()
2006-05-25 20:22:45 -04:00
(interactive)
(comint-send-string "*factor*" "\\ ")
(comint-send-string "*factor*" (thing-at-point 'sexp))
(comint-send-string "*factor*" " help\n"))
2006-05-24 07:18:51 -04:00
(defun factor-edit ()
2006-05-25 20:22:45 -04:00
(interactive)
(comint-send-string "*factor*" "\\ ")
(comint-send-string "*factor*" (thing-at-point 'sexp))
(comint-send-string "*factor*" " edit\n"))
(defun factor-comment-line ()
(interactive)
(beginning-of-line)
(insert "! "))
(define-key factor-mode-map "\C-c\C-f" 'factor-run-file)
(define-key factor-mode-map "\C-c\C-r" 'factor-send-region)
(define-key factor-mode-map "\C-c\C-s" 'factor-see)
(define-key factor-mode-map "\C-ce" 'factor-edit)
(define-key factor-mode-map "\C-c\C-h" 'factor-help)