| 1 |
;;; predictive-prog-mode.el ---
|
| 2 |
|
| 3 |
;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>
|
| 4 |
|
| 5 |
;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>,
|
| 6 |
|
| 7 |
;; Keywords: ruby rails languages oop
|
| 8 |
;; $URL: svn+ssh://rubyforge/var/svn/emacs-rails/trunk/rails.el $
|
| 9 |
;; $Id: rails.el 149 2007-03-29 15:07:49Z dimaexe $
|
| 10 |
|
| 11 |
;;; License
|
| 12 |
|
| 13 |
;; This program is free software; you can redistribute it and/or
|
| 14 |
;; modify it under the terms of the GNU General Public License
|
| 15 |
;; as published by the Free Software Foundation; either version 2
|
| 16 |
;; of the License, or (at your option) any later version.
|
| 17 |
|
| 18 |
;; This program is distributed in the hope that it will be useful,
|
| 19 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
;; GNU General Public License for more details.
|
| 22 |
|
| 23 |
;; You should have received a copy of the GNU General Public License
|
| 24 |
;; along with this program; if not, write to the Free Software
|
| 25 |
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 26 |
|
| 27 |
;;; Code:
|
| 28 |
|
| 29 |
(eval-when-compile
|
| 30 |
(require 'predictive nil t)
|
| 31 |
(require 'completion-ui nil t))
|
| 32 |
|
| 33 |
(require 'flyspell)
|
| 34 |
|
| 35 |
(defconst predictive-prog-text-faces
|
| 36 |
'(font-lock-comment-face font-lock-doc-face)
|
| 37 |
"Faces corresponding to text in programming-mode buffers.")
|
| 38 |
|
| 39 |
(defvar predictive-prog-mode-main-dict nil)
|
| 40 |
|
| 41 |
(defun activate-predictive-inside-comments (start end len)
|
| 42 |
"Looking at symbol at point and activate the `predictive-mode'
|
| 43 |
if there a string or a comment."
|
| 44 |
(save-excursion
|
| 45 |
(let ((p (get-text-property (- (point) 1) 'face))
|
| 46 |
(f (get-text-property (point) 'face)))
|
| 47 |
(if (or (memq f predictive-prog-text-faces)
|
| 48 |
(memq p predictive-prog-text-faces))
|
| 49 |
(setq predictive-main-dict predictive-prog-mode-main-dict)
|
| 50 |
(setq predictive-main-dict nil)))))
|
| 51 |
|
| 52 |
(defun predictive-prog-mode ()
|
| 53 |
"Enable the `predictive-mode' inside strings and comments
|
| 54 |
only, like `flyspell-prog-mode'."
|
| 55 |
(interactive)
|
| 56 |
(when (fboundp 'predictive-mode)
|
| 57 |
(set (make-local-variable 'predictive-main-dict) nil)
|
| 58 |
(set (make-local-variable 'predictive-prog-mode-main-dict) predictive-main-dict)
|
| 59 |
(if (find 'activate-predictive-inside-comments after-change-functions)
|
| 60 |
(progn
|
| 61 |
(remove-hook 'after-change-functions 'activate-predictive-inside-comments t)
|
| 62 |
(predictive-mode -1))
|
| 63 |
(progn
|
| 64 |
; (set (make-local-variable 'predictive-use-auto-learn-cache) nil)
|
| 65 |
(set (make-local-variable 'predictive-dict-autosave-on-kill-buffer) nil)
|
| 66 |
(predictive-mode 1)
|
| 67 |
(add-hook 'after-change-functions 'activate-predictive-inside-comments nil t)))))
|
| 68 |
|
| 69 |
(provide 'predictive-prog-mode)
|