| 1 |
;;; rails-compat.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 'snippet nil t)
|
| 31 |
(require 'completion-ui nil t))
|
| 32 |
|
| 33 |
(when (fboundp 'indent-and-complete)
|
| 34 |
(message "WARNNING: the `indent-and-complete' already defined."))
|
| 35 |
|
| 36 |
(defun indent-and-complete ()
|
| 37 |
"Indent line and Complete if point is at end of left a leave word."
|
| 38 |
(interactive)
|
| 39 |
|
| 40 |
(cond
|
| 41 |
;; snippet
|
| 42 |
((and (boundp 'snippet)
|
| 43 |
snippet)
|
| 44 |
(snippet-next-field))
|
| 45 |
|
| 46 |
;; completion-ui
|
| 47 |
((and (fboundp 'completion-overlay-at-point)
|
| 48 |
(completion-overlay-at-point))
|
| 49 |
(let* ((ov (completion-overlay-at-point))
|
| 50 |
(end (overlay-end ov))
|
| 51 |
;; setup <SPACE> as last command
|
| 52 |
(last-input-event 32)
|
| 53 |
(last-command-event 32))
|
| 54 |
;; skip message output
|
| 55 |
(flet ((message (format-string &rest args) nil))
|
| 56 |
(completion-self-insert))))
|
| 57 |
|
| 58 |
;; hippie-expand
|
| 59 |
((looking-at "\\_>")
|
| 60 |
;; skip message output
|
| 61 |
(flet ((message (format-string &rest args) nil))
|
| 62 |
(hippie-expand nil))))
|
| 63 |
|
| 64 |
;; always indent line
|
| 65 |
(indent-for-tab-command))
|
| 66 |
|
| 67 |
|
| 68 |
(when (fboundp 'try-complete-abbrev)
|
| 69 |
(message "WARRNING: the function `try-complete-abbrev' already defined"))
|
| 70 |
|
| 71 |
(defun try-complete-abbrev (old)
|
| 72 |
(if (abbrev-expansion-point-p)
|
| 73 |
(if (expand-abbrev)
|
| 74 |
t nil)
|
| 75 |
nil))
|
| 76 |
|
| 77 |
(defun abbrev-expansion-point-p ()
|
| 78 |
"returns true if point is a place that might be expanded"
|
| 79 |
(if (memq (get-text-property (- (point) 1) 'face)
|
| 80 |
'(font-lock-string-face font-lock-comment-face font-lock-doc-face))
|
| 81 |
(return nil) ;; we never expand inside of string literals or comments
|
| 82 |
(string-not-empty (syntax-word-before-point))))
|
| 83 |
|
| 84 |
(defun syntax-word-before-point ()
|
| 85 |
"Yields the word immediately preceding point"
|
| 86 |
(buffer-substring-no-properties
|
| 87 |
(+ (point) (save-excursion (skip-syntax-backward "w")))
|
| 88 |
(point)))
|
| 89 |
|
| 90 |
|
| 91 |
(unless (find 'try-complete-abbrev hippie-expand-try-functions-list)
|
| 92 |
(add-to-list 'hippie-expand-try-functions-list 'try-complete-abbrev))
|
| 93 |
(provide 'rails-compat)
|