public
Description: mmm-free Minor Mode for editing rhtml file in Emacs
Homepage: http://rinari.rubyforge.org
Clone URL: git://github.com/eschulte/rhtml.git
rhtml / rhtml-navigation.el
100644 59 lines (48 sloc) 1.918 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
;; TODO -- need a license boiler-plate
 
;; Handy RHTML functions
;; (C) 2006 Phil Hagelberg
 
;; Ripped from the previous rhtml-mode, sorry about making it break
;; too :( -- pst
 
(defun rhtml-controller-name-from-view ()
  (let* ((dirname (expand-file-name "."))
         (controller-with-module
          (and (string-match "app/views/\\(.*\\)$" dirname)
               (match-string 1 dirname))))
    (concat (rails-root)
            "/app/controllers/"
            controller-with-module
            "_controller.rb")))
 
(defun rhtml-find-action ()
  (interactive)
  (let ((action (file-name-sans-extension (file-name-nondirectory buffer-file-name))))
    (find-file (rhtml-controller-name-from-view))
    (beginning-of-buffer)
    (search-forward-regexp (concat "def *" action))
    (recenter)))
 
(defun rinari-find-by-context ()
 (interactive)
 (mapc (lambda (rule) (let ((pattern (car rule)) (line (current-line)))
                        (if (string-match pattern line) (apply (cdr rule) (match-strings line)))))
       ;; rules (warning; ALL matches will be acted upon, not just first!)
'((":partial +=> +['\":]\\([a-zA-Z_]+\\)['\" ]" . rhtml-find-partial)
(":controller +=> +['\":]\\([a-zA-Z_]+\\)['\" ,]?.*:action +=> +['\":]\\([a-zA-Z_]+\\)['\" ,]?"
           . rinari-find-action)
(":action +=> +['\":]\\([a-zA-Z_]+\\)['\"]?" . rinari-find-action)
          )
        ))
 
(defun rhtml-find-partial (partial)
  (interactive "MPartial: ")
  (find-file (concat "_" partial "\\.html\\.erb")))
 
;; utility functions
 
(defun current-line ()
  (save-excursion
    (beginning-of-line)
    (set-mark-command nil)
    (end-of-line)
    (buffer-substring-no-properties (mark) (point))))
 
(defun match-strings (string &optional n)
  (let* ((n (or n 1))
(this-match (match-string n string)))
    (when this-match
      (append (list this-match) (match-strings string (+ 1 n))))))
 
(provide 'rhtml-navigation)