predictive-ess.el 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. (require 'predictive-latex)
  2. (defun predictive-setup-ess (arg)
  3. "With a positive ARG, set up predictive mode for use with ESS files.
  4. With a negative ARG, undo these changes. Called when predictive
  5. mode is enabled via entry in `predictive-major-mode-alist'."
  6. (cond
  7. ;; enabling
  8. ((> arg 0)
  9. ;; R code (?)
  10. (auto-overlay-load-definition
  11. 'predictive
  12. `(nested
  13. :id Rcode
  14. (("\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\\(<<.*?>>=\\)" . 3)
  15. :edge start
  16. (dict . t) (exclusive . t) (priority . 55)
  17. (face . (background-color . ,predictive-overlay-debug-colour)))
  18. (("\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\\(@\\)" . 3)
  19. :edge end
  20. (dict . t) (exclusive . t) (priority . 55)
  21. (face . (background-color . ,predictive-overlay-debug-colour)))))
  22. ;; start R code block (?)
  23. (auto-overlay-load-definition
  24. 'predictive
  25. `(word
  26. :id Rcode-open
  27. (("\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\\(<<.*?>>=\\)" . 3)
  28. (dict . t) (exclusive . t) (priority . 55)
  29. (face . (background-color . ,predictive-overlay-debug-colour)))))
  30. ;; \Sexpr{...}
  31. (auto-overlay-load-definition
  32. 'predictive
  33. `(word
  34. :id Sexpr
  35. (("\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\\(\\\\Sexpr{.*\?}\\)" . 3)
  36. (dict . t) (priority . 45) (exclusive . t)
  37. (face . (background-color . ,predictive-overlay-debug-colour)))))
  38. (predictive-setup-latex arg))
  39. ;; disabling
  40. (t (predictive-setup-latex arg))))
  41. (defun predictive-ess-enable-hook-function ()
  42. "Function to add to `predictive-mode-hook'
  43. to enable predictive ESS support when `predictive-mode' is enabled."
  44. (cond
  45. ;; enable ESS support
  46. ((and (buffer-file-name)
  47. (string= (file-name-extension (buffer-file-name)) "Rnw"))
  48. (predictive-setup-ess 1))
  49. ;; enable LaTeX support
  50. ;; (note: can't use `predictive-major-mode-alist' any more for LaTeX
  51. ;; because ESS dynamically switches the major-more to and from latex-mode)
  52. ((or (eq major-mode 'latex-mode)
  53. (eq major-mode 'LaTeX-mode))
  54. (predictive-setup-latex 1))))
  55. (defun predictive-ess-disable-hook-function ()
  56. "Function to add to `predictive-mode-disable-hook'
  57. to disable predictive ESS support when `predictive-mode' is disabled."
  58. (cond
  59. ;; disable ESS support
  60. ((and (buffer-file-name)
  61. (string= (file-name-extension (buffer-file-name)) "Rnw"))
  62. (predictive-setup-ess -1))
  63. ;; disable LaTeX support
  64. ;; (note: can't use `predictive-major-mode-alist' any more for LaTeX
  65. ;; because ESS dynamically switches the major-mode to and from latex-mode)
  66. ((or (eq major-mode 'latex-mode)
  67. (eq major-mode 'LaTeX-mode))
  68. (predictive-setup-latex -1))))
  69. (add-hook 'predictive-mode-hook
  70. 'predictive-ess-disable-hook-function)
  71. (add-hook 'predictive-mode-disable-hook
  72. 'predictive-ess-enable-hook-function)
  73. ;; remove LaTeX entries from `predictive-major-mode-alist'; we use have to use
  74. ;; hook functions instead because ESS dynamically switches the major-mode to
  75. ;; and from latex-mode.
  76. (setq predictive-major-mode-alist
  77. (assq-delete-all 'LaTeX-mode predictive-major-mode-alist))
  78. (setq predictive-major-mode-alist
  79. (assq-delete-all 'latex-mode predictive-major-mode-alist))