/.emacs.d/el-get/nxhtml/related/smarty-mode.el

https://bitbucket.org/shuangxinyu/emacspack · Lisp · 2753 lines · 2230 code · 390 blank · 133 comment · 72 complexity · 6631c8e5de97ff1b6efec5bba142f6a4 MD5 · raw file

  1. ;;; smarty-mode.el --- major mode for editing Smarty templates
  2. ;; Author: Vincent DEBOUT <deboutv@free.fr>
  3. ;; Maintainer: Vincent DEBOUT <deboutv@free.fr>
  4. ;; Keywords: languages smarty templates
  5. ;; WWW: http://deboutv.free.fr/lisp/smarty/
  6. ;;; License
  7. ;; This program is free software; you can redistribute it and/or
  8. ;; modify it under the terms of the GNU General Public License
  9. ;; as published by the Free Software Foundation; either version 2
  10. ;; of the License, or (at your option) any later version.
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program; if not, write to the Free Software
  17. ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. ;; Minor changes by Lennart Borgman
  19. (defconst smarty-version "0.0.5"
  20. "Smarty Mode version number.")
  21. (defconst smarty-time-stamp "2007-11-01"
  22. "Smarty Mode time stamp for last update.")
  23. (defconst smarty-is-xemacs (string-match "XEmacs" emacs-version)
  24. "Non-nil if XEmacs is used.")
  25. (require 'font-lock)
  26. (when (not smarty-is-xemacs)
  27. (require 'cc-mode)
  28. (require 'custom)
  29. (require 'etags))
  30. (eval-when-compile
  31. (require 'regexp-opt))
  32. ;;(when smarty-is-xemacs
  33. (require 'easymenu)
  34. (require 'hippie-exp)
  35. ;;)
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ;;; Customization
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ;;;###autoload
  40. (defgroup smarty nil
  41. "Customizations for Smarty mode."
  42. :prefix "smarty-"
  43. :group 'languages)
  44. (defgroup smarty-mode nil
  45. "Customizations for Smarty mode."
  46. :group 'smarty)
  47. (defcustom smarty-electric-mode t
  48. "*Non-nil enables electrification (automatic template generation).
  49. If nil, template generators can still be invoked through key bindings and
  50. menu. Is indicated in the modeline by \"/e\" after the mode name and can be
  51. toggled by `\\[smarty-electric-mode]'."
  52. :type 'boolean
  53. :group 'smarty-mode)
  54. (defcustom smarty-stutter-mode t
  55. "*Non-nil enables stuttering.
  56. Is indicated in the modeline by \"/s\" after the mode name and can be toggled
  57. by `\\[smarty-stutter-mode]'."
  58. :type 'boolean
  59. :group 'smarty-mode)
  60. (defgroup smarty-menu nil
  61. "Customizations for menues."
  62. :group 'smarty)
  63. (defcustom smarty-source-file-menu t
  64. "*Non-nil means add a menu of all source files in current directory."
  65. :type 'boolean
  66. :group 'smarty-menu)
  67. (defgroup smarty-highlight nil
  68. "Customizations for highlight."
  69. :group 'smarty)
  70. (defcustom smarty-highlight-plugin-functions t
  71. "*Non-nil means highlight the plugin functions in the buffer."
  72. :type 'boolean
  73. :group 'smarty-highlight)
  74. (defgroup smarty-template nil
  75. "Customizations for templates."
  76. :group 'smarty)
  77. (defgroup smarty-header nil
  78. "Customizations for header template."
  79. :group 'smarty-template)
  80. (defcustom smarty-file-header ""
  81. "*String or file to insert as file header.
  82. If the string specifies an existing file name, the contents of the file is
  83. inserted, otherwise the string itself is inserted as file header.
  84. Type `C-j' for newlines.
  85. If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
  86. if the header needs to be version controlled.
  87. The following keywords for template generation are supported:
  88. <filename> : replaced by the name of the buffer
  89. <author> : replaced by the user name and email address
  90. \(`user-full-name',`mail-host-address', `user-mail-address')
  91. <login> : replaced by user login name (`user-login-name')
  92. <company> : replaced by contents of option `smarty-company-name'
  93. <date> : replaced by the current date
  94. <year> : replaced by the current year
  95. <copyright> : replaced by copyright string (`smarty-copyright-string')
  96. <cursor> : final cursor position."
  97. :type 'string
  98. :group 'smarty-header)
  99. (defcustom smarty-file-footer ""
  100. "*String or file to insert as file footer.
  101. If the string specifies an existing file name, the contents of the file is
  102. inserted, otherwise the string itself is inserted as file footer (i.e. at
  103. the end of the file).
  104. Type `C-j' for newlines.
  105. The same keywords as in option `smarty-file-header' can be used."
  106. :type 'string
  107. :group 'smarty-header)
  108. (defcustom smarty-company-name ""
  109. "*Name of company to insert in file header.
  110. See option `smarty-file-header'."
  111. :type 'string
  112. :group 'smarty-header)
  113. (defcustom smarty-copyright-string ""
  114. "*Copyright string to insert in file header.
  115. Can be multi-line string (type `C-j' for newline) and contain other file
  116. header keywords (see option `smarty-file-header')."
  117. :type 'string
  118. :group 'smarty-header)
  119. (defcustom smarty-date-format "%Y-%m-%d"
  120. "*Specifies the date format to use in the header.
  121. This string is passed as argument to the command `format-time-string'.
  122. For more information on format strings, see the documentation for the
  123. `format-time-string' command (C-h f `format-time-string')."
  124. :type 'string
  125. :group 'smarty-header)
  126. (defcustom smarty-modify-date-prefix-string ""
  127. "*Prefix string of modification date in Smarty file header.
  128. If actualization of the modification date is called (menu,
  129. `\\[smarty-template-modify]'), this string is searched and the rest
  130. of the line replaced by the current date."
  131. :type 'string
  132. :group 'smarty-header)
  133. (defcustom smarty-modify-date-on-saving nil
  134. "*Non-nil means update the modification date when the buffer is saved.
  135. Calls function `\\[smarty-template-modify]').
  136. NOTE: Activate the new setting in a Smarty buffer by using the menu entry
  137. \"Activate Options\"."
  138. :type 'boolean
  139. :group 'smarty-header)
  140. (defgroup smarty-misc nil
  141. "Miscellaneous customizations."
  142. :group 'smarty)
  143. (defcustom smarty-left-delimiter "{"
  144. "Left escaping delimiter."
  145. :type 'string
  146. :group 'smarty-misc)
  147. (defcustom smarty-right-delimiter "}"
  148. "Right escaping delimiter."
  149. :type 'string
  150. :group 'smarty-misc)
  151. (defcustom smarty-intelligent-tab t
  152. "*Non-nil means `TAB' does indentation, word completion and tab insertion.
  153. That is, if preceding character is part of a word then complete word,
  154. else if not at beginning of line then insert tab,
  155. else if last command was a `TAB' or `RET' then dedent one step,
  156. else indent current line (i.e. `TAB' is bound to `smarty-electric-tab').
  157. If nil, TAB always indents current line (i.e. `TAB' is bound to
  158. `indent-according-to-mode').
  159. NOTE: Activate the new setting in a Smarty buffer by using the menu entry
  160. \"Activate Options\"."
  161. :type 'boolean
  162. :group 'smarty-misc)
  163. (defcustom smarty-word-completion-in-minibuffer t
  164. "*Non-nil enables word completion in minibuffer (for template prompts).
  165. NOTE: Activate the new setting by restarting Emacs."
  166. :type 'boolean
  167. :group 'smarty-misc)
  168. (defcustom smarty-word-completion-case-sensitive nil
  169. "*Non-nil means word completion using `TAB' is case sensitive.
  170. That is, `TAB' completes words that start with the same letters and case.
  171. Otherwise, case is ignored."
  172. :type 'boolean
  173. :group 'smarty-misc)
  174. ;; Functions
  175. (defun smarty-customize ()
  176. "Call the customize function with `smarty' as argument."
  177. (interactive)
  178. (customize-browse 'smarty))
  179. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  180. ;; Variables
  181. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  182. (defvar smarty-menu-max-size 20
  183. "*Specifies the maximum size of a menu before splitting it into submenues.")
  184. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  185. ;; Menu tools functions
  186. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  187. (defun smarty-menu-split (list title)
  188. "Split menu LIST into several submenues, if number of
  189. elements > `smarty-menu-max-size'."
  190. (if (> (length list) smarty-menu-max-size)
  191. (let ((remain list)
  192. (result '())
  193. (sublist '())
  194. (menuno 1)
  195. (i 0))
  196. (while remain
  197. (setq sublist (cons (car remain) sublist))
  198. (setq remain (cdr remain))
  199. (setq i (+ i 1))
  200. (if (= i smarty-menu-max-size)
  201. (progn
  202. (setq result (cons (cons (format "%s %s" title menuno)
  203. (nreverse sublist)) result))
  204. (setq i 0)
  205. (setq menuno (+ menuno 1))
  206. (setq sublist '()))))
  207. (and sublist
  208. (setq result (cons (cons (format "%s %s" title menuno)
  209. (nreverse sublist)) result)))
  210. (nreverse result))
  211. list))
  212. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  213. ;; Source file menu
  214. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  215. (defvar smarty-sources-menu nil)
  216. ;; Create the source menu
  217. (defun smarty-add-source-files-menu ()
  218. "Scan directory for all Smarty source files and generate menu.
  219. The directory of the current source file is scanned."
  220. (interactive)
  221. (message "Scanning directory for source files ...")
  222. (let ((newmap (current-local-map))
  223. (file-list (smarty-get-source-files))
  224. menu-list found)
  225. ;; Create list for menu
  226. (setq found nil)
  227. (while file-list
  228. (setq found t)
  229. (setq menu-list (cons (vector (car file-list)
  230. (list 'find-file (car file-list)) t)
  231. menu-list))
  232. (setq file-list (cdr file-list)))
  233. (setq menu-list (smarty-menu-split menu-list "Sources"))
  234. (when found (setq menu-list (cons "--" menu-list)))
  235. (setq menu-list (cons ["*Rescan*" smarty-add-source-files-menu t] menu-list))
  236. (setq menu-list (cons "Sources" menu-list))
  237. ;; Create menu
  238. (easy-menu-add menu-list)
  239. (easy-menu-define smarty-sources-menu newmap
  240. "Smarty source files menu" menu-list))
  241. (message ""))
  242. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  243. ;; Smarty menu
  244. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  245. (defun smarty-create-mode-menu ()
  246. "Create Smarty Mode menu."
  247. `("Smarty"
  248. ("Templates"
  249. ("Built-in Functions"
  250. ["capture" smarty-template-capture t]
  251. ["config_load" smarty-template-config-load t]
  252. ["else" smarty-template-else t]
  253. ["elseif" smarty-template-elseif t]
  254. ["foreach" smarty-template-foreach t]
  255. ["foreachelse" smarty-template-foreachelse t]
  256. ["if" smarty-template-if t]
  257. ["include" smarty-template-include t]
  258. ["include_php" smarty-template-include-php t]
  259. ["insert" smarty-template-insert t]
  260. ["ldelim" smarty-template-ldelim t]
  261. ["literal" smarty-template-literal t]
  262. ["php" smarty-template-php t]
  263. ["rdelim" smarty-template-rdelim t]
  264. ["section" smarty-template-section t]
  265. ["sectionelse" smarty-template-sectionelse t]
  266. ["strip" smarty-template-strip t])
  267. ("Custom Functions"
  268. ["assign" smarty-template-assign t]
  269. ["counter" smarty-template-counter t]
  270. ["cycle" smarty-template-cycle t]
  271. ["debug" smarty-template-debug t]
  272. ["eval" smarty-template-eval t]
  273. ["fetch" smarty-template-fetch t]
  274. ["html_checkboxes" smarty-template-html-checkboxes t]
  275. ["html_image" smarty-template-html-image t]
  276. ["html_options" smarty-template-html-options t]
  277. ["html_radios" smarty-template-html-radios t]
  278. ["html_select_date" smarty-template-html-select-date t]
  279. ["html_select_time" smarty-template-html-select-time t]
  280. ["html_table" smarty-template-html-table t]
  281. ["mailto" smarty-template-mailto t]
  282. ["math" smarty-template-math t]
  283. ["popup" smarty-template-popup t]
  284. ["popup_init" smarty-template-popup-init t]
  285. ["textformat" smarty-template-textformat t])
  286. ("Variable Modifiers"
  287. ["capitalize" smarty-template-capitalize t]
  288. ["cat" smarty-template-cat t]
  289. ["count_characters" smarty-template-count-characters t]
  290. ["count_paragraphs" smarty-template-count-paragraphs t]
  291. ["count_sentences" smarty-template-count-sentences t]
  292. ["count_words" smarty-template-count-words t]
  293. ["date_format" smarty-template-date-format t]
  294. ["default" smarty-template-default t]
  295. ["escape" smarty-template-escape t]
  296. ["indent" smarty-template-indent t]
  297. ["lower" smarty-template-lower t]
  298. ["nl2br" smarty-template-nl2br t]
  299. ["regex_replace" smarty-template-regex-replace t]
  300. ["replace" smarty-template-replace t]
  301. ["spacify" smarty-template-spacify t]
  302. ["string_format" smarty-template-string-format t]
  303. ["strip" smarty-template-vstrip t]
  304. ["strip_tags" smarty-template-strip-tags t]
  305. ["truncate" smarty-template-truncate t]
  306. ["upper" smarty-template-upper t]
  307. ["wordwrap" smarty-template-wordwrap t])
  308. ("Plugins (Functions)"
  309. ("BlockRepeatPlugin"
  310. ["repeat" smarty-template-repeat t]
  311. ["str_repeat" smarty-template-str-repeat t])
  312. ("ClipCache"
  313. ["clipcache" smarty-template-clipcache t]
  314. ["include_clipcache" smarty-template-include-clipcache t])
  315. ("SmartyFormtool"
  316. ["formtool_checkall" smarty-template-formtool-checkall t]
  317. ["formtool_copy" smarty-template-formtool-copy t]
  318. ["formtool_count_chars" smarty-template-formtool-count-chars t]
  319. ["formtool_init" smarty-template-formtool-init t]
  320. ["formtool_move" smarty-template-formtool-move t]
  321. ["formtool_moveall" smarty-template-formtool-moveall t]
  322. ["formtool_movedown" smarty-template-formtool-movedown t]
  323. ["formtool_moveup" smarty-template-formtool-moveup t]
  324. ["formtool_remove" smarty-template-formtool-remove t]
  325. ["formtool_rename" smarty-template-formtool-rename t]
  326. ["formtool_save" smarty-template-formtool-save t]
  327. ["formtool_selectall" smarty-template-formtool-selectall t])
  328. ("SmartyPaginate"
  329. ["paginate_first" smarty-template-paginate-first t]
  330. ["paginate_last" smarty-template-paginate-last t]
  331. ["paginate_middle" smarty-template-paginate-middle t]
  332. ["paginate_next" smarty-template-paginate-next t]
  333. ["paginate_prev" smarty-template-paginate-prev t])
  334. ("SmartyValidate"
  335. ["validate" smarty-template-validate t]))
  336. ("Plugins (Variable Modifiers)"
  337. ("AlternativeDateModifierPlugin"
  338. ["date_format2" smarty-template-date-formatto t])
  339. ("B2Smilies"
  340. ["B2Smilies" smarty-template-btosmilies t])
  341. ("BBCodePlugin"
  342. ["bbcode2html" smarty-template-bbcodetohtml t])
  343. )
  344. "--"
  345. ["Insert Header" smarty-template-header t]
  346. ["Insert Footer" smarty-template-footer t]
  347. ["Insert Date" smarty-template-insert-date t]
  348. ["Modify Date" smarty-template-modify t])
  349. "--"
  350. ["Show Messages" smarty-show-messages :keys "C-c M-m"]
  351. ["Smarty Mode Documentation" smarty-doc-mode :keys "C-c C-h"]
  352. ["Version" smarty-version :keys "C-c C-v"]
  353. "--"
  354. ("Options"
  355. ("Mode"
  356. ["Electric Mode"
  357. (progn (customize-set-variable 'smarty-electric-mode
  358. (not smarty-electric-mode))
  359. (smarty-mode-line-update))
  360. :style toggle :selected smarty-electric-mode :keys "C-c C-m C-e"]
  361. ["Stutter Mode"
  362. (progn (customize-set-variable 'smarty-stutter-mode
  363. (not smarty-stutter-mode))
  364. (smarty-mode-line-update))
  365. :style toggle :selected smarty-stutter-mode :keys "C-c C-m C-s"]
  366. "--"
  367. ["Customize Group..." (customize-group 'smarty-mode) t])
  368. ("Menu"
  369. ["Source Menu"
  370. (customize-set-variable 'smarty-source-file-menu
  371. (not smarty-source-file-menu))
  372. :style toggle :selected smarty-source-file-menu]
  373. "--"
  374. ["Customize Group..." (customize-group 'smarty-menu) t])
  375. ("Highlight"
  376. ["Highlight plugin functions"
  377. (progn (customize-set-variable 'smarty-highlight-plugin-functions
  378. (not smarty-highlight-plugin-functions)))
  379. :style toggle :selected smarty-highlight-plugin-functions]
  380. "--"
  381. ["Customize Group..." (customize-group 'smarty-highlight) t])
  382. ("Template"
  383. ("Header"
  384. ["Header template..."
  385. (customize-option 'smarty-file-header) t]
  386. ["Footer template..."
  387. (customize-option 'smarty-file-footer) t]
  388. ["Company..."
  389. (customize-option 'smarty-company-name) t]
  390. ["Copyright..."
  391. (customize-option 'smarty-copyright-string) t]
  392. ["Date format..."
  393. (customize-option 'smarty-date-format) t]
  394. ["Modify date prefix..."
  395. (customize-option 'smarty-modify-date-prefix-string) t]
  396. ["Modify date on saving"
  397. (customize-set-variable 'smarty-modify-date-on-saving
  398. (not smarty-modify-date-on-saving))
  399. :style toggle :selected smarty-modify-date-on-saving]
  400. "--"
  401. ["Customize Group..." (customize-group 'smarty-header) t])
  402. "--"
  403. ["Customize Group..." (customize-group 'smarty-template) t])
  404. ("Miscellaneous"
  405. ["Left delimiter..."
  406. (customize-option 'smarty-left-delimiter) t]
  407. ["Right delimiter..."
  408. (customize-option 'smarty-right-delimiter) t]
  409. ["Use Intelligent Tab"
  410. (progn (customize-set-variable 'smarty-intelligent-tab
  411. (not smarty-intelligent-tab))
  412. (smarty-activate-customizations))
  413. :style toggle :selected smarty-intelligent-tab]
  414. ["Word Completion in Minibuffer"
  415. (progn (customize-set-variable 'smarty-word-completion-in-minibuffer
  416. (not smarty-word-completion-in-minibuffer))
  417. (message "Activate new setting by saving options and restarting Emacs"))
  418. :style toggle :selected smarty-word-completion-in-minibuffer]
  419. ["Completion is case sensitive"
  420. (customize-set-variable 'smarty-word-completion-case-sensitive
  421. (not smarty-word-completion-case-sensitive))
  422. :style toggle :selected smarty-word-completion-case-sensitive]
  423. "--"
  424. ["Customize Group..." (customize-group 'smarty-misc) t])
  425. "--"
  426. ["Save Options" customize-save-customized t]
  427. ["Activate Options" smarty-activate-customizations t]
  428. ["Browse Options..." smarty-customize t])))
  429. (defvar smarty-mode-menu-list (smarty-create-mode-menu)
  430. "Smarty Mode menu.")
  431. (defvar smarty-mode-map nil
  432. "Keymap for Smarty Mode.")
  433. (defun smarty-update-mode-menu ()
  434. "Update Smarty Mode menu."
  435. (interactive)
  436. (easy-menu-remove smarty-mode-menu-list)
  437. (setq smarty-mode-menu-list (smarty-create-mode-menu))
  438. (easy-menu-add smarty-mode-menu-list)
  439. (easy-menu-define smarty-mode-menu smarty-mode-map
  440. "Menu keymap for Smarty Mode." smarty-mode-menu-list))
  441. (defvar smarty-mode-hook nil)
  442. (defvar smarty-functions nil
  443. "List of Smarty functions.")
  444. (defvar smarty-functions-regexp nil
  445. "Regexp for Smarty functions.")
  446. (defconst smarty-01-functions
  447. '("capture" "config_load" "foreach" "foreachelse" "include"
  448. "include_php" "insert" "if" "elseif" "else" "ldelim" "rdelim"
  449. "literal" "php" "section" "sectionelse" "strip" "assign" "counter"
  450. "cycle" "debug" "eval" "fetch" "html_checkboxes" "html_image"
  451. "html_options" "html_radios" "html_select_date" "html_select_time"
  452. "html_table" "math" "mailto" "popup_init" "popup" "textformat")
  453. "Smarty built-in & custom functions.")
  454. (defvar smarty-modifiers nil
  455. "List of Smarty variable modifiers.")
  456. (defvar smarty-modifiers-regexp nil
  457. "Regexp for Smarty variable modifiers.")
  458. (defconst smarty-01-modifiers
  459. '("capitalize" "cat" "count_characters" "count_paragraphs"
  460. "count_sentences" "count_words" "date_format" "default"
  461. "escape" "indent" "lower" "nl2br" "regex_replace" "replace"
  462. "spacify" "string_format" "strip" "strip_tags" "truncate"
  463. "upper" "wordwrap")
  464. "Smarty variable modifiers.")
  465. (defvar smarty-plugins-functions nil
  466. "List of Smarty functions.")
  467. (defvar smarty-plugins-functions-regexp nil
  468. "Regexp for Smarty functions.")
  469. (defconst smarty-01-plugins-functions
  470. '("validate" "formtool_checkall" "formtool_copy" "formtool_count_chars"
  471. "formtool_init" "formtool_move" "formtool_moveall"
  472. "formtool_movedown" "formtool_moveup" "formtool_remove"
  473. "formtool_rename" "formtool_save" "formtool_selectall"
  474. "paginate_first" "paginate_last" "paginate_middle"
  475. "paginate_next" "paginate_prev" "clipcache" "include_clipcache"
  476. "repeat" "str_repeat")
  477. "Smarty plugins functions.")
  478. (defvar smarty-plugins-modifiers nil
  479. "List of Smarty variable modifiers.")
  480. (defvar smarty-plugins-modifiers-regexp nil
  481. "Regexp for Smarty functions.")
  482. (defconst smarty-01-plugins-modifiers
  483. '("B2Smilies" "bbcode2html" "date_format2")
  484. "Smarty plugins modifiers.")
  485. (defconst smarty-constants
  486. (eval-when-compile
  487. (regexp-opt
  488. '("TRUE" "FALSE" "NULL") t))
  489. "Smarty constants.")
  490. ;; Syntax table creation
  491. (defvar smarty-mode-syntax-table nil
  492. "Syntax table for smarty-mode.")
  493. (defvar smarty-mode-ext-syntax-table nil
  494. "Syntax table extended by `_' used in `smarty-mode' buffers.")
  495. (defun smarty-create-syntax-table ()
  496. (if smarty-mode-syntax-table
  497. ()
  498. (setq smarty-mode-syntax-table (make-syntax-table))
  499. ;; Make | a punctuation character
  500. (modify-syntax-entry ?| "." smarty-mode-syntax-table)
  501. ;; Make " a punctuation character so highlighing works withing html strings
  502. (modify-syntax-entry ?\" "." smarty-mode-syntax-table)
  503. ;; define parentheses to match
  504. (modify-syntax-entry ?\( "()" smarty-mode-syntax-table)
  505. (modify-syntax-entry ?\) ")(" smarty-mode-syntax-table)
  506. (modify-syntax-entry ?\[ "(]" smarty-mode-syntax-table)
  507. (modify-syntax-entry ?\] ")[" smarty-mode-syntax-table)
  508. (modify-syntax-entry ?\{ "(}" smarty-mode-syntax-table)
  509. (modify-syntax-entry ?\} "){" smarty-mode-syntax-table)
  510. )
  511. (set-syntax-table smarty-mode-syntax-table)
  512. ;; extended syntax table including '_' (for simpler search regexps)
  513. (setq smarty-mode-ext-syntax-table (copy-syntax-table smarty-mode-syntax-table))
  514. (modify-syntax-entry ?_ "w" smarty-mode-ext-syntax-table))
  515. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  516. ;; File/directory manipulation
  517. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  518. (defun smarty-directory-files (directory &optional full match)
  519. "Call `directory-files' if DIRECTORY exists, otherwise generate error
  520. message."
  521. (if (not (file-directory-p directory))
  522. (smarty-warning-when-idle "No such directory: \"%s\"" directory)
  523. (let ((dir (directory-files directory full match)))
  524. (setq dir (delete "." dir))
  525. (setq dir (delete ".." dir))
  526. dir)))
  527. (defun smarty-get-source-files (&optional full directory)
  528. "Get list of SMARTY source files in DIRECTORY or current directory."
  529. (let ((mode-alist auto-mode-alist)
  530. filename-regexp)
  531. ;; create regular expressions for matching file names
  532. (setq filename-regexp "\\`[^.].*\\(")
  533. (while mode-alist
  534. (when (eq (cdar mode-alist) 'smarty-mode)
  535. (setq filename-regexp
  536. (concat filename-regexp (caar mode-alist) "\\|")))
  537. (setq mode-alist (cdr mode-alist)))
  538. (setq filename-regexp
  539. (concat (substring filename-regexp 0
  540. (string-match "\\\\|$" filename-regexp)) "\\)"))
  541. ;; find files
  542. (smarty-directory-files
  543. (or directory default-directory) full filename-regexp)))
  544. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  545. ;; Messages reporting
  546. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  547. (defvar smarty-warnings nil
  548. "Warnings to tell the user during start up.")
  549. (defun smarty-run-when-idle (secs repeat function)
  550. "Wait until idle, then run FUNCTION."
  551. (if (fboundp 'start-itimer)
  552. (start-itimer "smarty-mode" function secs repeat t)
  553. ; (run-with-idle-timer secs repeat function)))
  554. ;; explicitely activate timer (necessary when Emacs is already idle)
  555. (aset (run-with-idle-timer secs repeat function) 0 nil)))
  556. (defun smarty-warning-when-idle (&rest args)
  557. "Wait until idle, then print out warning STRING and beep."
  558. (save-match-data ;; runs in timer
  559. (if noninteractive
  560. (smarty-warning (apply 'format args) t)
  561. (unless smarty-warnings
  562. (smarty-run-when-idle .1 nil 'smarty-print-warnings))
  563. (setq smarty-warnings (cons (apply 'format args) smarty-warnings)))))
  564. (defun smarty-warning (string &optional nobeep)
  565. "Print out warning STRING and beep."
  566. (message (concat "WARNING: " string))
  567. (unless (or nobeep noninteractive) (beep)))
  568. (defun smarty-print-warnings ()
  569. "Print out messages in variable `smarty-warnings'."
  570. (let ((no-warnings (length smarty-warnings)))
  571. (setq smarty-warnings (nreverse smarty-warnings))
  572. (while smarty-warnings
  573. (message (concat "WARNING: " (car smarty-warnings)))
  574. (setq smarty-warnings (cdr smarty-warnings)))
  575. (beep)
  576. (when (> no-warnings 1)
  577. (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
  578. (defun smarty-show-messages ()
  579. "Get *Messages* buffer to show recent messages."
  580. (interactive)
  581. (display-buffer " *Message-Log*"))
  582. (defun smarty-version ()
  583. "Echo the current version of Smarty Mode in the minibuffer."
  584. (interactive)
  585. (message "Smarty Mode %s (%s)" smarty-version smarty-time-stamp)
  586. (smarty-keep-region-active))
  587. ;; active regions
  588. (defun smarty-keep-region-active ()
  589. "Do whatever is necessary to keep the region active in XEmacs.
  590. Ignore byte-compiler warnings you might see."
  591. (and (boundp 'zmacs-region-stays)
  592. (setq zmacs-region-stays t)))
  593. (defmacro smarty-prepare-search-1 (&rest body)
  594. "Enable case insensitive search and switch to syntax table that includes '_',
  595. then execute BODY, and finally restore the old environment. Used for
  596. consistent searching."
  597. `(let ((case-fold-search t) ; case insensitive search
  598. (current-syntax-table (syntax-table))
  599. result
  600. (restore-prog ; program to restore enviroment
  601. '(progn
  602. ;; restore syntax table
  603. (set-syntax-table current-syntax-table))))
  604. ;; use extended syntax table
  605. (set-syntax-table smarty-mode-ext-syntax-table)
  606. ;; execute BODY safely
  607. (setq result
  608. (condition-case info
  609. (progn ,@body)
  610. (error (eval restore-prog) ; restore environment on error
  611. (error (cadr info))))) ; pass error up
  612. ;; restore environment
  613. (eval restore-prog)
  614. result))
  615. (defmacro smarty-prepare-search-2 (&rest body)
  616. "Enable case insensitive search, switch to syntax table that includes '_',
  617. and remove `intangible' overlays, then execute BODY, and finally restore the
  618. old environment. Used for consistent searching."
  619. `(let ((case-fold-search t) ; case insensitive search
  620. (current-syntax-table (syntax-table))
  621. result overlay-all-list overlay-intangible-list overlay
  622. (restore-prog ; program to restore enviroment
  623. '(progn
  624. ;; restore syntax table
  625. (set-syntax-table current-syntax-table)
  626. ;; restore `intangible' overlays
  627. (when (fboundp 'overlay-lists)
  628. (while overlay-intangible-list
  629. (overlay-put (car overlay-intangible-list) 'intangible t)
  630. (setq overlay-intangible-list
  631. (cdr overlay-intangible-list)))))))
  632. ;; use extended syntax table
  633. (set-syntax-table smarty-mode-ext-syntax-table)
  634. ;; remove `intangible' overlays
  635. (when (fboundp 'overlay-lists)
  636. (setq overlay-all-list (overlay-lists))
  637. (setq overlay-all-list
  638. (append (car overlay-all-list) (cdr overlay-all-list)))
  639. (while overlay-all-list
  640. (setq overlay (car overlay-all-list))
  641. (when (memq 'intangible (overlay-properties overlay))
  642. (setq overlay-intangible-list
  643. (cons overlay overlay-intangible-list))
  644. (overlay-put overlay 'intangible nil))
  645. (setq overlay-all-list (cdr overlay-all-list))))
  646. ;; execute BODY safely
  647. (setq result
  648. (condition-case info
  649. (progn ,@body)
  650. (error (eval restore-prog) ; restore environment on error
  651. (error (cadr info))))) ; pass error up
  652. ;; restore environment
  653. (eval restore-prog)
  654. result))
  655. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  656. ;; Enabling/disabling
  657. (defun smarty-mode-line-update ()
  658. "Update the modeline string for Smarty major mode."
  659. (setq mode-name (concat "Smarty"
  660. (and (or smarty-electric-mode smarty-stutter-mode) "/")
  661. (and smarty-electric-mode "e")
  662. (and smarty-stutter-mode "s")))
  663. (force-mode-line-update t))
  664. (defun smarty-electric-mode (arg)
  665. "Toggle Smarty electric mode.
  666. Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
  667. (interactive "P")
  668. (setq smarty-electric-mode
  669. (cond ((or (not arg) (zerop arg)) (not smarty-electric-mode))
  670. ((> arg 0) t) (t nil)))
  671. (smarty-mode-line-update))
  672. (defun smarty-stutter-mode (arg)
  673. "Toggle Smarty stuttering mode.
  674. Turn on if ARG positive, turn off if ARG negative, toggle if ARG zero or nil."
  675. (interactive "P")
  676. (setq smarty-stutter-mode
  677. (cond ((or (not arg) (zerop arg)) (not smarty-stutter-mode))
  678. ((> arg 0) t) (t nil)))
  679. (smarty-mode-line-update))
  680. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  681. ;;; Smarty code delimitation
  682. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  683. (defun smarty-in-literal ()
  684. "Determine if point is in a Smarty literal."
  685. (save-excursion
  686. (let ((here (point))
  687. start state)
  688. (beginning-of-line)
  689. (setq start (point))
  690. (goto-char here)
  691. (setq state (parse-partial-sexp start (point)))
  692. (cond
  693. ((nth 3 state) 'string)
  694. ((nth 4 state) 'comment)
  695. (t nil)))))
  696. (defun smarty-in-comment-p ()
  697. "Check if point is in a comment."
  698. (let ((result nil) (here (point-marker)) found)
  699. (save-excursion
  700. (setq found (re-search-backward (regexp-quote (concat smarty-left-delimiter "*")) nil t))
  701. (when found
  702. (setq result (re-search-forward (regexp-quote (concat "*" smarty-right-delimiter)) here t))
  703. (setq result (not result))))
  704. result))
  705. (defun smarty-after-ldelim ()
  706. "Check that the previous character is the left delimiter."
  707. (let ((here (point-marker)) ldelim-found ldelim-point)
  708. (save-excursion
  709. (setq ldelim-found (re-search-backward (regexp-quote smarty-left-delimiter) nil t))
  710. (re-search-forward (regexp-quote smarty-left-delimiter) here t)
  711. (setq ldelim-point (point-marker))
  712. (goto-char here)
  713. (if (and (= here ldelim-point) ldelim-found)
  714. t
  715. nil))))
  716. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  717. ;; Words to expand
  718. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  719. (defun smarty-words-init ()
  720. "Initialize reserved words."
  721. (setq smarty-functions smarty-01-functions)
  722. (setq smarty-modifiers smarty-01-modifiers)
  723. (setq smarty-plugins-functions smarty-01-plugins-functions)
  724. (setq smarty-plugins-modifiers smarty-01-plugins-modifiers)
  725. (setq smarty-functions-regexp (concat "\\<\\(" (regexp-opt smarty-functions) "\\)\\>"))
  726. (setq smarty-modifiers-regexp (concat "\\<\\(" (regexp-opt smarty-modifiers) "\\)\\>"))
  727. (setq smarty-plugins-functions-regexp (concat "\\<\\(" (regexp-opt smarty-plugins-functions) "\\)\\>"))
  728. (setq smarty-plugins-modifiers-regexp (concat "\\<\\(" (regexp-opt smarty-plugins-modifiers) "\\)\\>"))
  729. (smarty-abbrev-list-init))
  730. (defvar smarty-abbrev-list nil
  731. "Predefined abbreviations for Smarty.")
  732. (defun smarty-abbrev-list-init ()
  733. (setq smarty-abbrev-list
  734. (append
  735. (list nil) smarty-functions
  736. (list nil) smarty-modifiers
  737. (list nil) smarty-plugins-functions
  738. (list nil) smarty-plugins-modifiers)))
  739. (defvar smarty-expand-upper-case nil)
  740. (defun smarty-try-expand-abbrev (old)
  741. "Try expanding abbreviations from `smarty-abbrev-list'."
  742. (unless old
  743. (he-init-string (he-dabbrev-beg) (point))
  744. (setq he-expand-list
  745. (let ((abbrev-list smarty-abbrev-list)
  746. (sel-abbrev-list '()))
  747. (while abbrev-list
  748. ; (if (stringp (car abbrev-list))
  749. ; (insert (concat " " (car abbrev-list))))
  750. (when (or (not (stringp (car abbrev-list)))
  751. (string-match
  752. (concat "^" he-search-string) (car abbrev-list)))
  753. (setq sel-abbrev-list
  754. (cons (car abbrev-list) sel-abbrev-list)))
  755. (setq abbrev-list (cdr abbrev-list)))
  756. (nreverse sel-abbrev-list))))
  757. (while (and he-expand-list
  758. (or (not (stringp (car he-expand-list)))
  759. (he-string-member (car he-expand-list) he-tried-table t)))
  760. (unless (stringp (car he-expand-list))
  761. (setq smarty-expand-upper-case (car he-expand-list)))
  762. (setq he-expand-list (cdr he-expand-list)))
  763. (if (null he-expand-list)
  764. (progn (when old (he-reset-string))
  765. nil)
  766. (he-substitute-string
  767. (if smarty-expand-upper-case
  768. (upcase (car he-expand-list))
  769. (car he-expand-list))
  770. t)
  771. (setq he-expand-list (cdr he-expand-list))
  772. t))
  773. ;; initialize reserved words for Smarty Mode
  774. (smarty-words-init)
  775. ;; function for expanding abbrevs and dabbrevs
  776. (defun smarty-expand-abbrev (arg))
  777. (fset 'smarty-expand-abbrev (make-hippie-expand-function
  778. '(try-expand-dabbrev
  779. try-expand-dabbrev-all-buffers
  780. smarty-try-expand-abbrev)))
  781. ;; function for expanding parenthesis
  782. (defun smarty-expand-paren (arg))
  783. (fset 'smarty-expand-paren (make-hippie-expand-function
  784. '(try-expand-list
  785. try-expand-list-all-buffers)))
  786. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  787. ;;; Stuttering
  788. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  789. (defvar smarty-end-comment-column 80)
  790. (defvar found) ;; silence compiler, dyn var
  791. (defun smarty-electric-tab (&optional prefix-arg)
  792. "If preceding character is part of a word or a paren then hippie-expand,
  793. else if right of non whitespace on line then insert tab,
  794. else if last command was a tab or return then dedent one step or if a comment
  795. toggle between normal indent and inline comment indent,
  796. else indent `correctly'."
  797. (interactive "*P")
  798. (smarty-prepare-search-2
  799. (cond
  800. ;; expand word
  801. ((= (char-syntax (preceding-char)) ?w)
  802. (let ((case-fold-search (not smarty-word-completion-case-sensitive))
  803. (case-replace nil)
  804. (hippie-expand-only-buffers
  805. (or (and (boundp 'hippie-expand-only-buffers)
  806. hippie-expand-only-buffers)
  807. '(smarty-mode))))
  808. (smarty-expand-abbrev prefix-arg)))
  809. ;; expand parenthesis
  810. ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
  811. (let ((case-fold-search (not smarty-word-completion-case-sensitive))
  812. (case-replace nil))
  813. (smarty-expand-paren prefix-arg))))
  814. (setq this-command 'smarty-electric-tab)))
  815. (defun smarty-electric-space (count)
  816. "Expand abbreviations and self-insert space(s)."
  817. (interactive "p")
  818. (let ((here (point-marker)) ldelim-found ldelim-point rdelim-found rdelim-point
  819. delete-a)
  820. (setq ldelim-found (re-search-backward (regexp-quote smarty-left-delimiter) nil t))
  821. (re-search-forward (regexp-quote smarty-left-delimiter) here t)
  822. (setq ldelim-point (point-marker))
  823. (goto-char here)
  824. (setq rdelim-found (re-search-backward (regexp-quote (concat " " smarty-right-delimiter)) nil t))
  825. (re-search-forward (regexp-quote (concat " " smarty-right-delimiter)) here t)
  826. (setq rdelim-point (point-marker))
  827. (goto-char here)
  828. (cond ((and (= here ldelim-point) ldelim-found) (insert (concat "ldelim" smarty-right-delimiter)))
  829. ((and (= here rdelim-point) rdelim-found)
  830. (re-search-backward (regexp-quote (concat " " smarty-right-delimiter)) nil t)
  831. (delete-char 1)
  832. (insert (concat " " smarty-left-delimiter "rdelim"))
  833. (goto-char here))
  834. ((smarty-in-comment-p)
  835. (self-insert-command count)
  836. (cond ((>= (current-column) (+ 2 smarty-end-comment-column))
  837. (backward-char 1)
  838. (skip-chars-backward "^ \t\n")
  839. (indent-new-comment-line)
  840. (skip-chars-forward "^ \t\n")
  841. (forward-char 1))
  842. ((>= (current-column) smarty-end-comment-column)
  843. (indent-new-comment-line))
  844. (t nil)))
  845. ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
  846. (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z))
  847. (and (>= (preceding-char) ?0) (<= (preceding-char) ?9)))
  848. (progn
  849. (setq here (point-marker))
  850. (insert " ")
  851. (setq delete-a t)
  852. (if (re-search-backward "|" nil t)
  853. (progn
  854. (setq found (re-search-forward (regexp-quote "B2Smilies") here t))
  855. (if (and found (= here (point-marker)))
  856. (replace-match "btosmilies")
  857. (setq found (re-search-forward (regexp-quote "bbcode2html") here t))
  858. (if (and found (= here (point-marker)))
  859. (replace-match "bbcodetohtml")
  860. (setq found (re-search-forward (regexp-quote "date_format2") here t))
  861. (if (and found (= here (point-marker)))
  862. (replace-match "date_formatto")
  863. (goto-char here)
  864. (setq delete-a nil)
  865. (delete-char 1)))))
  866. (goto-char here)
  867. (setq delete-a nil)
  868. (delete-char 1)))
  869. (smarty-prepare-search-1 (expand-abbrev))
  870. (self-insert-command count)
  871. (if (and delete-a (looking-at " "))
  872. (delete-char 1)))
  873. (t (self-insert-command count)))))
  874. (defun smarty-electric-open-bracket (count)
  875. "'(' --> '(', '((' --> '[', '[(' --> '{'"
  876. (interactive "p")
  877. (if (and smarty-stutter-mode (= count 1) (not (smarty-in-literal)))
  878. (if (= (preceding-char) ?\()
  879. (progn (delete-char -1) (insert-char ?\[ 1))
  880. (if (= (preceding-char) ?\[)
  881. (progn (delete-char -1) (insert-char ?\{ 1))
  882. (insert-char ?\( 1)))
  883. (self-insert-command count)))
  884. (defun smarty-electric-close-bracket (count)
  885. "')' --> ')', '))' --> ']', '])' --> '}'"
  886. (interactive "p")
  887. (if (and smarty-stutter-mode (= count 1) (not (smarty-in-literal)))
  888. (progn
  889. (if (= (preceding-char) ?\))
  890. (progn (delete-char -1) (insert-char ?\] 1))
  891. (if (= (preceding-char) ?\])
  892. (progn (delete-char -1) (insert-char ?} 1))
  893. (insert-char ?\) 1)))
  894. (blink-matching-open))
  895. (self-insert-command count)))
  896. (defun smarty-electric-star (count)
  897. "After a left delimiter add a right delemiter to close the comment"
  898. (interactive "p")
  899. (let ((here (point-marker)) found)
  900. (if (and smarty-stutter-mode (= count 1) (not (smarty-in-literal)))
  901. (progn
  902. (setq found (re-search-backward (regexp-quote smarty-left-delimiter) nil t))
  903. (re-search-forward (regexp-quote smarty-left-delimiter) here t)
  904. (if (not (and (= here (point-marker)) found))
  905. (progn (goto-char here)
  906. (self-insert-command count))
  907. (self-insert-command count)
  908. (insert " ")
  909. (setq here (point-marker))
  910. (insert " *")
  911. (insert smarty-right-delimiter)
  912. (goto-char here)))
  913. (self-insert-command count))))
  914. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  915. ;;; Electrification
  916. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  917. (defconst smarty-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
  918. "Syntax of prompt inserted by template generators.")
  919. (defvar smarty-template-invoked-by-hook nil
  920. "Indicates whether a template has been invoked by a hook or by key or menu.
  921. Used for undoing after template abortion.")
  922. (defun smarty-minibuffer-tab (&optional prefix-arg)
  923. "If preceding character is part of a word or a paren then hippie-expand,
  924. else insert tab (used for word completion in Smarty minibuffer)."
  925. (interactive "P")
  926. (cond
  927. ;; expand word
  928. ((= (char-syntax (preceding-char)) ?w)
  929. (let ((case-fold-search (not smarty-word-completion-case-sensitive))
  930. (case-replace nil)
  931. (hippie-expand-only-buffers
  932. (or (and (boundp 'hippie-expand-only-buffers)
  933. hippie-expand-only-buffers)
  934. '(smarty-mode))))
  935. (smarty-expand-abbrev prefix-arg)))
  936. ;; expand parenthesis
  937. ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
  938. (let ((case-fold-search (not smarty-word-completion-case-sensitive))
  939. (case-replace nil))
  940. (smarty-expand-paren prefix-arg)))
  941. ;; insert tab
  942. (t (insert-tab))))
  943. ;; correct different behavior of function `unread-command-events' in XEmacs
  944. (defun smarty-character-to-event (arg))
  945. (defalias 'smarty-character-to-event
  946. (if (fboundp 'character-to-event) 'character-to-event 'identity))
  947. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  948. ;; Abbrev ook bindings
  949. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  950. (defvar smarty-mode-abbrev-table nil
  951. "Abbrev table to use in `smarty-mode' buffers.")
  952. (defun smarty-mode-abbrev-table-init ()
  953. "Initialize `smarty-mode-abbrev-table'."
  954. (when smarty-mode-abbrev-table (clear-abbrev-table smarty-mode-abbrev-table))
  955. (define-abbrev-table 'smarty-mode-abbrev-table
  956. (append
  957. '(
  958. ("capture" "" smarty-template-capture-hook 0)
  959. ("config_load" "" smarty-template-config-load-hook 0)
  960. ("else" "" smarty-template-else-hook 0)
  961. ("elseif" "" smarty-template-elseif-hook 0)
  962. ("foreach" "" smarty-template-foreach-hook 0)
  963. ("foreachelse" "" smarty-template-foreachelse-hook 0)
  964. ("if" "" smarty-template-if-hook 0)
  965. ("include" "" smarty-template-include-hook 0)
  966. ("include_php" "" smarty-template-include-php-hook 0)
  967. ("insert" "" smarty-template-insert-hook 0)
  968. ("ldelim" "" smarty-template-ldelim-hook 0)
  969. ("literal" "" smarty-template-literal-hook 0)
  970. ("php" "" smarty-template-php-hook 0)
  971. ("rdelim" "" smarty-template-rdelim-hook 0)
  972. ("section" "" smarty-template-section-hook 0)
  973. ("sectionelse" "" smarty-template-sectionelse-hook 0)
  974. ("strip" "" smarty-template-strip-hook 0)
  975. ("assign" "" smarty-template-assign-hook 0)
  976. ("counter" "" smarty-template-counter-hook 0)
  977. ("cycle" "" smarty-template-cycle-hook 0)
  978. ("debug" "" smarty-template-debug-hook 0)
  979. ("eval" "" smarty-template-eval-hook 0)
  980. ("fetch" "" smarty-template-fetch-hook 0)
  981. ("html_checkboxes" "" smarty-template-html-checkboxes-hook 0)
  982. ("html_image" "" smarty-template-html-image-hook 0)
  983. ("html_options" "" smarty-template-html-options-hook 0)
  984. ("html_radios" "" smarty-template-html-radios-hook 0)
  985. ("html_select_date" "" smarty-template-html-select-date-hook 0)
  986. ("html_select_time" "" smarty-template-html-select-time-hook 0)
  987. ("html_table" "" smarty-template-html-table-hook 0)
  988. ("mailto" "" smarty-template-mailto-hook 0)
  989. ("math" "" smarty-template-math-hook 0)
  990. ("popup" "" smarty-template-popup-hook 0)
  991. ("popup_init" "" smarty-template-popup-init-hook 0)
  992. ("textformat" "" smarty-template-textformat-hook 0)
  993. ("capitalize" "" smarty-template-capitalize-hook 0)
  994. ("cat" "" smarty-template-cat-hook 0)
  995. ("count_characters" "" smarty-template-count-characters-hook 0)
  996. ("count_paragraphs" "" smarty-template-count-paragraphs-hook 0)
  997. ("count_sentences" "" smarty-template-count-sentences-hook 0)
  998. ("count_words" "" smarty-template-count-words-hook 0)
  999. ("date_format" "" smarty-template-date-format-hook 0)
  1000. ("default" "" smarty-template-default-hook 0)
  1001. ("escape" "" smarty-template-escape-hook 0)
  1002. ("indent" "" smarty-template-indent-hook 0)
  1003. ("lower" "" smarty-template-lower-hook 0)
  1004. ("nl2br" "" smarty-template-nl2br-hook 0)
  1005. ("regex_replace" "" smarty-template-regex-replace-hook 0)
  1006. ("replace" "" smarty-template-replace-hook 0)
  1007. ("spacify" "" smarty-template-spacify-hook 0)
  1008. ("string_format" "" smarty-template-string-format-hook 0)
  1009. ("strip" "" smarty-template-vstrip-hook 0)
  1010. ("strip_tags" "" smarty-template-strip-tags-hook 0)
  1011. ("truncate" "" smarty-template-truncate-hook 0)
  1012. ("upper" "" smarty-template-upper-hook 0)
  1013. ("wordwrap" "" smarty-template-wordwrap-hook 0)
  1014. ("validate" "" smarty-template-validate-hook 0)
  1015. ("clipcache" "" smarty-template-clipcache-hook 0)
  1016. ("repeat" "" smarty-template-repeat-hook 0)
  1017. ("str_repeat" "" smarty-template-str-repeat-hook 0)
  1018. ("include_clipcache" "" smarty-template-include-clipcache-hook 0)
  1019. ("formtool_checkall" "" smarty-template-formtool-checkall-hook 0)
  1020. ("formtool_copy" "" smarty-template-formtool-copy-hook 0)
  1021. ("formtool_count_chars" "" smarty-template-formtool-count-chars-hook 0)
  1022. ("formtool_init" "" smarty-template-formtool-init-hook 0)
  1023. ("formtool_move" "" smarty-template-formtool-move-hook 0)
  1024. ("formtool_moveall" "" smarty-template-formtool-moveall-hook 0)
  1025. ("formtool_movedown" "" smarty-template-formtool-movedown-hook 0)
  1026. ("formtool_moveup" "" smarty-template-formtool-moveup-hook 0)
  1027. ("formtool_remove" "" smarty-template-formtool-remove-hook 0)
  1028. ("formtool_rename" "" smarty-template-formtool-rename-hook 0)
  1029. ("formtool_save" "" smarty-template-formtool-save-hook 0)
  1030. ("formtool_selectall" "" smarty-template-formtool-selectall-hook 0)
  1031. ("paginate_first" "" smarty-template-paginate-first-hook 0)
  1032. ("paginate_last" "" smarty-template-paginate-last-hook 0)
  1033. ("paginate_middle" "" smarty-template-paginate-middle-hook 0)
  1034. ("paginate_next" "" smarty-template-paginate-next-hook 0)
  1035. ("paginate_prev" "" smarty-template-paginate-prev-hook 0)
  1036. ("btosmilies" "" smarty-template-btosmilies-hook 0)
  1037. ("bbcodetohtml" "" smarty-template-bbcodetohtml-hook 0)
  1038. ("date_formatto" "" smarty-template-date-formatto-hook 0)))))
  1039. ;; initialize abbrev table for Smarty Mode
  1040. (smarty-mode-abbrev-table-init)
  1041. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1042. ;; Abbrev hooks
  1043. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1044. (defun smarty-hooked-abbrev (func)
  1045. "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
  1046. but not if inside a comment or quote)."
  1047. (if (or (smarty-in-literal)
  1048. (smarty-in-comment-p))
  1049. (progn
  1050. (insert " ")
  1051. (unexpand-abbrev)
  1052. (delete-char -1))
  1053. (if (not smarty-electric-mode)
  1054. (progn
  1055. (insert " ")
  1056. (unexpand-abbrev)
  1057. (backward-word 1)
  1058. (delete-char 1))
  1059. (let ((invoke-char last-command-event)
  1060. (abbrev-mode -1)
  1061. (smarty-template-invoked-by-hook t))
  1062. (let ((caught (catch 'abort
  1063. (funcall func))))
  1064. (when (stringp caught) (message caught)))
  1065. (when (= invoke-char ?-) (setq abbrev-start-location (point)))
  1066. ;; delete CR which is still in event queue
  1067. (if (fboundp 'enqueue-eval-event)
  1068. (enqueue-eval-event 'delete-char -1)
  1069. (setq unread-command-events ; push back a delete char
  1070. (list (smarty-character-to-event ?\177))))))))
  1071. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1072. ;;; Fontification
  1073. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1074. (defvar smarty-font-lock-keywords-1
  1075. (list
  1076. ;; Fontify built-in functions
  1077. (cons
  1078. (concat (regexp-quote smarty-left-delimiter) "[/]*" smarty-functions-regexp)
  1079. '(1 font-lock-keyword-face))
  1080. (cons
  1081. (concat "\\<\\(" smarty-constants "\\)\\>")
  1082. 'font-lock-constant-face)
  1083. (cons (concat "\\(" (regexp-quote (concat smarty-left-delimiter "*")) "\\(\\s-\\|\\w\\|\\s.\\|\\s_\\|\\s(\\|\\s)\\|\\s\\\\)*" (regexp-quote (concat "*" smarty-right-delimiter)) "\\)")
  1084. 'font-lock-comment-face)
  1085. )
  1086. "Subdued level highlighting for Smarty mode.")
  1087. (defconst smarty-font-lock-keywords-2
  1088. (append
  1089. smarty-font-lock-keywords-1
  1090. (list
  1091. ;; Fontify variable names (\\sw\\|\\s_\\) matches any word character +
  1092. ;; underscore
  1093. '("\\$\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face)) ; $variable
  1094. '("->\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face t t)) ; ->variable
  1095. '("\\.\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face t t)) ; .variable
  1096. '("->\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" (1 font-lock-function-name-face t t)) ; ->function_call
  1097. '("\\<\\(\\(?:\\sw\\|\\s_\\)+\\s-*\\)(" (1 font-lock-function-name-face)) ; word(
  1098. '("\\<\\(\\(?:\\sw\\|\\s_\\)+\\s-*\\)[[]" (1 font-lock-variable-name-face)) ; word[
  1099. '("\\<[0-9]+" . 'default) ; number (also matches word)
  1100. ;; Fontify strings
  1101. ;;'("\"\\([^\"]*\\)\"[^\"]+" (1 font-lock-string-face t t))
  1102. ))
  1103. "Medium level highlighting for Smarty mode.")
  1104. (defconst smarty-font-lock-keywords-3
  1105. (append
  1106. smarty-font-lock-keywords-2
  1107. (list
  1108. ;; Fontify modifiers
  1109. (cons (concat "|\\(" smarty-modifiers-regexp "\\)[:|]+") '(1 font-lock-function-name-face))
  1110. (cons (concat "|\\(" smarty-modifiers-regexp "\\)" (regexp-quote smarty-right-delimiter)) '(1 font-lock-function-name-face))
  1111. ;; Fontify config vars
  1112. (cons (concat (regexp-quote smarty-left-delimiter) "\\(#\\(?:\\sw\\|\\s_\\)+#\\)") '(1 font-lock-constant-face))))
  1113. "Balls-out highlighting for Smarty mode.")
  1114. (defconst smarty-font-lock-keywords-4
  1115. (append
  1116. smarty-font-lock-keywords-3
  1117. (list
  1118. ;; Fontify plugin functions
  1119. (cons
  1120. (concat (regexp-quote smarty-left-delimiter) "[/]*" smarty-plugins-functions-regexp)
  1121. '(1 font-lock-keyword-face))
  1122. (cons (concat "|\\(" smarty-plugins-modifiers-regexp "\\)[:|]+") '(1 font-lock-function-name-face))
  1123. (cons (concat "|\\(" smarty-plugins-modifiers-regexp "\\)" (regexp-quote smarty-right-delimiter)) '(1 font-lock-function-name-face)))))
  1124. (defvar smarty-font-lock-keywords smarty-font-lock-keywords-3
  1125. "Default highlighting level for Smarty mode")
  1126. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1127. ;;; Mode map
  1128. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1129. (defvar smarty-template-map nil
  1130. "Keymap for Smarty templates.")
  1131. (defun smarty-template-map-init ()
  1132. "Initialize `smarty-template-map'."
  1133. (setq smarty-template-map (make-sparse-keymap))
  1134. ;; key bindings for Smarty templates
  1135. (define-key smarty-template-map "\C-ba" 'smarty-template-capture)
  1136. (define-key smarty-template-map "\C-bc" 'smarty-template-config-load)
  1137. (define-key smarty-template-map "\C-b\M-e" 'smarty-template-else)
  1138. (define-key smarty-template-map "\C-b\C-e" 'smarty-template-elseif)
  1139. (define-key smarty-template-map "\C-b\C-f" 'smarty-template-foreach)
  1140. (define-key smarty-template-map "\C-b\M-f" 'smarty-template-foreachelse)
  1141. (define-key smarty-template-map "\C-bf" 'smarty-template-if)
  1142. (define-key smarty-template-map "\C-b\C-i" 'smarty-template-include)
  1143. (define-key smarty-template-map "\C-b\M-i" 'smarty-template-include-php)
  1144. (define-key smarty-template-map "\C-bi" 'smarty-template-insert)
  1145. (define-key smarty-template-map "\C-bl" 'smarty-template-ldelim)
  1146. (define-key smarty-template-map "\C-b\C-l" 'smarty-template-literal)
  1147. (define-key smarty-template-map "\C-bp" 'smarty-template-php)
  1148. (define-key smarty-template-map "\C-br" 'smarty-template-rdelim)
  1149. (define-key smarty-template-map "\C-b\C-s" 'smarty-template-section)
  1150. (define-key smarty-template-map "\C-b\M-s" 'smarty-template-sectionelse)
  1151. (define-key smarty-template-map "\C-bs" 'smarty-template-strip)
  1152. (define-key smarty-template-map "\C-ca" 'smarty-template-assign)
  1153. (define-key smarty-template-map "\C-co" 'smarty-template-counter)
  1154. (define-key smarty-template-map "\C-cc" 'smarty-template-cycle)
  1155. (define-key smarty-template-map "\C-cd" 'smarty-template-debug)
  1156. (define-key smarty-template-map "\C-ce" 'smarty-template-eval)
  1157. (define-key smarty-template-map "\C-cf" 'smarty-template-fetch)
  1158. (define-key smarty-template-map "\C-c\C-hc" 'smarty-template-html-checkboxes)
  1159. (define-key smarty-template-map "\C-c\C-hi" 'smarty-template-html-image)
  1160. (define-key smarty-template-map "\C-c\C-ho" 'smarty-template-html-options)
  1161. (define-key smarty-template-map "\C-c\C-hr" 'smarty-template-html-radios)
  1162. (define-key smarty-template-map "\C-c\C-hd" 'smarty-template-html-select-date)
  1163. (define-key smarty-template-map "\C-c\C-hm" 'smarty-template-html-select-time)
  1164. (define-key smarty-template-map "\C-c\C-ht" 'smarty-template-html-table)
  1165. (define-key smarty-template-map "\C-ci" 'smarty-template-mailto)
  1166. (define-key smarty-template-map "\C-ch" 'smarty-template-math)
  1167. (define-key smarty-template-map "\C-c\C-p" 'smarty-template-popup)
  1168. (define-key smarty-template-map "\C-c\M-p" 'smarty-template-popup-init)
  1169. (define-key smarty-template-map "\C-ct" 'smarty-template-textformat)
  1170. (define-key smarty-template-map "\C-vp" 'smarty-template-capitalize)
  1171. (define-key smarty-template-map "\C-vc" 'smarty-template-cat)
  1172. (define-key smarty-template-map "\C-v\C-cc" 'smarty-template-count-characters)
  1173. (define-key smarty-template-map "\C-v\C-cp" 'smarty-template-count-paragraphs)
  1174. (define-key smarty-template-map "\C-v\C-cs" 'smarty-template-count-sentences)
  1175. (define-key smarty-template-map "\C-v\C-cw" 'smarty-template-count-words)
  1176. (define-key smarty-template-map "\C-vf" 'smarty-template-date-format)
  1177. (define-key smarty-template-map "\C-vd" 'smarty-template-default)
  1178. (define-key smarty-template-map "\C-ve" 'smarty-template-escape)
  1179. (define-key smarty-template-map "\C-vi" 'smarty-template-indent)
  1180. (define-key smarty-template-map "\C-vl" 'smarty-template-lower)
  1181. (define-key smarty-template-map "\C-vn" 'smarty-template-nl2br)
  1182. (define-key smarty-template-map "\C-vx" 'smarty-template-regex-replace)
  1183. (define-key smarty-template-map "\C-v\C-p" 'smarty-template-replace)
  1184. (define-key smarty-template-map "\C-vy" 'smarty-template-spacify)
  1185. (define-key smarty-template-map "\C-vs" 'smarty-template-string-format)
  1186. (define-key smarty-template-map "\C-v\C-s" 'smarty-template-vstrip)
  1187. (define-key smarty-template-map "\C-v\M-s" 'smarty-template-strip-tags)
  1188. (define-key smarty-template-map "\C-vt" 'smarty-template-truncate)
  1189. (define-key smarty-template-map "\C-vu" 'smarty-template-upper)
  1190. (define-key smarty-template-map "\C-vw" 'smarty-template-wordwrap)
  1191. (define-key smarty-template-map "\C-h" 'smarty-template-header)
  1192. (define-key smarty-template-map "\C-f" 'smarty-template-footer)
  1193. (define-key smarty-template-map "\C-di" 'smarty-template-insert-date)
  1194. (define-key smarty-template-map "\C-dm" 'smarty-template-modify))
  1195. ;; initialize template map for Smarty Mode
  1196. (smarty-template-map-init)
  1197. (defun smarty-mode-map-init ()
  1198. "Initialize `smarty-mode-map'."
  1199. (setq smarty-mode-map (make-sparse-keymap))
  1200. ;; template key bindings
  1201. (define-key smarty-mode-map "\C-c\C-t" smarty-template-map)
  1202. ;; mode specific key bindings
  1203. (define-key smarty-mode-map "\C-c\C-m\C-e" 'smarty-electric-mode)
  1204. (define-key smarty-mode-map "\C-c\C-m\C-s" 'smarty-stutter-mode)
  1205. (define-key smarty-mode-map "\C-c\C-s\C-u" 'smarty-add-source-files-menu)
  1206. (define-key smarty-mode-map "\C-c\M-m" 'smarty-show-messages)
  1207. (define-key smarty-mode-map "\C-c\C-h" 'smarty-doc-mode)
  1208. (define-key smarty-mode-map "\C-c\C-v" 'smarty-version)
  1209. ;; electric key bindings
  1210. (when smarty-intelligent-tab
  1211. (define-key smarty-mode-map "\t" 'smarty-electric-tab))
  1212. (define-key smarty-mode-map " " 'smarty-electric-space)
  1213. (define-key smarty-mode-map "(" 'smarty-electric-open-bracket)
  1214. (define-key smarty-mode-map ")" 'smarty-electric-close-bracket)
  1215. (define-key smarty-mode-map "*" 'smarty-electric-star))
  1216. ;; initialize mode map for Smarty Mode
  1217. (smarty-mode-map-init)
  1218. (defvar smarty-minibuffer-local-map
  1219. (let ((map (make-sparse-keymap)))
  1220. (set-keymap-parent map minibuffer-local-map)
  1221. (when smarty-word-completion-in-minibuffer
  1222. (define-key map "\t" 'smarty-minibuffer-tab))
  1223. map)
  1224. "Keymap for minibuffer used in Smarty Mode.")
  1225. (mapcar
  1226. (function
  1227. (lambda (sym)
  1228. (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
  1229. (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
  1230. '(smarty-electric-space
  1231. smarty-electric-tab
  1232. smarty-electric-open-bracket
  1233. smarty-electric-close-bracket
  1234. smarty-electric-star))
  1235. ;;;###autoload
  1236. (defun smarty-mode ()
  1237. "Smarty Mode
  1238. ***********
  1239. Smarty Mode is a GNU XEmacs major mode for editing Smarty templates.
  1240. 1 Introduction
  1241. **************
  1242. Smarty-Mode is a mode allowing easy edit of Smarty templates:
  1243. highlight, templates, navigation into source files...
  1244. Features (new features in bold) :
  1245. * Completion
  1246. * Customizable
  1247. * Highlight
  1248. * Menu
  1249. * Stuttering
  1250. * Templates
  1251. - Built-in Functions
  1252. - User Functions
  1253. - Variable Modifiers
  1254. - Plugin (Functions)
  1255. * BlockRepeatPlugin
  1256. * ClipCache
  1257. * Smarty Formtool
  1258. * Smarty Paginate
  1259. * Smarty Validate
  1260. - Plugin (Variable Modifiers)
  1261. * AlternativeDateModifierPlugin
  1262. * B2Smilies
  1263. * BBCodePlugin
  1264. - Fonctions Non-Smarty
  1265. This manual describes Smarty Mode version 0.0.5.
  1266. 2 Installation
  1267. **************
  1268. 2.1 Requirements
  1269. ================
  1270. Smarty Mode is a XEmacs major mode that needs the following
  1271. software/packages:
  1272. * XEmacs (http://www.xemacs.org/).
  1273. * `font-lock' mode generaly installed with XEmacs.
  1274. * `assoc' mode generaly installed with XEmacs.
  1275. * `easymenu' mode generaly installed with XEmacs.
  1276. * `hippie-exp' mode generaly installed with XEmacs.
  1277. Before continuing, you must be sure to have all this packages
  1278. installed.
  1279. 2.2 Download
  1280. ============
  1281. Two internet address to download Smarty Mode :
  1282. * Principal: Smarty-Mode 0.0.5
  1283. (http://deboutv.free.fr/lisp/smarty/download/smarty-0.0.5.tar.gz)
  1284. (http://deboutv.free.fr/lisp/smarty/)
  1285. * Secondary: Smarty-Mode 0.0.5
  1286. (http://www.morinie.fr/lisp/smarty/download/smarty-0.0.5.tar.gz)
  1287. (http://www.morinie.fr/lisp/smarty/)
  1288. * Old releases: Smarty-Mode
  1289. (http://deboutv.free.fr/lisp/smarty/download.php)
  1290. (http://deboutv.free.fr/lisp/smarty/)
  1291. 2.3 Installation
  1292. ================
  1293. 2.3.1 Installation
  1294. ------------------
  1295. To install Smarty Mode you need to choose an installation directory
  1296. \(for example `/usr/local/share/lisp' or `c:\lisp'). The administrator
  1297. must have the write rights on this directory.
  1298. With your favorite unzip software, unzip the archive in the
  1299. installation directory.
  1300. Example:
  1301. cd /usr/local/share/lisp
  1302. tar zxvf smarty-0.0.5.tar.gz
  1303. Now you have a `smarty' directory in the installation directory. This
  1304. directory contains 2 files `smarty-mode.el' and `smarty-mode.elc' and
  1305. another directory `docs' containing the documentation.
  1306. You need to configure XEmacs. open you initialization file `init.el'
  1307. \(open the file or start XEmacs then choose the Options menu and Edit
  1308. Init File). Add the following lines (the installation directory in
  1309. this example is `/usr/local/share/lisp') :
  1310. (setq load-path
  1311. (append (list \"/usr/local/share/lisp/\") load-path))
  1312. (autoload 'smarty-mode \"smarty-mode\" \"Smarty Mode\" t)
  1313. 2.3.2 Update
  1314. ------------
  1315. The update is easy. You need to unzip the archive in the installation
  1316. directory to remove the old release.
  1317. Example:
  1318. cd /usr/local/share/lisp
  1319. rm -rf smarty
  1320. tar zxvf smarty-0.0.5.tar.gz
  1321. 2.4 Invoke Smarty-Mode
  1322. ======================
  1323. You have two possibilities to invoke the Smarty Mode.
  1324. - Manually: At each file opening you need to launch Smarty Mode
  1325. with the following command:
  1326. `M-x smarty-mode'
  1327. - Automatically: Add the following linesin your initialization
  1328. file `init.el' :
  1329. (setq auto-mode-alist
  1330. (append
  1331. '((\"\\.tpl$\" . smarty-mode))
  1332. auto-mode-alist))
  1333. 3 Customization
  1334. ***************
  1335. This chapter describes the differents parameters and functions that
  1336. you can change to customize Smarty Mode. To do that, open a Smarty
  1337. file, click on the Smarty menu and choose Options then Browse
  1338. Options....
  1339. 3.1 Parameters
  1340. ==============
  1341. 3.1.1 Mode
  1342. ----------
  1343. Smarty Mode has 2 modes allowing to simplify the writing of Smarty
  1344. templates. You can enable/disable each mode individually.
  1345. `smarty-electric-mode'
  1346. Type: boolean
  1347. Default value: `t'
  1348. Description: If `t'; enable automatic generation of template.
  1349. If `nil'; template generators can still be invoked through key
  1350. bindings and menu. Is indicated in the modeline by \"/e\" after
  1351. the mode name and can be toggled by `smarty-electric-mode'.
  1352. `smarty-stutter-mode'
  1353. Type: boolean
  1354. Default value: `t'
  1355. Description: If `t'; enable the stuttering. Is indicated in the
  1356. modeline by \"/s\" after the mode name and can be toggled by
  1357. `smarty-stutter-mode'.
  1358. 3.1.2 Menu
  1359. ----------
  1360. Smarty Mode has also 1 menu that you can enable/disable. The menu
  1361. Sources is specific to each Smarty files opened.
  1362. `smarty-source-file-menu'
  1363. Type: boolean
  1364. Default value: `t'
  1365. Description: If `t'; the Sources menu is enabled. This menu
  1366. contains the list of Smarty file located in the current
  1367. directory. The Sources menu scans the directory when a file is
  1368. opened.
  1369. 3.1.3 Menu
  1370. ----------
  1371. `smarty-highlight-plugin-functions'
  1372. Type: boolean
  1373. Default value: `t'
  1374. Description: If `t'; the functions described in the smarty
  1375. plugins are highlighted.
  1376. 3.1.4 Templates
  1377. ---------------
  1378. 3.1.4.1 Header
  1379. ..............
  1380. `smarty-file-header'
  1381. Type: string
  1382. Default value: `\"\"'
  1383. Description: String or file to insert as file header. If the
  1384. string specifies an existing file name the contents of the file
  1385. is inserted; otherwise the string itself is inserted as file
  1386. header.
  1387. Type `C-j' for newlines.
  1388. The follonwing keywords are supported:
  1389. <filename>: replaced by the file name.
  1390. <author>: replaced by the user name and email address.
  1391. <login>: replaced by `user-login-name'.
  1392. <company>: replaced by `smarty-company-name' content.
  1393. <date>: replaced by the current date.
  1394. <year>: replaced by the current year.
  1395. <copyright>: replaced by `smarty-copyright-string' content.
  1396. <cursor>: final cursor position.
  1397. `smarty-file-footer'
  1398. Type: string
  1399. Default value: `\"\"'
  1400. Description: String or file to insert as file footer. See
  1401. `smarty-file-header'
  1402. `smarty-company-name'
  1403. Type: string
  1404. Default value: `\"\"'
  1405. Description: Name of the company to insert in file header.
  1406. `smarty-copyright-string'
  1407. Type: string
  1408. Default value: `\"\"'
  1409. Description: Coryright string to insert in file header.
  1410. `smarty-date-format'
  1411. Type: string
  1412. Default value: `\"%Y-%m-%d\"'
  1413. Description: Date format.
  1414. `smarty-modify-date-prefix-string'
  1415. Type: string
  1416. Default value: `\"\"'
  1417. Description: Prefix string of modification date in Smarty file
  1418. header.
  1419. `smarty-modify-date-on-saving'
  1420. Type: bool
  1421. Default value: `nil'
  1422. Description: If `t'; update the modification date when the
  1423. buffer is saved.
  1424. 3.1.5 Miscellaneous
  1425. -------------------
  1426. `smarty-left-delimiter'
  1427. Type: string
  1428. Default value: `\"\"'
  1429. Description: Left escaping delimiter for Smarty templates.
  1430. `smarty-right-delimiter'
  1431. Type: string
  1432. Default value: `\"\"'
  1433. Description: Right escaping delimiter for Smarty templates.
  1434. `smarty-intelligent-tab'
  1435. Type: bool
  1436. Default value: `t'
  1437. Description: If `t'; TAB does indentation; completion and insert
  1438. tabulations. If `nil'; TAB does only indentation.
  1439. `smarty-word-completion-in-minibuffer'
  1440. Type: bool
  1441. Default value: `t'
  1442. Description: If `t'; enable completion in the minibuffer.
  1443. `smarty-word-completion-case-sensitive'
  1444. Type: bool
  1445. Default value: `nil'
  1446. Description: If `t'; completion is case sensitive.
  1447. 3.2 Functions
  1448. =============
  1449. 3.2.1 Mode
  1450. ----------
  1451. `smarty-electric-mode'
  1452. Menu: Smarty -> Options -> Mode -> Electric Mode
  1453. Keybinding: `C-c C-m C-e'
  1454. Description: This functions is used to enable/disable the
  1455. electric mode.
  1456. `smarty-stutter-mode'
  1457. Menu: Smarty -> Options -> Mode -> Stutter Mode
  1458. Keybinding: `C-c C-m C-s'
  1459. Description: This function is used to enable/disable the stutter
  1460. mode.
  1461. 4 Menus
  1462. *******
  1463. There are 2 menus: Smarty and Sources. All theses menus can be
  1464. accessed from the menubar or from the right click. This chapter
  1465. describes each menus.
  1466. 4.1 Smarty
  1467. ==========
  1468. This is the main menu of Smarty Mode. It allows an easy access to the
  1469. main features of the Smarty Mode: Templates (see *Note Templates::)
  1470. and Options (see *Note Customization::).
  1471. This menu contains also 3 functions that are discussed in the next
  1472. part.
  1473. 4.1.1 Functions
  1474. ---------------
  1475. `smarty-show-messages'
  1476. Menu: Smarty -> Show Messages
  1477. Keybinding: `C-c M-m'
  1478. Description: This function opens the *Messages* buffer to
  1479. display previous error messages.
  1480. `smarty-doc-mode'
  1481. Menu: Smarty -> Smarty Mode Documentation
  1482. Keybinding: `C-c C-h'
  1483. Description: This function opens the *Help* buffer and prints in
  1484. it the Smarty Mode documentation.
  1485. `smarty-version'
  1486. Menu: Smarty -> Version
  1487. Keybinding: `C-c C-v'
  1488. Description: This function displays in the minibuffer the
  1489. current Smarty Mode version with the timestamp.
  1490. 4.2 Sources
  1491. ===========
  1492. The Sources menu shows the Smarty files in the current directory. If
  1493. you add or delete a file in the current directory, you need to
  1494. refresh the menu.
  1495. 4.2.1 Customization
  1496. -------------------
  1497. `smarty-source-file-menu'
  1498. Type: boolean
  1499. Default value: `t'
  1500. Description: If `t'; the Sources menu is enabled. This menu
  1501. contains the list of Smarty file located in the current
  1502. directory. The Sources menu scans the directory when a file is
  1503. opened.
  1504. 4.2.2 Functions
  1505. ---------------
  1506. `smarty-add-source-files-menu'
  1507. Menu: Sources -> *Rescan*
  1508. Keybinding: `C-c C-s C-u'
  1509. Description: This function is used to refresh the Sources menu.
  1510. 5 Stuttering
  1511. ************
  1512. The stutter mode is a mode that affects a function to a key. For
  1513. example, when you use the `ENTER' key, the associated function will
  1514. create a new line and indent it.
  1515. 5.1 Customization
  1516. =================
  1517. `smarty-stutter-mode'
  1518. Type: boolean
  1519. Default value: `t'
  1520. Description: If `t'; enable the stuttering. Is indicated in the
  1521. modeline by \"/s\" after the mode name and can be toggled by
  1522. `smarty-stutter-mode'.
  1523. 5.2 Functions
  1524. =============
  1525. `SPACE'
  1526. If in comment, indent the comment and add new line if necessary.
  1527. In other case, add a space.
  1528. `('
  1529. If the previous character is a `(', the `((' will be replaced by
  1530. `['.
  1531. If the previous character is a `[', the `[(' will be replaced by
  1532. `{'.
  1533. In other case, insert a `('.
  1534. `)'
  1535. If the previous character is a `)', the `))' will be replaced by
  1536. `]'.
  1537. If the previous character is a `]', the `])' will be replaced by
  1538. `}'.
  1539. In other case, insert a `)'.
  1540. 6 Templates
  1541. ***********
  1542. In the Smarty Mode, the Smarty functions (like if, while, for, fopen,
  1543. fclose) are predefined in functions called \"Templates\".
  1544. Each template can be invoked by the function name or by using the
  1545. <SPACE> key after the Smarty function name in the buffer (Note, using
  1546. `M-<SPACE>' disable the template).
  1547. A template can be aborted by using the `C-g' or by lefting empty the
  1548. tempate prompt (in the minibuffer).
  1549. 6.1 Customization
  1550. =================
  1551. `smarty-electric-mode'
  1552. Type: boolean
  1553. Default value: `t'
  1554. Description: If `t'; enable automatic generation of template.
  1555. If `nil'; template generators can still be invoked through key
  1556. bindings and menu. Is indicated in the modeline by \"/e\" after
  1557. the mode name and can be toggled by `smarty-electric-mode'.
  1558. For a complete description of the template customizable variables,
  1559. see *Note Cu01-Pa01-Template::
  1560. 6.2 Functions
  1561. =============
  1562. 6.2.1 Smarty Functions
  1563. ----------------------
  1564. For Smarty functions, see PDF or HTML documentation.
  1565. 6.2.2 Non-Smarty Functions
  1566. --------------------------
  1567. `smarty-template-header'
  1568. Menu: Smarty -> Templates -> Insert Header
  1569. Keybinding: `C-c C-t C-h'
  1570. Description: This function is used to insert a header in the
  1571. current buffer.
  1572. `smarty-template-footer'
  1573. Menu: Smarty -> Templates -> Insert Footer
  1574. Keybinding: `C-c C-t C-f'
  1575. Description: This function is used to insert a footer in the
  1576. current buffer.
  1577. `smarty-template-insert-date'
  1578. Menu: Smarty -> Templates -> Insert Date
  1579. Keybinding: `C-c C-t C-d i'
  1580. Description: This function is used to insert the date in the
  1581. current buffer.
  1582. `smarty-template-modify'
  1583. Menu: Smarty -> Templates -> Modify Date
  1584. Keybinding: `C-c C-t C-d m'
  1585. Description: This function is used to modify the last
  1586. modification date in the current buffer.
  1587. 7 Bugs, Help
  1588. ************
  1589. * To report bugs: Bugtracker
  1590. (http://bugtracker.morinie.fr/lisp/set_project.php?project_id=2)
  1591. * To obtain help you can post on the dedicated forum: Forum
  1592. (http://forum.morinie.fr/lisp/)
  1593. 8 Key bindings
  1594. **************
  1595. \\{smarty-mode-map}"
  1596. (interactive)
  1597. (kill-all-local-variables)
  1598. (setq major-mode 'smarty-mode)
  1599. (setq mode-name "Smarty")
  1600. (smarty-create-syntax-table)
  1601. ;; set maps and tables
  1602. (use-local-map smarty-mode-map)
  1603. (set-syntax-table smarty-mode-syntax-table)
  1604. (setq local-abbrev-table smarty-mode-abbrev-table)
  1605. (set (make-local-variable 'comment-start) (concat smarty-left-delimiter "*"))
  1606. (set (make-local-variable 'comment-end) (concat "*" smarty-right-delimiter))
  1607. (set (make-local-variable 'comment-multi-line) t)
  1608. (set (make-local-variable 'smarty-end-comment-column) 80)
  1609. (make-local-variable 'font-lock-defaults)
  1610. (if smarty-highlight-plugin-functions
  1611. (setq smarty-font-lock-keywords smarty-font-lock-keywords-4)
  1612. (setq smarty-font-lock-keywords smarty-font-lock-keywords-3))
  1613. (setq font-lock-defaults
  1614. '((smarty-font-lock-keywords)
  1615. nil ; Keywords only (i.e. no comment or string highlighting
  1616. t ; case fold
  1617. nil ; syntax-alist
  1618. nil ; syntax-begin
  1619. ))
  1620. (setq font-lock-maximum-decoration t
  1621. case-fold-search t)
  1622. ;; add source file menu
  1623. (if smarty-source-file-menu (smarty-add-source-files-menu))
  1624. ;; add Smarty menu
  1625. (easy-menu-add smarty-mode-menu-list)
  1626. (easy-menu-define smarty-mode-menu smarty-mode-map
  1627. "Menu keymap for Smarty Mode." smarty-mode-menu-list)
  1628. ;; (message "Smarty Mode %s.%s" smarty-version
  1629. ;; (if noninteractive "" " See menu for documentation and release notes."))
  1630. (smarty-mode-line-update)
  1631. (run-hooks 'smarty-mode-hook))
  1632. (defun smarty-doc-mode ()
  1633. "Display Smarty Mode documentation in *Help* buffer."
  1634. (interactive)
  1635. (with-output-to-temp-buffer
  1636. (if (fboundp 'help-buffer) (help-buffer) "*Help*")
  1637. (princ mode-name)
  1638. (princ " mode:\n")
  1639. (princ (documentation 'smarty-mode))
  1640. (with-current-buffer standard-output
  1641. (help-mode))
  1642. (print-help-return-message)))
  1643. (defun smarty-activate-customizations ()
  1644. "Activate all customizations on local variables."
  1645. (interactive)
  1646. (smarty-mode-map-init)
  1647. (use-local-map smarty-mode-map)
  1648. (set-syntax-table smarty-mode-syntax-table)
  1649. (smarty-update-mode-menu)
  1650. (run-hooks 'menu-bar-update-hook)
  1651. (smarty-mode-line-update))
  1652. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1653. ;;; Templates
  1654. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1655. (defun smarty-template-field (prompt &optional follow-string optional
  1656. begin end is-string string-char default)
  1657. "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
  1658. If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
  1659. an empty string is inserted, return nil and call `smarty-template-undo' for
  1660. the region between BEGIN and END. IS-STRING indicates whether a string
  1661. with double-quotes is to be inserted. DEFAULT specifies a default string."
  1662. (let ((position (point))
  1663. string)
  1664. (insert "<" prompt ">")
  1665. (if (not (> (length string-char) 0))
  1666. (setq string-char "\""))
  1667. (setq string
  1668. (condition-case ()
  1669. (read-from-minibuffer (concat prompt ": ")
  1670. (or (and is-string (cons (concat string-char string-char) 1)) default)
  1671. smarty-minibuffer-local-map)
  1672. (quit (if (and optional begin end)
  1673. (progn (beep) "")
  1674. (keyboard-quit)))))
  1675. (when (or (not (equal string "")) optional)
  1676. (delete-region position (point)))
  1677. (when (and (equal string "") optional begin end)
  1678. (smarty-template-undo begin end)
  1679. (message "Template aborted"))
  1680. (unless (equal string "")
  1681. (insert string))
  1682. (when (or (not (equal string "")) (not optional))
  1683. (insert (or follow-string "")))
  1684. (if (equal string "") nil string)))
  1685. (defun smarty-template-undo (begin end)
  1686. "Undo aborted template by deleting region and unexpanding the keyword."
  1687. (cond (smarty-template-invoked-by-hook
  1688. (goto-char end)
  1689. (insert " ")
  1690. (delete-region begin end)
  1691. (unexpand-abbrev))
  1692. (t (delete-region begin end))))
  1693. (defun smarty-template-generic-function (label close-label field mandatory-count &optional infinite special-field force-var)
  1694. "Generic function template 'label field1= field2=..."
  1695. (interactive)
  1696. (let ((start (point)) found here result-value elt continue field-count stop prompt)
  1697. (if smarty-template-invoked-by-hook
  1698. (setq found (smarty-after-ldelim))
  1699. (insert smarty-left-delimiter)
  1700. (setq found t))
  1701. (insert label)
  1702. (setq here (point-marker))
  1703. (insert " ")
  1704. (when found
  1705. (setq elt field)
  1706. (setq continue t)
  1707. (setq field-count 0)
  1708. (setq stop nil)
  1709. (while (and elt continue)
  1710. (setq prompt (car elt))
  1711. (when (not special-field)
  1712. (insert prompt "="))
  1713. (setq result-value (smarty-template-field prompt nil t))
  1714. (if (and (not result-value)
  1715. (< field-count mandatory-count))
  1716. (progn (setq continue nil)
  1717. (delete-region start (point))
  1718. (insert (concat label " "))
  1719. (setq stop t))
  1720. (if (not result-value)
  1721. (setq continue nil)
  1722. (setq here (point-marker))
  1723. (insert " ")))
  1724. (setq field-count (+ 1 field-count))
  1725. (setq elt (cdr elt)))
  1726. (when (and infinite (or continue force-var))
  1727. (when (not continue)
  1728. (delete-region here (point))
  1729. (insert " "))
  1730. (setq continue t)
  1731. (while continue
  1732. (setq result-value (smarty-template-field "var_name" "=" t here))
  1733. (if (not result-value)
  1734. (setq continue nil)
  1735. (setq continue (smarty-template-field "var_value" nil t here))
  1736. (setq here (point-marker))
  1737. (insert " "))))
  1738. (when (not stop)
  1739. (delete-region here (point))
  1740. (if (> 0 mandatory-count)
  1741. (delete-char -1))
  1742. (insert smarty-right-delimiter)
  1743. (setq here (point-marker))
  1744. (if close-label
  1745. (insert smarty-left-delimiter "/" label smarty-right-delimiter))
  1746. (goto-char here)))))
  1747. (defun smarty-template-generic-modifier (label field mandatory-count)
  1748. "Generic modifier template '|label:field1:field2..."
  1749. (interactive)
  1750. (let ((start (point)) found here result-value elt continue field-count stop prompt)
  1751. (setq found (re-search-backward (concat (regexp-quote smarty-left-delimiter) "\\$\\(\\sw\\|\\s.\\)+" (regexp-quote "|")) nil t))
  1752. (if found
  1753. (progn
  1754. (setq found (re-search-forward (regexp-quote smarty-right-delimiter) start t))
  1755. (if (not found)
  1756. (progn
  1757. (goto-char start)
  1758. (insert label)
  1759. (setq here (point-marker))
  1760. (setq elt field)
  1761. (setq continue t)
  1762. (setq field-count 0)
  1763. (setq stop nil)
  1764. (while (and elt continue)
  1765. (setq prompt (car elt))
  1766. (insert ":")
  1767. (setq result-value (smarty-template-field prompt nil t))
  1768. (if (and (not result-value)
  1769. (< field-count mandatory-count))
  1770. (progn (setq continue nil)
  1771. (delete-region start (point))
  1772. (insert (concat label " "))
  1773. (setq stop t))
  1774. (if (not result-value)
  1775. (setq continue nil)
  1776. (setq here (point-marker))
  1777. (insert ":")))
  1778. (setq field-count (+ 1 field-count))
  1779. (setq elt (cdr elt)))
  1780. (when (not stop)
  1781. (delete-region here (point))
  1782. (if (not (or (looking-at smarty-right-delimiter)
  1783. (looking-at "|")))
  1784. (insert smarty-right-delimiter))))
  1785. (goto-char start)
  1786. (insert label " ")))
  1787. (goto-char start)
  1788. (insert label " "))))
  1789. (defun smarty-template-capture-hook ()
  1790. (smarty-hooked-abbrev 'smarty-template-capture))
  1791. (defun smarty-template-config-load-hook ()
  1792. (smarty-hooked-abbrev 'smarty-template-config-load))
  1793. (defun smarty-template-else-hook ()
  1794. (smarty-hooked-abbrev 'smarty-template-else))
  1795. (defun smarty-template-elseif-hook ()
  1796. (smarty-hooked-abbrev 'smarty-template-elseif))
  1797. (defun smarty-template-foreach-hook ()
  1798. (smarty-hooked-abbrev 'smarty-template-foreach))
  1799. (defun smarty-template-foreachelse-hook ()
  1800. (smarty-hooked-abbrev 'smarty-template-foreachelse))
  1801. (defun smarty-template-if-hook ()
  1802. (smarty-hooked-abbrev 'smarty-template-if))
  1803. (defun smarty-template-include-hook ()
  1804. (smarty-hooked-abbrev 'smarty-template-include))
  1805. (defun smarty-template-include-php-hook ()
  1806. (smarty-hooked-abbrev 'smarty-template-include-php))
  1807. (defun smarty-template-insert-hook ()
  1808. (smarty-hooked-abbrev 'smarty-template-insert))
  1809. (defun smarty-template-ldelim-hook ()
  1810. (smarty-hooked-abbrev 'smarty-template-ldelim))
  1811. (defun smarty-template-literal-hook ()
  1812. (smarty-hooked-abbrev 'smarty-template-literal))
  1813. (defun smarty-template-php-hook ()
  1814. (smarty-hooked-abbrev 'smarty-template-php))
  1815. (defun smarty-template-rdelim-hook ()
  1816. (smarty-hooked-abbrev 'smarty-template-rdelim))
  1817. (defun smarty-template-section-hook ()
  1818. (smarty-hooked-abbrev 'smarty-template-section))
  1819. (defun smarty-template-sectionelse-hook ()
  1820. (smarty-hooked-abbrev 'smarty-template-sectionelse))
  1821. (defun smarty-template-strip-hook ()
  1822. (smarty-hooked-abbrev 'smarty-template-strip))
  1823. (defun smarty-template-assign-hook ()
  1824. (smarty-hooked-abbrev 'smarty-template-assign))
  1825. (defun smarty-template-counter-hook ()
  1826. (smarty-hooked-abbrev 'smarty-template-counter))
  1827. (defun smarty-template-cycle-hook ()
  1828. (smarty-hooked-abbrev 'smarty-template-cycle))
  1829. (defun smarty-template-debug-hook ()
  1830. (smarty-hooked-abbrev 'smarty-template-debug))
  1831. (defun smarty-template-eval-hook ()
  1832. (smarty-hooked-abbrev 'smarty-template-eval))
  1833. (defun smarty-template-fetch-hook ()
  1834. (smarty-hooked-abbrev 'smarty-template-fetch))
  1835. (defun smarty-template-html-checkboxes-hook ()
  1836. (smarty-hooked-abbrev 'smarty-template-html-checkboxes))
  1837. (defun smarty-template-html-image-hook ()
  1838. (smarty-hooked-abbrev 'smarty-template-html-image))
  1839. (defun smarty-template-html-options-hook ()
  1840. (smarty-hooked-abbrev 'smarty-template-html-options))
  1841. (defun smarty-template-html-radios-hook ()
  1842. (smarty-hooked-abbrev 'smarty-template-html-radios))
  1843. (defun smarty-template-html-select-date-hook ()
  1844. (smarty-hooked-abbrev 'smarty-template-html-select-date))
  1845. (defun smarty-template-html-select-time-hook ()
  1846. (smarty-hooked-abbrev 'smarty-template-html-select-time))
  1847. (defun smarty-template-html-table-hook ()
  1848. (smarty-hooked-abbrev 'smarty-template-html-table))
  1849. (defun smarty-template-mailto-hook ()
  1850. (smarty-hooked-abbrev 'smarty-template-mailto))
  1851. (defun smarty-template-math-hook ()
  1852. (smarty-hooked-abbrev 'smarty-template-math))
  1853. (defun smarty-template-popup-hook ()
  1854. (smarty-hooked-abbrev 'smarty-template-popup))
  1855. (defun smarty-template-popup-init-hook ()
  1856. (smarty-hooked-abbrev 'smarty-template-popup-init))
  1857. (defun smarty-template-textformat-hook ()
  1858. (smarty-hooked-abbrev 'smarty-template-textformat))
  1859. (defun smarty-template-capitalize-hook ()
  1860. (smarty-hooked-abbrev 'smarty-template-capitalize))
  1861. (defun smarty-template-cat-hook ()
  1862. (smarty-hooked-abbrev 'smarty-template-cat))
  1863. (defun smarty-template-count-characters-hook ()
  1864. (smarty-hooked-abbrev 'smarty-template-count-characters))
  1865. (defun smarty-template-count-paragraphs-hook ()
  1866. (smarty-hooked-abbrev 'smarty-template-count-paragraphs))
  1867. (defun smarty-template-count-sentences-hook ()
  1868. (smarty-hooked-abbrev 'smarty-template-count-sentences))
  1869. (defun smarty-template-count-words-hook ()
  1870. (smarty-hooked-abbrev 'smarty-template-count-words))
  1871. (defun smarty-template-date-format-hook ()
  1872. (smarty-hooked-abbrev 'smarty-template-date-format))
  1873. (defun smarty-template-default-hook ()
  1874. (smarty-hooked-abbrev 'smarty-template-default))
  1875. (defun smarty-template-escape-hook ()
  1876. (smarty-hooked-abbrev 'smarty-template-escape))
  1877. (defun smarty-template-indent-hook ()
  1878. (smarty-hooked-abbrev 'smarty-template-indent))
  1879. (defun smarty-template-lower-hook ()
  1880. (smarty-hooked-abbrev 'smarty-template-lower))
  1881. (defun smarty-template-nl2br-hook ()
  1882. (smarty-hooked-abbrev 'smarty-template-nl2br))
  1883. (defun smarty-template-regex-replace-hook ()
  1884. (smarty-hooked-abbrev 'smarty-template-regex-replace))
  1885. (defun smarty-template-replace-hook ()
  1886. (smarty-hooked-abbrev 'smarty-template-replace))
  1887. (defun smarty-template-spacify-hook ()
  1888. (smarty-hooked-abbrev 'smarty-template-spacify))
  1889. (defun smarty-template-string-format-hook ()
  1890. (smarty-hooked-abbrev 'smarty-template-string-format))
  1891. (defun smarty-template-vstrip-hook ()
  1892. (smarty-hooked-abbrev 'smarty-template-vstrip))
  1893. (defun smarty-template-strip-tags-hook ()
  1894. (smarty-hooked-abbrev 'smarty-template-strip-tags))
  1895. (defun smarty-template-truncate-hook ()
  1896. (smarty-hooked-abbrev 'smarty-template-truncate))
  1897. (defun smarty-template-upper-hook ()
  1898. (smarty-hooked-abbrev 'smarty-template-upper))
  1899. (defun smarty-template-wordwrap-hook ()
  1900. (smarty-hooked-abbrev 'smarty-template-wordwrap))
  1901. (defun smarty-template-validate-hook ()
  1902. (smarty-hooked-abbrev 'smarty-template-validate))
  1903. (defun smarty-template-clipcache-hook ()
  1904. (smarty-hooked-abbrev 'smarty-template-clipcache))
  1905. (defun smarty-template-include-clipcache-hook ()
  1906. (smarty-hooked-abbrev 'smarty-template-include-clipcache))
  1907. (defun smarty-template-formtool-checkall-hook ()
  1908. (smarty-hooked-abbrev 'smarty-template-formtool-checkall))
  1909. (defun smarty-template-formtool-copy-hook ()
  1910. (smarty-hooked-abbrev 'smarty-template-formtool-copy))
  1911. (defun smarty-template-formtool-count-chars-hook ()
  1912. (smarty-hooked-abbrev 'smarty-template-formtool-count-chars))
  1913. (defun smarty-template-formtool-init-hook ()
  1914. (smarty-hooked-abbrev 'smarty-template-formtool-init))
  1915. (defun smarty-template-formtool-move-hook ()
  1916. (smarty-hooked-abbrev 'smarty-template-formtool-move))
  1917. (defun smarty-template-formtool-moveall-hook ()
  1918. (smarty-hooked-abbrev 'smarty-template-formtool-moveall))
  1919. (defun smarty-template-formtool-movedown-hook ()
  1920. (smarty-hooked-abbrev 'smarty-template-formtool-movedown))
  1921. (defun smarty-template-formtool-moveup-hook ()
  1922. (smarty-hooked-abbrev 'smarty-template-formtool-moveup))
  1923. (defun smarty-template-formtool-remove-hook ()
  1924. (smarty-hooked-abbrev 'smarty-template-formtool-remove))
  1925. (defun smarty-template-formtool-rename-hook ()
  1926. (smarty-hooked-abbrev 'smarty-template-formtool-rename))
  1927. (defun smarty-template-formtool-save-hook ()
  1928. (smarty-hooked-abbrev 'smarty-template-formtool-save))
  1929. (defun smarty-template-formtool-selectall-hook ()
  1930. (smarty-hooked-abbrev 'smarty-template-formtool-selectall))
  1931. (defun smarty-template-paginate-first-hook ()
  1932. (smarty-hooked-abbrev 'smarty-template-paginate-first))
  1933. (defun smarty-template-paginate-last-hook ()
  1934. (smarty-hooked-abbrev 'smarty-template-paginate-last))
  1935. (defun smarty-template-paginate-middle-hook ()
  1936. (smarty-hooked-abbrev 'smarty-template-paginate-middle))
  1937. (defun smarty-template-paginate-next-hook ()
  1938. (smarty-hooked-abbrev 'smarty-template-paginate-next))
  1939. (defun smarty-template-paginate-prev-hook ()
  1940. (smarty-hooked-abbrev 'smarty-template-paginate-prev))
  1941. (defun smarty-template-btosmilies-hook ()
  1942. (smarty-hooked-abbrev 'smarty-template-btosmilies))
  1943. (defun smarty-template-bbcodetohtml-hook ()
  1944. (smarty-hooked-abbrev 'smarty-template-bbcodetohtml))
  1945. (defun smarty-template-date-formatto-hook ()
  1946. (smarty-hooked-abbrev 'smarty-template-date-formatto))
  1947. (defun smarty-template-capture ()
  1948. "Insert a capture statement."
  1949. (interactive)
  1950. (smarty-template-generic-function "capture" t '("name" "assign") 0))
  1951. (defun smarty-template-config-load ()
  1952. "Insert a config_load statement."
  1953. (interactive)
  1954. (smarty-template-generic-function "config_load" nil '("file" "section" "scope" "global") 1))
  1955. (defun smarty-template-else ()
  1956. "Insert a else statement."
  1957. (interactive)
  1958. (smarty-template-generic-function "else" nil '() 0))
  1959. (defun smarty-template-elseif ()
  1960. "Insert a elseif statement."
  1961. (interactive)
  1962. (smarty-template-generic-function "elseif" nil '("condition") 1 nil t))
  1963. (defun smarty-template-foreach ()
  1964. "Insert a foreach statement."
  1965. (interactive)
  1966. (smarty-template-generic-function "foreach" t '("from" "item" "key" "name") 2))
  1967. (defun smarty-template-foreachelse ()
  1968. "Insert a foreachelse statement."
  1969. (interactive)
  1970. (smarty-template-generic-function "foreachelse" nil '() 0))
  1971. (defun smarty-template-if ()
  1972. "Insert a if statement."
  1973. (interactive)
  1974. (smarty-template-generic-function "if" t '("condition") 1 nil t))
  1975. (defun smarty-template-include ()
  1976. "Insert a include statement."
  1977. (interactive)
  1978. (smarty-template-generic-function "include" nil '("file" "assign") 1 t))
  1979. (defun smarty-template-include-php ()
  1980. "Insert a include_php statement."
  1981. (interactive)
  1982. (smarty-template-generic-function "include_php" nil '("file" "once" "assign") 1))
  1983. (defun smarty-template-insert ()
  1984. "Insert a insert statement."
  1985. (interactive)
  1986. (smarty-template-generic-function "insert" nil '("name" "assign" "script") 1 t))
  1987. (defun smarty-template-ldelim ()
  1988. "Insert a ldelim statement."
  1989. (interactive)
  1990. (smarty-template-generic-function "ldelim" nil '() 0))
  1991. (defun smarty-template-literal ()
  1992. "Insert a literal statement."
  1993. (interactive)
  1994. (smarty-template-generic-function "literal" t '() 0))
  1995. (defun smarty-template-php ()
  1996. "Insert a php statement."
  1997. (interactive)
  1998. (smarty-template-generic-function "php" t '() 0))
  1999. (defun smarty-template-rdelim ()
  2000. "Insert a rdelim statement."
  2001. (interactive)
  2002. (smarty-template-generic-function "rdelim" nil '() 0))
  2003. (defun smarty-template-section ()
  2004. "Insert a section statement."
  2005. (interactive)
  2006. (smarty-template-generic-function "section" t '("name" "loop" "start" "step" "max" "show") 2))
  2007. (defun smarty-template-sectionelse ()
  2008. "Insert a sectionelse statement."
  2009. (interactive)
  2010. (smarty-template-generic-function "sectionelse" nil '() 0))
  2011. (defun smarty-template-strip ()
  2012. "Insert a strip statement."
  2013. (interactive)
  2014. (smarty-template-generic-function "strip" t '() 0))
  2015. (defun smarty-template-assign ()
  2016. "Insert a assign statement."
  2017. (interactive)
  2018. (smarty-template-generic-function "assign" nil '("var" "value") 2))
  2019. (defun smarty-template-counter ()
  2020. "Insert a counter statement."
  2021. (interactive)
  2022. (smarty-template-generic-function "counter" nil '("name" "start" "skip" "direction" "print" "assign") 0))
  2023. (defun smarty-template-cycle ()
  2024. "Insert a cycle statement."
  2025. (interactive)
  2026. (smarty-template-generic-function "cycle" nil '("values" "name" "print" "advance" "delimiter" "assign" "reset") 1))
  2027. (defun smarty-template-debug ()
  2028. "Insert a debug statement."
  2029. (interactive)
  2030. (smarty-template-generic-function "debug" nil '("output") 0))
  2031. (defun smarty-template-eval ()
  2032. "Insert a eval statement."
  2033. (interactive)
  2034. (smarty-template-generic-function "eval" nil '("var" "assign") 1))
  2035. (defun smarty-template-fetch ()
  2036. "Insert a fetch statement."
  2037. (interactive)
  2038. (smarty-template-generic-function "fetch" nil '("file" "assign") 1))
  2039. (defun smarty-template-html-checkboxes ()
  2040. "Insert a html_checkboxes statement."
  2041. (interactive)
  2042. (smarty-template-generic-function "html_checkboxes" nil '("name" "values" "output" "selected" "options" "separator" "assign" "labels") 0))
  2043. (defun smarty-template-html-image ()
  2044. "Insert a html_image statement."
  2045. (interactive)
  2046. (smarty-template-generic-function "html_image" nil '("file" "height" "width" "basedir" "alt" "href" "path_prefix") 1))
  2047. (defun smarty-template-html-options ()
  2048. "Insert a html_options statement."
  2049. (interactive)
  2050. (smarty-template-generic-function "html_options" nil '("name" "values" "output" "selected" "options") 0))
  2051. (defun smarty-template-html-radios ()
  2052. "Insert a html_radios statement."
  2053. (interactive)
  2054. (smarty-template-generic-function "html_radios" nil '("name" "values" "output" "selected" "options" "separator" "assign") 0))
  2055. (defun smarty-template-html-select-date ()
  2056. "Insert a html_select_date statement."
  2057. (interactive)
  2058. (smarty-template-generic-function "html_select_date" nil '("prefix" "time" "start_year" "end_year" "display_days" "display_months" "display_years" "month_format" "day_format" "day_value_format" "year_as_text" "reverse_years" "field_array" "day_size" "month_size" "year_size" "all_extra" "day_extra" "month_extra" "year_extra" "field_order" "field_separator" "month_value_format" "year_empty" "month_empty" "day_empty") 0))
  2059. (defun smarty-template-html-select-time ()
  2060. "Insert a html_select_time statement."
  2061. (interactive)
  2062. (smarty-template-generic-function "html_select_time" nil '("prefix" "time" "display_hours" "display_minutes" "display_seconds" "display_meridian" "use_24_hours" "minute_interval" "second_interval" "field_array" "all_extra" "hour_extra" "minute_extra" "second_extra" "meridian_extra") 0))
  2063. (defun smarty-template-html-table ()
  2064. "Insert a html_table statement."
  2065. (interactive)
  2066. (smarty-template-generic-function "html_table" nil '("loop" "cols" "rows" "inner" "caption" "table_attr" "th_attr" "tr_attr" "td_attr" "trailpad" "hdir" "vdir") 1))
  2067. (defun smarty-template-mailto ()
  2068. "Insert a mailto statement."
  2069. (interactive)
  2070. (smarty-template-generic-function "mailto" nil '("address" "text" "encode" "cc" "bcc" "subject" "newsgroups" "followupto" "extra") 1))
  2071. (defun smarty-template-math ()
  2072. "Insert a math statement."
  2073. (interactive)
  2074. (smarty-template-generic-function "math" nil '("equation" "format" "assign") 1 t nil t))
  2075. (defun smarty-template-popup ()
  2076. "Insert a popup statement."
  2077. (interactive)
  2078. (smarty-template-generic-function "popup" nil '("text" "trigger" "sticky" "caption" "fgcolor" "bgcolor" "textcolor" "capcolor" "closecolor" "textfont" "captionfont" "closefont" "textsize" "captionsize" "closesize" "width" "height" "left" "right" "center" "above" "below" "border" "offsetx" "offsety" "fgbackground" "bgbackground" "closetext" "noclose" "status" "autostatus" "autostatuscap" "inarray" "caparray" "capicon" "snapx" "snapy" "fixx" "fixy" "background" "padx" "pady" "fullhtml" "frame" "function" "delay" "hauto" "vauto") 1))
  2079. (defun smarty-template-popup-init ()
  2080. "Insert a popup_init statement."
  2081. (interactive)
  2082. (smarty-template-generic-function "popup_init" nil '("src") 1))
  2083. (defun smarty-template-textformat ()
  2084. "Insert a textformat statement."
  2085. (interactive)
  2086. (smarty-template-generic-function "textformat" t '("style" "indent" "indent_first" "indent_char" "wrap" "wrap_char" "wrap_cut" "assign") 0))
  2087. (defun smarty-template-capitalize ()
  2088. "Insert a capitalize statement."
  2089. (interactive)
  2090. (smarty-template-generic-modifier "capitalize" '("upcase_numeric") 0))
  2091. (defun smarty-template-cat ()
  2092. "Insert a cat statement."
  2093. (interactive)
  2094. (smarty-template-generic-modifier "cat" '("value") 0))
  2095. (defun smarty-template-count-characters ()
  2096. "Insert a count_characters statement."
  2097. (interactive)
  2098. (smarty-template-generic-modifier "count_characters" '("include_whitespace") 0))
  2099. (defun smarty-template-count-paragraphs ()
  2100. "Insert a count_paragraphs statement."
  2101. (interactive)
  2102. (smarty-template-generic-modifier "count_paragraphs" '() 0))
  2103. (defun smarty-template-count-sentences ()
  2104. "Insert a count_sentences statement."
  2105. (interactive)
  2106. (smarty-template-generic-modifier "count_sentences" '() 0))
  2107. (defun smarty-template-count-words ()
  2108. "Insert a count_words statement."
  2109. (interactive)
  2110. (smarty-template-generic-modifier "count_words" '() 0))
  2111. (defun smarty-template-date-format ()
  2112. "Insert a date_format statement."
  2113. (interactive)
  2114. (smarty-template-generic-modifier "date_format" '("format" "default") 0))
  2115. (defun smarty-template-default ()
  2116. "Insert a default statement."
  2117. (interactive)
  2118. (smarty-template-generic-modifier "default" '("value") 0))
  2119. (defun smarty-template-escape ()
  2120. "Insert a escape statement."
  2121. (interactive)
  2122. (smarty-template-generic-modifier "escape" '("html|htmlall|url|urlpathinfo|quotes|hex|hexentity|javascript|mail" "charset") 0))
  2123. (defun smarty-template-indent ()
  2124. "Insert a indent statement."
  2125. (interactive)
  2126. (smarty-template-generic-modifier "indent" '("value" "character") 0))
  2127. (defun smarty-template-lower ()
  2128. "Insert a lower statement."
  2129. (interactive)
  2130. (smarty-template-generic-modifier "lower" '() 0))
  2131. (defun smarty-template-nl2br ()
  2132. "Insert a nl2br statement."
  2133. (interactive)
  2134. (smarty-template-generic-modifier "nl2br" '() 0))
  2135. (defun smarty-template-regex-replace ()
  2136. "Insert a regex_replace statement."
  2137. (interactive)
  2138. (smarty-template-generic-modifier "regex_replace" '("regexp" "string_to_replace") 2))
  2139. (defun smarty-template-replace ()
  2140. "Insert a replace statement."
  2141. (interactive)
  2142. (smarty-template-generic-modifier "replace" '("string" "string_to_replace_with") 2))
  2143. (defun smarty-template-spacify ()
  2144. "Insert a spacify statement."
  2145. (interactive)
  2146. (smarty-template-generic-modifier "spacify" '("character") 0))
  2147. (defun smarty-template-string-format ()
  2148. "Insert a string_format statement."
  2149. (interactive)
  2150. (smarty-template-generic-modifier "string_format" '("format") 1))
  2151. (defun smarty-template-vstrip ()
  2152. "Insert a strip statement."
  2153. (interactive)
  2154. (smarty-template-generic-modifier "strip" '() 0))
  2155. (defun smarty-template-strip-tags ()
  2156. "Insert a strip_tags statement."
  2157. (interactive)
  2158. (smarty-template-generic-modifier "strip_tags" '("replace_by_space") 0))
  2159. (defun smarty-template-truncate ()
  2160. "Insert a truncate statement."
  2161. (interactive)
  2162. (smarty-template-generic-modifier "truncate" '("count" "text_to_replace" "character_boundary" "middle_string") 0))
  2163. (defun smarty-template-upper ()
  2164. "Insert a upper statement."
  2165. (interactive)
  2166. (smarty-template-generic-modifier "upper" '() 0))
  2167. (defun smarty-template-wordwrap ()
  2168. "Insert a wordwrap statement."
  2169. (interactive)
  2170. (smarty-template-generic-modifier "wordwrap" '("count" "string" "character_boundary") 0))
  2171. (defun smarty-template-validate ()
  2172. "Insert a validate statement."
  2173. (interactive)
  2174. (smarty-template-generic-function "validate" nil '("field" "criteria" "message" "form" "transform" "trim" "empty" "halt" "assign" "append" "page") 3))
  2175. (defun smarty-template-repeat ()
  2176. "Insert a repeat statement."
  2177. (interactive)
  2178. (smarty-template-generic-function "repeat" nil '("count" "assign") 1))
  2179. (defun smarty-template-str_repeat ()
  2180. "Insert a str_repeat statement."
  2181. (interactive)
  2182. (smarty-template-generic-function "str_repeat" nil '("string" "count" "assign") 2))
  2183. (defun smarty-template-clipcache ()
  2184. "Insert a clipcache statement."
  2185. (interactive)
  2186. (smarty-template-generic-function "clipcache" nil '("id" "group" "ttl" "ldelim" "rdelim") 3))
  2187. (defun smarty-template-include-clipcache ()
  2188. "Insert a include_clipcache statement."
  2189. (interactive)
  2190. (smarty-template-generic-function "include_clipcache" nil '("file" "cache_id" "cache_lifetime" "ldelim" "rdelim") 3))
  2191. (defun smarty-template-formtool-checkall ()
  2192. "Insert a formtool_checkall statement."
  2193. (interactive)
  2194. (smarty-template-generic-function "formtool_checkall" nil '("name" "class" "style") 1))
  2195. (defun smarty-template-formtool-copy ()
  2196. "Insert a formtool_copy statement."
  2197. (interactive)
  2198. (smarty-template-generic-function "formtool_copy" nil '("from" "to" "save" "button_text" "all" "counter" "class" "style") 3))
  2199. (defun smarty-template-formtool-count-chars ()
  2200. "Insert a formtool_count_chars statement."
  2201. (interactive)
  2202. (smarty-template-generic-function "formtool_count_chars" nil '("name" "limit" "alert") 3))
  2203. (defun smarty-template-formtool-init ()
  2204. "Insert a formtool_init statement."
  2205. (interactive)
  2206. (smarty-template-generic-function "formtool_init" nil '("src") 1))
  2207. (defun smarty-template-formtool-move ()
  2208. "Insert a formtool_move statement."
  2209. (interactive)
  2210. (smarty-template-generic-function "formtool_move" nil '("from" "to" "save_from" "save_to" "all" "count_to" "count_from" "class" "style") 4))
  2211. (defun smarty-template-formtool-moveall ()
  2212. "Insert a formtool_moveall statement."
  2213. (interactive)
  2214. (smarty-template-generic-function "formtool_moveall" nil '("from" "to" "save_from" "save_to" "all" "count_to" "count_from" "class" "style") 4))
  2215. (defun smarty-template-formtool-movedown ()
  2216. "Insert a formtool_movedown statement."
  2217. (interactive)
  2218. (smarty-template-generic-function "formtool_movedown" nil '("save" "name" "class" "style") 2))
  2219. (defun smarty-template-formtool-moveup ()
  2220. "Insert a formtool_moveup statement."
  2221. (interactive)
  2222. (smarty-template-generic-function "formtool_moveup" nil '("save" "name" "class" "style") 2))
  2223. (defun smarty-template-formtool-remove ()
  2224. "Insert a formtool_remove statement."
  2225. (interactive)
  2226. (smarty-template-generic-function "formtool_remove" nil '("from" "save" "all" "counter" "class" "style") 2))
  2227. (defun smarty-template-formtool-rename ()
  2228. "Insert a formtool_rename statement."
  2229. (interactive)
  2230. (smarty-template-generic-function "formtool_rename" nil '("name" "from" "save" "class" "style") 3))
  2231. (defun smarty-template-formtool-save ()
  2232. "Insert a formtool_save statement."
  2233. (interactive)
  2234. (smarty-template-generic-function "formtool_save" nil '("from" "name" "save") 3))
  2235. (defun smarty-template-formtool-selectall ()
  2236. "Insert a formtool_selectall statement."
  2237. (interactive)
  2238. (smarty-template-generic-function "formtool_selectall" nil '("name" "class" "style") 1))
  2239. (defun smarty-template-paginate-first ()
  2240. "Insert a paginate_first statement."
  2241. (interactive)
  2242. (smarty-template-generic-function "paginate_first" nil '("id" "text") 0))
  2243. (defun smarty-template-paginate-last ()
  2244. "Insert a paginate_last statement."
  2245. (interactive)
  2246. (smarty-template-generic-function "paginate_last" nil '("id" "text") 0))
  2247. (defun smarty-template-paginate-middle ()
  2248. "Insert a paginate_middle statement."
  2249. (interactive)
  2250. (smarty-template-generic-function "paginate_middle" nil '("id" "format" "prefix" "page_limit" "link_prefix" "link_suffix") 0))
  2251. (defun smarty-template-paginate-next ()
  2252. "Insert a paginate_next statement."
  2253. (interactive)
  2254. (smarty-template-generic-function "paginate_next" nil '("id" "text") 0))
  2255. (defun smarty-template-paginate-prev ()
  2256. "Insert a paginate_prev statement."
  2257. (interactive)
  2258. (smarty-template-generic-function "paginate_prev" nil '("id" "text") 0))
  2259. (defun smarty-template-btosmilies ()
  2260. "Insert a B2Smilies statement."
  2261. (interactive)
  2262. (smarty-template-generic-modifier "B2Smilies" '() 0))
  2263. (defun smarty-template-bbcodetohtml ()
  2264. "Insert a bbcode2html statement."
  2265. (interactive)
  2266. (smarty-template-generic-modifier "bbcode2html" '() 0))
  2267. (defun smarty-template-date-formatto ()
  2268. "Insert a date_format2 statement."
  2269. (interactive)
  2270. (smarty-template-generic-modifier "date_format2" '("format" "default") 0))
  2271. ;;
  2272. (defun smarty-resolve-env-variable (string)
  2273. "Resolve environment variables in STRING."
  2274. (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
  2275. (setq string (concat (match-string 1 string)
  2276. (getenv (match-string 2 string))
  2277. (match-string 4 string))))
  2278. string)
  2279. (defun smarty-insert-string-or-file (string)
  2280. "Insert STRING or file contents if STRING is an existing file name."
  2281. (unless (equal string "")
  2282. (let ((file-name
  2283. (progn (string-match "^\\([^\n]+\\)" string)
  2284. (smarty-resolve-env-variable (match-string 1 string)))))
  2285. (if (file-exists-p file-name)
  2286. (forward-char (cadr (insert-file-contents file-name)))
  2287. (insert string)))))
  2288. (defun smarty-template-insert-date ()
  2289. "Insert date in appropriate format."
  2290. (interactive)
  2291. (insert
  2292. (cond
  2293. ;; 'american, 'european, 'scientific kept for backward compatibility
  2294. ((eq smarty-date-format 'american) (format-time-string "%m/%d/%Y" nil))
  2295. ((eq smarty-date-format 'european) (format-time-string "%d.%m.%Y" nil))
  2296. ((eq smarty-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
  2297. (t (format-time-string smarty-date-format nil)))))
  2298. (defun smarty-template-header (&optional file-title)
  2299. "Insert a Smarty file header."
  2300. (interactive)
  2301. (unless (equal smarty-file-header "")
  2302. (let (pos)
  2303. (save-excursion
  2304. (smarty-insert-string-or-file smarty-file-header)
  2305. (setq pos (point-marker)))
  2306. (smarty-template-replace-header-keywords
  2307. (point-min-marker) pos file-title))))
  2308. (defun smarty-template-footer ()
  2309. "Insert a Smarty file footer."
  2310. (interactive)
  2311. (unless (equal smarty-file-footer "")
  2312. (let (pos)
  2313. (save-excursion
  2314. (setq pos (point-marker))
  2315. (smarty-insert-string-or-file smarty-file-footer)
  2316. (unless (= (preceding-char) ?\n)
  2317. (insert "\n")))
  2318. (smarty-template-replace-header-keywords pos (point-max-marker)))))
  2319. (defun smarty-template-replace-header-keywords (beg end &optional file-title is-model)
  2320. "Replace keywords in header and footer."
  2321. (let ()
  2322. (smarty-prepare-search-2
  2323. (save-excursion
  2324. (goto-char beg)
  2325. (while (search-forward "<filename>" end t)
  2326. (replace-match (buffer-name) t t))
  2327. (goto-char beg)
  2328. (while (search-forward "<copyright>" end t)
  2329. (replace-match smarty-copyright-string t t))
  2330. (goto-char beg)
  2331. (while (search-forward "<author>" end t)
  2332. (replace-match "" t t)
  2333. (insert (user-full-name))
  2334. (when user-mail-address (insert " <" user-mail-address ">")))
  2335. (goto-char beg)
  2336. (while (search-forward "<login>" end t)
  2337. (replace-match (user-login-name) t t))
  2338. (goto-char beg)
  2339. (while (search-forward "<company>" end t)
  2340. (replace-match smarty-company-name t t))
  2341. (goto-char beg)
  2342. ;; Replace <RCS> with $, so that RCS for the source is
  2343. ;; not over-enthusiastic with replacements
  2344. (while (search-forward "<RCS>" end t)
  2345. (replace-match "$" nil t))
  2346. (goto-char beg)
  2347. (while (search-forward "<date>" end t)
  2348. (replace-match "" t t)
  2349. (smarty-template-insert-date))
  2350. (goto-char beg)
  2351. (while (search-forward "<year>" end t)
  2352. (replace-match (format-time-string "%Y" nil) t t))
  2353. (goto-char beg)
  2354. (let (string)
  2355. (while
  2356. (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
  2357. (setq string (read-string (concat (match-string 1) ": ")))
  2358. (replace-match string t t)))
  2359. (goto-char beg)
  2360. (when (and (not is-model) (search-forward "<cursor>" end t))
  2361. (replace-match "" t t))))))
  2362. (provide 'smarty-mode)
  2363. ;;; smarty-mode.el ends here