[Typo3-dev] TypoScript 2: a bit of a RFC

Elmar Hinz elmar.DOT.hinz at team.MINUS.red.DOT.net
Wed Nov 30 19:17:21 CET 2005


Michael Scharkow wrote:
> space and make debugging and writing without an IDE harder. Ruby and 

No IDE? Here it comes.

Elmar


;;; ts-mode-el -- Major mode for editing TS files

;; Author: Christoph Kepper <kepper at diefirma.de>
;; Created: 28 Oct 2004
;; Keywords: TS major-mode

;; Based on WPDL-Mode Tutorial by Scott Andrew Borton

;; Copyright (C) 2004 Christoph Kepper <kepper at diefirma.de>
;; Copyright (C) 2000, 2003 Scott Andrew Borton <scott at pp.htv.fi>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or (at
;; your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
;; USA

;;; COMMENTARY
;;
;; This mode is based on an example by Scott Andrew Borton used in a
;; tutorial about Emacs mode creation. The tutorial can be found here:
;; http://two-wugs.net/emacs/mode-tutorial.html
;;
;; This is my first Emacs-mode - please be patient, if things don't work
;; as planned

;;; INSTALLATION
;;
;; To automatically load files with a .ts extension, put the following
;; lines in your .emacs file:
;; (autoload 'ts-mode "ts-mode")
;; (setq auto-mode-alist
;;       (cons '("\\.ts\\'" . ts-mode) auto-mode-alist))

;;; TODO
;;
;; * Disable highlighting for file endings (.html, .php etc.) - still
;;   looking for the correct regex
;; * Include more TypoScript constants

;;; CODE
(defvar ts-mode-hook nil)
(defvar ts-mode-map
   (let ((ts-mode-map (make-keymap)))
     (define-key ts-mode-map "\C-j" 'newline-and-indent)
     ts-mode-map)
   "Keymap for TS major mode")

(add-to-list 'auto-mode-alist '("\\.ts\\'" . ts-mode))

(defconst ts-font-lock-keywords-1
   (list
    ;; These define the beginning and end of each TS entity definition
    '("\\(\\\$\\w*\\|\< \.*\\)" . font-lock-variable-name-face))
   "Minimal highlighting expressions for TS mode.")

(defconst ts-font-lock-keywords-2
   (append ts-font-lock-keywords-1
	  (list
	   ;; These are some possible attributes of TS entities
	   ;; "admPanel" "allWrap" "ATagParams" "case" "config" "doNotLinkIt"
	   ;; "entryLevel" "excludeUidList" "htmlSpecialChars" "includeCSS"
	   ;; "list" "noBlur" "range" "shortcutIcon" "special" "stdWrap"
	   ;; "upper" "userFunc" "value" "wrap"
	 
'("\\<\\(ATagParams\\|a\\(?:dmPanel\\|llWrap\\)\\|c\\(?:ase\\|onfig\\)\\|doNotLinkIt\\|e\\(?:ntryLevel\\|xcludeUidList\\)\\|htmlSpecialChars\\|includeCSS\\|list\\|noBlur\\|range\\|s\\(?:hortcutIcon\\|pecial\\|tdWrap\\)\\|u\\(?:pper\\|serFunc\\)\\|value\\|wrap\\)\\>" 
. font-lock-builtin-face)))
   "Additional Keywords to highlight in TS mode.")

(defconst ts-font-lock-keywords-3
   (append ts-font-lock-keywords-2
	  (list
	   ;; These are some possible keywords for default TypoScript objects

	   ;; "TEMPLATE" "FILE" "PAGE" "HMENU" "GMENU" "TEXT" "USER" "NO"
	   ;; "ACT" "CUR" "TMENU" "HRULER" "IMGTEXT" "HMENU" "JSMENUITEM"
	   ;; "TMENU" "TMENUITEM" "IMGMENU" "IMGMENUITEM" "JSMENU"
	   ;; "GMENU_LAYERS" "HMENU" "TMENU_LAYERS" "GMENU_FOLDOUT" "GMENU"
	   ;; "CLEARGIF" "CONTENT" "RECORDS" "CTABLE" "OTABLE" "COLUMNS"
	   ;; "HTML" "TEXT" "COA" "COA_INT" "COBJ_ARRAY" "FILE" "IMAGE"
	   ;; "IMG_RESOURCE" "CASE" "LOAD_REGISTER" "MULTIMEDIA"
	   ;; "EDITPANEL" "SEARCHRESULT" "USER" "USER_INT" "PHP_SCRIPT"
	   ;; "PHP_SCRIPT_INT" "PHP_SCRIPT_EXT" "TEMPLATE" "FORM" "TEST"

	 
'("\\<\\(ACT\\|C\\(?:ASE\\|LEARGIF\\|O\\(?:A\\(?:_INT\\)?\\|BJ_ARRAY\\|LUMNS\\|NTENT\\)\\|TABLE\\|UR\\)\\|EDITPANEL\\|F\\(?:ILE\\(?:\\)?\\|ORM\\)\\|GMENU\\(?:_\\(?:FOLDOUT\\|LAYERS\\)\\)??\\|H\\(?:MENU\\(?:\\)??\\|RULER\\|TML\\)\\|IM\\(?:AGE\\|G\\(?:MENU\\(?:ITEM\\)?\\|TEXT\\|_RESOURCE\\)\\)\\|JSMENU\\(?:ITEM\\)?\\|LOAD_REGISTER\\|MULTIMEDIA\\|NO\\|OTABLE\\|P\\(?:AGE\\|HP_SCRIPT\\(?:_\\(?:\\(?:EX\\|IN\\)T\\)\\)?\\)\\|RECORDS\\|SEARCHRESULT\\|T\\(?:E\\(?:MPLATE\\(?:\\)?\\|[SX]T\\)\\|MENU\\(?:ITEM\\|_LAYERS\\)??\\)\\|USER\\(?:_INT\\)??\\)\\>" 
. font-lock-keyword-face)
	   ;; All custom properties are matched by this expression
	   ;; TODO: Ausnahme für .php .html .css
	   '("\\([.]\\w+\\)" . font-lock-type-face)
	   )
	  )
   "Balls-out highlighting in TS mode.")

(defvar ts-font-lock-keywords ts-font-lock-keywords-3
   "Default highlighting expressions for TS mode.")

(defun ts-indent-line ()
   "Indent current line as TS code."
   (interactive)
   (beginning-of-line)
   ;; Regel 1
   (if (bobp)
	  (indent-line-to 0)		   ; First line is always non-indented
	(let ((not-indented t) cur-indent)
	  (if (looking-at "^[ \t]*}") ; If the line we are looking at is the 
end of a block, then decrease the indentation
		  (progn
			(save-excursion
			  (forward-line -1)
			  (setq cur-indent (- (current-indentation) default-tab-width)))
			(if (< cur-indent 0) ; We can't indent past the left margin
				(setq cur-indent 0)))
		(save-excursion
		  (while not-indented ; Iterate backwards until we find an indentation 
hint
			(forward-line -1)
			(if (looking-at "^[ \t]*}") ; This hint indicates that we need to 
indent at the level of the END_ token
				(progn
				  (setq cur-indent (current-indentation))
				  (setq not-indented nil))
			  (if (looking-at "^.*{[ \t]*$") ; This hint indicates that we need 
to indent an extra level
				  (progn
					(setq cur-indent (+ (current-indentation) default-tab-width)) ; Do 
the actual indenting
					(setq not-indented nil))
				(if (bobp)
					(setq not-indented nil)))))))
	  (if cur-indent
		  (indent-line-to cur-indent)
		(indent-line-to 0))))) ; If we didn't see an indentation hint, then 
allow no indentation

(defvar ts-mode-syntax-table
   (let ((ts-mode-syntax-table (make-syntax-table)))
	
     ;; This is added so entity names with underscores can be more 
easily parsed
     (modify-syntax-entry ?_ "w" ts-mode-syntax-table) 	

	
     ;; Comment start with # and end with a newline
     (modify-syntax-entry ?\# "<")
     (modify-syntax-entry ?\n ">")

     ts-mode-syntax-table)
   "Syntax table for ts-mode")

(defun ts-mode ()
   "Major Mode for editing TypoScript files"
   (interactive)
   (kill-all-local-variables)
   (use-local-map ts-mode-map)
   (set-syntax-table ts-mode-syntax-table)
   ;; Set up font-lock
   (set (make-local-variable 'font-lock-defaults) '(ts-font-lock-keywords))
   ;; Register our indentation function
   (set (make-local-variable 'indent-line-function) 'ts-indent-line)
   (set (make-local-variable 'default-tab-width) 2)
   (setq major-mode 'ts-mode)
   (setq mode-name "TS")
   (run-hooks 'ts-mode-hook))

(provide 'ts-mode)

;;; ts-mode.el ends here






More information about the TYPO3-dev mailing list