rails-compat.el
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-or-complete) 34 (message "WARNNING: the `indent-or-complete' already defined.")) 35 36 (defun indent-or-complete () 37 "Complete if point is at end of left a leave word, otherwise indent line." 38 (interactive) 39 (cond 40 ;; snippet 41 ((and (boundp 'snippet) 42 snippet) 43 (snippet-next-field)) 44 45 ;; completion-ui 46 ((and (fboundp 'completion-overlay-at-point) 47 (completion-overlay-at-point)) 48 (let* ((ov (completion-overlay-at-point)) 49 (end (overlay-end ov)) 50 ;; setup <SPACE> as last command 51 (last-input-event 32) 52 (last-command-event 32)) 53 ;; skip message output 54 (flet ((message (format-string &rest args) nil)) 55 (completion-self-insert)))) 56 57 ;; hippie-expand 58 ((looking-at "\\_>") 59 ;; skip message output 60 (flet ((message (format-string &rest args) nil)) 61 (hippie-expand nil))) 62 63 ;; run default indent command 64 (t (indent-for-tab-command)))) 65 66 (when (fboundp 'try-complete-abbrev) 67 (message "WARNING: the function `try-complete-abbrev' is already defined")) 68 69 (defun try-complete-abbrev (old) 70 (let ((point-end (point)) 71 (point-start (point)) 72 distance) 73 (save-excursion 74 (while (not (zerop (setq distance (skip-syntax-backward "w")))) 75 (setq point-start (+ point-start distance)))) 76 (when (and (not (= point-start point-end)) 77 (not (memq 78 (get-text-property (- point-end 1) 'face) 79 '(font-lock-string-face font-lock-comment-face font-lock-doc-face)))) 80 (let ((abbr (buffer-substring-no-properties point-start point-end))) 81 (when (and (abbrev-symbol abbr) 82 (expand-abbrev)) 83 t))))) 84 85 (unless (find 'try-complete-abbrev hippie-expand-try-functions-list) 86 (add-to-list 'hippie-expand-try-functions-list 'try-complete-abbrev)) 87 88 (provide 'rails-compat)