| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | ;;; factor.el --- Interacting with Factor within emacs | 
					
						
							|  |  |  |  | ;; | 
					
						
							|  |  |  |  | ;; Authors: Eduardo Cavazos <wayo.cavazos@gmail.com> | 
					
						
							|  |  |  |  | ;;          Jose A Ortega Ruiz <jao@gnu.org> | 
					
						
							|  |  |  |  | ;; Keywords: languages | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | ;;; Commentary: | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | ;;; Quick setup: | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | ;; Add these lines to your .emacs file: | 
					
						
							|  |  |  |  | ;; | 
					
						
							|  |  |  |  | ;;   (load-file "/scratch/repos/Factor/misc/factor.el") | 
					
						
							|  |  |  |  | ;;   (setq factor-binary "/scratch/repos/Factor/factor") | 
					
						
							|  |  |  |  | ;;   (setq factor-image "/scratch/repos/Factor/factor.image") | 
					
						
							|  |  |  |  | ;; | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | ;; Of course, you'll have to edit the directory paths for your system | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | ;; accordingly. Alternatively, put this file in your load-path and use | 
					
						
							|  |  |  |  | ;; | 
					
						
							|  |  |  |  | ;;   (require 'factor) | 
					
						
							|  |  |  |  | ;; | 
					
						
							|  |  |  |  | ;; instead of load-file. | 
					
						
							|  |  |  |  | ;; | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | ;; 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. | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | ;; | 
					
						
							|  |  |  |  | ;; For further customization options, | 
					
						
							|  |  |  |  | ;;   M-x customize-group RET factor | 
					
						
							|  |  |  |  | ;; | 
					
						
							|  |  |  |  | ;; To start a Factor listener inside Emacs, | 
					
						
							|  |  |  |  | ;;   M-x run-factor | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;; Requirements: | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | (require 'font-lock) | 
					
						
							|  |  |  |  | (require 'comint) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (require 'view) | 
					
						
							| 
									
										
										
										
											2008-11-29 09:45:00 -05:00
										 |  |  |  | (require 'ring) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | ;;; Customization: | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defgroup factor nil | 
					
						
							|  |  |  |  |   "Factor mode" | 
					
						
							|  |  |  |  |   :group 'languages) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 10:21:47 -05:00
										 |  |  |  | (defcustom factor-default-indent-width 4 | 
					
						
							|  |  |  |  |   "Default indentantion width for factor-mode.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | This value will be used for the local variable | 
					
						
							|  |  |  |  | `factor-indent-width' in new factor buffers. For existing code, | 
					
						
							|  |  |  |  | we first check if `factor-indent-width' is set explicitly in a | 
					
						
							|  |  |  |  | local variable section or line (e.g. '! -*- factor-indent-witdth: 2 -*-'). | 
					
						
							|  |  |  |  | If that's not the case, `factor-mode' tries to infer its correct | 
					
						
							|  |  |  |  | value from the existing code in the buffer."
 | 
					
						
							|  |  |  |  |   :type 'integer | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | (defcustom factor-binary "~/factor/factor" | 
					
						
							|  |  |  |  |   "Full path to the factor executable to use when starting a listener." | 
					
						
							|  |  |  |  |   :type '(file :must-match t) | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defcustom factor-image "~/factor/factor.image" | 
					
						
							|  |  |  |  |   "Full path to the factor image to use when starting a listener." | 
					
						
							|  |  |  |  |   :type '(file :must-match t) | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (defcustom factor-use-doc-window t | 
					
						
							|  |  |  |  |   "When on, use a separate window to display help information.
 | 
					
						
							|  |  |  |  | Disable to see that information in the factor-listener comint | 
					
						
							|  |  |  |  | window."
 | 
					
						
							|  |  |  |  |   :type 'boolean | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defcustom factor-listener-use-other-window t | 
					
						
							|  |  |  |  |   "Use a window other than the current buffer's when switching to
 | 
					
						
							|  |  |  |  | the factor-listener buffer."
 | 
					
						
							|  |  |  |  |   :type 'boolean | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defcustom factor-listener-window-allow-split t | 
					
						
							|  |  |  |  |   "Allow window splitting when switching to the factor-listener
 | 
					
						
							|  |  |  |  | buffer."
 | 
					
						
							|  |  |  |  |   :type 'boolean | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defcustom factor-help-always-ask t | 
					
						
							|  |  |  |  |   "When enabled, always ask for confirmation in help prompts." | 
					
						
							|  |  |  |  |   :type 'boolean | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | (defcustom factor-help-use-minibuffer t | 
					
						
							|  |  |  |  |   "When enabled, use the minibuffer for short help messages." | 
					
						
							|  |  |  |  |   :type 'boolean | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-05 17:30:04 -04:00
										 |  |  |  | (defcustom factor-display-compilation-output t | 
					
						
							|  |  |  |  |   "Display the REPL buffer before compiling files." | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  |   :type 'boolean | 
					
						
							| 
									
										
										
										
											2008-07-05 17:30:04 -04:00
										 |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 10:21:47 -05:00
										 |  |  |  | (defcustom factor-mode-hook nil | 
					
						
							|  |  |  |  |   "Hook run when entering Factor mode." | 
					
						
							|  |  |  |  |   :type 'hook | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (defcustom factor-help-mode-hook nil | 
					
						
							|  |  |  |  |   "Hook run by `factor-help-mode'." | 
					
						
							|  |  |  |  |   :type 'hook | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  | (defgroup factor-faces nil | 
					
						
							|  |  |  |  |   "Faces used in Factor mode" | 
					
						
							|  |  |  |  |   :group 'factor | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-parsing-word (face-default-spec font-lock-keyword-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for parsing words." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | (defface factor-font-lock-declaration (face-default-spec font-lock-keyword-face) | 
					
						
							|  |  |  |  |   "Face for declaration words (inline, parsing ...)." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-comment (face-default-spec font-lock-comment-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for comments." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-string (face-default-spec font-lock-string-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for strings." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-stack-effect (face-default-spec font-lock-comment-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for stack effect specifications." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-word-definition (face-default-spec font-lock-function-name-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for word, generic or method being defined." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-symbol-definition (face-default-spec font-lock-variable-name-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for name of symbol being defined." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-vocabulary-name (face-default-spec font-lock-constant-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for names of vocabularies in USE or USING." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-type-definition (face-default-spec font-lock-type-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for type (tuple) names." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-constructor (face-default-spec font-lock-type-face) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  |   "Face for constructors (<foo>)." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-setter-word (face-default-spec font-lock-function-name-face) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  |   "Face for setter words (>>foo)." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 16:44:05 -05:00
										 |  |  |  | (defface factor-font-lock-parsing-word (face-default-spec font-lock-keyword-face) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   "Face for parsing words." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (defface factor-font-lock-help-mode-headlines '((t (:bold t :weight bold))) | 
					
						
							|  |  |  |  |   "Face for headlines in help buffers." | 
					
						
							|  |  |  |  |   :group 'factor-faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-29 09:45:00 -05:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Compatibility | 
					
						
							|  |  |  |  | (when (not (fboundp 'ring-member)) | 
					
						
							|  |  |  |  |   (defun ring-member (ring item) | 
					
						
							|  |  |  |  |     (catch 'found | 
					
						
							|  |  |  |  |       (dotimes (ind (ring-length ring) nil) | 
					
						
							|  |  |  |  |         (when (equal item (ring-ref ring ind)) | 
					
						
							|  |  |  |  |           (throw 'found ind)))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Factor mode font lock: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-13 20:54:37 -05:00
										 |  |  |  | (defconst factor--parsing-words | 
					
						
							|  |  |  |  |   '("{" "}" "^:" "^::" ";" "<<" "<PRIVATE" ">>" | 
					
						
							|  |  |  |  |     "BIN:" "BV{" "B{" "C:" "C-STRUCT:" "C-UNION:" "CHAR:" "CS{" "C{" | 
					
						
							| 
									
										
										
										
											2008-11-15 19:51:20 -05:00
										 |  |  |  |     "DEFER:" "ERROR:" "EXCLUDE:" "FORGET:" | 
					
						
							| 
									
										
										
										
											2008-11-13 20:54:37 -05:00
										 |  |  |  |     "GENERIC#" "GENERIC:" "HEX:" "HOOK:" "H{" | 
					
						
							|  |  |  |  |     "IN:" "INSTANCE:" "INTERSECTION:" | 
					
						
							|  |  |  |  |     "M:" "MACRO:" "MACRO::" "MAIN:" "MATH:" "METHOD:" "MIXIN:" | 
					
						
							|  |  |  |  |     "OCT:" "POSTPONE:" "PREDICATE:" "PRIMITIVE:" "PRIVATE>" "PROVIDE:" | 
					
						
							|  |  |  |  |     "REQUIRE:"  "REQUIRES:" "SINGLETON:" "SLOT:" "SYMBOL:" "SYMBOLS:" | 
					
						
							|  |  |  |  |     "TUPLE:" "T{" "t\\??" "TYPEDEF:" | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  |     "UNION:" "USE:" "USING:" "V{" "VARS:" "W{")) | 
					
						
							| 
									
										
										
										
											2008-11-13 20:54:37 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-15 18:16:13 -05:00
										 |  |  |  | (defconst factor--regex-parsing-words-ext | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  |   (regexp-opt '("B" "call-next-method" "delimiter" "f" "initial:" "read-only") | 
					
						
							| 
									
										
										
										
											2008-11-13 20:54:37 -05:00
										 |  |  |  |               'words)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | (defconst factor--declaration-words | 
					
						
							|  |  |  |  |   '("flushable" "foldable" "inline" "parsing" "recursive")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regex-declaration-words | 
					
						
							|  |  |  |  |   (regexp-opt factor--declaration-words 'words)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 10:21:47 -05:00
										 |  |  |  | (defsubst factor--regex-second-word (prefixes) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   (format "^%s +\\([^ \r\n]+\\)" (regexp-opt prefixes t))) | 
					
						
							| 
									
										
										
										
											2008-11-15 18:16:13 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  | (defconst factor--regex-method-definition | 
					
						
							|  |  |  |  |   "^M: +\\([^ ]+\\) +\\([^ ]+\\)") | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-15 18:16:13 -05:00
										 |  |  |  | (defconst factor--regex-word-definition | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  |   (factor--regex-second-word '(":" "::" "GENERIC:"))) | 
					
						
							| 
									
										
										
										
											2008-11-15 18:16:13 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regex-type-definition | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  |   (factor--regex-second-word '("TUPLE:" "SINGLETON:"))) | 
					
						
							| 
									
										
										
										
											2008-11-15 18:16:13 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  | (defconst factor--regex-parent-type "^TUPLE: +[^ ]+ +< +\\([^ ]+\\)") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regex-constructor "<[^ >]+>") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regex-setter "\\W>>[^ ]+\\b") | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  | (defconst factor--regex-symbol-definition | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  |   (factor--regex-second-word '("SYMBOL:" "VAR:"))) | 
					
						
							| 
									
										
										
										
											2008-11-15 18:16:13 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | (defconst factor--regex-stack-effect " ( .* )") | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  | (defconst factor--regex-using-lines "^USING: +\\(\\([^;]\\|[\n\r\f]\\)*\\);") | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-15 19:51:20 -05:00
										 |  |  |  | (defconst factor--regex-use-line "^USE: +\\(.*\\)$") | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  | (defconst factor--font-lock-keywords | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  |   `((,factor--regex-stack-effect . 'factor-font-lock-stack-effect) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |     ("\\(P\\|SBUF\\)\"" 1 'factor-font-lock-parsing-word) | 
					
						
							| 
									
										
										
										
											2008-11-13 20:54:37 -05:00
										 |  |  |  |     ,@(mapcar #'(lambda (w) (cons (concat "\\(^\\| \\)\\(" w "\\)\\($\\| \\)") | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |                              '(2 'factor-font-lock-parsing-word))) | 
					
						
							| 
									
										
										
										
											2008-11-13 20:54:37 -05:00
										 |  |  |  |               factor--parsing-words) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |     (,factor--regex-parsing-words-ext . 'factor-font-lock-parsing-word) | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  |     (,factor--regex-declaration-words 1 'factor-font-lock-declaration) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |     (,factor--regex-word-definition 2 'factor-font-lock-word-definition) | 
					
						
							|  |  |  |  |     (,factor--regex-type-definition 2 'factor-font-lock-type-definition) | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  |     (,factor--regex-method-definition (1 'factor-font-lock-type-definition) | 
					
						
							|  |  |  |  |                                       (2 'factor-font-lock-word-definition)) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  |     (,factor--regex-parent-type 1 'factor-font-lock-type-definition) | 
					
						
							|  |  |  |  |     (,factor--regex-constructor . 'factor-font-lock-constructor) | 
					
						
							|  |  |  |  |     (,factor--regex-setter . 'factor-font-lock-setter-word) | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |     (,factor--regex-symbol-definition 2 'factor-font-lock-symbol-definition) | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  |     (,factor--regex-use-line 1 'factor-font-lock-vocabulary-name)) | 
					
						
							|  |  |  |  |   "Font lock keywords definition for Factor mode.") | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Factor mode syntax: | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | (defconst factor--regex-definition-starters | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  |   (regexp-opt '("VARS" "TUPLE" "MACRO" "MACRO:" "M" ":" ""))) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | (defconst factor--regex-definition-start | 
					
						
							|  |  |  |  |   (format "^\\(%s:\\) " factor--regex-definition-starters)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regex-definition-end | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |   (format "\\(;\\( +%s\\)*\\)" factor--regex-declaration-words)) | 
					
						
							| 
									
										
										
										
											2008-11-25 15:53:06 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  | (defconst factor--font-lock-syntactic-keywords | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  |   `(("\\(#!\\)" (1 "<")) | 
					
						
							| 
									
										
										
										
											2008-11-26 16:58:11 -05:00
										 |  |  |  |     (" \\(!\\)" (1 "<")) | 
					
						
							|  |  |  |  |     ("^\\(!\\)" (1 "<")) | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  |     ("\\(!(\\) .* \\()\\)" (1 "<") (2 ">")))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | (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 "_   " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |       (setq i (1+ i))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ;; Word components. | 
					
						
							|  |  |  |  |     (setq i ?0) | 
					
						
							|  |  |  |  |     (while (<= i ?9) | 
					
						
							|  |  |  |  |       (modify-syntax-entry i "w   " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |       (setq i (1+ i))) | 
					
						
							|  |  |  |  |     (setq i ?A) | 
					
						
							|  |  |  |  |     (while (<= i ?Z) | 
					
						
							|  |  |  |  |       (modify-syntax-entry i "w   " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |       (setq i (1+ i))) | 
					
						
							|  |  |  |  |     (setq i ?a) | 
					
						
							|  |  |  |  |     (while (<= i ?z) | 
					
						
							|  |  |  |  |       (modify-syntax-entry i "w   " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |       (setq i (1+ i))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ;; Whitespace | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\t " " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\f " " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\r " " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?  " " factor-mode-syntax-table) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  |     ;; (end of) Comments | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\n ">" factor-mode-syntax-table) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ;; Parenthesis | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  |     (modify-syntax-entry ?\[ "(]  " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\] ")[  " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?{ "(}  " factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?} "){  " factor-mode-syntax-table) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\( "()" factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\) ")(" factor-mode-syntax-table) | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     ;; Strings | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\" "\"" factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\\ "/" factor-mode-syntax-table))) | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |  | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | ;;; symbol-at-point | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--beginning-of-symbol () | 
					
						
							|  |  |  |  |   "Move point to the beginning of the current symbol." | 
					
						
							|  |  |  |  |   (while (eq (char-before) ?:) (backward-char)) | 
					
						
							|  |  |  |  |   (skip-syntax-backward "w_")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--end-of-symbol () | 
					
						
							|  |  |  |  |   "Move point to the end of the current symbol." | 
					
						
							|  |  |  |  |   (skip-syntax-forward "w_") | 
					
						
							|  |  |  |  |   (while (looking-at ":") (forward-char))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (put 'factor-symbol 'end-op 'factor--end-of-symbol) | 
					
						
							|  |  |  |  | (put 'factor-symbol 'beginning-op 'factor--beginning-of-symbol) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor--symbol-at-point () | 
					
						
							|  |  |  |  |   (let ((s (substring-no-properties (thing-at-point 'factor-symbol)))) | 
					
						
							|  |  |  |  |     (and (> (length s) 0) s))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Factor mode indentation: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (make-variable-buffer-local | 
					
						
							|  |  |  |  |  (defvar factor-indent-width factor-default-indent-width | 
					
						
							|  |  |  |  |    "Indentation width in factor buffers. A local variable.")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--guess-indent-width () | 
					
						
							|  |  |  |  |   "Chooses an indentation value from existing code." | 
					
						
							|  |  |  |  |   (let ((word-cont "^ +[^ ]") | 
					
						
							|  |  |  |  |         (iw)) | 
					
						
							|  |  |  |  |     (save-excursion | 
					
						
							|  |  |  |  |       (beginning-of-buffer) | 
					
						
							|  |  |  |  |       (while (not iw) | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  |         (if (not (re-search-forward factor--regex-definition-start nil t)) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  |             (setq iw factor-default-indent-width) | 
					
						
							|  |  |  |  |           (forward-line) | 
					
						
							|  |  |  |  |           (when (looking-at word-cont) | 
					
						
							|  |  |  |  |             (setq iw (current-indentation)))))) | 
					
						
							|  |  |  |  |     iw)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor--ppss-brackets-depth () | 
					
						
							|  |  |  |  |   (nth 0 (syntax-ppss))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor--ppss-brackets-start () | 
					
						
							|  |  |  |  |   (nth 1 (syntax-ppss))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | (defun factor--ppss-brackets-end () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (goto-char (factor--ppss-brackets-start)) | 
					
						
							| 
									
										
										
										
											2008-11-28 19:55:08 -05:00
										 |  |  |  |     (condition-case nil | 
					
						
							|  |  |  |  |         (progn (forward-sexp) | 
					
						
							|  |  |  |  |                (1- (point))) | 
					
						
							| 
									
										
										
										
											2008-11-28 19:58:20 -05:00
										 |  |  |  |       (error -1)))) | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-19 04:37:54 -05:00
										 |  |  |  | (defsubst factor--indentation-at (pos) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  |   (save-excursion (goto-char pos) (current-indentation))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor--at-first-char-p () | 
					
						
							|  |  |  |  |   (= (- (point) (line-beginning-position)) (current-indentation))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regex-single-liner | 
					
						
							| 
									
										
										
										
											2008-11-19 04:37:54 -05:00
										 |  |  |  |   (format "^%s" (regexp-opt '("DEFER:" "GENERIC:" "IN:" | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  |                               "PRIVATE>" "<PRIVATE" | 
					
						
							|  |  |  |  |                               "SINGLETON:" "SYMBOL:" "USE:" "VAR:")))) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  | (defconst factor--regex-begin-of-def | 
					
						
							|  |  |  |  |   (format "^USING: \\|\\(%s\\)\\|\\(%s .*\\)" | 
					
						
							|  |  |  |  |           factor--regex-definition-start | 
					
						
							|  |  |  |  |           factor--regex-single-liner)) | 
					
						
							| 
									
										
										
										
											2008-11-18 20:00:00 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 19:55:08 -05:00
										 |  |  |  | (defconst factor--regex-end-of-def-line | 
					
						
							|  |  |  |  |   (format "^.*%s" factor--regex-definition-end)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  | (defconst factor--regex-end-of-def | 
					
						
							|  |  |  |  |   (format "\\(%s\\)\\|\\(%s .*\\)" | 
					
						
							|  |  |  |  |           factor--regex-end-of-def-line | 
					
						
							|  |  |  |  |           factor--regex-single-liner)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor--at-begin-of-def () | 
					
						
							|  |  |  |  |   (looking-at factor--regex-begin-of-def)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | (defsubst factor--at-end-of-def () | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |   (looking-at factor--regex-end-of-def)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor--looking-at-emptiness () | 
					
						
							|  |  |  |  |   (looking-at "^[ \t]*$")) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 20:00:00 -05:00
										 |  |  |  | (defun factor--at-setter-line () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (beginning-of-line) | 
					
						
							|  |  |  |  |     (if (not (factor--looking-at-emptiness)) | 
					
						
							|  |  |  |  |         (re-search-forward factor--regex-setter (line-end-position) t) | 
					
						
							|  |  |  |  |       (forward-line -1) | 
					
						
							|  |  |  |  |       (or (factor--at-constructor-line) | 
					
						
							|  |  |  |  |           (factor--at-setter-line))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--at-constructor-line () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (beginning-of-line) | 
					
						
							|  |  |  |  |     (re-search-forward factor--regex-constructor (line-end-position) t))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-19 04:37:54 -05:00
										 |  |  |  | (defsubst factor--increased-indentation (&optional i) | 
					
						
							|  |  |  |  |   (+ (or i (current-indentation)) factor-indent-width)) | 
					
						
							|  |  |  |  | (defsubst factor--decreased-indentation (&optional i) | 
					
						
							|  |  |  |  |   (- (or i (current-indentation)) factor-indent-width)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  | (defun factor--indent-in-brackets () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (beginning-of-line) | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  |     (when (> (factor--ppss-brackets-depth) 0) | 
					
						
							|  |  |  |  |       (let ((op (factor--ppss-brackets-start)) | 
					
						
							|  |  |  |  |             (cl (factor--ppss-brackets-end)) | 
					
						
							|  |  |  |  |             (ln (line-number-at-pos))) | 
					
						
							|  |  |  |  |         (when (> ln (line-number-at-pos op)) | 
					
						
							| 
									
										
										
										
											2008-11-28 19:55:08 -05:00
										 |  |  |  |           (if (and (> cl 0) (= ln (line-number-at-pos cl))) | 
					
						
							| 
									
										
										
										
											2008-11-19 04:37:54 -05:00
										 |  |  |  |               (factor--indentation-at op) | 
					
						
							|  |  |  |  |             (factor--increased-indentation (factor--indentation-at op)))))))) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--indent-definition () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (beginning-of-line) | 
					
						
							|  |  |  |  |     (when (factor--at-begin-of-def) 0))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 20:00:00 -05:00
										 |  |  |  | (defun factor--indent-setter-line () | 
					
						
							|  |  |  |  |   (when (factor--at-setter-line) | 
					
						
							|  |  |  |  |     (save-excursion | 
					
						
							| 
									
										
										
										
											2008-11-19 04:37:54 -05:00
										 |  |  |  |       (let ((indent (and (factor--at-constructor-line) (current-indentation)))) | 
					
						
							| 
									
										
										
										
											2008-11-18 20:00:00 -05:00
										 |  |  |  |         (while (not (or indent | 
					
						
							|  |  |  |  |                         (bobp) | 
					
						
							|  |  |  |  |                         (factor--at-begin-of-def) | 
					
						
							|  |  |  |  |                         (factor--at-end-of-def))) | 
					
						
							|  |  |  |  |           (if (factor--at-constructor-line) | 
					
						
							| 
									
										
										
										
											2008-11-19 04:37:54 -05:00
										 |  |  |  |               (setq indent (factor--increased-indentation)) | 
					
						
							| 
									
										
										
										
											2008-11-18 20:00:00 -05:00
										 |  |  |  |             (forward-line -1))) | 
					
						
							|  |  |  |  |         indent)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  | (defun factor--indent-continuation () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (forward-line -1) | 
					
						
							| 
									
										
										
										
											2008-11-19 04:37:54 -05:00
										 |  |  |  |     (while (and (not (bobp)) (factor--looking-at-emptiness)) | 
					
						
							|  |  |  |  |       (forward-line -1)) | 
					
						
							|  |  |  |  |     (if (or (factor--at-end-of-def) (factor--at-setter-line)) | 
					
						
							|  |  |  |  |         (factor--decreased-indentation) | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |       (if (and (factor--at-begin-of-def) | 
					
						
							|  |  |  |  |                (not (looking-at factor--regex-using-lines))) | 
					
						
							| 
									
										
										
										
											2008-11-19 04:37:54 -05:00
										 |  |  |  |           (factor--increased-indentation) | 
					
						
							|  |  |  |  |         (current-indentation))))) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--calculate-indentation () | 
					
						
							|  |  |  |  |   "Calculate Factor indentation for line at point." | 
					
						
							|  |  |  |  |   (or (and (bobp) 0) | 
					
						
							|  |  |  |  |       (factor--indent-definition) | 
					
						
							|  |  |  |  |       (factor--indent-in-brackets) | 
					
						
							| 
									
										
										
										
											2008-11-18 20:00:00 -05:00
										 |  |  |  |       (factor--indent-setter-line) | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  |       (factor--indent-continuation) | 
					
						
							|  |  |  |  |       0)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--indent-line () | 
					
						
							|  |  |  |  |   "Indent current line as Factor code" | 
					
						
							|  |  |  |  |   (let ((target (factor--calculate-indentation)) | 
					
						
							|  |  |  |  |         (pos (- (point-max) (point)))) | 
					
						
							|  |  |  |  |     (if (= target (current-indentation)) | 
					
						
							|  |  |  |  |         (if (< (current-column) (current-indentation)) | 
					
						
							|  |  |  |  |             (back-to-indentation)) | 
					
						
							|  |  |  |  |       (beginning-of-line) | 
					
						
							|  |  |  |  |       (delete-horizontal-space) | 
					
						
							|  |  |  |  |       (indent-to target) | 
					
						
							|  |  |  |  |       (if (> (- (point-max) pos) (point)) | 
					
						
							|  |  |  |  |           (goto-char (- (point-max) pos)))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  |  | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | ;; Factor mode: | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | (defvar factor-mode-map (make-sparse-keymap) | 
					
						
							|  |  |  |  |   "Key map used by Factor mode.") | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-30 07:53:15 -05:00
										 |  |  |  | (defsubst factor--beginning-of-defun (&optional times) | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |   (re-search-backward factor--regex-begin-of-def nil t times)) | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor--end-of-defun () | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |   (re-search-forward factor--regex-end-of-def nil t)) | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | ;;;###autoload | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  | (defun factor-mode () | 
					
						
							|  |  |  |  |   "A mode for editing programs written in the Factor programming language.
 | 
					
						
							|  |  |  |  | \\{factor-mode-map}"
 | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (kill-all-local-variables) | 
					
						
							|  |  |  |  |   (use-local-map factor-mode-map) | 
					
						
							|  |  |  |  |   (setq major-mode 'factor-mode) | 
					
						
							|  |  |  |  |   (setq mode-name "Factor") | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |   ;; Font locking | 
					
						
							| 
									
										
										
										
											2008-11-16 10:21:47 -05:00
										 |  |  |  |   (set (make-local-variable 'comment-start) "! ") | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |   (set (make-local-variable 'parse-sexp-lookup-properties) t) | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  |   (set (make-local-variable 'font-lock-comment-face) 'factor-font-lock-comment) | 
					
						
							|  |  |  |  |   (set (make-local-variable 'font-lock-string-face) 'factor-font-lock-string) | 
					
						
							| 
									
										
										
										
											2008-11-16 10:21:47 -05:00
										 |  |  |  |   (set (make-local-variable 'font-lock-defaults) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |        `(factor--font-lock-keywords | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  |          nil nil nil nil | 
					
						
							|  |  |  |  |          (font-lock-syntactic-keywords . ,factor--font-lock-syntactic-keywords))) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   (set-syntax-table factor-mode-syntax-table) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |   ;; Defun navigation | 
					
						
							| 
									
										
										
										
											2008-11-28 16:51:36 -05:00
										 |  |  |  |   (set (make-local-variable 'beginning-of-defun-function) 'factor--beginning-of-defun) | 
					
						
							|  |  |  |  |   (set (make-local-variable 'end-of-defun-function) 'factor--end-of-defun) | 
					
						
							|  |  |  |  |   (set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |   ;; Indentation | 
					
						
							| 
									
										
										
										
											2008-11-18 18:59:43 -05:00
										 |  |  |  |   (set (make-local-variable 'indent-line-function) 'factor--indent-line) | 
					
						
							| 
									
										
										
										
											2008-11-16 10:21:47 -05:00
										 |  |  |  |   (setq factor-indent-width (factor--guess-indent-width)) | 
					
						
							|  |  |  |  |   (setq indent-tabs-mode nil) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  |   ;; ElDoc | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  |   (set (make-local-variable 'eldoc-documentation-function) 'factor--eldoc) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-15 21:16:57 -05:00
										 |  |  |  |   (run-hooks 'factor-mode-hook)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (add-to-list 'auto-mode-alist '("\\.factor\\'" . factor-mode)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  |  | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | ;;; Factor listener mode: | 
					
						
							| 
									
										
										
										
											2007-11-25 14:37:05 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-17 21:47:13 -05:00
										 |  |  |  | ;;;###autoload | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (define-derived-mode factor-listener-mode comint-mode "Factor Listener" | 
					
						
							|  |  |  |  |   "Major mode for interacting with an inferior Factor listener process.
 | 
					
						
							|  |  |  |  | \\{factor-listener-mode-map}"
 | 
					
						
							|  |  |  |  |   (set (make-local-variable 'comint-prompt-regexp) "^( [^)]+ ) ")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defvar factor--listener-buffer nil | 
					
						
							|  |  |  |  |   "The buffer in which the Factor listener is running.") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--listener-start-process () | 
					
						
							|  |  |  |  |   "Start an inferior Factor listener process, using
 | 
					
						
							|  |  |  |  | `factor-binary' and `factor-image'."
 | 
					
						
							|  |  |  |  |   (setq factor--listener-buffer | 
					
						
							|  |  |  |  |         (apply 'make-comint "factor" (expand-file-name factor-binary) nil | 
					
						
							|  |  |  |  |                `("-run=listener" ,(format "-i=%s" (expand-file-name factor-image))))) | 
					
						
							|  |  |  |  |   (with-current-buffer factor--listener-buffer | 
					
						
							|  |  |  |  |     (factor-listener-mode))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  | (defun factor--listener-process (&optional start) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |   (or (and (buffer-live-p factor--listener-buffer) | 
					
						
							|  |  |  |  |            (get-buffer-process factor--listener-buffer)) | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |       (if (not start) | 
					
						
							|  |  |  |  |           (error "No running factor listener. Try M-x run-factor.") | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  |         (factor--listener-start-process) | 
					
						
							|  |  |  |  |         (factor--listener-process t)))) | 
					
						
							| 
									
										
										
										
											2007-11-25 14:37:05 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-17 21:47:13 -05:00
										 |  |  |  | ;;;###autoload | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (defalias 'switch-to-factor 'run-factor) | 
					
						
							|  |  |  |  | ;;;###autoload | 
					
						
							|  |  |  |  | (defun run-factor (&optional arg) | 
					
						
							|  |  |  |  |   "Show the factor-listener buffer, starting the process if needed." | 
					
						
							| 
									
										
										
										
											2007-11-25 14:37:05 -05:00
										 |  |  |  |   (interactive) | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  |   (let ((buf (process-buffer (factor--listener-process t))) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |         (pop-up-windows factor-listener-window-allow-split)) | 
					
						
							|  |  |  |  |     (if factor-listener-use-other-window | 
					
						
							|  |  |  |  |         (pop-to-buffer buf) | 
					
						
							|  |  |  |  |       (switch-to-buffer buf)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | (defun factor-telnet-to-port (port) | 
					
						
							|  |  |  |  |   (interactive "nPort: ") | 
					
						
							|  |  |  |  |   (switch-to-buffer | 
					
						
							|  |  |  |  |    (make-comint-in-buffer "factor-telnet" nil (cons "localhost" port)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-telnet () | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (factor-telnet-to-port 9000)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-telnet-factory () | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (factor-telnet-to-port 9010)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Factor listener interaction: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--listener-send-cmd (cmd) | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  |   (let ((proc (factor--listener-process))) | 
					
						
							|  |  |  |  |     (when proc | 
					
						
							|  |  |  |  |       (let* ((out (get-buffer-create "*factor messages*")) | 
					
						
							|  |  |  |  |              (beg (with-current-buffer out (goto-char (point-max))))) | 
					
						
							|  |  |  |  |         (comint-redirect-send-command-to-process cmd out proc nil t) | 
					
						
							|  |  |  |  |         (with-current-buffer factor--listener-buffer | 
					
						
							|  |  |  |  |           (while (not comint-redirect-completed) (sleep-for 0 1))) | 
					
						
							|  |  |  |  |         (with-current-buffer out | 
					
						
							|  |  |  |  |           (split-string (buffer-substring-no-properties beg (point-max)) | 
					
						
							|  |  |  |  |                         "[\"\f\n\r\v]+" t)))))) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;;;; Current vocabulary: | 
					
						
							|  |  |  |  | (make-variable-buffer-local | 
					
						
							|  |  |  |  |  (defvar factor--current-vocab nil | 
					
						
							|  |  |  |  |    "Current vocabulary.")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regexp-current-vocab "^IN: +\\([^ \r\n\f]+\\)") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--current-buffer-vocab () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (when (or (re-search-backward factor--regexp-current-vocab nil t) | 
					
						
							|  |  |  |  |               (re-search-forward factor--regexp-current-vocab nil t)) | 
					
						
							|  |  |  |  |       (setq factor--current-vocab (match-string-no-properties 1))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--current-listener-vocab () | 
					
						
							|  |  |  |  |   (car (factor--listener-send-cmd "USING: parser ; in get ."))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--set-current-listener-vocab (&optional vocab) | 
					
						
							|  |  |  |  |   (factor--listener-send-cmd | 
					
						
							|  |  |  |  |    (format "IN: %s" (or vocab (factor--current-buffer-vocab)))) | 
					
						
							|  |  |  |  |   t) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defmacro factor--with-vocab (vocab &rest body) | 
					
						
							|  |  |  |  |   (let ((current (make-symbol "current"))) | 
					
						
							|  |  |  |  |     `(let ((,current (factor--current-listener-vocab))) | 
					
						
							|  |  |  |  |        (factor--set-current-listener-vocab ,vocab) | 
					
						
							|  |  |  |  |        (prog1 (condition-case nil (progn . ,body) (error nil)) | 
					
						
							|  |  |  |  |          (factor--set-current-listener-vocab ,current))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (put 'factor--with-vocab 'lisp-indent-function 1) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;;;; Synchronous interaction: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  | (defsubst factor--listener-vocab-cmds (cmds &optional vocab) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  |   (factor--with-vocab vocab | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  |     (mapcar #'factor--listener-send-cmd cmds))) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  | (defsubst factor--listener-vocab-cmd (cmd &optional vocab) | 
					
						
							|  |  |  |  |   (factor--with-vocab vocab | 
					
						
							|  |  |  |  |     (factor--listener-send-cmd cmd))) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-29 09:45:00 -05:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | ;;;;; Buffer cycling and docs | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--cycle-endings | 
					
						
							|  |  |  |  |   '(".factor" "-tests.factor" "-docs.factor")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regex-cycle-endings | 
					
						
							|  |  |  |  |   (format "\\(.*?\\)\\(%s\\)$" | 
					
						
							|  |  |  |  |           (regexp-opt factor--cycle-endings))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--cycle-endings-ring | 
					
						
							|  |  |  |  |   (let ((ring (make-ring (length factor--cycle-endings)))) | 
					
						
							|  |  |  |  |     (dolist (e factor--cycle-endings ring) | 
					
						
							|  |  |  |  |       (ring-insert ring e)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--cycle-next (file) | 
					
						
							|  |  |  |  |   (let* ((match (string-match factor--regex-cycle-endings file)) | 
					
						
							|  |  |  |  |          (base (and match (match-string-no-properties 1 file))) | 
					
						
							|  |  |  |  |          (ending (and match (match-string-no-properties 2 file))) | 
					
						
							|  |  |  |  |          (idx (and ending (ring-member factor--cycle-endings-ring ending))) | 
					
						
							|  |  |  |  |          (gfl (lambda (i) (concat base (ring-ref factor--cycle-endings-ring i))))) | 
					
						
							|  |  |  |  |     (if (not idx) file | 
					
						
							|  |  |  |  |       (let ((l (length factor--cycle-endings)) (i 1) next) | 
					
						
							|  |  |  |  |         (while (and (not next) (< i l)) | 
					
						
							|  |  |  |  |           (when (file-exists-p (funcall gfl (+ idx i))) | 
					
						
							|  |  |  |  |             (setq next (+ idx i))) | 
					
						
							|  |  |  |  |           (setq i (1+ i))) | 
					
						
							|  |  |  |  |         (funcall gfl (or next idx)))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-visit-other-file (&optional file) | 
					
						
							|  |  |  |  |   "Cycle between code, tests and docs factor files." | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (find-file (factor--cycle-next (or file (buffer-file-name))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | ;;;;; Interface: See | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--regex-error-marker "^Type :help for debugging") | 
					
						
							|  |  |  |  | (defconst factor--regex-data-stack "^--- Data stack:") | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 07:23:15 -05:00
										 |  |  |  | (defun factor--prune-ans-strings (ans) | 
					
						
							|  |  |  |  |   (nreverse | 
					
						
							|  |  |  |  |    (catch 'done | 
					
						
							|  |  |  |  |      (let ((res)) | 
					
						
							|  |  |  |  |        (dolist (a ans res) | 
					
						
							|  |  |  |  |          (cond ((string-match factor--regex-stack-effect a) | 
					
						
							|  |  |  |  |                 (throw 'done (cons a res))) | 
					
						
							|  |  |  |  |                ((string-match factor--regex-data-stack a) | 
					
						
							|  |  |  |  |                 (throw 'done res)) | 
					
						
							|  |  |  |  |                ((string-match factor--regex-error-marker a) | 
					
						
							|  |  |  |  |                 (throw 'done nil)) | 
					
						
							|  |  |  |  |                (t (push a res)))))))) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--see-ans-to-string (ans) | 
					
						
							| 
									
										
										
										
											2008-11-28 07:23:15 -05:00
										 |  |  |  |   (let ((s (mapconcat #'identity (factor--prune-ans-strings ans) " ")) | 
					
						
							|  |  |  |  |         (font-lock-verbose nil)) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  |     (and (> (length s) 0) | 
					
						
							| 
									
										
										
										
											2008-11-28 07:23:15 -05:00
										 |  |  |  |          (with-temp-buffer | 
					
						
							|  |  |  |  |            (insert s) | 
					
						
							|  |  |  |  |            (factor-mode) | 
					
						
							|  |  |  |  |            (font-lock-fontify-buffer) | 
					
						
							|  |  |  |  |            (buffer-string))))) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--see-current-word (&optional word) | 
					
						
							|  |  |  |  |   (let ((word (or word (factor--symbol-at-point)))) | 
					
						
							|  |  |  |  |     (when word | 
					
						
							|  |  |  |  |       (let ((answer (factor--listener-send-cmd (format "\\ %s see" word)))) | 
					
						
							| 
									
										
										
										
											2008-11-27 20:37:49 -05:00
										 |  |  |  |         (and answer (factor--see-ans-to-string answer)))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defalias 'factor--eldoc 'factor--see-current-word) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-see-current-word (&optional word) | 
					
						
							|  |  |  |  |   "Echo in the minibuffer information about word at point." | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |   (let* ((proc (factor--listener-process)) | 
					
						
							|  |  |  |  |          (word (or word (factor--symbol-at-point))) | 
					
						
							|  |  |  |  |          (msg (factor--see-current-word word))) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  |     (if msg (message "%s" msg) | 
					
						
							|  |  |  |  |       (if word (message "No help found for '%s'" word) | 
					
						
							|  |  |  |  |         (message "No word at point"))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;; to fix: | 
					
						
							|  |  |  |  | (defun factor-run-file () | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (when (and (buffer-modified-p) | 
					
						
							|  |  |  |  |              (y-or-n-p (format "Save file %s? " (buffer-file-name)))) | 
					
						
							|  |  |  |  |     (save-buffer)) | 
					
						
							|  |  |  |  |   (when factor-display-compilation-output | 
					
						
							|  |  |  |  |     (factor-display-output-buffer)) | 
					
						
							|  |  |  |  |   (comint-send-string "*factor*" (format "\"%s\"" (buffer-file-name))) | 
					
						
							|  |  |  |  |   (comint-send-string "*factor*" " run-file\n")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-display-output-buffer () | 
					
						
							|  |  |  |  |   (with-current-buffer "*factor*" | 
					
						
							|  |  |  |  |     (goto-char (point-max)) | 
					
						
							|  |  |  |  |     (unless (get-buffer-window (current-buffer) t) | 
					
						
							|  |  |  |  |       (display-buffer (current-buffer) t)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-send-string (str) | 
					
						
							|  |  |  |  |   (let ((n (length (split-string str "\n")))) | 
					
						
							|  |  |  |  |     (save-excursion | 
					
						
							|  |  |  |  |       (set-buffer "*factor*") | 
					
						
							|  |  |  |  |       (goto-char (point-max)) | 
					
						
							|  |  |  |  |       (if (> n 1) (newline)) | 
					
						
							|  |  |  |  |       (insert str) | 
					
						
							|  |  |  |  |       (comint-send-input)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-send-region (start end) | 
					
						
							|  |  |  |  |   (interactive "r") | 
					
						
							|  |  |  |  |   (let ((str (buffer-substring start end)) | 
					
						
							|  |  |  |  |         (n   (count-lines      start end))) | 
					
						
							|  |  |  |  |     (save-excursion | 
					
						
							|  |  |  |  |       (set-buffer "*factor*") | 
					
						
							|  |  |  |  |       (goto-char (point-max)) | 
					
						
							|  |  |  |  |       (if (> n 1) (newline)) | 
					
						
							|  |  |  |  |       (insert str) | 
					
						
							|  |  |  |  |       (comint-send-input)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-send-definition () | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (factor-send-region (search-backward ":") | 
					
						
							|  |  |  |  |                       (search-forward  ";"))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-edit () | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (comint-send-string "*factor*" "\\ ") | 
					
						
							|  |  |  |  |   (comint-send-string "*factor*" (thing-at-point 'sexp)) | 
					
						
							|  |  |  |  |   (comint-send-string "*factor*" " edit\n")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-clear () | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (factor-send-string "clear")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-comment-line () | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (beginning-of-line) | 
					
						
							|  |  |  |  |   (insert "! ")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | ;;;; Factor help mode: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defvar factor-help-mode-map (make-sparse-keymap) | 
					
						
							|  |  |  |  |   "Keymap for Factor help mode.") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--help-headlines | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  |   (regexp-opt '("Definition" | 
					
						
							|  |  |  |  |                 "Examples" | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |                 "Generic word contract" | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  |                 "Inputs and outputs" | 
					
						
							|  |  |  |  |                 "Parent topics:" | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |                 "See also" | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  |                 "Syntax" | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |                 "Vocabulary" | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  |                 "Warning" | 
					
						
							|  |  |  |  |                 "Word description") | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |               t)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--help-headlines-regexp (format "^%s" factor--help-headlines)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor--help-font-lock-keywords | 
					
						
							|  |  |  |  |   `((,factor--help-headlines-regexp . 'factor-font-lock-help-mode-headlines) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |     ,@factor--font-lock-keywords)) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-help-mode () | 
					
						
							|  |  |  |  |   "Major mode for displaying Factor help messages.
 | 
					
						
							|  |  |  |  | \\{factor-help-mode-map}"
 | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (kill-all-local-variables) | 
					
						
							|  |  |  |  |   (use-local-map factor-help-mode-map) | 
					
						
							|  |  |  |  |   (setq mode-name "Factor Help") | 
					
						
							|  |  |  |  |   (setq major-mode 'factor-help-mode) | 
					
						
							|  |  |  |  |   (set (make-local-variable 'font-lock-defaults) | 
					
						
							|  |  |  |  |        '(factor--help-font-lock-keywords t nil nil nil)) | 
					
						
							|  |  |  |  |   (set (make-local-variable 'comint-redirect-subvert-readonly) t) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |   (set (make-local-variable 'comint-redirect-echo-input) nil) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |   (set (make-local-variable 'view-no-disable-on-exit) t) | 
					
						
							|  |  |  |  |   (view-mode) | 
					
						
							|  |  |  |  |   (setq view-exit-action | 
					
						
							|  |  |  |  |         (lambda (buffer) | 
					
						
							|  |  |  |  |           ;; Use `with-current-buffer' to make sure that `bury-buffer' | 
					
						
							|  |  |  |  |           ;; also removes BUFFER from the selected window. | 
					
						
							|  |  |  |  |           (with-current-buffer buffer | 
					
						
							|  |  |  |  |             (bury-buffer)))) | 
					
						
							|  |  |  |  |   (run-mode-hooks 'factor-help-mode-hook)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--listener-help-buffer () | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |   (with-current-buffer (get-buffer-create "*factor-help*") | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  |     (let ((inhibit-read-only t)) (erase-buffer)) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |     (factor-help-mode) | 
					
						
							|  |  |  |  |     (current-buffer))) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defvar factor--help-history nil) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor--listener-show-help (&optional see) | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |   (let* ((proc (factor--listener-process)) | 
					
						
							|  |  |  |  |          (def (factor--symbol-at-point)) | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  |          (prompt (format "See%s help on%s: " (if see " short" "") | 
					
						
							|  |  |  |  |                          (if def (format " (%s)" def) ""))) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |          (ask (or (not (eq major-mode 'factor-mode)) | 
					
						
							|  |  |  |  |                   (not def) | 
					
						
							|  |  |  |  |                   factor-help-always-ask)) | 
					
						
							|  |  |  |  |          (cmd (format "\\ %s %s" | 
					
						
							|  |  |  |  |                       (if ask (read-string prompt nil 'factor--help-history def) def) | 
					
						
							|  |  |  |  |                       (if see "see" "help"))) | 
					
						
							| 
									
										
										
										
											2008-11-28 21:49:35 -05:00
										 |  |  |  |          (hb (factor--listener-help-buffer))) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |     (comint-redirect-send-command-to-process cmd hb proc nil) | 
					
						
							| 
									
										
										
										
											2008-11-24 04:18:47 -05:00
										 |  |  |  |     (pop-to-buffer hb) | 
					
						
							|  |  |  |  |     (beginning-of-buffer hb))) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  | ;;;; Interface: see/help commands | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-see (&optional arg) | 
					
						
							|  |  |  |  |   "See a help summary of symbol at point.
 | 
					
						
							|  |  |  |  | By default, the information is shown in the minibuffer. When | 
					
						
							|  |  |  |  | called with a prefix argument, the information is displayed in a | 
					
						
							|  |  |  |  | separate help buffer."
 | 
					
						
							|  |  |  |  |   (interactive "P") | 
					
						
							|  |  |  |  |   (if (if factor-help-use-minibuffer (not arg) arg) | 
					
						
							|  |  |  |  |       (factor-see-current-word) | 
					
						
							|  |  |  |  |     (factor--listener-show-help t))) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-help () | 
					
						
							| 
									
										
										
										
											2008-11-27 19:51:33 -05:00
										 |  |  |  |   "Show extended help about the symbol at point, using a help
 | 
					
						
							|  |  |  |  | buffer."
 | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (factor--listener-show-help)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2007-11-25 14:37:05 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-refresh-all () | 
					
						
							| 
									
										
										
										
											2008-11-17 21:47:13 -05:00
										 |  |  |  |   "Reload source files and documentation for all loaded
 | 
					
						
							|  |  |  |  | vocabularies which have been modified on disk."
 | 
					
						
							| 
									
										
										
										
											2007-11-25 14:37:05 -05:00
										 |  |  |  |   (interactive) | 
					
						
							| 
									
										
										
										
											2008-03-16 17:57:37 -04:00
										 |  |  |  |   (comint-send-string "*factor*" "refresh-all\n")) | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | ;;; Key bindings: | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-25 05:48:11 -05:00
										 |  |  |  | (defun factor--define-key (key cmd &optional both) | 
					
						
							|  |  |  |  |   (let ((ms (list factor-mode-map))) | 
					
						
							|  |  |  |  |     (when both (push factor-help-mode-map ms)) | 
					
						
							|  |  |  |  |     (dolist (m ms) | 
					
						
							|  |  |  |  |       (define-key m (vector '(control ?c) key) cmd) | 
					
						
							|  |  |  |  |       (define-key m (vector '(control ?c) `(control ,key)) cmd)))) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 19:55:08 -05:00
										 |  |  |  | (defun factor--define-auto-indent-key (key) | 
					
						
							|  |  |  |  |   (define-key factor-mode-map (vector key) | 
					
						
							|  |  |  |  |     (lambda (n) | 
					
						
							|  |  |  |  |       (interactive "p") | 
					
						
							|  |  |  |  |       (self-insert-command n) | 
					
						
							|  |  |  |  |       (indent-for-tab-command)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (factor--define-key ?f 'factor-run-file) | 
					
						
							|  |  |  |  | (factor--define-key ?r 'factor-send-region) | 
					
						
							|  |  |  |  | (factor--define-key ?d 'factor-send-definition) | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  | (factor--define-key ?s 'factor-see t) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (factor--define-key ?e 'factor-edit) | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  | (factor--define-key ?z 'switch-to-factor t) | 
					
						
							| 
									
										
										
										
											2008-11-29 09:45:00 -05:00
										 |  |  |  | (factor--define-key ?o 'factor-visit-other-file) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (factor--define-key ?c 'comment-region) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-28 19:55:08 -05:00
										 |  |  |  | (factor--define-auto-indent-key ?\]) | 
					
						
							|  |  |  |  | (factor--define-auto-indent-key ?\}) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (define-key factor-mode-map "\C-ch" 'factor-help) | 
					
						
							| 
									
										
										
										
											2008-11-23 18:45:48 -05:00
										 |  |  |  | (define-key factor-help-mode-map "\C-ch" 'factor-help) | 
					
						
							| 
									
										
										
										
											2008-11-21 22:22:38 -05:00
										 |  |  |  | (define-key factor-mode-map "\C-m" 'newline-and-indent) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (define-key factor-listener-mode-map [f8] 'factor-refresh-all) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2008-11-16 16:10:19 -05:00
										 |  |  |  | (provide 'factor) | 
					
						
							|  |  |  |  | ;;; factor.el ends here |