predictive-latex-color.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ;;; predictive-latex-color.el --- predictive mode LaTeX color package support
  2. ;; Copyright (C) 2008, 2013 Toby Cubitt
  3. ;; Author: Toby Cubitt <toby-predictive@dr-qubit.org>
  4. ;; Version: 0.2.1
  5. ;; Keywords: predictive, latex, package, color
  6. ;; URL: http://www.dr-qubit.org/emacs.php
  7. ;; This file is NOT part of Emacs.
  8. ;;
  9. ;; This file is free software: you can redistribute it and/or modify it under
  10. ;; the terms of the GNU General Public License as published by the Free
  11. ;; Software Foundation, either version 3 of the License, or (at your option)
  12. ;; any later version.
  13. ;;
  14. ;; This program is distributed in the hope that it will be useful, but WITHOUT
  15. ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. ;; more details.
  18. ;;
  19. ;; You should have received a copy of the GNU General Public License along
  20. ;; with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;; Code:
  22. (require 'predictive-latex)
  23. ;; register package setup function
  24. (predictive-assoc-delete-all "color" predictive-latex-usepackage-functions)
  25. (push '("color" . predictive-latex-setup-color)
  26. predictive-latex-usepackage-functions)
  27. ;; define LaTeX colour completion source
  28. (completion-ui-register-source
  29. predictive-complete
  30. :name predictive-latex-color
  31. :completion-args 2
  32. :other-args (dict-latex-colours)
  33. :accept-functions (lambda (prefix completion &optional arg)
  34. (run-hook-with-args 'predictive-accept-functions
  35. prefix completion arg))
  36. :reject-functions (lambda (prefix completion &optional arg)
  37. (run-hook-with-args 'predictive-reject-functions
  38. prefix completion arg))
  39. :syntax-alist ((?w . (predictive-latex-smart-within-braces-resolve-behaviour
  40. predictive-latex-word-completion-behaviour)))
  41. :override-syntax-alist
  42. ((?} . (predictive-latex-punctuation-resolve-behaviour none)))
  43. :word-thing predictive-latex-word
  44. :menu predictive-latex-construct-browser-menu
  45. :browser predictive-latex-construct-browser-function
  46. :no-auto-completion t
  47. :no-command t
  48. :no-predictive t)
  49. (defun predictive-latex-setup-color (arg)
  50. ;; With positive ARG, load cleveref package support. With negative ARG,
  51. ;; unload it.
  52. (cond
  53. ;; --- load color support ---
  54. ((> arg 0)
  55. ;; load colour dictionary
  56. (predictive-load-dict 'dict-latex-colours)
  57. ;; add new browser sub-menu definition
  58. (nconc predictive-latex-browser-submenu-alist
  59. (list (cons "\\\\\\(text\\|page\\|\\)color" 'dict-latex-colours)))
  60. ;; add completion source regexps
  61. (nconc
  62. auto-completion-source-regexps
  63. ;; color commands
  64. (list
  65. `(,(concat predictive-latex-odd-backslash-regexp
  66. "\\(?:\\|text\\|page\\)color\\(?:\\[.*?\\]\\)?"
  67. predictive-latex-brace-group-regexp)
  68. predictive-latex-color looking-at 1))))
  69. ;; --- unload color support ---
  70. ((< arg 0)
  71. ;; remove browser sub-menu definition
  72. (setq predictive-latex-browser-submenu-alist
  73. (predictive-assoc-delete-all
  74. "\\\\\\(text\\|page\\|\\)color"
  75. predictive-latex-browser-submenu-alist))
  76. ;; remove auto-completion source regexps
  77. (setq auto-completion-source-regexps
  78. (predictive-assoc-delete-all
  79. (concat predictive-latex-odd-backslash-regexp
  80. "\\(?:\\|text\\|page\\)color\\(?:\\[.*?\\]\\)?"
  81. predictive-latex-brace-group-regexp)
  82. auto-completion-source-regexps))
  83. ;; unload colour dictionary
  84. (predictive-unload-dict 'dict-latex-colours))
  85. ))
  86. (provide 'predictive-latex-color)
  87. ;;; predictive-latex-color ends here