| 
									
										
										
										
											2013-05-07 02:03:26 -04:00
										 |  |  |  | ;;; factor-mode.el --- Major mode for editing Factor programs. | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | ;; Copyright (C) 2013 Erik Charlebois | 
					
						
							| 
									
										
										
										
											2010-08-12 22:25:57 -04:00
										 |  |  |  | ;; Copyright (C) 2008, 2009, 2010 Jose Antonio Ortega Ruiz | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | ;; See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | ;; Maintainer: Erik Charlebois <erikcharlebois@gmail.com> | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org> | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | ;; Keywords: languages, factor | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | ;; Start date: Tue Dec 02, 2008 21:32 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 02:03:26 -04:00
										 |  |  |  | ;;; Commentary: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ;; A major mode for editing Factor programs. It provides indenting and | 
					
						
							|  |  |  |  | ;; font-lock support. | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;; Code: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (require 'thingatpt) | 
					
						
							|  |  |  |  | (require 'font-lock) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | (require 'ring) | 
					
						
							| 
									
										
										
										
											2013-07-13 13:13:39 -04:00
										 |  |  |  | (require 'fuel-base) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;; Customization: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | ;;;###autoload | 
					
						
							|  |  |  |  | (defgroup factor nil | 
					
						
							| 
									
										
										
										
											2008-12-21 21:07:45 -05:00
										 |  |  |  |   "Major mode for Factor source code." | 
					
						
							|  |  |  |  |   :group 'languages) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defcustom factor-cycling-no-ask nil | 
					
						
							|  |  |  |  |   "Whether to never create source/doc/tests file when cycling." | 
					
						
							|  |  |  |  |   :type 'boolean | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defcustom factor-cycle-always-ask-p t | 
					
						
							|  |  |  |  |   "Whether to always ask for file creation when cycling to a
 | 
					
						
							|  |  |  |  | source/docs/tests file. When set to false, you'll be asked only once."
 | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |   :type 'boolean | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |   :group 'factor) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-07 17:53:24 -04:00
										 |  |  |  | (defcustom factor-indent-level 4 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |   "Indentation of Factor statements." | 
					
						
							|  |  |  |  |   :type 'integer | 
					
						
							|  |  |  |  |   :safe 'integerp | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defcustom factor-comment-column 32 | 
					
						
							|  |  |  |  |   "Indentation column of comments." | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |   :type 'integer | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |   :safe 'integerp | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 07:43:39 -04:00
										 |  |  |  | (defcustom factor-mode-use-fuel t | 
					
						
							|  |  |  |  |   "Whether to use the full FUEL facilities in factor mode.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | Set this variable to nil if you just want to use Emacs as the | 
					
						
							|  |  |  |  | external editor of your Factor environment, e.g., by putting | 
					
						
							|  |  |  |  | these lines in your .emacs: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   (add-to-list 'load-path \"/path/to/factor/misc/fuel\") | 
					
						
							|  |  |  |  |   (setq factor-mode-use-fuel nil) | 
					
						
							|  |  |  |  |   (require 'factor-mode) | 
					
						
							|  |  |  |  | "
 | 
					
						
							|  |  |  |  |   :type 'boolean | 
					
						
							|  |  |  |  |   :group 'factor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Faces: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;;###autoload | 
					
						
							|  |  |  |  | (defgroup factor-faces nil | 
					
						
							|  |  |  |  |   "Faces used by factor-mode." | 
					
						
							|  |  |  |  |   :group 'factor | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-constructor '((t (:inherit font-lock-type-face))) | 
					
						
							|  |  |  |  |   "Factor for constructor words." | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-constant '((t (:inherit font-lock-constant-face))) | 
					
						
							|  |  |  |  |   "Face for constant and literal values." | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-number '((t (:inherit font-lock-constant-face))) | 
					
						
							|  |  |  |  |   "Face for integer and floating-point constants." | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-ratio '((t (:inherit font-lock-constant-face))) | 
					
						
							|  |  |  |  |   "Face for ratio constants." | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-parsing-word '((t (:inherit font-lock-keyword-face))) | 
					
						
							|  |  |  |  |   "parsing words" | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-setter-word | 
					
						
							|  |  |  |  |   '((t (:inherit font-lock-function-name-face))) | 
					
						
							|  |  |  |  |   "setter words (>>foo)" | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-getter-word | 
					
						
							|  |  |  |  |   '((t (:inherit font-lock-function-name-face))) | 
					
						
							|  |  |  |  |   "getter words (foo>>)" | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-string '((t (:inherit font-lock-string-face))) | 
					
						
							|  |  |  |  |   "strings" | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-symbol '((t (:inherit font-lock-variable-name-face))) | 
					
						
							|  |  |  |  |   "name of symbol being defined" | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-type-name '((t (:inherit font-lock-type-face))) | 
					
						
							|  |  |  |  |   "type names" | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-vocabulary-name | 
					
						
							|  |  |  |  |   '((t (:inherit font-lock-constant-face))) | 
					
						
							|  |  |  |  |   "vocabulary names" | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-word | 
					
						
							|  |  |  |  |   '((t (:inherit font-lock-function-name-face))) | 
					
						
							|  |  |  |  |   "Face for the word, generic or method being defined." | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-invalid-syntax | 
					
						
							|  |  |  |  |   '((t (:inherit font-lock-warning-face))) | 
					
						
							|  |  |  |  |   "syntactically invalid constructs" | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-comment '((t (:inherit font-lock-comment-face))) | 
					
						
							|  |  |  |  |   "Face for Factor comments." | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defface factor-font-lock-stack-effect '((t :inherit font-lock-comment-face)) | 
					
						
							|  |  |  |  |   "Face for Factor stack effect declarations." | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-20 10:35:49 -04:00
										 |  |  |  | (defface factor-font-lock-type-in-stack-effect '((t :inherit font-lock-comment-face | 
					
						
							|  |  |  |  |                                                     :bold t)) | 
					
						
							|  |  |  |  |   "Face for Factor types in stack effect declarations." | 
					
						
							|  |  |  |  |   :group 'factor-faces | 
					
						
							|  |  |  |  |   :group 'faces) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |  | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | ;;; Thing-at-point: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-beginning-of-symbol () | 
					
						
							|  |  |  |  |   "Move point to the beginning of the current symbol." | 
					
						
							| 
									
										
										
										
											2016-03-13 03:36:31 -04:00
										 |  |  |  |   (skip-syntax-backward "w_()\"")) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-end-of-symbol () | 
					
						
							|  |  |  |  |   "Move point to the end of the current symbol." | 
					
						
							| 
									
										
										
										
											2016-03-13 03:36:31 -04:00
										 |  |  |  |   (skip-syntax-forward "w_()\"")) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-27 18:17:01 -04:00
										 |  |  |  | (put 'factor-symbol 'end-op 'factor-end-of-symbol) | 
					
						
							|  |  |  |  | (put 'factor-symbol 'beginning-op 'factor-beginning-of-symbol) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-13 03:36:31 -04:00
										 |  |  |  | (defun factor-symbol-at-point () | 
					
						
							| 
									
										
										
										
											2016-03-27 18:17:01 -04:00
										 |  |  |  |   (let ((thing (thing-at-point 'factor-symbol t))) | 
					
						
							| 
									
										
										
										
											2016-03-13 03:36:31 -04:00
										 |  |  |  |     (and (> (length thing) 0) thing))) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | ;;; Regexps galore: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-20 08:09:10 -04:00
										 |  |  |  | ;; Utility regexp used by other regexps to match a Factor symbol name | 
					
						
							| 
									
										
										
										
											2015-08-04 19:41:33 -04:00
										 |  |  |  | (setq-local symbol "\\(\\(?:\\sw\\|\\s_\\|\\s(\\|\\s)\\)+\\)") | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  | (setq-local ws+ "[ \n\t]+") | 
					
						
							|  |  |  |  | (setq-local symbols-to-semicolon "\\([^;\t]*\\)\\(;\\)") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun one-symbol (content) | 
					
						
							|  |  |  |  |   (concat "\\_<\\(" content "\\)\\_>")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun syntax-begin (content) | 
					
						
							|  |  |  |  |   (one-symbol (concat (regexp-opt content) ":"))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-04 20:28:07 -04:00
										 |  |  |  | (defun syntax-and-1-symbol (prefixes) | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  |   (concat (syntax-begin prefixes) ws+ symbol)) | 
					
						
							| 
									
										
										
										
											2013-09-20 08:09:10 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-04 20:28:07 -04:00
										 |  |  |  | (defun syntax-and-2-symbols (prefixes) | 
					
						
							| 
									
										
										
										
											2015-08-05 07:57:53 -04:00
										 |  |  |  |   (concat (syntax-and-1-symbol prefixes) ws+ symbol)) | 
					
						
							| 
									
										
										
										
											2015-08-04 20:28:07 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-01 08:37:23 -05:00
										 |  |  |  | ;; Used to font-lock stack effect declarations with may be nested. | 
					
						
							|  |  |  |  | (defun factor-match-brackets (limit) | 
					
						
							|  |  |  |  |   (let ((start (point))) | 
					
						
							|  |  |  |  |     (when (re-search-forward "[ \n]([ \n]" limit t) | 
					
						
							|  |  |  |  |       (backward-char 2) | 
					
						
							|  |  |  |  |       (let ((bracket-start (point))) | 
					
						
							| 
									
										
										
										
											2013-12-03 09:47:40 -05:00
										 |  |  |  |         (when (condition-case nil | 
					
						
							|  |  |  |  |                   (progn (forward-sexp) 't) | 
					
						
							|  |  |  |  |                 ('scan-error nil)) | 
					
						
							|  |  |  |  |           (let ((bracket-stop (point))) | 
					
						
							|  |  |  |  |             (goto-char bracket-start) | 
					
						
							| 
									
										
										
										
											2015-08-04 19:41:33 -04:00
										 |  |  |  |             (re-search-forward "\\(.\\|\n\\)+" bracket-stop 'mv))))))) | 
					
						
							| 
									
										
										
										
											2013-12-01 08:37:23 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-05 12:39:11 -04:00
										 |  |  |  | ;; Excludes parsing words that are handled by other regexps | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defconst factor-parsing-words | 
					
						
							| 
									
										
										
										
											2015-07-12 19:30:59 -04:00
										 |  |  |  |   '(":" "::" ";" ":>" "&:" "<<" "<PRIVATE" ">>" | 
					
						
							| 
									
										
										
										
											2015-08-05 10:58:27 -04:00
										 |  |  |  |     "ABOUT:" "ARTICLE:" | 
					
						
							|  |  |  |  |     "B" | 
					
						
							|  |  |  |  |     "COLOR:" | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     "CONSULT:" "call-next-method" | 
					
						
							| 
									
										
										
										
											2015-12-04 06:43:01 -05:00
										 |  |  |  |     "EBNF:" ";EBNF" | 
					
						
							| 
									
										
										
										
											2013-12-01 08:17:14 -05:00
										 |  |  |  |     "FOREIGN-ATOMIC-TYPE:" "FOREIGN-ENUM-TYPE:" "FOREIGN-RECORD-TYPE:" "FUNCTION-ALIAS:" | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  |     "GIR:" | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     "GLSL-SHADER:" "GLSL-PROGRAM:" | 
					
						
							| 
									
										
										
										
											2015-08-05 07:57:53 -04:00
										 |  |  |  |     "HINTS:" | 
					
						
							| 
									
										
										
										
											2016-03-11 01:36:23 -05:00
										 |  |  |  |     "initial:" "IMPLEMENT-STRUCTS:" | 
					
						
							| 
									
										
										
										
											2015-12-04 06:43:01 -05:00
										 |  |  |  |     "MATH:" | 
					
						
							| 
									
										
										
										
											2015-10-14 20:41:40 -04:00
										 |  |  |  |     "METHOD:" | 
					
						
							| 
									
										
										
										
											2015-08-05 07:57:53 -04:00
										 |  |  |  |     "PRIVATE>" "PROTOCOL:" "PROVIDE:" | 
					
						
							| 
									
										
										
										
											2016-03-11 01:36:23 -05:00
										 |  |  |  |     "read-only" | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  |     "SLOT:" | 
					
						
							| 
									
										
										
										
											2016-03-11 01:36:23 -05:00
										 |  |  |  |     "STRING:" "SYNTAX:" | 
					
						
							| 
									
										
										
										
											2015-06-07 18:59:12 -04:00
										 |  |  |  |     "UNIFORM-TUPLE:" | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     "VARIANT:" "VERTEX-FORMAT:")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-parsing-words-regex | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  |   (format "\\(?:^\\| \\)%s" (regexp-opt factor-parsing-words 'symbols))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-constant-words | 
					
						
							|  |  |  |  |   '("f" "t")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-constant-words-regex | 
					
						
							|  |  |  |  |   (regexp-opt factor-constant-words 'symbols)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-bracer-words | 
					
						
							| 
									
										
										
										
											2015-12-04 06:43:01 -05:00
										 |  |  |  |   '("B" "BV" "C" "CS" "H" "HS" "S" "T" "V" "W")) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-brace-words-regex | 
					
						
							|  |  |  |  |   (format "%s{" (regexp-opt factor-bracer-words t))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-declaration-words | 
					
						
							| 
									
										
										
										
											2014-04-17 20:47:28 -04:00
										 |  |  |  |   '("deprecated" | 
					
						
							| 
									
										
										
										
											2015-10-14 20:41:40 -04:00
										 |  |  |  |     "final" | 
					
						
							| 
									
										
										
										
											2014-04-17 20:47:28 -04:00
										 |  |  |  |     "flushable" | 
					
						
							|  |  |  |  |     "foldable" | 
					
						
							|  |  |  |  |     "inline" | 
					
						
							|  |  |  |  |     "parsing" | 
					
						
							|  |  |  |  |     "recursive" | 
					
						
							|  |  |  |  |     "delimiter")) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-declaration-words-regex | 
					
						
							|  |  |  |  |   (regexp-opt factor-declaration-words 'symbols)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-integer-regex | 
					
						
							| 
									
										
										
										
											2015-10-14 20:41:40 -04:00
										 |  |  |  |   "\\_<-?\\(0[xob][0-9a-fA-F]+\\|[0-9][0-9,]*\\)\\_>") | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-raw-float-regex | 
					
						
							|  |  |  |  |   "[0-9]*\\.[0-9]*\\([eEpP][+-]?[0-9]+\\)?") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-float-regex | 
					
						
							|  |  |  |  |   (format "\\_<-?%s\\_>" factor-raw-float-regex)) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defconst factor-number-regex | 
					
						
							|  |  |  |  |   (format "\\([0-9]+\\|%s\\)" factor-raw-float-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-ratio-regex | 
					
						
							|  |  |  |  |   (format "\\_<[+-]?%s/-?%s\\_>" factor-number-regex factor-number-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-bad-string-regex | 
					
						
							|  |  |  |  |   "\\_<\"[^>]\\([^\"\n]\\|\\\\\"\\)*\n") | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  | (defconst factor-word-starters | 
					
						
							|  |  |  |  |   '(":" "::" "GENERIC:" "GENERIC#" "DEFER:" "HOOK:" | 
					
						
							|  |  |  |  |     "MACRO:" "MACRO::" "MATH:" "MEMO:" "MEMO::" | 
					
						
							|  |  |  |  |     "POSTPONE:" "PRIMITIVE:" "SYNTAX:" "TYPED:" "TYPED::")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defconst factor-word-definition-regex | 
					
						
							| 
									
										
										
										
											2015-08-05 07:57:53 -04:00
										 |  |  |  |   (concat | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  |    (format "\\_<\\(%s\\)" (regexp-opt factor-word-starters)) | 
					
						
							| 
									
										
										
										
											2015-08-05 07:57:53 -04:00
										 |  |  |  |    ws+ symbol)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 18:59:12 -04:00
										 |  |  |  | ;; [parsing-word] [vocab-word] | 
					
						
							| 
									
										
										
										
											2013-08-05 12:39:11 -04:00
										 |  |  |  | (defconst factor-vocab-ref-regex | 
					
						
							| 
									
										
										
										
											2015-08-05 07:57:53 -04:00
										 |  |  |  |   (syntax-and-1-symbol '("IN" "USE" "QUALIFIED"))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  | (defconst factor-using-lines-regex | 
					
						
							|  |  |  |  |   (concat (syntax-begin '("USING")) ws+ symbols-to-semicolon)) | 
					
						
							| 
									
										
										
										
											2013-08-05 12:39:11 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 18:59:12 -04:00
										 |  |  |  | ;; [parsing-word] [symbol-word] | 
					
						
							| 
									
										
										
										
											2013-12-03 09:28:21 -05:00
										 |  |  |  | (defconst factor-symbol-definition-regex | 
					
						
							| 
									
										
										
										
											2015-08-04 20:28:07 -04:00
										 |  |  |  |   (syntax-and-1-symbol | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  |    '("&" "CONSTANT" "DESTRUCTOR" "FORGET" "GAME" "HELP" "LIBRARY" | 
					
						
							| 
									
										
										
										
											2015-10-14 20:41:40 -04:00
										 |  |  |  |      "MAIN" "MAIN-WINDOW" "STRING" "SYMBOL" "VAR"))) | 
					
						
							| 
									
										
										
										
											2013-12-03 09:28:21 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 18:59:12 -04:00
										 |  |  |  | ;; [parsing-word] [symbol-word]* ; | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  | (defconst factor-symbols-lines-regex | 
					
						
							|  |  |  |  |   (concat (syntax-begin '("SYMBOLS")) ws+ symbols-to-semicolon)) | 
					
						
							| 
									
										
										
										
											2013-12-03 09:28:21 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  | (defconst factor-types-lines-regex | 
					
						
							| 
									
										
										
										
											2016-03-11 01:36:23 -05:00
										 |  |  |  |   (concat | 
					
						
							|  |  |  |  |    (syntax-begin '("INTERSECTION" "SINGLETONS" "SPECIALIZED-ARRAYS")) | 
					
						
							|  |  |  |  |    ws+ symbols-to-semicolon)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-type-definition-regex | 
					
						
							| 
									
										
										
										
											2015-08-04 20:28:07 -04:00
										 |  |  |  |   (syntax-and-1-symbol | 
					
						
							| 
									
										
										
										
											2015-10-14 20:41:40 -04:00
										 |  |  |  |    '("COM-INTERFACE" "C-TYPE" "MIXIN" "SINGLETON" "SPECIALIZED-ARRAY" | 
					
						
							|  |  |  |  |      "TUPLE-ARRAY"))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-constructor-regex | 
					
						
							| 
									
										
										
										
											2015-08-05 10:58:27 -04:00
										 |  |  |  |   (one-symbol "<[^ >]+>")) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-getter-regex | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  |   (one-symbol "\\(?:\\sw\\|\\s_\\)+>>")) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-setter-regex | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  |   (one-symbol ">>\\(?:\\sw\\|\\s_\\)+\\|\\(?:\\sw\\|\\s_\\)+<<")) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-stack-effect-regex | 
					
						
							| 
									
										
										
										
											2013-09-20 10:35:49 -04:00
										 |  |  |  |   "\\( ( [^)]* )\\)\\|\\( (( [^)]* ))\\)") | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-use-line-regex "^USE: +\\(.*\\)$") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-current-vocab-regex "^IN: +\\([^ \r\n\f]+\\)") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-sub-vocab-regex "^<\\([^ \n]+\\) *$") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-indent-def-starts | 
					
						
							|  |  |  |  |   '("" ":" | 
					
						
							|  |  |  |  |     "AFTER" "BEFORE" | 
					
						
							|  |  |  |  |     "COM-INTERFACE" "CONSULT" | 
					
						
							|  |  |  |  |     "ENUM" "ERROR" | 
					
						
							|  |  |  |  |     "FROM" "FUNCTION:" "FUNCTION-ALIAS:" | 
					
						
							|  |  |  |  |     "INTERSECTION:" | 
					
						
							|  |  |  |  |     "M" "M:" "MACRO" "MACRO:" | 
					
						
							| 
									
										
										
										
											2015-12-04 06:43:01 -05:00
										 |  |  |  |     "MAIN-WINDOW:" "MEMO" "MEMO:" "METHOD" | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     "SYNTAX" | 
					
						
							|  |  |  |  |     "PREDICATE" "PRIMITIVE" "PROTOCOL" | 
					
						
							|  |  |  |  |     "SINGLETONS" | 
					
						
							|  |  |  |  |     "STRUCT" "SYMBOLS" "TAG" "TUPLE" | 
					
						
							|  |  |  |  |     "TYPED" "TYPED:" | 
					
						
							|  |  |  |  |     "UNIFORM-TUPLE" | 
					
						
							|  |  |  |  |     "UNION-STRUCT" "UNION" | 
					
						
							|  |  |  |  |     "VARIANT" "VERTEX-FORMAT")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-no-indent-def-starts | 
					
						
							|  |  |  |  |   '("ARTICLE" "HELP" "SPECIALIZED-ARRAYS")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-indent-def-start-regex | 
					
						
							|  |  |  |  |   (format "^\\(%s:\\)\\( \\|\n\\)" (regexp-opt factor-indent-def-starts))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-definition-start-regex | 
					
						
							|  |  |  |  |   (format "^\\(%s:\\) " (regexp-opt (append factor-no-indent-def-starts | 
					
						
							|  |  |  |  |                                             factor-indent-def-starts)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-definition-end-regex | 
					
						
							|  |  |  |  |   (format "\\(\\(^\\| +\\);\\( *%s\\)*\\($\\| +\\)\\)" | 
					
						
							|  |  |  |  |           factor-declaration-words-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-single-liner-regex | 
					
						
							|  |  |  |  |   (regexp-opt '("ABOUT:" | 
					
						
							|  |  |  |  |                 "ALIAS:" | 
					
						
							| 
									
										
										
										
											2015-04-24 05:40:06 -04:00
										 |  |  |  |                 "CONSTANT:" "C-GLOBAL:" "C-TYPE:" | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |                 "DEFER:" "DESTRUCTOR:" | 
					
						
							|  |  |  |  |                 "FORGET:" | 
					
						
							|  |  |  |  |                 "GAME:" "GENERIC:" "GENERIC#" "GLSL-PROGRAM:" | 
					
						
							|  |  |  |  |                 "HOOK:" | 
					
						
							|  |  |  |  |                 "IN:" "INSTANCE:" | 
					
						
							|  |  |  |  |                 "LIBRARY:" | 
					
						
							|  |  |  |  |                 "MAIN:" "MATH:" "MIXIN:" | 
					
						
							|  |  |  |  |                 "NAN:" | 
					
						
							|  |  |  |  |                 "POSTPONE:" "PRIVATE>" "<PRIVATE" | 
					
						
							|  |  |  |  |                 "QUALIFIED-WITH:" "QUALIFIED:" | 
					
						
							|  |  |  |  |                 "RENAME:" | 
					
						
							| 
									
										
										
										
											2013-08-05 12:39:11 -04:00
										 |  |  |  |                 "SINGLETON:" "SLOT:" "SPECIALIZED-ARRAY:" | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |                 "TYPEDEF:" | 
					
						
							| 
									
										
										
										
											2013-08-05 12:39:11 -04:00
										 |  |  |  |                 "USE:"))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-begin-of-def-regex | 
					
						
							|  |  |  |  |   (format "^USING: \\|\\(%s\\)\\|\\(^%s .*\\)" | 
					
						
							|  |  |  |  |           factor-definition-start-regex | 
					
						
							|  |  |  |  |           factor-single-liner-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-end-of-def-line-regex | 
					
						
							|  |  |  |  |   (format "^.*%s" factor-definition-end-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-end-of-def-regex | 
					
						
							|  |  |  |  |   (format "\\(%s\\)\\|\\(^%s .*\\)" | 
					
						
							|  |  |  |  |           factor-end-of-def-line-regex | 
					
						
							|  |  |  |  |           factor-single-liner-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-word-signature-regex | 
					
						
							|  |  |  |  |   (format ":[^ ]* \\([^ ]+\\)\\(%s\\)*" factor-stack-effect-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-defun-signature-regex | 
					
						
							|  |  |  |  |   (format "\\(%s\\|%s\\)" | 
					
						
							|  |  |  |  |           factor-word-signature-regex | 
					
						
							|  |  |  |  |           "M[^:]*: [^ ]+ [^ ]+")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-typedef-regex | 
					
						
							| 
									
										
										
										
											2015-08-04 20:28:07 -04:00
										 |  |  |  |   (syntax-and-2-symbols '("TYPEDEF" "INSTANCE"))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defconst factor-rename-regex | 
					
						
							| 
									
										
										
										
											2015-08-04 20:28:07 -04:00
										 |  |  |  |   (concat (syntax-and-2-symbols '("RENAME")) ws+ "\\(=>\\)" ws+ symbol)) | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-from/exclude-regex | 
					
						
							|  |  |  |  |   (concat (syntax-begin '("FROM" "EXCLUDE")) ws+ | 
					
						
							|  |  |  |  |           symbol ws+ | 
					
						
							|  |  |  |  |           "\\(=>\\)" ws+ symbols-to-semicolon)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  | (defconst factor-predicate-regex | 
					
						
							|  |  |  |  |   (concat (syntax-begin '("PREDICATE")) ws+ symbol ws+ "\\(<\\)" ws+ symbol)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-04 06:43:01 -05:00
										 |  |  |  | (defconst factor-alien-function-regex | 
					
						
							|  |  |  |  |   (concat (syntax-begin '("GL-FUNCTION" "FUNCTION" "GL-CALLBACK" "CALLBACK")) | 
					
						
							|  |  |  |  |           ws+ symbol | 
					
						
							|  |  |  |  |           ws+ symbol ws+)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-function-alias-regex | 
					
						
							|  |  |  |  |   (concat (syntax-begin '("FUNCTION-ALIAS")) | 
					
						
							|  |  |  |  |           ws+ symbol | 
					
						
							|  |  |  |  |           ws+ symbol | 
					
						
							|  |  |  |  |           ws+ symbol ws+)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 10:58:27 -04:00
										 |  |  |  | (defconst factor-group-name-to-face | 
					
						
							|  |  |  |  |   #s(hash-table test equal data | 
					
						
							|  |  |  |  |                 ("C" 'factor-font-lock-comment | 
					
						
							|  |  |  |  |                  "CO" 'factor-font-lock-constructor | 
					
						
							|  |  |  |  |                  "CT" 'factor-font-lock-constant | 
					
						
							|  |  |  |  |                  "P" 'factor-font-lock-parsing-word | 
					
						
							|  |  |  |  |                  "V" 'factor-font-lock-vocabulary-name | 
					
						
							|  |  |  |  |                  "T" 'factor-font-lock-type-name | 
					
						
							|  |  |  |  |                  "W" 'factor-font-lock-word))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-group-name-to-face (group-name) | 
					
						
							|  |  |  |  |   (gethash group-name factor-group-name-to-face)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-groups-to-font-lock (groups) | 
					
						
							|  |  |  |  |   (let ((i 0)) | 
					
						
							|  |  |  |  |     (mapcar (lambda (x) | 
					
						
							|  |  |  |  |               (setq i (1+ i)) | 
					
						
							|  |  |  |  |               (list i (factor-group-name-to-face x))) | 
					
						
							|  |  |  |  |             groups))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-syntax (regex groups) | 
					
						
							|  |  |  |  |   (append (list regex) (factor-groups-to-font-lock groups))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Font lock: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defconst factor-font-lock-keywords | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  |   `( | 
					
						
							| 
									
										
										
										
											2015-08-05 10:58:27 -04:00
										 |  |  |  |     ,(factor-syntax factor-brace-words-regex '("P")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-vocab-ref-regex '("P" "V")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-using-lines-regex '("P" "V" "P")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-symbols-lines-regex '("P" "W" "P")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-from/exclude-regex '("P" "V" "P" "W" "P")) | 
					
						
							|  |  |  |  |     ,(factor-syntax (syntax-and-2-symbols '("C")) '("P" "W" "T")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-symbol-definition-regex '("P" "W")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-typedef-regex '("P" "T" "T")) | 
					
						
							|  |  |  |  |     ,(factor-syntax (syntax-and-2-symbols '("C-GLOBAL")) '("P" "T" "W")) | 
					
						
							|  |  |  |  |     ,(factor-syntax (syntax-and-2-symbols '("QUALIFIED-WITH")) '("P" "V" "W")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-rename-regex '("P" "W" "V" "P" "W")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-declaration-words-regex '("C")) | 
					
						
							|  |  |  |  |     ,(factor-syntax factor-word-definition-regex '("P" "W")) | 
					
						
							|  |  |  |  |     ,(factor-syntax (syntax-and-2-symbols '("ALIAS")) '("P" "W" "W")) | 
					
						
							|  |  |  |  |     ,(factor-syntax (syntax-and-1-symbol '("ALIEN" "CHAR" "NAN")) '("P" "CT")) | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  |     ,(factor-syntax factor-types-lines-regex '("P" "T")) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (,factor-integer-regex . 'factor-font-lock-number) | 
					
						
							|  |  |  |  |     (,factor-float-regex . 'factor-font-lock-number) | 
					
						
							|  |  |  |  |     (,factor-ratio-regex . 'factor-font-lock-ratio) | 
					
						
							| 
									
										
										
										
											2015-08-05 10:58:27 -04:00
										 |  |  |  |     ,(factor-syntax factor-type-definition-regex '("P" "T")) | 
					
						
							|  |  |  |  |     ,(factor-syntax (syntax-and-2-symbols '("M" "M:" "BEFORE" "AFTER")) | 
					
						
							|  |  |  |  |                     '("P" "T" "W")) | 
					
						
							| 
									
										
										
										
											2013-08-05 12:39:11 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-20 08:09:10 -04:00
										 |  |  |  |     ;; Highlights tuple and struct definitions. The TUPLE/STRUCT | 
					
						
							|  |  |  |  |     ;; parsing word, class name and optional parent classes are | 
					
						
							|  |  |  |  |     ;; matched in three groups. Then the text up until the end of the | 
					
						
							|  |  |  |  |     ;; definition that is terminated with ";" is searched for words | 
					
						
							|  |  |  |  |     ;; that are slot names which are highlighted with the face | 
					
						
							|  |  |  |  |     ;; factor-font-lock-symbol. | 
					
						
							|  |  |  |  |     (,(format | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  |        "\\(%s:\\)[ \n]+%s\\(?:[ \n]+\\(<\\)[ \n]+%s\\)?" | 
					
						
							|  |  |  |  |        (regexp-opt '("BUILTIN" | 
					
						
							|  |  |  |  |                      "ENUM" | 
					
						
							| 
									
										
										
										
											2015-07-12 20:18:53 -04:00
										 |  |  |  |                      "ERROR" | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  |                      "PROTOCOL" | 
					
						
							|  |  |  |  |                      "STRUCT" | 
					
						
							|  |  |  |  |                      "TUPLE" | 
					
						
							|  |  |  |  |                      "UNION" | 
					
						
							|  |  |  |  |                      "UNION-STRUCT")) | 
					
						
							| 
									
										
										
										
											2013-09-20 08:09:10 -04:00
										 |  |  |  |        symbol | 
					
						
							|  |  |  |  |        symbol) | 
					
						
							| 
									
										
										
										
											2013-08-13 16:46:17 -04:00
										 |  |  |  |      (1 'factor-font-lock-parsing-word) | 
					
						
							|  |  |  |  |      (2 'factor-font-lock-type-name) | 
					
						
							| 
									
										
										
										
											2015-07-12 20:04:27 -04:00
										 |  |  |  |      (3 'factor-font-lock-parsing-word nil t) | 
					
						
							|  |  |  |  |      (4 'factor-font-lock-type-name nil t) | 
					
						
							| 
									
										
										
										
											2013-09-20 08:09:10 -04:00
										 |  |  |  |      ;; A slot is either a single symbol or a sequence along the | 
					
						
							| 
									
										
										
										
											2013-08-13 16:46:17 -04:00
										 |  |  |  |      ;; lines: { foo initial: "bar } | 
					
						
							|  |  |  |  |      ("\\(\\(?:\\sw\\|\\s_\\)+\\)\\|\\(?:{[ \n]+\\(\\(?:\\sw\\|\\s_\\)+\\)[^}]+\\)" | 
					
						
							| 
									
										
										
										
											2013-09-20 10:35:49 -04:00
										 |  |  |  |       (factor-find-end-of-def) | 
					
						
							| 
									
										
										
										
											2013-08-13 16:46:17 -04:00
										 |  |  |  |       nil | 
					
						
							|  |  |  |  |       (1 'factor-font-lock-symbol nil t) | 
					
						
							|  |  |  |  |       (2 'factor-font-lock-symbol nil t))) | 
					
						
							| 
									
										
										
										
											2015-10-28 19:44:08 -04:00
										 |  |  |  |     ,(factor-syntax factor-predicate-regex '("P" "T" "P" "T")) | 
					
						
							| 
									
										
										
										
											2013-09-20 10:35:49 -04:00
										 |  |  |  |     ;; Highlights alien function definitions. Types in stack effect | 
					
						
							|  |  |  |  |     ;; declarations are given a bold face. | 
					
						
							| 
									
										
										
										
											2015-12-04 06:43:01 -05:00
										 |  |  |  |     (,factor-alien-function-regex | 
					
						
							| 
									
										
										
										
											2013-09-20 10:35:49 -04:00
										 |  |  |  |      (1 'factor-font-lock-parsing-word) | 
					
						
							|  |  |  |  |      (2 'factor-font-lock-type-name) | 
					
						
							|  |  |  |  |      (3 'factor-font-lock-word) | 
					
						
							|  |  |  |  |      ;; Regexp from hell that puts every type name in the first group, | 
					
						
							|  |  |  |  |      ;; names and brackets in the second and third. | 
					
						
							|  |  |  |  |      ("\\(?:\\(\\(?:\\sw\\|\\s_\\)+\\)[ \n]+\\(\\(?:\\sw\\|\\s_\\)+,?\\(?:[ \n]+)\\)?\\)\\|\\([()]\\)\\)" | 
					
						
							| 
									
										
										
										
											2015-08-04 20:35:09 -04:00
										 |  |  |  |       (factor-find-ending-bracket) | 
					
						
							| 
									
										
										
										
											2013-09-20 10:35:49 -04:00
										 |  |  |  |       nil | 
					
						
							|  |  |  |  |       (1 'factor-font-lock-type-in-stack-effect nil t) | 
					
						
							|  |  |  |  |       (2 'factor-font-lock-stack-effect nil t) | 
					
						
							|  |  |  |  |       (3 'factor-font-lock-stack-effect nil t))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     ;; Almost identical to the previous one, but for function aliases. | 
					
						
							| 
									
										
										
										
											2015-12-04 06:43:01 -05:00
										 |  |  |  |     (,factor-function-alias-regex | 
					
						
							| 
									
										
										
										
											2013-09-20 10:35:49 -04:00
										 |  |  |  |      (1 'factor-font-lock-parsing-word) | 
					
						
							|  |  |  |  |      (2 'factor-font-lock-word) | 
					
						
							|  |  |  |  |      (3 'factor-font-lock-type-name) | 
					
						
							|  |  |  |  |      (4 'factor-font-lock-word) | 
					
						
							|  |  |  |  |      ("\\(?:\\(\\(?:\\sw\\|\\s_\\)+\\)[ \n]+\\(\\(?:\\sw\\|\\s_\\)+,?\\(?:[ \n]+)\\)?\\)\\|\\([()]\\)\\)" | 
					
						
							| 
									
										
										
										
											2015-08-04 20:35:09 -04:00
										 |  |  |  |       (factor-find-ending-bracket) | 
					
						
							| 
									
										
										
										
											2013-09-20 10:35:49 -04:00
										 |  |  |  |       nil | 
					
						
							|  |  |  |  |       (1 'factor-font-lock-type-in-stack-effect nil t) | 
					
						
							|  |  |  |  |       (2 'factor-font-lock-stack-effect nil t) | 
					
						
							|  |  |  |  |       (3 'factor-font-lock-stack-effect nil t))) | 
					
						
							| 
									
										
										
										
											2013-12-01 08:37:23 -05:00
										 |  |  |  |     (factor-match-brackets . 'factor-font-lock-stack-effect) | 
					
						
							| 
									
										
										
										
											2015-08-05 10:58:27 -04:00
										 |  |  |  |     ,(factor-syntax factor-constructor-regex '("CO")) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (,factor-setter-regex . 'factor-font-lock-setter-word) | 
					
						
							|  |  |  |  |     (,factor-getter-regex . 'factor-font-lock-getter-word) | 
					
						
							|  |  |  |  |     (,factor-bad-string-regex . 'factor-font-lock-invalid-syntax) | 
					
						
							|  |  |  |  |     ("\\_<\\(P\\|SBUF\\|DLL\\)\"" 1 'factor-font-lock-parsing-word) | 
					
						
							|  |  |  |  |     (,factor-constant-words-regex . 'factor-font-lock-constant) | 
					
						
							| 
									
										
										
										
											2015-08-05 10:58:27 -04:00
										 |  |  |  |     ,(factor-syntax factor-parsing-words-regex '("P")) | 
					
						
							| 
									
										
										
										
											2013-08-07 17:53:24 -04:00
										 |  |  |  |     (,"\t" . 'whitespace-highlight-face))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-07 12:27:59 -04:00
										 |  |  |  | ;; Handling of multi-line constructs | 
					
						
							|  |  |  |  | (defun factor-font-lock-extend-region () | 
					
						
							|  |  |  |  |   (eval-when-compile (defvar font-lock-beg) (defvar font-lock-end)) | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (goto-char font-lock-beg) | 
					
						
							|  |  |  |  |     (let ((found (or (re-search-backward "\n\n" nil t) (point-min)))) | 
					
						
							|  |  |  |  |       (goto-char font-lock-end) | 
					
						
							|  |  |  |  |       (when (re-search-forward "\n\n" nil t) | 
					
						
							|  |  |  |  |         (beginning-of-line) | 
					
						
							|  |  |  |  |         (setq font-lock-end (point))) | 
					
						
							|  |  |  |  |       (setq font-lock-beg found)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | ;;; Source code analysis: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-brackets-depth () | 
					
						
							|  |  |  |  |   (nth 0 (syntax-ppss))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-brackets-start () | 
					
						
							|  |  |  |  |   (nth 1 (syntax-ppss))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-brackets-end () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (goto-char (factor-brackets-start)) | 
					
						
							|  |  |  |  |     (condition-case nil | 
					
						
							|  |  |  |  |         (progn (forward-sexp) | 
					
						
							|  |  |  |  |                (1- (point))) | 
					
						
							|  |  |  |  |       (error -1)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-indentation-at (pos) | 
					
						
							|  |  |  |  |   (save-excursion (goto-char pos) (current-indentation))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-at-begin-of-def () | 
					
						
							|  |  |  |  |   (looking-at factor-begin-of-def-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-at-begin-of-indent-def () | 
					
						
							|  |  |  |  |   (looking-at factor-indent-def-start-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-at-end-of-def () | 
					
						
							|  |  |  |  |   (looking-at factor-end-of-def-regex)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-looking-at-emptiness () | 
					
						
							|  |  |  |  |   (looking-at "^[ ]*$\\|$")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-is-last-char (pos) | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (goto-char (1+ pos)) | 
					
						
							|  |  |  |  |     (looking-at-p "[ ]*$"))) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defsubst factor-line-offset (pos) | 
					
						
							|  |  |  |  |   (- pos (save-excursion | 
					
						
							|  |  |  |  |            (goto-char pos) | 
					
						
							|  |  |  |  |            (beginning-of-line) | 
					
						
							|  |  |  |  |            (point)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-previous-non-blank () | 
					
						
							|  |  |  |  |   (forward-line -1) | 
					
						
							|  |  |  |  |   (while (and (not (bobp)) (factor-looking-at-emptiness)) | 
					
						
							|  |  |  |  |     (forward-line -1))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-beginning-of-defun (&optional times) | 
					
						
							|  |  |  |  |   (re-search-backward factor-begin-of-def-regex nil t times)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-end-of-defun () | 
					
						
							|  |  |  |  |   (re-search-forward factor-end-of-def-regex nil t)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-beginning-of-block-pos () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (if (> (factor-brackets-depth) 0) | 
					
						
							|  |  |  |  |         (factor-brackets-start) | 
					
						
							|  |  |  |  |       (factor-beginning-of-defun) | 
					
						
							|  |  |  |  |       (point)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-at-setter-line () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (beginning-of-line) | 
					
						
							|  |  |  |  |     (when (re-search-forward factor-setter-regex | 
					
						
							|  |  |  |  |                              (line-end-position) | 
					
						
							|  |  |  |  |                              t) | 
					
						
							|  |  |  |  |       (let* ((to (match-beginning 0)) | 
					
						
							|  |  |  |  |              (from (factor-beginning-of-block-pos))) | 
					
						
							|  |  |  |  |         (goto-char from) | 
					
						
							|  |  |  |  |         (let ((depth (factor-brackets-depth))) | 
					
						
							|  |  |  |  |           (and (or (re-search-forward factor-constructor-regex to t) | 
					
						
							|  |  |  |  |                    (re-search-forward factor-setter-regex to t)) | 
					
						
							|  |  |  |  |                (= depth (factor-brackets-depth)))))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-at-constructor-line () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (beginning-of-line) | 
					
						
							|  |  |  |  |     (re-search-forward factor-constructor-regex (line-end-position) t))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 12:39:10 -04:00
										 |  |  |  | (defun factor-on-vocab () | 
					
						
							|  |  |  |  |   "t if point is on a vocab name. We just piggyback on
 | 
					
						
							|  |  |  |  |   font-lock's pretty accurate information."
 | 
					
						
							|  |  |  |  |   (eq (get-char-property (point) 'face) 'factor-font-lock-vocabulary-name)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-end-of-defun-pos () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (re-search-forward factor-end-of-def-regex nil t) | 
					
						
							|  |  |  |  |     (point))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-04 20:35:09 -04:00
										 |  |  |  | (defun factor-find-end-of-def (&rest foo) | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (re-search-forward "[ \n];" nil t) | 
					
						
							|  |  |  |  |     (1- (point)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-find-ending-bracket (&rest foo) | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (re-search-forward "[ \n]\)" nil t) | 
					
						
							|  |  |  |  |     (point))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-beginning-of-body () | 
					
						
							|  |  |  |  |   (let ((p (point))) | 
					
						
							|  |  |  |  |     (and (factor-beginning-of-defun) | 
					
						
							|  |  |  |  |          (re-search-forward factor-defun-signature-regex p t) | 
					
						
							|  |  |  |  |          (not (re-search-forward factor-end-of-def-regex p t))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-beginning-of-sexp () | 
					
						
							|  |  |  |  |   (if (> (factor-brackets-depth) 0) | 
					
						
							|  |  |  |  |       (goto-char (factor-brackets-start)) | 
					
						
							|  |  |  |  |     (factor-beginning-of-body))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-beginning-of-sexp-pos () | 
					
						
							|  |  |  |  |   (save-excursion (factor-beginning-of-sexp) (point))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | ;;; USING/IN: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-13 10:34:47 -04:00
										 |  |  |  | (defvar-local factor-current-vocab-function 'factor-find-vocab-name) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-current-vocab () | 
					
						
							|  |  |  |  |   (funcall factor-current-vocab-function)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-find-in () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							| 
									
										
										
										
											2014-04-17 21:06:34 -04:00
										 |  |  |  |     (beginning-of-line) | 
					
						
							|  |  |  |  |     (if (re-search-backward factor-current-vocab-regex nil t) | 
					
						
							|  |  |  |  |         (match-string-no-properties 1) | 
					
						
							|  |  |  |  |       (when (re-search-forward factor-current-vocab-regex nil t) | 
					
						
							|  |  |  |  |         (match-string-no-properties 1))))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-13 10:34:47 -04:00
										 |  |  |  | (defun factor-in-private? () | 
					
						
							|  |  |  |  |   "t if point is withing a PRIVATE-block, nil otherwise." | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (when (re-search-backward "\\_<<?PRIVATE>?\\_>" nil t) | 
					
						
							|  |  |  |  |       (string= (match-string-no-properties 0) "<PRIVATE")))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-find-vocab-name () | 
					
						
							| 
									
										
										
										
											2014-04-14 08:49:34 -04:00
										 |  |  |  |   "Name of the vocab with possible .private suffix" | 
					
						
							| 
									
										
										
										
											2014-04-13 10:34:47 -04:00
										 |  |  |  |   (concat (factor-find-in) (if (factor-in-private?) ".private" ""))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 08:49:34 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defvar-local factor-usings-function 'factor-find-usings) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-usings () | 
					
						
							|  |  |  |  |   (funcall factor-usings-function)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-file-has-private () | 
					
						
							|  |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (goto-char (point-min)) | 
					
						
							|  |  |  |  |     (and (re-search-forward "\\_<<PRIVATE\\_>" nil t) | 
					
						
							|  |  |  |  |          (re-search-forward "\\_<PRIVATE>\\_>" nil t)))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-find-usings (&optional no-private) | 
					
						
							| 
									
										
										
										
											2014-04-14 08:49:34 -04:00
										 |  |  |  |   "Lists all vocabs used by the vocab." | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (let ((usings)) | 
					
						
							|  |  |  |  |       (goto-char (point-max)) | 
					
						
							|  |  |  |  |       (while (re-search-backward factor-using-lines-regex nil t) | 
					
						
							| 
									
										
										
										
											2014-04-14 08:49:34 -04:00
										 |  |  |  |         (dolist (u (split-string (match-string-no-properties 2) nil t)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |           (push u usings))) | 
					
						
							|  |  |  |  |       (when (and (not no-private) (factor-file-has-private)) | 
					
						
							|  |  |  |  |         (goto-char (point-max)) | 
					
						
							|  |  |  |  |         (push (concat (factor-find-in) ".private") usings)) | 
					
						
							|  |  |  |  |       usings))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Indentation: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-increased-indentation (&optional i) | 
					
						
							|  |  |  |  |   (+ (or i (current-indentation)) factor-indent-level)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defsubst factor-decreased-indentation (&optional i) | 
					
						
							|  |  |  |  |   (- (or i (current-indentation)) factor-indent-level)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-indent-in-brackets () | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (beginning-of-line) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (when (> (factor-brackets-depth) 0) | 
					
						
							|  |  |  |  |       (let* ((bs (factor-brackets-start)) | 
					
						
							|  |  |  |  |              (be (factor-brackets-end)) | 
					
						
							| 
									
										
										
										
											2008-12-19 08:54:18 -05:00
										 |  |  |  |              (ln (line-number-at-pos))) | 
					
						
							|  |  |  |  |         (when (> ln (line-number-at-pos bs)) | 
					
						
							|  |  |  |  |           (cond ((and (> be 0) | 
					
						
							|  |  |  |  |                       (= (- be (point)) (current-indentation)) | 
					
						
							|  |  |  |  |                       (= ln (line-number-at-pos be))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |                  (factor-indentation-at bs)) | 
					
						
							|  |  |  |  |                 ((or (factor-is-last-char bs) | 
					
						
							| 
									
										
										
										
											2008-12-19 08:54:18 -05:00
										 |  |  |  |                      (not (eq ?\ (char-after (1+ bs))))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |                  (factor-increased-indentation | 
					
						
							|  |  |  |  |                   (factor-indentation-at bs))) | 
					
						
							|  |  |  |  |                 (t (+ 2 (factor-line-offset bs))))))))) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-indent-definition () | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |   (save-excursion | 
					
						
							|  |  |  |  |     (beginning-of-line) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (when (factor-at-begin-of-def) 0))) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defsubst factor-previous-non-empty () | 
					
						
							| 
									
										
										
										
											2009-06-14 14:29:27 -04:00
										 |  |  |  |   (forward-line -1) | 
					
						
							|  |  |  |  |   (while (and (not (bobp)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |               (factor-looking-at-emptiness)) | 
					
						
							| 
									
										
										
										
											2009-06-14 14:29:27 -04:00
										 |  |  |  |     (forward-line -1))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-indent-setter-line () | 
					
						
							|  |  |  |  |   (when (factor-at-setter-line) | 
					
						
							| 
									
										
										
										
											2009-06-14 14:29:27 -04:00
										 |  |  |  |     (or (save-excursion | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |           (let ((indent (and (factor-at-constructor-line) | 
					
						
							| 
									
										
										
										
											2009-06-14 14:29:27 -04:00
										 |  |  |  |                              (current-indentation)))) | 
					
						
							|  |  |  |  |             (while (not (or indent | 
					
						
							|  |  |  |  |                             (bobp) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |                             (factor-at-begin-of-def) | 
					
						
							|  |  |  |  |                             (factor-at-end-of-def))) | 
					
						
							|  |  |  |  |               (if (factor-at-constructor-line) | 
					
						
							|  |  |  |  |                   (setq indent (factor-increased-indentation)) | 
					
						
							| 
									
										
										
										
											2009-06-14 14:29:27 -04:00
										 |  |  |  |                 (forward-line -1))) | 
					
						
							|  |  |  |  |             indent)) | 
					
						
							|  |  |  |  |         (save-excursion | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |           (factor-previous-non-empty) | 
					
						
							| 
									
										
										
										
											2009-06-14 14:29:27 -04:00
										 |  |  |  |           (current-indentation))))) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-indent-continuation () | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |   (save-excursion | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (factor-previous-non-empty) | 
					
						
							|  |  |  |  |     (cond ((or (factor-at-end-of-def) | 
					
						
							|  |  |  |  |                (factor-at-setter-line)) | 
					
						
							|  |  |  |  |            (factor-decreased-indentation)) | 
					
						
							|  |  |  |  |           ((factor-at-begin-of-indent-def) | 
					
						
							|  |  |  |  |            (factor-increased-indentation)) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |           (t (current-indentation))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-calculate-indentation () | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |   "Calculate Factor indentation for line at point." | 
					
						
							|  |  |  |  |   (or (and (bobp) 0) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |       (factor-indent-definition) | 
					
						
							|  |  |  |  |       (factor-indent-in-brackets) | 
					
						
							|  |  |  |  |       (factor-indent-setter-line) | 
					
						
							|  |  |  |  |       (factor-indent-continuation) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |       0)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-indent-line (&optional ignored) | 
					
						
							|  |  |  |  |   "Indents the current Factor line." | 
					
						
							|  |  |  |  |   (interactive) | 
					
						
							|  |  |  |  |   (let ((target (factor-calculate-indentation)) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |         (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)))))) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | ;;; Buffer cycling: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defconst factor-cycle-endings | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |   '(".factor" "-tests.factor" "-docs.factor")) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defvar factor-cycle-ring | 
					
						
							|  |  |  |  |   (let ((ring (make-ring (length factor-cycle-endings)))) | 
					
						
							|  |  |  |  |     (dolist (e factor-cycle-endings ring) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |       (ring-insert ring e)) | 
					
						
							|  |  |  |  |     ring)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defconst factor-cycle-basename-regex | 
					
						
							|  |  |  |  |   (format "\\(.+?\\)\\(%s\\)$" (regexp-opt factor-cycle-endings))) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-cycle-split (basename) | 
					
						
							|  |  |  |  |   (when (string-match factor-cycle-basename-regex basename) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |     (cons (match-string 1 basename) (match-string 2 basename)))) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-cycle-next (file skip) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |   (let* ((dir (file-name-directory file)) | 
					
						
							|  |  |  |  |          (basename (file-name-nondirectory file)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |          (p/s (factor-cycle-split basename)) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |          (prefix (car p/s)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |          (ring factor-cycle-ring) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |          (idx (or (ring-member ring (cdr p/s)) 0)) | 
					
						
							|  |  |  |  |          (len (ring-size ring)) | 
					
						
							|  |  |  |  |          (i 1) | 
					
						
							|  |  |  |  |          (result nil)) | 
					
						
							|  |  |  |  |     (while (and (< i len) (not result)) | 
					
						
							|  |  |  |  |       (let* ((suffix (ring-ref ring (+ i idx))) | 
					
						
							|  |  |  |  |              (path (expand-file-name (concat prefix suffix) dir))) | 
					
						
							|  |  |  |  |         (when (or (file-exists-p path) | 
					
						
							| 
									
										
										
										
											2009-02-22 14:20:46 -05:00
										 |  |  |  |                   (and (not skip) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |                        (not (member suffix factor-cycling-no-ask)) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |                        (y-or-n-p (format "Create %s? " path)))) | 
					
						
							|  |  |  |  |           (setq result path)) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |         (when (and (not factor-cycle-always-ask-p) | 
					
						
							|  |  |  |  |                    (not (member suffix factor-cycling-no-ask))) | 
					
						
							|  |  |  |  |           (setq factor-cycling-no-ask | 
					
						
							|  |  |  |  |                 (cons name factor-cycling-no-ask)))) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |       (setq i (1+ i))) | 
					
						
							|  |  |  |  |     result)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defun factor-visit-other-file (&optional create) | 
					
						
							| 
									
										
										
										
											2009-02-22 14:20:46 -05:00
										 |  |  |  |   "Cycle between code, tests and docs factor files.
 | 
					
						
							| 
									
										
										
										
											2010-02-21 06:27:16 -05:00
										 |  |  |  | With prefix, non-existing files will be created."
 | 
					
						
							| 
									
										
										
										
											2009-02-22 14:20:46 -05:00
										 |  |  |  |   (interactive "P") | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |   (let ((file (factor-cycle-next (buffer-file-name) (not create)))) | 
					
						
							| 
									
										
										
										
											2009-01-08 17:52:38 -05:00
										 |  |  |  |     (unless file (error "No other file found")) | 
					
						
							|  |  |  |  |     (find-file file) | 
					
						
							|  |  |  |  |     (unless (file-exists-p file) | 
					
						
							|  |  |  |  |       (set-buffer-modified-p t) | 
					
						
							|  |  |  |  |       (save-buffer)))) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | ;;; factor-mode: | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-05 12:39:11 -04:00
										 |  |  |  | ;; I think it is correct to put almost all punctuation characters in | 
					
						
							|  |  |  |  | ;; the word class because Factor words can be made up of almost | 
					
						
							|  |  |  |  | ;; anything. Otherwise you get incredibly annoying regexps. | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (defvar factor-mode-syntax-table | 
					
						
							|  |  |  |  |   (let ((table (make-syntax-table prog-mode-syntax-table))) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\" "\"" table) | 
					
						
							| 
									
										
										
										
											2015-06-07 14:36:34 -04:00
										 |  |  |  |     (modify-syntax-entry ?# "_" table) | 
					
						
							| 
									
										
										
										
											2015-04-24 05:40:06 -04:00
										 |  |  |  |     (modify-syntax-entry ?! "_" table) | 
					
						
							| 
									
										
										
										
											2015-06-07 14:36:34 -04:00
										 |  |  |  |     (modify-syntax-entry ?\n ">   " table) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (modify-syntax-entry ?$ "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?@ "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?? "_" table) | 
					
						
							| 
									
										
										
										
											2013-08-14 11:41:36 -04:00
										 |  |  |  |     (modify-syntax-entry ?_ "_" table) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (modify-syntax-entry ?: "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?< "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?> "_" table) | 
					
						
							| 
									
										
										
										
											2013-08-14 11:41:36 -04:00
										 |  |  |  |     (modify-syntax-entry ?. "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?, "_" table) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (modify-syntax-entry ?& "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?| "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?% "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?= "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?/ "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?+ "_" table) | 
					
						
							| 
									
										
										
										
											2013-08-14 11:41:36 -04:00
										 |  |  |  |     (modify-syntax-entry ?* "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?- "_" table) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (modify-syntax-entry ?\; "_" table) | 
					
						
							| 
									
										
										
										
											2014-04-17 21:53:42 -04:00
										 |  |  |  |     (modify-syntax-entry ?\' "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?^ "_" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?~ "_" table) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  |     (modify-syntax-entry ?\( "()" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\) ")(" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\{ "(}" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\} "){" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\[ "(]" table) | 
					
						
							|  |  |  |  |     (modify-syntax-entry ?\] ")[" table) | 
					
						
							|  |  |  |  |     table)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | (defun factor-font-lock-string (str) | 
					
						
							|  |  |  |  |   "Fontify STR as if it was Factor code." | 
					
						
							|  |  |  |  |   (with-temp-buffer | 
					
						
							|  |  |  |  |     (set-syntax-table factor-mode-syntax-table) | 
					
						
							|  |  |  |  |     (setq-local parse-sexp-ignore-comments t) | 
					
						
							|  |  |  |  |     (setq-local parse-sexp-lookup-properties t) | 
					
						
							|  |  |  |  |     (setq-local font-lock-defaults '(factor-font-lock-keywords nil nil nil nil)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     (insert str) | 
					
						
							|  |  |  |  |     (let ((font-lock-verbose nil)) | 
					
						
							|  |  |  |  |       (font-lock-fontify-buffer)) | 
					
						
							|  |  |  |  |     (buffer-string))) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 14:36:34 -04:00
										 |  |  |  | (defun factor-syntax-propertize (start end) | 
					
						
							|  |  |  |  |   (funcall | 
					
						
							|  |  |  |  |    (syntax-propertize-rules | 
					
						
							|  |  |  |  |     ("\\(^\\| \\|\t\\)\\(!\\|#!\\)\\($\\| \\|\t\\)" (2 "<   "))) | 
					
						
							|  |  |  |  |    start end)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | ;;;###autoload | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | (define-derived-mode factor-mode prog-mode "Factor" | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  |   "A mode for editing programs written in the Factor programming language.
 | 
					
						
							|  |  |  |  | \\{factor-mode-map}"
 | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   (setq-local comment-start "! ") | 
					
						
							|  |  |  |  |   (setq-local comment-end "") | 
					
						
							|  |  |  |  |   (setq-local comment-column factor-comment-column) | 
					
						
							|  |  |  |  |   (setq-local comment-start-skip "!+ *") | 
					
						
							|  |  |  |  |   (setq-local parse-sexp-ignore-comments t) | 
					
						
							|  |  |  |  |   (setq-local parse-sexp-lookup-properties t) | 
					
						
							| 
									
										
										
										
											2013-08-07 12:27:59 -04:00
										 |  |  |  |   (setq-local font-lock-defaults '(factor-font-lock-keywords)) | 
					
						
							|  |  |  |  |   ;; Some syntactic constructs are often split over multiple lines so | 
					
						
							|  |  |  |  |   ;; we need to setup multiline font-lock. | 
					
						
							|  |  |  |  |   (setq-local font-lock-multiline t) | 
					
						
							|  |  |  |  |   (add-hook 'font-lock-extend-region-functions 'factor-font-lock-extend-region) | 
					
						
							| 
									
										
										
										
											2015-06-07 14:36:34 -04:00
										 |  |  |  |   (setq-local syntax-propertize-function 'factor-syntax-propertize) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   (define-key factor-mode-map [remap ff-get-other-file] | 
					
						
							|  |  |  |  |     'factor-visit-other-file) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   (setq-local electric-indent-chars | 
					
						
							|  |  |  |  |               (append '(?\] ?\} ?\n) electric-indent-chars)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   (setq-local indent-line-function 'factor-indent-line) | 
					
						
							| 
									
										
										
										
											2013-08-07 17:53:24 -04:00
										 |  |  |  |   ;; No tabs for you!! | 
					
						
							|  |  |  |  |   (setq-local indent-tabs-mode nil) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   (setq-local beginning-of-defun-function 'factor-beginning-of-defun) | 
					
						
							| 
									
										
										
										
											2013-08-06 07:43:39 -04:00
										 |  |  |  |   (setq-local end-of-defun-function 'factor-end-of-defun) | 
					
						
							|  |  |  |  |   ;; Load fuel-mode too if factor-mode-use-fuel is t. | 
					
						
							|  |  |  |  |   (when factor-mode-use-fuel (require 'fuel-mode) (fuel-mode))) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;;###autoload | 
					
						
							|  |  |  |  | (add-to-list 'auto-mode-alist '("\\.factor\\'" . factor-mode)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ;;;###autoload | 
					
						
							|  |  |  |  | (add-to-list 'interpreter-mode-alist '("factor" . factor-mode)) | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |  | 
					
						
							|  |  |  |  | (provide 'factor-mode) | 
					
						
							| 
									
										
										
										
											2013-05-05 00:48:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-05 22:34:25 -05:00
										 |  |  |  | ;;; factor-mode.el ends here |