/plugins/nxhtml/related/smarty-mode.el
Emacs Lisp | 2745 lines | 2231 code | 387 blank | 127 comment | 73 complexity | d98779a1cf7c467fc8881c07c74c72f2 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- ;;; smarty-mode.el --- major mode for editing Smarty templates
- ;; Author: Vincent DEBOUT <deboutv@free.fr>
- ;; Maintainer: Vincent DEBOUT <deboutv@free.fr>
- ;; Keywords: languages smarty templates
- ;; WWW: http://deboutv.free.fr/lisp/smarty/
- ;;; License
- ;; 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.
- (defconst smarty-version "0.0.5"
- "Smarty Mode version number.")
- (defconst smarty-time-stamp "2007-11-01"
- "Smarty Mode time stamp for last update.")
- (defconst smarty-is-xemacs (string-match "XEmacs" emacs-version)
- "Non-nil if XEmacs is used.")
- (require 'font-lock)
- (when (not smarty-is-xemacs)
- (require 'cc-mode)
- (require 'custom)
- (require 'etags))
- (eval-when-compile
- (require 'regexp-opt))
- (when smarty-is-xemacs
- (require 'easymenu)
- (require 'hippie-exp))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Customization
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defgroup smarty nil
- "Customizations for Smarty mode."
- :prefix "smarty-"
- :group 'languages)
- (defgroup smarty-mode nil
- "Customizations for Smarty mode."
- :group 'smarty)
- (defcustom smarty-electric-mode t
- "*Non-nil enables electrification (automatic template generation).
- If nil, template generators can still be invoked through key bindings and
- menu. Is indicated in the modeline by \"/e\" after the mode name and can be
- toggled by `\\[smarty-electric-mode]'."
- :type 'boolean
- :group 'smarty-mode)
- (defcustom smarty-stutter-mode t
- "*Non-nil enables stuttering.
- Is indicated in the modeline by \"/s\" after the mode name and can be toggled
- by `\\[smarty-stutter-mode]'."
- :type 'boolean
- :group 'smarty-mode)
- (defgroup smarty-menu nil
- "Customizations for menues."
- :group 'smarty)
- (defcustom smarty-source-file-menu t
- "*Non-nil means add a menu of all source files in current directory."
- :type 'boolean
- :group 'smarty-menu)
- (defgroup smarty-highlight nil
- "Customizations for highlight."
- :group 'smarty)
- (defcustom smarty-highlight-plugin-functions t
- "*Non-nil means highlight the plugin functions in the buffer."
- :type 'boolean
- :group 'smarty-highlight)
- (defgroup smarty-template nil
- "Customizations for templates."
- :group 'smarty)
- (defgroup smarty-header nil
- "Customizations for header template."
- :group 'smarty-template)
- (defcustom smarty-file-header ""
- "*String or file to insert as file header.
- If the string specifies an existing file name, the contents of the file is
- inserted, otherwise the string itself is inserted as file header.
- Type `C-j' for newlines.
- If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
- if the header needs to be version controlled.
- The following keywords for template generation are supported:
- <filename> : replaced by the name of the buffer
- <author> : replaced by the user name and email address
- \(`user-full-name',`mail-host-address', `user-mail-address')
- <login> : replaced by user login name (`user-login-name')
- <company> : replaced by contents of option `smarty-company-name'
- <date> : replaced by the current date
- <year> : replaced by the current year
- <copyright> : replaced by copyright string (`smarty-copyright-string')
- <cursor> : final cursor position."
- :type 'string
- :group 'smarty-header)
- (defcustom smarty-file-footer ""
- "*String or file to insert as file footer.
- If the string specifies an existing file name, the contents of the file is
- inserted, otherwise the string itself is inserted as file footer (i.e. at
- the end of the file).
- Type `C-j' for newlines.
- The same keywords as in option `smarty-file-header' can be used."
- :type 'string
- :group 'smarty-header)
- (defcustom smarty-company-name ""
- "*Name of company to insert in file header.
- See option `smarty-file-header'."
- :type 'string
- :group 'smarty-header)
- (defcustom smarty-copyright-string ""
- "*Copyright string to insert in file header.
- Can be multi-line string (type `C-j' for newline) and contain other file
- header keywords (see option `smarty-file-header')."
- :type 'string
- :group 'smarty-header)
- (defcustom smarty-date-format "%Y-%m-%d"
- "*Specifies the date format to use in the header.
- This string is passed as argument to the command `format-time-string'.
- For more information on format strings, see the documentation for the
- `format-time-string' command (C-h f `format-time-string')."
- :type 'string
- :group 'smarty-header)
- (defcustom smarty-modify-date-prefix-string ""
- "*Prefix string of modification date in Smarty file header.
- If actualization of the modification date is called (menu,
- `\\[smarty-template-modify]'), this string is searched and the rest
- of the line replaced by the current date."
- :type 'string
- :group 'smarty-header)
- (defcustom smarty-modify-date-on-saving nil
- "*Non-nil means update the modification date when the buffer is saved.
- Calls function `\\[smarty-template-modify]').
- NOTE: Activate the new setting in a Smarty buffer by using the menu entry
- \"Activate Options\"."
- :type 'boolean
- :group 'smarty-header)
- (defgroup smarty-misc nil
- "Miscellaneous customizations."
- :group 'smarty)
- (defcustom smarty-left-delimiter "{"
- "Left escaping delimiter."
- :type 'string
- :group 'smarty-misc)
- (defcustom smarty-right-delimiter "}"
- "Right escaping delimiter."
- :type 'string
- :group 'smarty-misc)
- (defcustom smarty-intelligent-tab t
- "*Non-nil means `TAB' does indentation, word completion and tab insertion.
- That is, if preceding character is part of a word then complete word,
- else if not at beginning of line then insert tab,
- else if last command was a `TAB' or `RET' then dedent one step,
- else indent current line (i.e. `TAB' is bound to `smarty-electric-tab').
- If nil, TAB always indents current line (i.e. `TAB' is bound to
- `indent-according-to-mode').
- NOTE: Activate the new setting in a Smarty buffer by using the menu entry
- \"Activate Options\"."
- :type 'boolean
- :group 'smarty-misc)
- (defcustom smarty-word-completion-in-minibuffer t
- "*Non-nil enables word completion in minibuffer (for template prompts).
- NOTE: Activate the new setting by restarting Emacs."
- :type 'boolean
- :group 'smarty-misc)
- (defcustom smarty-word-completion-case-sensitive nil
- "*Non-nil means word completion using `TAB' is case sensitive.
- That is, `TAB' completes words that start with the same letters and case.
- Otherwise, case is ignored."
- :type 'boolean
- :group 'smarty-misc)
- ;; Functions
- (defun smarty-customize ()
- "Call the customize function with `smarty' as argument."
- (interactive)
- (customize-browse 'smarty))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Variables
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defvar smarty-menu-max-size 20
- "*Specifies the maximum size of a menu before splitting it into submenues.")
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Menu tools functions
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun smarty-menu-split (list title)
- "Split menu LIST into several submenues, if number of
- elements > `smarty-menu-max-size'."
- (if (> (length list) smarty-menu-max-size)
- (let ((remain list)
- (result '())
- (sublist '())
- (menuno 1)
- (i 0))
- (while remain
- (setq sublist (cons (car remain) sublist))
- (setq remain (cdr remain))
- (setq i (+ i 1))
- (if (= i smarty-menu-max-size)
- (progn
- (setq result (cons (cons (format "%s %s" title menuno)
- (nreverse sublist)) result))
- (setq i 0)
- (setq menuno (+ menuno 1))
- (setq sublist '()))))
- (and sublist
- (setq result (cons (cons (format "%s %s" title menuno)
- (nreverse sublist)) result)))
- (nreverse result))
- list))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Source file menu
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defvar smarty-sources-menu nil)
- ;; Create the source menu
- (defun smarty-add-source-files-menu ()
- "Scan directory for all Smarty source files and generate menu.
- The directory of the current source file is scanned."
- (interactive)
- (message "Scanning directory for source files ...")
- (let ((newmap (current-local-map))
- (file-list (smarty-get-source-files))
- menu-list found)
- ;; Create list for menu
- (setq found nil)
- (while file-list
- (setq found t)
- (setq menu-list (cons (vector (car file-list)
- (list 'find-file (car file-list)) t)
- menu-list))
- (setq file-list (cdr file-list)))
- (setq menu-list (smarty-menu-split menu-list "Sources"))
- (when found (setq menu-list (cons "--" menu-list)))
- (setq menu-list (cons ["*Rescan*" smarty-add-source-files-menu t] menu-list))
- (setq menu-list (cons "Sources" menu-list))
- ;; Create menu
- (easy-menu-add menu-list)
- (easy-menu-define smarty-sources-menu newmap
- "Smarty source files menu" menu-list))
- (message ""))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Smarty menu
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun smarty-create-mode-menu ()
- "Create Smarty Mode menu."
- `("Smarty"
- ("Templates"
- ("Built-in Functions"
- ["capture" smarty-template-capture t]
- ["config_load" smarty-template-config-load t]
- ["else" smarty-template-else t]
- ["elseif" smarty-template-elseif t]
- ["foreach" smarty-template-foreach t]
- ["foreachelse" smarty-template-foreachelse t]
- ["if" smarty-template-if t]
- ["include" smarty-template-include t]
- ["include_php" smarty-template-include-php t]
- ["insert" smarty-template-insert t]
- ["ldelim" smarty-template-ldelim t]
- ["literal" smarty-template-literal t]
- ["php" smarty-template-php t]
- ["rdelim" smarty-template-rdelim t]
- ["section" smarty-template-section t]
- ["sectionelse" smarty-template-sectionelse t]
- ["strip" smarty-template-strip t])
- ("Custom Functions"
- ["assign" smarty-template-assign t]
- ["counter" smarty-template-counter t]
- ["cycle" smarty-template-cycle t]
- ["debug" smarty-template-debug t]
- ["eval" smarty-template-eval t]
- ["fetch" smarty-template-fetch t]
- ["html_checkboxes" smarty-template-html-checkboxes t]
- ["html_image" smarty-template-html-image t]
- ["html_options" smarty-template-html-options t]
- ["html_radios" smarty-template-html-radios t]
- ["html_select_date" smarty-template-html-select-date t]
- ["html_select_time" smarty-template-html-select-time t]
- ["html_table" smarty-template-html-table t]
- ["mailto" smarty-template-mailto t]
- ["math" smarty-template-math t]
- ["popup" smarty-template-popup t]
- ["popup_init" smarty-template-popup-init t]
- ["textformat" smarty-template-textformat t])
- ("Variable Modifiers"
- ["capitalize" smarty-template-capitalize t]
- ["cat" smarty-template-cat t]
- ["count_characters" smarty-template-count-characters t]
- ["count_paragraphs" smarty-template-count-paragraphs t]
- ["count_sentences" smarty-template-count-sentences t]
- ["count_words" smarty-template-count-words t]
- ["date_format" smarty-template-date-format t]
- ["default" smarty-template-default t]
- ["escape" smarty-template-escape t]
- ["indent" smarty-template-indent t]
- ["lower" smarty-template-lower t]
- ["nl2br" smarty-template-nl2br t]
- ["regex_replace" smarty-template-regex-replace t]
- ["replace" smarty-template-replace t]
- ["spacify" smarty-template-spacify t]
- ["string_format" smarty-template-string-format t]
- ["strip" smarty-template-vstrip t]
- ["strip_tags" smarty-template-strip-tags t]
- ["truncate" smarty-template-truncate t]
- ["upper" smarty-template-upper t]
- ["wordwrap" smarty-template-wordwrap t])
- ("Plugins (Functions)"
- ("BlockRepeatPlugin"
- ["repeat" smarty-template-repeat t]
- ["str_repeat" smarty-template-str-repeat t])
- ("ClipCache"
- ["clipcache" smarty-template-clipcache t]
- ["include_clipcache" smarty-template-include-clipcache t])
- ("SmartyFormtool"
- ["formtool_checkall" smarty-template-formtool-checkall t]
- ["formtool_copy" smarty-template-formtool-copy t]
- ["formtool_count_chars" smarty-template-formtool-count-chars t]
- ["formtool_init" smarty-template-formtool-init t]
- ["formtool_move" smarty-template-formtool-move t]
- ["formtool_moveall" smarty-template-formtool-moveall t]
- ["formtool_movedown" smarty-template-formtool-movedown t]
- ["formtool_moveup" smarty-template-formtool-moveup t]
- ["formtool_remove" smarty-template-formtool-remove t]
- ["formtool_rename" smarty-template-formtool-rename t]
- ["formtool_save" smarty-template-formtool-save t]
- ["formtool_selectall" smarty-template-formtool-selectall t])
- ("SmartyPaginate"
- ["paginate_first" smarty-template-paginate-first t]
- ["paginate_last" smarty-template-paginate-last t]
- ["paginate_middle" smarty-template-paginate-middle t]
- ["paginate_next" smarty-template-paginate-next t]
- ["paginate_prev" smarty-template-paginate-prev t])
- ("SmartyValidate"
- ["validate" smarty-template-validate t]))
- ("Plugins (Variable Modifiers)"
- ("AlternativeDateModifierPlugin"
- ["date_format2" smarty-template-date-formatto t])
- ("B2Smilies"
- ["B2Smilies" smarty-template-btosmilies t])
- ("BBCodePlugin"
- ["bbcode2html" smarty-template-bbcodetohtml t])
- )
- "--"
- ["Insert Header" smarty-template-header t]
- ["Insert Footer" smarty-template-footer t]
- ["Insert Date" smarty-template-insert-date t]
- ["Modify Date" smarty-template-modify t])
- "--"
- ["Show Messages" smarty-show-messages :keys "C-c M-m"]
- ["Smarty Mode Documentation" smarty-doc-mode :keys "C-c C-h"]
- ["Version" smarty-version :keys "C-c C-v"]
- "--"
- ("Options"
- ("Mode"
- ["Electric Mode"
- (progn (customize-set-variable 'smarty-electric-mode
- (not smarty-electric-mode))
- (smarty-mode-line-update))
- :style toggle :selected smarty-electric-mode :keys "C-c C-m C-e"]
- ["Stutter Mode"
- (progn (customize-set-variable 'smarty-stutter-mode
- (not smarty-stutter-mode))
- (smarty-mode-line-update))
- :style toggle :selected smarty-stutter-mode :keys "C-c C-m C-s"]
- "--"
- ["Customize Group..." (customize-group 'smarty-mode) t])
- ("Menu"
- ["Source Menu"
- (customize-set-variable 'smarty-source-file-menu
- (not smarty-source-file-menu))
- :style toggle :selected smarty-source-file-menu]
- "--"
- ["Customize Group..." (customize-group 'smarty-menu) t])
- ("Highlight"
- ["Highlight plugin functions"
- (progn (customize-set-variable 'smarty-highlight-plugin-functions
- (not smarty-highlight-plugin-functions)))
- :style toggle :selected smarty-highlight-plugin-functions]
- "--"
- ["Customize Group..." (customize-group 'smarty-highlight) t])
- ("Template"
- ("Header"
- ["Header template..."
- (customize-option 'smarty-file-header) t]
- ["Footer template..."
- (customize-option 'smarty-file-footer) t]
- ["Company..."
- (customize-option 'smarty-company-name) t]
- ["Copyright..."
- (customize-option 'smarty-copyright-string) t]
- ["Date format..."
- (customize-option 'smarty-date-format) t]
- ["Modify date prefix..."
- (customize-option 'smarty-modify-date-prefix-string) t]
- ["Modify date on saving"
- (customize-set-variable 'smarty-modify-date-on-saving
- (not smarty-modify-date-on-saving))
- :style toggle :selected smarty-modify-date-on-saving]
- "--"
- ["Customize Group..." (customize-group 'smarty-header) t])
- "--"
- ["Customize Group..." (customize-group 'smarty-template) t])
- ("Miscellaneous"
- ["Left delimiter..."
- (customize-option 'smarty-left-delimiter) t]
- ["Right delimiter..."
- (customize-option 'smarty-right-delimiter) t]
- ["Use Intelligent Tab"
- (progn (customize-set-variable 'smarty-intelligent-tab
- (not smarty-intelligent-tab))
- (smarty-activate-customizations))
- :style toggle :selected smarty-intelligent-tab]
- ["Word Completion in Minibuffer"
- (progn (customize-set-variable 'smarty-word-completion-in-minibuffer
- (not smarty-word-completion-in-minibuffer))
- (message "Activate new setting by saving options and restarting Emacs"))
- :style toggle :selected smarty-word-completion-in-minibuffer]
- ["Completion is case sensitive"
- (customize-set-variable 'smarty-word-completion-case-sensitive
- (not smarty-word-completion-case-sensitive))
- :style toggle :selected smarty-word-completion-case-sensitive]
- "--"
- ["Customize Group..." (customize-group 'smarty-misc) t])
- "--"
- ["Save Options" customize-save-customized t]
- ["Activate Options" smarty-activate-customizations t]
- ["Browse Options..." smarty-customize t])))
- (defvar smarty-mode-menu-list (smarty-create-mode-menu)
- "Smarty Mode menu.")
- (defvar smarty-mode-map nil
- "Keymap for Smarty Mode.")
- (defun smarty-update-mode-menu ()
- "Update Smarty Mode menu."
- (interactive)
- (easy-menu-remove smarty-mode-menu-list)
- (setq smarty-mode-menu-list (smarty-create-mode-menu))
- (easy-menu-add smarty-mode-menu-list)
- (easy-menu-define smarty-mode-menu smarty-mode-map
- "Menu keymap for Smarty Mode." smarty-mode-menu-list))
- (defvar smarty-mode-hook nil)
- (defvar smarty-functions nil
- "List of Smarty functions.")
- (defvar smarty-functions-regexp nil
- "Regexp for Smarty functions.")
- (defconst smarty-01-functions
- '("capture" "config_load" "foreach" "foreachelse" "include"
- "include_php" "insert" "if" "elseif" "else" "ldelim" "rdelim"
- "literal" "php" "section" "sectionelse" "strip" "assign" "counter"
- "cycle" "debug" "eval" "fetch" "html_checkboxes" "html_image"
- "html_options" "html_radios" "html_select_date" "html_select_time"
- "html_table" "math" "mailto" "popup_init" "popup" "textformat")
- "Smarty built-in & custom functions.")
- (defvar smarty-modifiers nil
- "List of Smarty variable modifiers.")
- (defvar smarty-modifiers-regexp nil
- "Regexp for Smarty variable modifiers.")
- (defconst smarty-01-modifiers
- '("capitalize" "cat" "count_characters" "count_paragraphs"
- "count_sentences" "count_words" "date_format" "default"
- "escape" "indent" "lower" "nl2br" "regex_replace" "replace"
- "spacify" "string_format" "strip" "strip_tags" "truncate"
- "upper" "wordwrap")
- "Smarty variable modifiers.")
- (defvar smarty-plugins-functions nil
- "List of Smarty functions.")
- (defvar smarty-plugins-functions-regexp nil
- "Regexp for Smarty functions.")
- (defconst smarty-01-plugins-functions
- '("validate" "formtool_checkall" "formtool_copy" "formtool_count_chars"
- "formtool_init" "formtool_move" "formtool_moveall"
- "formtool_movedown" "formtool_moveup" "formtool_remove"
- "formtool_rename" "formtool_save" "formtool_selectall"
- "paginate_first" "paginate_last" "paginate_middle"
- "paginate_next" "paginate_prev" "clipcache" "include_clipcache"
- "repeat" "str_repeat")
- "Smarty plugins functions.")
- (defvar smarty-plugins-modifiers nil
- "List of Smarty variable modifiers.")
- (defvar smarty-plugins-modifiers-regexp nil
- "Regexp for Smarty functions.")
- (defconst smarty-01-plugins-modifiers
- '("B2Smilies" "bbcode2html" "date_format2")
- "Smarty plugins modifiers.")
- (defconst smarty-constants
- (eval-when-compile
- (regexp-opt
- '("TRUE" "FALSE" "NULL") t))
- "Smarty constants.")
-
-
- ;; Syntax table creation
- (defvar smarty-mode-syntax-table nil
- "Syntax table for smarty-mode.")
- (defvar smarty-mode-ext-syntax-table nil
- "Syntax table extended by `_' used in `smarty-mode' buffers.")
- (defun smarty-create-syntax-table ()
- (if smarty-mode-syntax-table
- ()
- (setq smarty-mode-syntax-table (make-syntax-table))
-
- ;; Make | a punctuation character
- (modify-syntax-entry ?| "." smarty-mode-syntax-table)
- ;; Make " a punctuation character so highlighing works withing html strings
- (modify-syntax-entry ?\" "." smarty-mode-syntax-table)
- ;; define parentheses to match
- (modify-syntax-entry ?\( "()" smarty-mode-syntax-table)
- (modify-syntax-entry ?\) ")(" smarty-mode-syntax-table)
- (modify-syntax-entry ?\[ "(]" smarty-mode-syntax-table)
- (modify-syntax-entry ?\] ")[" smarty-mode-syntax-table)
- (modify-syntax-entry ?\{ "(}" smarty-mode-syntax-table)
- (modify-syntax-entry ?\} "){" smarty-mode-syntax-table)
- )
- (set-syntax-table smarty-mode-syntax-table)
- ;; extended syntax table including '_' (for simpler search regexps)
- (setq smarty-mode-ext-syntax-table (copy-syntax-table smarty-mode-syntax-table))
- (modify-syntax-entry ?_ "w" smarty-mode-ext-syntax-table))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; File/directory manipulation
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun smarty-directory-files (directory &optional full match)
- "Call `directory-files' if DIRECTORY exists, otherwise generate error
- message."
- (if (not (file-directory-p directory))
- (smarty-warning-when-idle "No such directory: \"%s\"" directory)
- (let ((dir (directory-files directory full match)))
- (setq dir (delete "." dir))
- (setq dir (delete ".." dir))
- dir)))
- (defun smarty-get-source-files (&optional full directory)
- "Get list of SMARTY source files in DIRECTORY or current directory."
- (let ((mode-alist auto-mode-alist)
- filename-regexp)
- ;; create regular expressions for matching file names
- (setq filename-regexp "\\`[^.].*\\(")
- (while mode-alist
- (when (eq (cdar mode-alist) 'smarty-mode)
- (setq filename-regexp
- (concat filename-regexp (caar mode-alist) "\\|")))
- (setq mode-alist (cdr mode-alist)))
- (setq filename-regexp
- (concat (substring filename-regexp 0
- (string-match "\\\\|$" filename-regexp)) "\\)"))
- ;; find files
- (smarty-directory-files
- (or directory default-directory) full filename-regexp)))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Messages reporting
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defvar smarty-warnings nil
- "Warnings to tell the user during start up.")
- (defun smarty-run-when-idle (secs repeat function)
- "Wait until idle, then run FUNCTION."
- (if (fboundp 'start-itimer)
- (start-itimer "smarty-mode" function secs repeat t)
- ; (run-with-idle-timer secs repeat function)))
- ;; explicitely activate timer (necessary when Emacs is already idle)
- (aset (run-with-idle-timer secs repeat function) 0 nil)))
- (defun smarty-warning-when-idle (&rest args)
- "Wait until idle, then print out warning STRING and beep."
- (save-match-data ;; runs in timer
- (if noninteractive
- (smarty-warning (apply 'format args) t)
- (unless smarty-warnings
- (smarty-run-when-idle .1 nil 'smarty-print-warnings))
- (setq smarty-warnings (cons (apply 'format args) smarty-warnings)))))
- (defun smarty-warning (string &optional nobeep)
- "Print out warning STRING and beep."
- (message (concat "WARNING: " string))
- (unless (or nobeep noninteractive) (beep)))
- (defun smarty-print-warnings ()
- "Print out messages in variable `smarty-warnings'."
- (let ((no-warnings (length smarty-warnings)))
- (setq smarty-warnings (nreverse smarty-warnings))
- (while smarty-warnings
- (message (concat "WARNING: " (car smarty-warnings)))
- (setq smarty-warnings (cdr smarty-warnings)))
- (beep)
- (when (> no-warnings 1)
- (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
- (defun smarty-show-messages ()
- "Get *Messages* buffer to show recent messages."
- (interactive)
- (display-buffer " *Message-Log*"))
- (defun smarty-version ()
- "Echo the current version of Smarty Mode in the minibuffer."
- (interactive)
- (message "Smarty Mode %s (%s)" smarty-version smarty-time-stamp)
- (smarty-keep-region-active))
- ;; active regions
- (defun smarty-keep-region-active ()
- "Do whatever is necessary to keep the region active in XEmacs.
- Ignore byte-compiler warnings you might see."
- (and (boundp 'zmacs-region-stays)
- (setq zmacs-region-stays t)))
- (defmacro smarty-prepare-search-1 (&rest body)
- "Enable case insensitive search and switch to syntax table that includes '_',
- then execute BODY, and finally restore the old environment. Used for
- consistent searching."
- `(let ((case-fold-search t) ; case insensitive search
- (current-syntax-table (syntax-table))
- result
- (restore-prog ; program to restore enviroment
- '(progn
- ;; restore syntax table
- (set-syntax-table current-syntax-table))))
- ;; use extended syntax table
- (set-syntax-table smarty-mode-ext-syntax-table)
- ;; execute BODY safely
- (setq result
- (condition-case info
- (progn ,@body)
- (error (eval restore-prog) ; restore environment on error
- (error (cadr info))))) ; pass error up
- ;; restore environment
- (eval restore-prog)
- result))
- (defmacro smarty-prepare-search-2 (&rest body)
- "Enable case insensitive search, switch to syntax table that includes '_',
- and remove `intangible' overlays, then execute BODY, and finally restore the
- old environment. Used for consistent searching."
- `(let ((case-fold-search t) ; case insensitive search
- (current-syntax-table (syntax-table))
- result overlay-all-list overlay-intangible-list overlay
- (restore-prog ; program to restore enviroment
- '(progn
- ;; restore syntax table
- (set-syntax-table current-syntax-table)
- ;; restore `intangible' overlays
- (when (fboundp 'overlay-lists)
- (while overlay-intangible-list
- (overlay-put (car overlay-intangible-list) 'intangible t)
- (setq overlay-intangible-list
- (cdr overlay-intangible-list)))))))
- ;; use extended syntax table
- (set-syntax-table smarty-mode-ext-syntax-table)
- ;; remove `intangible' overlays
- (when (fboundp 'overlay-lists)
- (setq overlay-all-list (overlay-lists))
- (setq overlay-all-list
- (append (car overlay-all-list) (cdr overlay-all-list)))
- (while overlay-all-list
- (setq overlay (car overlay-all-list))
- (when (memq 'intangible (overlay-properties overlay))
- (setq overlay-intangible-list
- (cons overlay overlay-intangible-list))
- (overlay-put overlay 'intangible nil))
- (setq overlay-all-list (cdr overlay-all-list))))
- ;; execute BODY safely
- (setq result
- (condition-case info
- (progn ,@body)
- (error (eval restore-prog) ; restore environment on error
- (error (cadr info))))) ; pass error up
- ;; restore environment
- (eval restore-prog)
- result))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Enabling/disabling
- (defun smarty-mode-line-update ()
- "Update the modeline string for Smarty major mode."
- (setq mode-name (concat "Smarty"
- (and (or smarty-electric-mode smarty-stutter-mode) "/")
- (and smarty-electric-mode "e")
- (and smarty-stutter-mode "s")))
- (force-mode-line-update t))
- (defun smarty-electric-mode (arg)
- "Toggle Smarty electric mode.
- Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
- (interactive "P")
- (setq smarty-electric-mode
- (cond ((or (not arg) (zerop arg)) (not smarty-electric-mode))
- ((> arg 0) t) (t nil)))
- (smarty-mode-line-update))
- (defun smarty-stutter-mode (arg)
- "Toggle Smarty stuttering mode.
- Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
- (interactive "P")
- (setq smarty-stutter-mode
- (cond ((or (not arg) (zerop arg)) (not smarty-stutter-mode))
- ((> arg 0) t) (t nil)))
- (smarty-mode-line-update))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Smarty code delimitation
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun smarty-in-literal ()
- "Determine if point is in a Smarty literal."
- (save-excursion
- (let ((here (point))
- start state)
- (beginning-of-line)
- (setq start (point))
- (goto-char here)
- (setq state (parse-partial-sexp start (point)))
- (cond
- ((nth 3 state) 'string)
- ((nth 4 state) 'comment)
- (t nil)))))
- (defun smarty-in-comment-p ()
- "Check if point is in a comment."
- (let ((result nil) (here (point-marker)) found)
- (save-excursion
- (setq found (re-search-backward (regexp-quote (concat smarty-left-delimiter "*")) nil t))
- (when found
- (setq result (re-search-forward (regexp-quote (concat "*" smarty-right-delimiter)) here t))
- (setq result (not result))))
- result))
- (defun smarty-after-ldelim ()
- "Check that the previous character is the left delimiter."
- (let ((here (point-marker)) ldelim-found ldelim-point)
- (save-excursion
- (setq ldelim-found (re-search-backward (regexp-quote smarty-left-delimiter) nil t))
- (re-search-forward (regexp-quote smarty-left-delimiter) here t)
- (setq ldelim-point (point-marker))
- (goto-char here)
- (if (and (= here ldelim-point) ldelim-found)
- t
- nil))))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Words to expand
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun smarty-words-init ()
- "Initialize reserved words."
- (setq smarty-functions smarty-01-functions)
- (setq smarty-modifiers smarty-01-modifiers)
- (setq smarty-plugins-functions smarty-01-plugins-functions)
- (setq smarty-plugins-modifiers smarty-01-plugins-modifiers)
- (setq smarty-functions-regexp (concat "\\<\\(" (regexp-opt smarty-functions) "\\)\\>"))
- (setq smarty-modifiers-regexp (concat "\\<\\(" (regexp-opt smarty-modifiers) "\\)\\>"))
- (setq smarty-plugins-functions-regexp (concat "\\<\\(" (regexp-opt smarty-plugins-functions) "\\)\\>"))
- (setq smarty-plugins-modifiers-regexp (concat "\\<\\(" (regexp-opt smarty-plugins-modifiers) "\\)\\>"))
- (smarty-abbrev-list-init))
- (defvar smarty-abbrev-list nil
- "Predefined abbreviations for Smarty.")
- (defun smarty-abbrev-list-init ()
- (setq smarty-abbrev-list
- (append
- (list nil) smarty-functions
- (list nil) smarty-modifiers
- (list nil) smarty-plugins-functions
- (list nil) smarty-plugins-modifiers)))
- (defvar smarty-expand-upper-case nil)
- (defun smarty-try-expand-abbrev (old)
- "Try expanding abbreviations from `smarty-abbrev-list'."
- (unless old
- (he-init-string (he-dabbrev-beg) (point))
- (setq he-expand-list
- (let ((abbrev-list smarty-abbrev-list)
- (sel-abbrev-list '()))
- (while abbrev-list
- ; (if (stringp (car abbrev-list))
- ; (insert (concat " " (car abbrev-list))))
- (when (or (not (stringp (car abbrev-list)))
- (string-match
- (concat "^" he-search-string) (car abbrev-list)))
- (setq sel-abbrev-list
- (cons (car abbrev-list) sel-abbrev-list)))
- (setq abbrev-list (cdr abbrev-list)))
- (nreverse sel-abbrev-list))))
- (while (and he-expand-list
- (or (not (stringp (car he-expand-list)))
- (he-string-member (car he-expand-list) he-tried-table t)))
- (unless (stringp (car he-expand-list))
- (setq smarty-expand-upper-case (car he-expand-list)))
- (setq he-expand-list (cdr he-expand-list)))
- (if (null he-expand-list)
- (progn (when old (he-reset-string))
- nil)
- (he-substitute-string
- (if smarty-expand-upper-case
- (upcase (car he-expand-list))
- (car he-expand-list))
- t)
- (setq he-expand-list (cdr he-expand-list))
- t))
- ;; initialize reserved words for Smarty Mode
- (smarty-words-init)
- ;; function for expanding abbrevs and dabbrevs
- (defun smarty-expand-abbrev (arg))
- (fset 'smarty-expand-abbrev (make-hippie-expand-function
- '(try-expand-dabbrev
- try-expand-dabbrev-all-buffers
- smarty-try-expand-abbrev)))
- ;; function for expanding parenthesis
- (defun smarty-expand-paren (arg))
- (fset 'smarty-expand-paren (make-hippie-expand-function
- '(try-expand-list
- try-expand-list-all-buffers)))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Stuttering
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun smarty-electric-tab (&optional prefix-arg)
- "If preceding character is part of a word or a paren then hippie-expand,
- else if right of non whitespace on line then insert tab,
- else if last command was a tab or return then dedent one step or if a comment
- toggle between normal indent and inline comment indent,
- else indent `correctly'."
- (interactive "*P")
- (smarty-prepare-search-2
- (cond
- ;; expand word
- ((= (char-syntax (preceding-char)) ?w)
- (let ((case-fold-search (not smarty-word-completion-case-sensitive))
- (case-replace nil)
- (hippie-expand-only-buffers
- (or (and (boundp 'hippie-expand-only-buffers)
- hippie-expand-only-buffers)
- '(smarty-mode))))
- (smarty-expand-abbrev prefix-arg)))
- ;; expand parenthesis
- ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
- (let ((case-fold-search (not smarty-word-completion-case-sensitive))
- (case-replace nil))
- (smarty-expand-paren prefix-arg))))
- (setq this-command 'smarty-electric-tab)))
- (defun smarty-electric-space (count)
- "Expand abbreviations and self-insert space(s)."
- (interactive "p")
- (let ((here (point-marker)) ldelim-found ldelim-point rdelim-found rdelim-point
- delete-a)
- (setq ldelim-found (re-search-backward (regexp-quote smarty-left-delimiter) nil t))
- (re-search-forward (regexp-quote smarty-left-delimiter) here t)
- (setq ldelim-point (point-marker))
- (goto-char here)
- (setq rdelim-found (re-search-backward (regexp-quote (concat " " smarty-right-delimiter)) nil t))
- (re-search-forward (regexp-quote (concat " " smarty-right-delimiter)) here t)
- (setq rdelim-point (point-marker))
- (goto-char here)
- (cond ((and (= here ldelim-point) ldelim-found) (insert (concat "ldelim" smarty-right-delimiter)))
- ((and (= here rdelim-point) rdelim-found)
- (re-search-backward (regexp-quote (concat " " smarty-right-delimiter)) nil t)
- (delete-char 1)
- (insert (concat " " smarty-left-delimiter "rdelim"))
- (goto-char here))
- ((smarty-in-comment-p)
- (self-insert-command count)
- (cond ((>= (current-column) (+ 2 end-comment-column))
- (backward-char 1)
- (skip-chars-backward "^ \t\n")
- (indent-new-comment-line)
- (skip-chars-forward "^ \t\n")
- (forward-char 1))
- ((>= (current-column) end-comment-column)
- (indent-new-comment-line))
- (t nil)))
- ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
- (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z))
- (and (>= (preceding-char) ?0) (<= (preceding-char) ?9)))
- (progn
- (setq here (point-marker))
- (insert " ")
- (setq delete-a t)
- (if (re-search-backward "|" nil t)
- (progn
- (setq found (re-search-forward (regexp-quote "B2Smilies") here t))
- (if (and found (= here (point-marker)))
- (replace-match "btosmilies")
- (setq found (re-search-forward (regexp-quote "bbcode2html") here t))
- (if (and found (= here (point-marker)))
- (replace-match "bbcodetohtml")
- (setq found (re-search-forward (regexp-quote "date_format2") here t))
- (if (and found (= here (point-marker)))
- (replace-match "date_formatto")
- (goto-char here)
- (setq delete-a nil)
- (delete-char 1)))))
- (goto-char here)
- (setq delete-a nil)
- (delete-char 1)))
- (smarty-prepare-search-1 (expand-abbrev))
- (self-insert-command count)
- (if (and delete-a (looking-at " "))
- (delete-char 1)))
- (t (self-insert-command count)))))
- (defun smarty-electric-open-bracket (count)
- "'(' --> '(', '((' --> '[', '[(' --> '{'"
- (interactive "p")
- (if (and smarty-stutter-mode (= count 1) (not (smarty-in-literal)))
- (if (= (preceding-char) ?\()
- (progn (delete-char -1) (insert-char ?\[ 1))
- (if (= (preceding-char) ?\[)
- (progn (delete-char -1) (insert-char ?\{ 1))
- (insert-char ?\( 1)))
- (self-insert-command count)))
- (defun smarty-electric-close-bracket (count)
- "')' --> ')', '))' --> ']', '])' --> '}'"
- (interactive "p")
- (if (and smarty-stutter-mode (= count 1) (not (smarty-in-literal)))
- (progn
- (if (= (preceding-char) ?\))
- (progn (delete-char -1) (insert-char ?\] 1))
- (if (= (preceding-char) ?\])
- (progn (delete-char -1) (insert-char ?} 1))
- (insert-char ?\) 1)))
- (blink-matching-open))
- (self-insert-command count)))
- (defun smarty-electric-star (count)
- "After a left delimiter add a right delemiter to close the comment"
- (interactive "p")
- (let ((here (point-marker)) found)
- (if (and smarty-stutter-mode (= count 1) (not (smarty-in-literal)))
- (progn
- (setq found (re-search-backward (regexp-quote smarty-left-delimiter) nil t))
- (re-search-forward (regexp-quote smarty-left-delimiter) here t)
- (if (not (and (= here (point-marker)) found))
- (progn (goto-char here)
- (self-insert-command count))
- (self-insert-command count)
- (insert " ")
- (setq here (point-marker))
- (insert " *")
- (insert smarty-right-delimiter)
- (goto-char here)))
- (self-insert-command count))))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Electrification
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defconst smarty-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
- "Syntax of prompt inserted by template generators.")
- (defvar smarty-template-invoked-by-hook nil
- "Indicates whether a template has been invoked by a hook or by key or menu.
- Used for undoing after template abortion.")
- (defun smarty-minibuffer-tab (&optional prefix-arg)
- "If preceding character is part of a word or a paren then hippie-expand,
- else insert tab (used for word completion in Smarty minibuffer)."
- (interactive "P")
- (cond
- ;; expand word
- ((= (char-syntax (preceding-char)) ?w)
- (let ((case-fold-search (not smarty-word-completion-case-sensitive))
- (case-replace nil)
- (hippie-expand-only-buffers
- (or (and (boundp 'hippie-expand-only-buffers)
- hippie-expand-only-buffers)
- '(smarty-mode))))
- (smarty-expand-abbrev prefix-arg)))
- ;; expand parenthesis
- ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
- (let ((case-fold-search (not smarty-word-completion-case-sensitive))
- (case-replace nil))
- (smarty-expand-paren prefix-arg)))
- ;; insert tab
- (t (insert-tab))))
- ;; correct different behavior of function `unread-command-events' in XEmacs
- (defun smarty-character-to-event (arg))
- (defalias 'smarty-character-to-event
- (if (fboundp 'character-to-event) 'character-to-event 'identity))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Abbrev ook bindings
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defvar smarty-mode-abbrev-table nil
- "Abbrev table to use in `smarty-mode' buffers.")
- (defun smarty-mode-abbrev-table-init ()
- "Initialize `smarty-mode-abbrev-table'."
- (when smarty-mode-abbrev-table (clear-abbrev-table smarty-mode-abbrev-table))
- (define-abbrev-table 'smarty-mode-abbrev-table
- (append
- '(
- ("capture" "" smarty-template-capture-hook 0)
- ("config_load" "" smarty-template-config-load-hook 0)
- ("else" "" smarty-template-else-hook 0)
- ("elseif" "" smarty-template-elseif-hook 0)
- ("foreach" "" smarty-template-foreach-hook 0)
- ("foreachelse" "" smarty-template-foreachelse-hook 0)
- ("if" "" smarty-template-if-hook 0)
- ("include" "" smarty-template-include-hook 0)
- ("include_php" "" smarty-template-include-php-hook 0)
- ("insert" "" smarty-template-insert-hook 0)
- ("ldelim" "" smarty-template-ldelim-hook 0)
- ("literal" "" smarty-template-literal-hook 0)
- ("php" "" smarty-template-php-hook 0)
- ("rdelim" "" smarty-template-rdelim-hook 0)
- ("section" "" smarty-template-section-hook 0)
- ("sectionelse" "" smarty-template-sectionelse-hook 0)
- ("strip" "" smarty-template-strip-hook 0)
- ("assign" "" smarty-template-assign-hook 0)
- ("counter" "" smarty-template-counter-hook 0)
- ("cycle" "" smarty-template-cycle-hook 0)
- ("debug" "" smarty-template-debug-hook 0)
- ("eval" "" smarty-template-eval-hook 0)
- ("fetch" "" smarty-template-fetch-hook 0)
- ("html_checkboxes" "" smarty-template-html-checkboxes-hook 0)
- ("html_image" "" smarty-template-html-image-hook 0)
- ("html_options" "" smarty-template-html-options-hook 0)
- ("html_radios" "" smarty-template-html-radios-hook 0)
- ("html_select_date" "" smarty-template-html-select-date-hook 0)
- ("html_select_time" "" smarty-template-html-select-time-hook 0)
- ("html_table" "" smarty-template-html-table-hook 0)
- ("mailto" "" smarty-template-mailto-hook 0)
- ("math" "" smarty-template-math-hook 0)
- ("popup" "" smarty-template-popup-hook 0)
- ("popup_init" "" smarty-template-popup-init-hook 0)
- ("textformat" "" smarty-template-textformat-hook 0)
- ("capitalize" "" smarty-template-capitalize-hook 0)
- ("cat" "" smarty-template-cat-hook 0)
- ("count_characters" "" smarty-template-count-characters-hook 0)
- ("count_paragraphs" "" smarty-template-count-paragraphs-hook 0)
- ("count_sentences" "" smarty-template-count-sentences-hook 0)
- ("count_words" "" smarty-template-count-words-hook 0)
- ("date_format" "" smarty-template-date-format-hook 0)
- ("default" "" smarty-template-default-hook 0)
- ("escape" "" smarty-template-escape-hook 0)
- ("indent" "" smarty-template-indent-hook 0)
- ("lower" "" smarty-template-lower-hook 0)
- ("nl2br" "" smarty-template-nl2br-hook 0)
- ("regex_replace" "" smarty-template-regex-replace-hook 0)
- ("replace" "" smarty-template-replace-hook 0)
- ("spacify" "" smarty-template-spacify-hook 0)
- ("string_format" "" smarty-template-string-format-hook 0)
- ("strip" "" smarty-template-vstrip-hook 0)
- ("strip_tags" "" smarty-template-strip-tags-hook 0)
- ("truncate" "" smarty-template-truncate-hook 0)
- ("upper" "" smarty-template-upper-hook 0)
- ("wordwrap" "" smarty-template-wordwrap-hook 0)
- ("validate" "" smarty-template-validate-hook 0)
- ("clipcache" "" smarty-template-clipcache-hook 0)
- ("repeat" "" smarty-template-repeat-hook 0)
- ("str_repeat" "" smarty-template-str-repeat-hook 0)
- ("include_clipcache" "" smarty-template-include-clipcache-hook 0)
- ("formtool_checkall" "" smarty-template-formtool-checkall-hook 0)
- ("formtool_copy" "" smarty-template-formtool-copy-hook 0)
- ("formtool_count_chars" "" smarty-template-formtool-count-chars-hook 0)
- ("formtool_init" "" smarty-template-formtool-init-hook 0)
- ("formtool_move" "" smarty-template-formtool-move-hook 0)
- ("formtool_moveall" "" smarty-template-formtool-moveall-hook 0)
- ("formtool_movedown" "" smarty-template-formtool-movedown-hook 0)
- ("formtool_moveup" "" smarty-template-formtool-moveup-hook 0)
- ("formtool_remove" "" smarty-template-formtool-remove-hook 0)
- ("formtool_rename" "" smarty-template-formtool-rename-hook 0)
- ("formtool_save" "" smarty-template-formtool-save-hook 0)
- ("formtool_selectall" "" smarty-template-formtool-selectall-hook 0)
- ("paginate_first" "" smarty-template-paginate-first-hook 0)
- ("paginate_last" "" smarty-template-paginate-last-hook 0)
- ("paginate_middle" "" smarty-template-paginate-middle-hook 0)
- ("paginate_next" "" smarty-template-paginate-next-hook 0)
- ("paginate_prev" "" smarty-template-paginate-prev-hook 0)
- ("btosmilies" "" smarty-template-btosmilies-hook 0)
- ("bbcodetohtml" "" smarty-template-bbcodetohtml-hook 0)
- ("date_formatto" "" smarty-template-date-formatto-hook 0)))))
- ;; initialize abbrev table for Smarty Mode
- (smarty-mode-abbrev-table-init)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Abbrev hooks
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun smarty-hooked-abbrev (func)
- "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
- but not if inside a comment or quote)."
- (if (or (smarty-in-literal)
- (smarty-in-comment-p))
- (progn
- (insert " ")
- (unexpand-abbrev)
- (delete-char -1))
- (if (not smarty-electric-mode)
- (progn
- (insert " ")
- (unexpand-abbrev)
- (backward-word 1)
- (delete-char 1))
- (let ((invoke-char last-command-char)
- (abbrev-mode -1)
- (smarty-template-invoked-by-hook t))
- (let ((caught (catch 'abort
- (funcall func))))
- (when (stringp caught) (message caught)))
- (when (= invoke-char ?-) (setq abbrev-start-location (point)))
- ;; delete CR which is still in event queue
- (if (fboundp 'enqueue-eval-event)
- (enqueue-eval-event 'delete-char -1)
- (setq unread-command-events ; push back a delete char
- (list (smarty-character-to-event ?\177))))))))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Fontification
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defvar smarty-font-lock-keywords-1
- (list
-
- ;; Fontify built-in functions
- (cons
- (concat (regexp-quote smarty-left-delimiter) "[/]*" smarty-functions-regexp)
- '(1 font-lock-keyword-face))
- (cons
- (concat "\\<\\(" smarty-constants "\\)\\>")
- 'font-lock-constant-face)
- (cons (concat "\\(" (regexp-quote (concat smarty-left-delimiter "*")) "\\(\\s-\\|\\w\\|\\s.\\|\\s_\\|\\s(\\|\\s)\\|\\s\\\\)*" (regexp-quote (concat "*" smarty-right-delimiter)) "\\)")
- 'font-lock-comment-face)
- )
- "Subdued level highlighting for Smarty mode.")
- (defconst smarty-font-lock-keywords-2
- (append
- smarty-font-lock-keywords-1
- (list
- ;; Fontify variable names (\\sw\\|\\s_\\) matches any word character +
- ;; underscore
- '("\\$\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face)) ; $variable
- '("->\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face t t)) ; ->variable
- '("\\.\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face t t)) ; .variable
- '("->\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" (1 font-lock-function-name-face t t)) ; ->function_call
- '("\\<\\(\\(?:\\sw\\|\\s_\\)+\\s-*\\)(" (1 font-lock-function-name-face)) ; word(
- '("\\<\\(\\(?:\\sw\\|\\s_\\)+\\s-*\\)[[]" (1 font-lock-variable-name-face)) ; word[
- '("\\<[0-9]+" . default) ; number (also matches word)
- ;; Fontify strings
- ;;'("\"\\([^\"]*\\)\"[^\"]+" (1 font-lock-string-face t t))
- ))
-
- "Medium level highlighting for Smarty mode.")
- (defconst smarty-font-lock-keywords-3
- (append
- smarty-font-lock-keywords-2
- (list
- ;; Fontify modifiers
- (cons (concat "|\\(" smarty-modifiers-regexp "\\)[:|]+") '(1 font-lock-function-name-face))
- (cons (concat "|\\(" smarty-modifiers-regexp "\\)" (regexp-quote smarty-right-delimiter)) '(1 font-lock-function-name-face))
-
- ;; Fontify config vars
- (cons (concat (regexp-quote smarty-left-delimiter) "\\(#\\(?:\\sw\\|\\s_\\)+#\\)") '(1 font-lock-constant-face))))
- "Balls-out highlighting for Smarty mode.")
- (defconst smarty-font-lock-keywords-4
- (append
- smarty-font-lock-keywords-3
- (list
- ;; Fontify plugin functions
- (cons
- (concat (regexp-quote smarty-left-delimiter) "[/]*" smarty-plugins-functions-regexp)
- '(1 font-lock-keyword-face))
- (cons (concat "|\\(" smarty-plugins-modifiers-regexp "\\)[:|]+") '(1 font-lock-function-name-face))
- (cons (concat "|\\(" smarty-plugins-modifiers-regexp "\\)" (regexp-quote smarty-right-delimiter)) '(1 font-lock-function-name-face)))))
- (defvar smarty-font-lock-keywords smarty-font-lock-keywords-3
- "Default highlighting level for Smarty mode")
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Mode map
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defvar smarty-template-map nil
- "Keymap for Smarty templates.")
- (defun smarty-template-map-init ()
- "Initialize `smarty-template-map'."
- (setq smarty-template-map (make-sparse-keymap))
- ;; key bindings for Smarty templates
- (define-key smarty-template-map "\C-ba" 'smarty-template-capture)
- (define-key smarty-template-map "\C-bc" 'smarty-template-config-load)
- (define-key smarty-template-map "\C-b\M-e" 'smarty-template-else)
- (define-key smarty-template-map "\C-b\C-e" 'smarty-template-elseif)
- (define-key smarty-template-map "\C-b\C-f" 'smarty-template-foreach)
- (define-key smarty-template-map "\C-b\M-f" 'smarty-template-foreachelse)
- (define-key smarty-template-map "\C-bf" 'smarty-template-if)
- (define-key smarty-template-map "\C-b\C-i" 'smarty-template-include)
- (define-key smarty-template-map "\C-b\M-i" 'smarty-template-include-php)
- (define-key smarty-template-map "\C-bi" 'smarty-template-insert)
- (define-key smarty-template-…
Large files files are truncated, but you can click here to view the full file