PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/nxhtml/related/smarty-mode.el

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