richleland / emacs

fork of emacs

.emacs.d config files

Clone this repository (size: 245.8 KB): HTTPS / SSH
$ hg clone http://code.richleland.com/emacs

Changed (Δ3.5 KB):

raw changeset »

plugins/textmate-mode.el (126 lines added, 0 lines removed)

Up to file-list plugins/textmate-mode.el:

1
;; TextMate behaviour on Emacs
2
;; Copyright (C) 2008  Orestis Markou
3
4
;; This program is free software; you can redistribute it and/or
5
;; modify it under the terms of the GNU General Public License
6
;; as published by the Free Software Foundation; either version 2
7
;; of the License, or (at your option) any later version.
8
9
;; This program is distributed in the hope that it will be useful,
10
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
;; GNU General Public License for more details.
13
14
;; You should have received a copy of the GNU General Public License
15
;; along with this program; if not, write to the Free Software
16
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
;;
18
;; You can file issues, send comments and get the latest version at:
19
;; http://code.google.com/p/emacs-textmate/
20
;;
21
;; Contributions welcome!
22
;;
23
;;
24
;;
25
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
27
(provide 'textmate-mode)
28
29
(define-minor-mode textmate-mode
30
       "Toggle Textmate mode.
31
     With no argument, this command toggles the mode.
32
     Non-null prefix argument turns on the mode.
33
     Null prefix argument turns off the mode.
34
"     
35
      ;; The initial value.
36
      nil
37
      ;; The indicator for the mode line.
38
      " TM"
39
      ;; The minor mode bindings.
40
      '(
41
	([backspace] . textmate-backspace2)
42
        ("\"" . move-over-dbl-quote)
43
        ("\'" . move-over-quote)
44
        (")" . move-over-bracket)
45
        ("]" . move-over-square)
46
        ("}" . move-over-curly)
47
        ("[" . skeleton-pair-insert-maybe)
48
        ("(" . skeleton-pair-insert-maybe)
49
        ("{" . skeleton-pair-insert-maybe)
50
	;; Duplicate TextMate's auto-indent
51
	([return] . newline-and-indent)
52
	;; Duplicate TextMate's command-return
53
	("\M-\r" . open-next-line)
54
	;; Duplicate TextMate's goto line
55
	("\M-l" . goto-line)
56
        )       
57
      :group 'textmate
58
      (progn
59
        (setq skeleton-pair t))
60
      )
61
62
;;implementation stuff
63
64
;; Function to open and goto indented next line
65
(defun open-next-line()
66
  (interactive)
67
  (move-end-of-line nil)
68
  (newline-and-indent))
69
70
(setq textmate-pairs '( ( ?\( . ?\) )
71
  (  ?\' . ?\' )
72
  (  ?\" . ?\" )
73
  (  ?[ . ?] )
74
  (  ?{ . ?} )
75
  )
76
      )
77
78
(defun is-empty-pair ()
79
  (interactive)
80
  (eq (cdr (assoc (char-before)  textmate-pairs)) (char-after)  )
81
  )
82
83
(defun textmate-backspace2 ()
84
 (interactive)
85
 (if (eq (char-after) nil)
86
  nil   ;; if char-after is nil, just backspace
87
 (if (is-empty-pair)
88
     (delete-char 1)
89
   )
90
 )
91
(delete-backward-char 1)
92
)
93
94
(setq pushovers
95
      '(
96
        (?\" . (lambda () (forward-char 1) ))
97
        (?\' . (lambda () (forward-char 1) ))
98
        (?\) . (lambda () (up-list 1) ))
99
        (?\] . (lambda () (up-list 1) ))
100
        (?\} . (lambda () (up-list 1) ))
101
        ))
102
103
(setq defaults
104
      '(
105
        (?\" . (lambda () (skeleton-pair-insert-maybe nil) ))
106
        (?\' . (lambda () (skeleton-pair-insert-maybe nil) ))
107
        (?\) . (lambda () (insert-char ?\) 1) ))
108
        (?\] . (lambda () (insert-char ?\] 1) ))
109
        (?\} . (lambda () (insert-char ?\} 1) ))
110
        ))
111
112
(defun move-over (char)
113
(if (eq (char-after) char)
114
    (funcall (cdr (assoc char pushovers)))
115
    (funcall (cdr (assoc char defaults)))
116
  )
117
)
118
119
120
(defun move-over-bracket ()  (interactive)(move-over ?\) ))
121
(defun move-over-curly ()  (interactive)(move-over ?\} ))
122
(defun move-over-square ()  (interactive)(move-over ?\] ))
123
(defun move-over-quote ()  (interactive)(move-over ?\' ))
124
(defun move-over-dbl-quote ()  (interactive)(move-over ?\" )) 
125
126