Permalink
Browse files

rails-compat.el: apply patch #12743, replace

	`indent-or-complete` to `indent-and-complete` (thanks Peter Williams)


git-svn-id: svn+ssh://rubyforge.org/var/svn/emacs-rails/trunk@202 cc5033d0-740f-0410-afc7-949910e492f2
  • Loading branch information...
1 parent 8f16848 commit 80c3b474fb408e2d9685f6f8645813ff73b57d49 dimaexe committed Aug 4, 2007
Showing with 35 additions and 24 deletions.
  1. +5 −0 ChangeLog
  2. +28 −22 rails-compat.el
  3. +2 −2 rails.el
View
@@ -1,3 +1,8 @@
+2007-08-05 Dmitry Galinsky <dima.exe@gmail.com>
+
+ * rails-compat.el: apply patch #12743, replace
+ `indent-or-complete` to `indent-and-complete` (thanks Peter Williams)
+
2007-08-04 Dmitry Galinsky <dima.exe@gmail.com>
* rails-navigation.el (rails-nav:goto-layouts): fixed bug #12754,
View
@@ -30,12 +30,13 @@
(require 'snippet nil t)
(require 'completion-ui nil t))
-(when (fboundp 'indent-or-complete)
- (message "WARNNING: the `indent-or-complete' already defined."))
+(when (fboundp 'indent-and-complete)
+ (message "WARNNING: the `indent-and-complete' already defined."))
-(defun indent-or-complete ()
- "Complete if point is at end of left a leave word, otherwise indent line."
+(defun indent-and-complete ()
+ "Indent line and Complete if point is at end of left a leave word."
(interactive)
+
(cond
;; snippet
((and (boundp 'snippet)
@@ -58,31 +59,36 @@
((looking-at "\\_>")
;; skip message output
(flet ((message (format-string &rest args) nil))
- (hippie-expand nil)))
+ (hippie-expand nil))))
+
+ ;; always indent line
+ (indent-for-tab-command))
- ;; run default indent command
- (t (indent-for-tab-command))))
(when (fboundp 'try-complete-abbrev)
(message "WARRNING: the function `try-complete-abbrev' already defined"))
(defun try-complete-abbrev (old)
- (let ((point-end (point))
- (point-start (point))
- distance)
- (save-excursion
- (while (not (zerop (setq distance (skip-syntax-backward "w"))))
- (setq point-start (+ point-start distance))))
- (when (and (not (= point-start point-end))
- (not (memq
- (get-text-property (- point-end 1) 'face)
- '(font-lock-string-face font-lock-comment-face font-lock-doc-face))))
- (let ((abbr (buffer-substring-no-properties point-start point-end)))
- (when (and (abbrev-symbol abbr)
- (expand-abbrev))
- t)))))
+ (if (abbrev-expansion-point-p)
+ (progn
+ (expand-abbrev)
+ t)
+ 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)
View
@@ -402,7 +402,7 @@ necessary."
(local-set-key (kbd "C-.") 'complete-tag)
(local-set-key (if rails-use-another-define-key
(kbd "TAB") (kbd "<tab>"))
- 'indent-or-complete)
+ 'indent-and-complete)
(local-set-key (rails-key "f") '(lambda()
(interactive)
(mouse-major-mode-menu (rails-core:menu-position))))
@@ -422,7 +422,7 @@ necessary."
(progn
(local-set-key (if rails-use-another-define-key
(kbd "TAB") (kbd "<tab>"))
- 'indent-or-complete)
+ 'indent-and-complete)
(rails-minor-mode t)
(rails-apply-for-buffer-type)))))

0 comments on commit 80c3b47

Please sign in to comment.