Skip to content

Commit

Permalink
added: groovy-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ncaq committed Jun 29, 2015
1 parent e34b77c commit 9843d97
Show file tree
Hide file tree
Showing 8 changed files with 1,323 additions and 0 deletions.
167 changes: 167 additions & 0 deletions elpa/groovy-mode-20141209.1133/groovy-electric.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
;;; groovy-electric.el --- Electric mode for Groovy
;; -*-Emacs-Lisp-*-

;; Author: Jim Morris <morris@wolfman.com>
;; Created: 2009-12-11

;; Copyright (C) 2009 Jim Morris

;; This program is free software; you can redistribute it and/or modify it under the terms of the GNU
;; General Public License as published by the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
;; the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
;; License for more details.
;;
;; You should have received a copy of the GNU General Public License along with this program; if not, write
;; to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
;;
;; Based on ruby-electric.el Copyright (C) 2005 by Dee Zsombor <dee dot zsombor at gmail dot com>.
;; Due credit: original work was inspired by a code snippet posted by
;; Frederick Ros at http://rubygarden.org/ruby?EmacsExtensions.

;;; Commentary:
;;
;; By default automatically inserts closing delimiter for {[('"
;; Additionally when in a GString typing a $ will insert { } and place
;; cursor between the braces. All these can be turned on or off
;; individually in the customization window for groovy-electric
;;
;;
;; Usage:
;;
;; 0) copy groovy-electric.el into directory where emacs can find it.
;;
;; 1) modify your startup file (.emacs or whatever) by adding
;; following lines to load and enable the mode when groovy-mode loads
;;
;; (add-hook 'groovy-mode-hook
;; '(lambda ()
;; (require 'groovy-electric)
;; (groovy-electric-mode)))
;;
;; or add this to your init file
;;
;; (require 'groovy-electric)
;;
;; note that you need to have font lock enabled beforehand.
;;
;; 2) toggle Groovy Electric Mode on/off with groovy-electric-mode.

;;; History:

;;; Code:
(require 'groovy-mode)
(defgroup groovy-electric nil
"Minor mode providing electric editing commands for groovy files"
:group 'groovy)

(defvar groovy-electric-matching-delimeter-alist
'((?\[ . ?\])
(?\( . ?\))
(?\' . ?\')
(?\" . ?\")))

(defcustom groovy-electric-expand-delimiters-list '(all)
"*List of contexts where matching delimiter should be inserted.
The word 'all' will do all insertions."
:type '(set :extra-offset 8
(const :tag "Everything" all )
(const :tag "Curly brace" ?\{ )
(const :tag "Square brace" ?\[ )
(const :tag "Round brace" ?\( )
(const :tag "Quote" ?\' )
(const :tag "Double quote" ?\" )
(const :tag "Dollar in GStrings" ?\$ ))
:group 'groovy-electric)

(defcustom groovy-electric-newline-before-closing-bracket nil
"*Controls whether a newline should be inserted before the
closing bracket or not."
:type 'boolean :group 'groovy-electric)

;;;###autoload
(define-minor-mode groovy-electric-mode
"Toggle Groovy Electric minor mode.
With no argument, this command toggles the mode. Non-null prefix
argument turns on the mode. Null prefix argument turns off the
mode.
When Groovy Electric mode is enabled, simple, double and back
quotes as well as braces are paired auto-magically. Expansion
does not occur inside comments and strings. Note that you must
have Font Lock enabled. ${ } is expanded when in a GString"
;; initial value.
nil
;;indicator for the mode line.
" Ge"
;;keymap
groovy-mode-map
(groovy-electric-setup-keymap))

(defun groovy-electric-setup-keymap()
(define-key groovy-mode-map "{" 'groovy-electric-curlies)
(define-key groovy-mode-map "(" 'groovy-electric-matching-char)
(define-key groovy-mode-map "[" 'groovy-electric-matching-char)
(define-key groovy-mode-map "\"" 'groovy-electric-matching-char)
(define-key groovy-mode-map "\'" 'groovy-electric-matching-char)
(define-key groovy-mode-map "\$" 'groovy-electric-pound)
)

(defun groovy-electric-code-at-point-p()
(and groovy-electric-mode
(let* ((properties (text-properties-at (point))))
(and (null (memq 'font-lock-string-face properties))
(null (memq 'font-lock-comment-face properties))))))

(defun groovy-electric-string-at-point-p()
(and groovy-electric-mode
(consp (memq 'font-lock-string-face (text-properties-at (point))))))

;; This checks it is a GString ("...") not normal string '...'
(defun groovy-electric-gstring-at-point-p()
(and groovy-electric-mode
(consp (memq 'font-lock-string-face (text-properties-at (point))))
(save-excursion
(char-equal ?\" (char-after (car (c-literal-limits)))))))

(defun groovy-electric-is-last-command-char-expandable-punct-p()
(or (memq 'all groovy-electric-expand-delimiters-list)
(memq last-command-char groovy-electric-expand-delimiters-list)))

(defun groovy-electric-curlies(arg)
(interactive "P")
(self-insert-command (prefix-numeric-value arg))
(when (and (groovy-electric-is-last-command-char-expandable-punct-p)
(groovy-electric-code-at-point-p))
(insert " ")
(save-excursion
(if groovy-electric-newline-before-closing-bracket
(newline))
(insert "}"))))

(defun groovy-electric-matching-char(arg)
(interactive "P")
(self-insert-command (prefix-numeric-value arg))
(and (groovy-electric-is-last-command-char-expandable-punct-p)
(groovy-electric-code-at-point-p)
(save-excursion
(insert (cdr (assoc last-command-char
groovy-electric-matching-delimeter-alist))))))

(defun groovy-electric-pound(arg)
(interactive "P")
(self-insert-command (prefix-numeric-value arg))
(when (and (groovy-electric-is-last-command-char-expandable-punct-p)
(groovy-electric-gstring-at-point-p)
(not (save-excursion ; make sure it is not escaped
(backward-char 1)
(char-equal ?\\ (preceding-char)))))
(insert "{}")
(backward-char 1)))


(provide 'groovy-electric)

;;; groovy-electric.el ends here
Binary file not shown.
118 changes: 118 additions & 0 deletions elpa/groovy-mode-20141209.1133/groovy-mode-autoloads.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
;;; groovy-mode-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (or (file-name-directory #$) (car load-path)))

;;;### (autoloads nil "groovy-electric" "groovy-electric.el" (21904
;;;;;; 52174 647059 792000))
;;; Generated autoloads from groovy-electric.el

(autoload 'groovy-electric-mode "groovy-electric" "\
Toggle Groovy Electric minor mode.
With no argument, this command toggles the mode. Non-null prefix
argument turns on the mode. Null prefix argument turns off the
mode.
When Groovy Electric mode is enabled, simple, double and back
quotes as well as braces are paired auto-magically. Expansion
does not occur inside comments and strings. Note that you must
have Font Lock enabled. ${ } is expanded when in a GString
\(fn &optional ARG)" t nil)

;;;***

;;;### (autoloads nil "groovy-mode" "groovy-mode.el" (21904 52174
;;;;;; 609059 619000))
;;; Generated autoloads from groovy-mode.el
(add-to-list 'auto-mode-alist '("\\.g\\(?:ant\\|roovy\\|radle\\)\\'" . groovy-mode))

(defvar groovy-mode-hook nil "\
*Hook called by `groovy-mode'.")

(custom-autoload 'groovy-mode-hook "groovy-mode" t)

(autoload 'groovy-mode "groovy-mode" "\
Major mode for editing Groovy code.
The hook `c-mode-common-hook' is run with no args at mode
initialization, then `groovy-mode-hook'.
Key bindings:
\\{groovy-mode-map}
\(fn)" t nil)

;;;***

;;;### (autoloads nil "inf-groovy" "inf-groovy.el" (21904 52174 646059
;;;;;; 787000))
;;; Generated autoloads from inf-groovy.el

(autoload 'inf-groovy-keys "inf-groovy" "\
Set local key defs for inf-groovy in groovy-mode
\(fn)" nil nil)

(autoload 'inferior-groovy-mode "inf-groovy" "\
Major mode for interacting with an inferior groovy (groovysh) process.
The following commands are available:
\\{inferior-groovy-mode-map}
A groovy process can be fired up with M-x run-groovy.
Customisation: Entry to this mode runs the hooks on comint-mode-hook and
inferior-groovy-mode-hook (in that order).
You can send text to the inferior groovy process from other buffers containing
Groovy source.
switch-to-groovy switches the current buffer to the groovy process buffer.
groovy-send-definition sends the current definition to the groovy process.
groovy-send-region sends the current region to the groovy process.
groovy-send-definition-and-go, groovy-send-region-and-go,
switch to the groovy process buffer after sending their text.
For information on running multiple processes in multiple buffers, see
documentation for variable groovy-buffer.
Commands:
Return after the end of the process' output sends the text from the
end of process to point.
Return before the end of the process' output copies the sexp ending at point
to the end of the process' output, and sends it.
Delete converts tabs to spaces as it moves back.
Tab indents for groovy; with argument, shifts rest
of expression rigidly with the current line.
C-M-q does Tab on each line starting within following expression.
Paragraphs are separated only by blank lines. # start comments.
If you accidentally suspend your process, use \\[comint-continue-subjob]
to continue it.
\(fn)" t nil)

(autoload 'run-groovy "inf-groovy" "\
Run an inferior Groovy process, input and output via buffer *groovy*.
If there is a process already running in `*groovy*', switch to that buffer.
With argument, allows you to edit the command line (default is value
of `groovy-program-name'). Runs the hooks `inferior-groovy-mode-hook'
\(after the `comint-mode-hook' is run).
\(Type \\[describe-mode] in the process buffer for a list of commands.)
\(fn CMD)" t nil)

(eval-after-load 'groovy-mode (add-hook 'groovy-mode-hook 'inf-groovy-keys))

;;;***

;;;### (autoloads nil nil ("groovy-mode-pkg.el") (21904 52174 657430
;;;;;; 115000))

;;;***

;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
;;; groovy-mode-autoloads.el ends here
5 changes: 5 additions & 0 deletions elpa/groovy-mode-20141209.1133/groovy-mode-pkg.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(define-package "groovy-mode" "20141209.1133" "Major mode for Groovy source files" 'nil :keywords
'("languages"))
;; Local Variables:
;; no-byte-compile: t
;; End:
Loading

0 comments on commit 9843d97

Please sign in to comment.