]> gitweb.factorcode.org Git - factor.git/commitdiff
Faces used in factor-mode are now customizable (plus a bit of
authorJose A. Ortega Ruiz <jao@gnu.org>
Sun, 16 Nov 2008 02:16:57 +0000 (03:16 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Sun, 16 Nov 2008 02:16:57 +0000 (03:16 +0100)
reordering in factor.el).

misc/factor.el

index 0b1207797700db969f16072b98c8385606f38e28..b25493dd5e3065ca2ae25bf5782ce592846648b7 100644 (file)
@@ -31,6 +31,9 @@
   :type '(choice (const :tag "Enable" t) (const :tag "Disable" nil))
   :group 'factor)
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; factor-mode syntax
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (if factor-mode-syntax-table
     ()
     (modify-syntax-entry ?\) ")(" factor-mode-syntax-table)
     (modify-syntax-entry ?\" "\"    " factor-mode-syntax-table)))
 
-(defvar factor-mode-map (make-sparse-keymap))
-
 (defcustom factor-mode-hook nil
   "Hook run when entering Factor mode."
   :type 'hook
   :group 'factor)
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; factor-mode font lock
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(require 'font-lock)
+
+(defgroup factor-faces nil
+  "Faces used in Factor mode"
+  :group 'factor
+  :group 'faces)
+
+(defsubst factor--face (face) `((t ,(face-attr-construct face))))
+
+(defface factor-font-lock-parsing-word (factor--face font-lock-keyword-face)
+  "Face for parsing words."
+  :group 'factor-faces)
+
+(defface factor-font-lock-comment (factor--face font-lock-comment-face)
+  "Face for comments."
+  :group 'factor-faces)
+
+(defface factor-font-lock-string (factor--face font-lock-string-face)
+  "Face for strings."
+  :group 'factor-faces)
+
+(defface factor-font-lock-stack-effect (factor--face font-lock-comment-face)
+  "Face for stack effect specifications."
+  :group 'factor-faces)
+
+(defface factor-font-lock-word-definition (factor--face font-lock-function-name-face)
+  "Face for word, generic or method being defined."
+  :group 'factor-faces)
+
+(defface factor-font-lock-symbol-definition (factor--face font-lock-variable-name-face)
+  "Face for name of symbol being defined."
+  :group 'factor-faces)
+
+(defface factor-font-lock-vocabulary-name (factor--face font-lock-constant-face)
+  "Face for names of vocabularies in USE or USING."
+  :group 'factor-faces)
+
+(defface factor-font-lock-type-definition (factor--face font-lock-type-face)
+  "Face for type (tuple) names."
+  :group 'factor-faces)
+
+(defface factor-font-lock-parsing-word (factor--face font-lock-keyword-face)
+  "Face for parsing words."
+  :group 'factor-faces)
+
 (defconst factor--parsing-words
   '("{" "}" "^:" "^::" ";" "<<" "<PRIVATE" ">>"
     "BIN:" "BV{" "B{" "C:" "C-STRUCT:" "C-UNION:" "CHAR:" "CS{" "C{"
               'words))
 
 (defun factor--regex-second-word (prefixes)
-  (format "^%s +\\([^ ]+\\)" (regexp-opt prefixes t)))
+  (format "^%s +\\([^ \r\n]+\\)" (regexp-opt prefixes t)))
 
 (defconst factor--regex-word-definition
   (factor--regex-second-word '(":" "::" "M:" "GENERIC:")))
 (defconst factor--regex-type-definition
   (factor--regex-second-word '("TUPLE:")))
 
-(defconst factor--regex-const-definition
+(defconst factor--regex-symbol-definition
   (factor--regex-second-word '("SYMBOL:")))
 
 (defconst factor--regex-using-line "^USING: +\\([^;]*\\);")
 (defconst factor--regex-use-line "^USE: +\\(.*\\)$")
 
 (defconst factor-font-lock-keywords
-  `(("#!.*$" . font-lock-comment-face)
-    ("!( .* )" . font-lock-comment-face)
-    ("^!.*$" . font-lock-comment-face)
-    (" !.*$" . font-lock-comment-face)
-    ("( .* )" . font-lock-comment-face)
-    ("\"\\(\\\\\"\\|[^\"]\\)*\"" . font-lock-string-face)
-    ("\\(P\\|SBUF\\)\"" 1 font-lock-keyword-face)
+  `(("#!.*$" . 'factor-font-lock-comment)
+    ("!( .* )" . 'factor-font-lock-comment)
+    ("^!.*$" . 'factor-font-lock-comment)
+    (" !.*$" . 'factor-font-lock-comment)
+    ("( .* )" . 'factor-font-lock-stack-effect)
+    ("\"\\(\\\\\"\\|[^\"]\\)*\"" . 'factor-font-lock-string)
+    ("\\(P\\|SBUF\\)\"" 1 'factor-font-lock-parsing-word)
     ,@(mapcar #'(lambda (w) (cons (concat "\\(^\\| \\)\\(" w "\\)\\($\\| \\)")
-                             '(2 font-lock-keyword-face)))
+                             '(2 'factor-font-lock-parsing-word)))
               factor--parsing-words)
-    (,factor--regex-parsing-words-ext . font-lock-keyword-face)
-    (,factor--regex-word-definition 2 font-lock-function-name-face)
-    (,factor--regex-type-definition 2 font-lock-type-face)
-    (,factor--regex-const-definition 2 font-lock-constant-face)
-    (,factor--regex-using-line 1 font-lock-constant-face)
-    (,factor--regex-use-line 1 font-lock-constant-face)))
-
-(defun factor-indent-line ()
-  "Indent current line as Factor code"
-  (indent-line-to (+ (current-indentation) 4)))
-
-(defun factor-mode ()
-  "A mode for editing programs written in the Factor programming language.
-\\{factor-mode-map}"
-  (interactive)
-  (kill-all-local-variables)
-  (use-local-map factor-mode-map)
-  (setq major-mode 'factor-mode)
-  (setq mode-name "Factor")
-  (set (make-local-variable 'indent-line-function) #'factor-indent-line)
-  (make-local-variable 'comment-start)
-  (setq comment-start "! ")
-  (make-local-variable 'font-lock-defaults)
-  (setq font-lock-defaults
-       '(factor-font-lock-keywords t nil nil nil))
-  (set-syntax-table factor-mode-syntax-table)
-  (make-local-variable 'indent-line-function)
-  (setq indent-line-function 'factor-indent-line)
-  (run-hooks 'factor-mode-hook))
-
-(add-to-list 'auto-mode-alist '("\\.factor\\'" . factor-mode))
+    (,factor--regex-parsing-words-ext . 'factor-font-lock-parsing-word)
+    (,factor--regex-word-definition 2 'factor-font-lock-word-definition)
+    (,factor--regex-type-definition 2 'factor-font-lock-type-definition)
+    (,factor--regex-symbol-definition 2 'factor-font-lock-symbol-definition)
+    (,factor--regex-using-line 1 'factor-font-lock-vocabulary-name)
+    (,factor--regex-use-line 1 'factor-font-lock-vocabulary-name)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; factor-mode commands
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (require 'comint)
 
   (beginning-of-line)
   (insert "! "))
 
+(defvar factor-mode-map (make-sparse-keymap))
+
 (define-key factor-mode-map "\C-c\C-f" 'factor-run-file)
 (define-key factor-mode-map "\C-c\C-r" 'factor-send-region)
 (define-key factor-mode-map "\C-c\C-d" 'factor-send-definition)
 (define-key factor-mode-map [tab]      'indent-for-tab-command)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; indentation
+;; factor-mode indentation
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defun factor-indent-line ()
+  "Indent current line as Factor code"
+  (indent-line-to (+ (current-indentation) 4)))
+
 (defconst factor-word-starting-keywords
   '("" ":" "TUPLE" "MACRO" "MACRO:" "M"))
 
       (if (> (- (point-max) pos) (point))
           (goto-char (- (point-max) pos))))))
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; factor-mode
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun factor-mode ()
+  "A mode for editing programs written in the Factor programming language.
+\\{factor-mode-map}"
+  (interactive)
+  (kill-all-local-variables)
+  (use-local-map factor-mode-map)
+  (setq major-mode 'factor-mode)
+  (setq mode-name "Factor")
+  (set (make-local-variable 'indent-line-function) #'factor-indent-line)
+  (make-local-variable 'comment-start)
+  (setq comment-start "! ")
+  (make-local-variable 'font-lock-defaults)
+  (setq font-lock-defaults
+        '(factor-font-lock-keywords t nil nil nil))
+  (set-syntax-table factor-mode-syntax-table)
+  (make-local-variable 'indent-line-function)
+  (setq indent-line-function 'factor-indent-line)
+  (run-hooks 'factor-mode-hook))
+
+(add-to-list 'auto-mode-alist '("\\.factor\\'" . factor-mode))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; factor-listener-mode
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;