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