/vendor/rhtml/rhtml-mode.el

http://github.com/rejeep/emacs · Lisp · 107 lines · 51 code · 19 blank · 37 comment · 1 complexity · ffc3f4475ec56d4148177407b9b1e00b MD5 · raw file

  1. ;;;
  2. ;;; rhtml-mode.el - major mode for editing RHTML files
  3. ;;;
  4. ;; ***** BEGIN LICENSE BLOCK *****
  5. ;; Version: MPL 1.1/GPL 2.0/LGPL 2.1
  6. ;; The contents of this file are subject to the Mozilla Public License Version
  7. ;; 1.1 (the "License"); you may not use this file except in compliance with
  8. ;; the License. You may obtain a copy of the License at
  9. ;; http://www.mozilla.org/MPL/
  10. ;; Software distributed under the License is distributed on an "AS IS" basis,
  11. ;; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. ;; for the specific language governing rights and limitations under the
  13. ;; License.
  14. ;; The Original Code is RHTML-MODE.
  15. ;; The Initial Developer of the Original Code is
  16. ;; Paul Nathan Stickney <pstickne@gmail.com>.
  17. ;; Portions created by the Initial Developer are Copyright (C) 2006
  18. ;; the Initial Developer. All Rights Reserved.
  19. ;; Contributor(s):
  20. ;; Phil Hagelberg
  21. ;; Alternatively, the contents of this file may be used under the terms of
  22. ;; either the GNU General Public License Version 2 or later (the "GPL"), or
  23. ;; the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  24. ;; in which case the provisions of the GPL or the LGPL are applicable instead
  25. ;; of those above. If you wish to allow use of your version of this file only
  26. ;; under the terms of either the GPL or the LGPL, and not to allow others to
  27. ;; use your version of this file under the terms of the MPL, indicate your
  28. ;; decision by deleting the provisions above and replace them with the notice
  29. ;; and other provisions required by the GPL or the LGPL. If you do not delete
  30. ;; the provisions above, a recipient may use your version of this file under
  31. ;; the terms of any one of the MPL, the GPL or the LGPL.
  32. ;; ***** END LICENSE BLOCK *****
  33. (require 'rhtml-fonts) ;; basic fontification
  34. ;; don't require if you don't want it...
  35. (require 'rhtml-sgml-hacks) ;; indent erb with sgml
  36. (define-derived-mode rhtml-mode
  37. html-mode "RHTML"
  38. "Embedded Ruby Mode (RHTML)"
  39. (interactive)
  40. (abbrev-mode)
  41. ;; disable if you don't want it...
  42. (rhtml-activate-fontification))
  43. (add-to-list 'auto-mode-alist '("\\.html\\.erb$" . rhtml-mode))
  44. (define-key ruby-mode-map
  45. "\C-c\C-v" (lambda () (interactive) (toggle-buffer 'rails-view)))
  46. (define-key rhtml-mode-map
  47. "\C-c\C-b" 'rinari-find-by-context)
  48. (defun extract-partial (begin end partial-name)
  49. (interactive "r\nsName your partial: ")
  50. (kill-region begin end)
  51. (find-file (concat "_" partial-name "\\.html\\.erb"))
  52. (yank)
  53. (pop-to-buffer nil)
  54. (insert (concat "<%= render :partial => '" partial-name "' %>\n")))
  55. ;; PST -- uses rhtml-erb-regions which is defined in rhtml-font which
  56. ;; should be moved.
  57. (defun rhtml-dashize (&optional mode)
  58. "Add or remove dashes from the end of ERb blocks. The dash tells ERb to
  59. strip the following newline. This function will NOT add or remove dashes
  60. from blocks that end in a # or #- sequence.
  61. MODE controls how dashes are added or removed. If MODE is `strip' then all
  62. ERb blocks will have the dash removed. If MODE is `add' then all blocks
  63. will have a dash added. If MODE is `auto' or nil then ERb blocks which are
  64. followed by a newline will have a dash added while all other blocks will
  65. have the dash removed."
  66. (interactive "cDashize mode: s) strip, a) add, x) auto (default)")
  67. (let ((real-mode (case mode
  68. ((?s strip) 'strip)
  69. ((?a add) 'add))))
  70. (mapc (lambda (i)
  71. (let ((end (nth 2 i)))
  72. (save-excursion
  73. (goto-char (- end 2))
  74. (case (or real-mode
  75. (if (eq (char-after end) ?\n)
  76. 'add
  77. 'strip))
  78. (strip
  79. (when (and (eq (char-before) ?-)
  80. (not (eq (char-before (1- (point))) ?#)))
  81. (delete-backward-char 1)))
  82. (add
  83. (unless (memq (char-before) '(?# ?-))
  84. (insert "-")))))))
  85. ;; seq.
  86. (rhtml-erb-regions (point-min) (point-max)))))
  87. (require 'rhtml-navigation)
  88. (provide 'rhtml-mode)