predictive-html.el 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. ;;; predictive-setup-html.el --- predictive mode HTML setup function
  2. ;; Copyright (C) 2005 Toby Cubitt
  3. ;; Author: Toby Cubitt <toby-predictive@dr-qubit.org>
  4. ;; Version: 0.2
  5. ;; Keywords: predictive, setup function, html
  6. ;; URL: http://www.dr-qubit.org/emacs.php
  7. ;; This file is part of the Emacs Predictive Completion package.
  8. ;;
  9. ;; This program is free software; you can redistribute it and/or
  10. ;; modify it under the terms of the GNU General Public License
  11. ;; as published by the Free Software Foundation; either version 2
  12. ;; of the License, or (at your option) any later version.
  13. ;;
  14. ;; This program is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;;
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with this program; if not, write to the Free Software
  21. ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. ;; MA 02110-1301, USA.
  23. ;;; Change Log:
  24. ;;
  25. ;; Version 0.2.1
  26. ;; * updated to reflect changes in completion-ui.el
  27. ;;
  28. ;; Version 0.2
  29. ;; * modified to use the new auto-overlays package
  30. ;;
  31. ;; Version 0.1
  32. ;; * initial release
  33. ;;; Code:
  34. (require 'predictive)
  35. (provide 'predictive-html)
  36. ;; variable to store identifier from call to `auto-overlay-init'
  37. (defvar predictive-html-regexps nil)
  38. (make-local-variable 'predictive-html-regexps)
  39. (defvar predictive-html-debug-color nil)
  40. (defun predictive-setup-html ()
  41. "Sets up predictive mode for use with html major modes."
  42. (interactive)
  43. ;; load the dictionaries
  44. (predictive-load-dict 'dict-html)
  45. ;; general attributes
  46. (predictive-load-dict 'dict-html-common)
  47. (predictive-load-dict 'dict-html-core)
  48. (predictive-load-dict 'dict-html-events)
  49. (predictive-load-dict 'dict-html-international)
  50. ;; tag-specific attributes
  51. (predictive-load-dict 'dict-html-a)
  52. (predictive-load-dict 'dict-html-area)
  53. (predictive-load-dict 'dict-html-base)
  54. (predictive-load-dict 'dict-html-quote)
  55. (predictive-load-dict 'dict-html-body)
  56. (predictive-load-dict 'dict-html-button)
  57. (predictive-load-dict 'dict-html-col)
  58. (predictive-load-dict 'dict-html-del)
  59. (predictive-load-dict 'dict-html-form)
  60. (predictive-load-dict 'dict-html-head)
  61. (predictive-load-dict 'dict-html-img)
  62. (predictive-load-dict 'dict-html-input)
  63. (predictive-load-dict 'dict-html-ins)
  64. (predictive-load-dict 'dict-html-label)
  65. (predictive-load-dict 'dict-html-legend)
  66. (predictive-load-dict 'dict-html-link)
  67. (predictive-load-dict 'dict-html-map)
  68. (predictive-load-dict 'dict-html-meta)
  69. (predictive-load-dict 'dict-html-object)
  70. (predictive-load-dict 'dict-html-optgroup)
  71. (predictive-load-dict 'dict-html-option)
  72. (predictive-load-dict 'dict-html-param)
  73. (predictive-load-dict 'dict-html-script)
  74. (predictive-load-dict 'dict-html-select)
  75. (predictive-load-dict 'dict-html-style)
  76. (predictive-load-dict 'dict-html-table)
  77. (predictive-load-dict 'dict-html-td)
  78. (predictive-load-dict 'dict-html-textarea)
  79. (predictive-load-dict 'dict-html-tr)
  80. ;; add dictionary of html tags to active dictionaries
  81. (make-local-variable 'predictive-main-dict)
  82. (when (atom predictive-main-dict)
  83. (setq predictive-main-dict (list predictive-main-dict)))
  84. (add-to-list 'predictive-main-dict 'dict-html)
  85. ;; setup regexps defining switch-dict regions
  86. (setq predictive-html-regexps
  87. (auto-overlay-init
  88. '(
  89. ;; "<!--" and "-->" delimit comments
  90. (stack
  91. (start "<!--" (dict . predictive-main-dict) (priority . 2)
  92. (face . (background-color . ,predictive-html-debug-color)))
  93. (end "-->" (dict . predictive-main-dict) (priority . 2)))
  94. ;; ;; "<" starts an HTML tag, which ends at the next non-letter
  95. ;; ;; character
  96. ;; (word ("</?\\([[:alnum:]]*?\\)\\([^[:alnum:]]\\|$\\)" . 1)
  97. ;; (dict . dict-html))
  98. ;; "<a" starts an anchor, ended by ">". "<" makes sure all other
  99. ;; ">"s are matched
  100. (stack
  101. (start "<a " (dict . (list dict-html-a dict-html-common))
  102. (priority . 1)
  103. (face . (background-color . ,predictive-html-debug-color)))
  104. (start "<area " (dict . (list dict-html-area dict-html-common))
  105. (priority . 1)
  106. (face . (background-color . ,predictive-html-debug-color)))
  107. (start "<base " (dict . dict-html-base) (priority . 1)
  108. (face . (background-color . ,predictive-html-debug-color)))
  109. (start "<bdo "
  110. (dict . (list dict-html-international dict-html-core))
  111. (priority . 1)
  112. (face . (background-color . ,predictive-html-debug-color)))
  113. (start "<\\(blockquote\\|q\\) "
  114. (dict . (list dict-html-quote dict-html-common))
  115. (priority . 1)
  116. (face . (background-color . ,predictive-html-debug-color)))
  117. (start "<body " (dict . (list dict-html-body dict-html-common))
  118. (priority . 1)
  119. (face . (background-color . ,predictive-html-debug-color)))
  120. (start "<br " (dict . dict-html-core) (priority . 1)
  121. (face . (background-color . ,predictive-html-debug-color)))
  122. (start "<button " (dict . (list dict-html-button dict-html-common))
  123. (priority . 1)
  124. (face . (background-color . ,predictive-html-debug-color)))
  125. (start "<col " (dict . (list dict-html-col dict-html-common))
  126. (priority . 1)
  127. (face . (background-color . ,predictive-html-debug-color)))
  128. (start "<colgroup " (dict . (list dict-html-col dict-html-common))
  129. (priority . 1)
  130. (face . (background-color . ,predictive-html-debug-color)))
  131. (start "<del " (dict . (list dict-html-del dict-html-common))
  132. (priority . 1)
  133. (face . (background-color . ,predictive-html-debug-color)))
  134. (start "<form " (dict . (list dict-html-form dict-html-common))
  135. (priority . 1)
  136. (face . (background-color . ,predictive-html-debug-color)))
  137. (start "<head "
  138. (dict . (list dict-html-head dict-html-international))
  139. (priority . 1)
  140. (face . (background-color . ,predictive-html-debug-color)))
  141. (start "<hr " (dict . (list dict-html-core dict-html-events))
  142. (priority . 1)
  143. (face . (background-color . ,predictive-html-debug-color)))
  144. (start "<html " (dict . dict-html-international) (priority . 1)
  145. (face . (background-color . ,predictive-html-debug-color)))
  146. (start "<img " (dict . (list dict-html-img dict-html-common))
  147. (priority . 1)
  148. (face . (background-color . ,predictive-html-debug-color)))
  149. (start "<input " (dict . (list dict-html-input dict-html-common))
  150. (priority . 1)
  151. (face . (background-color . ,predictive-html-debug-color)))
  152. (start "<ins " (dict . (list dict-html-ins dict-html-common))
  153. (priority . 1)
  154. (face . (background-color . ,predictive-html-debug-color)))
  155. (start "<label " (dict . (list dict-html-label dict-html-common))
  156. (priority . 1)
  157. (face . (background-color . ,predictive-html-debug-color)))
  158. (start "<legend " (dict . (list dict-html-legend dict-html-common))
  159. (priority . 1)
  160. (face . (background-color . ,predictive-html-debug-color)))
  161. (start "<link " (dict . (list dict-html-link dict-html-common))
  162. (priority . 1)
  163. (face . (background-color . ,predictive-html-debug-color)))
  164. (start "<map " (dict . (list dict-html-map dict-html-common))
  165. (priority . 1)
  166. (face . (background-color . ,predictive-html-debug-color)))
  167. (start "<meta "
  168. (dict . (list dict-html-meta dict-html-international))
  169. (priority . 1)
  170. (face . (background-color . ,predictive-html-debug-color)))
  171. (start "<object " (dict . (list dict-html-object dict-html-common))
  172. (priority . 1)
  173. (face . (background-color . ,predictive-html-debug-color)))
  174. (start "<optgroup "
  175. (dict . (list dict-html-optgroup dict-html-common))
  176. (priority . 1)
  177. (face . (background-color . ,predictive-html-debug-color)))
  178. (start "<option " (dict . (list dict-html-option dict-html-common))
  179. (priority . 1)
  180. (face . (background-color . ,predictive-html-debug-color)))
  181. (start "<param " (dict . dict-html-param) (priority . 1)
  182. (face . (background-color . ,predictive-html-debug-color)))
  183. (start "<script " (dict . dict-html-script) (priority . 1)
  184. (face . (background-color . ,predictive-html-debug-color)))
  185. (start "<select " (dict . (list dict-html-select dict-html-common))
  186. (priority . 1)
  187. (face . (background-color . ,predictive-html-debug-color)))
  188. (start "<style "
  189. (dict . (list dict-html-style dict-html-international))
  190. (priority . 1)
  191. (face . (background-color . ,predictive-html-debug-color)))
  192. (start "<table " (dict . (list dict-html-table dict-html-common))
  193. (priority . 1)
  194. (face . (background-color . ,predictive-html-debug-color)))
  195. (start "<t\\(r\\|body\\|head\\|foot\\) "
  196. (list dict-html-tr dict-html-common) (priority . 1)
  197. (face . (background-color . ,predictive-html-debug-color)))
  198. (start "<t[dh] " (dict . (list dict-html-td dict-html-common))
  199. (priority . 1)
  200. (face . (background-color . ,predictive-html-debug-color)))
  201. (start "<textarea "
  202. (dict . (list dict-html-textarea dict-html-common))
  203. (priority . 1)
  204. (face . (background-color . ,predictive-html-debug-color)))
  205. (start "<title " (dict . dict-html-international) (priority . 1)
  206. (face . (background-color . ,predictive-html-debug-color)))
  207. (start "<[[:alnum:]]+? " (dict . dict-html-common) (priority . 1)
  208. (face . (background-color . ,predictive-html-debug-color)))
  209. (end ">" (priority . 1)
  210. (face . (background-color . ,predictive-html-debug-color))))
  211. )))
  212. ;; make "<" and ">" do the right thing
  213. (setq completion-override-syntax-alist
  214. '((?< . (accept . (lambda () (complete "") nil)))
  215. (?> . (accept . nil))))
  216. t ; indicate succesful setup
  217. )
  218. ;;; predictive-html.el ends here