public
Description: Tomtt's version of the minor mode for editing RubyOnRails code in Emacs
Homepage: http://rubyforge.org/projects/emacs-rails/
Clone URL: git://github.com/tomtt/emacs-rails.git
emacs-rails / rails-compat.el
100644 94 lines (71 sloc) 3.118 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;;; rails-compat.el ---
 
;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>
 
;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>,
 
;; Keywords: ruby rails languages oop
;; $URL: svn+ssh://rubyforge/var/svn/emacs-rails/trunk/rails.el $
;; $Id: rails.el 149 2007-03-29 15:07:49Z dimaexe $
 
;;; License
 
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 2
;; of the License, or (at your option) any later version.
 
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
 
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
;;; Code:
 
(eval-when-compile
  (require 'snippet nil t)
  (require 'completion-ui nil t))
 
(when (fboundp 'indent-and-complete)
  (message "WARNNING: the `indent-and-complete' already defined."))
 
(defun indent-and-complete ()
  "Indent line and Complete if point is at end of left a leave word."
  (interactive)
 
  (cond
   ;; snippet
   ((and (boundp 'snippet)
         snippet)
    (snippet-next-field))
 
   ;; completion-ui
   ((and (fboundp 'completion-overlay-at-point)
         (completion-overlay-at-point))
    (let* ((ov (completion-overlay-at-point))
           (end (overlay-end ov))
           ;; setup <SPACE> as last command
           (last-input-event 32)
           (last-command-event 32))
      ;; skip message output
      (flet ((message (format-string &rest args) nil))
        (completion-self-insert))))
 
   ;; hippie-expand
   ((looking-at "\\_>")
    ;; skip message output
    (flet ((message (format-string &rest args) nil))
      (hippie-expand nil))))
 
  ;; always indent line
  (indent-for-tab-command))
 
 
(when (fboundp 'try-complete-abbrev)
  (message "WARRNING: the function `try-complete-abbrev' already defined"))
 
(defun try-complete-abbrev (old)
  (if (abbrev-expansion-point-p)
      (if (expand-abbrev)
          t nil)
    nil))
 
(defun abbrev-expansion-point-p ()
  "returns true if point is a place that might be expanded"
  (if (memq (get-text-property (- (point) 1) 'face)
            '(font-lock-string-face font-lock-comment-face font-lock-doc-face))
      (return nil) ;; we never expand inside of string literals or comments
    (string-not-empty (syntax-word-before-point))))
 
(defun syntax-word-before-point ()
  "Yields the word immediately preceding point"
  (buffer-substring-no-properties
   (+ (point) (save-excursion (skip-syntax-backward "w")))
   (point)))
 
 
(unless (find 'try-complete-abbrev hippie-expand-try-functions-list)
  (add-to-list 'hippie-expand-try-functions-list 'try-complete-abbrev))
(provide 'rails-compat)