Skip to content

Commit

Permalink
Several changes to the mode has been made
Browse files Browse the repository at this point in the history
Added new templates for statements and prepared the source for function and documentation templates
Added new scala electric minor mode for having electric braces on request from Hemant Kumar
Added scala electric load to scala-mode-auto.el and its turned off per default


git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala-tool-support/trunk/src/emacs@15791 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
  • Loading branch information
nielsen committed Aug 14, 2008
1 parent 4d695d4 commit 81af86b
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 66 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ELISP_OPTIONS += -f batch-byte-compile
ELISP_FILES += inferior-scala-mode
ELISP_FILES += scala-mode-auto
ELISP_FILES += scala-mode
ELISP_FILES += scala-electric
ELISP_SOURCES += $(ELISP_FILES:%=$(SOURCE_DIR)/%.el)

##############################################################################
Expand All @@ -35,7 +36,7 @@ TOUCH ?= touch
all: .latest-build

clean:
$(RM) *.elc .latest-*
$(RM) *.elc .latest-* autoloads.el

.PHONY: all
.PHONY: clean
Expand All @@ -48,3 +49,6 @@ clean:
@$(TOUCH) $@

##############################################################################

autoloads: $(ELISP_SOURCES)
emacs -batch -q --no-site-file --eval "(setq make-backup-files nil)" --eval "(setq generated-autoload-file (expand-file-name \"autoloads.el\"))" -f batch-update-autoloads `pwd`
1 change: 1 addition & 0 deletions inferior-scala-mode.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
;;; -*-Emacs-Lisp-*-
;;; inferior-scala-mode.el - Interaction with a Scala interpreter.
;;; $Id$

Expand Down
124 changes: 124 additions & 0 deletions scala-electric.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
;;; -*-Emacs-Lisp-*-
;;; scala-electric.el - electric editing commands for scala files
;;; $Id$

;;; Modified by Anders Bach Nielsen <andersbach.nielsen at epfl dot ch> to fit into the scala mode
;;; Copyright (C) 2008 by Hemant Kumar (gethemant at gmail to com)
;;; Based on ruby-electric by Dee Zsombor <dee dot zsombor at gmail dot com>.


;;; Variables

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

;;; Customization

(defgroup scala-electric nil
"Minor mode providing electric editing commands for scala files"
:group 'scala)


(defcustom scala-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 "Back quote" ?\` )
(const :tag "Vertical bar" ?\| ))
:group 'scala-electric)


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

;;; Mode setup

(defvar scala-electric-mode t
"nil disables scala electric mode, non-nil enables.")

(make-variable-buffer-local 'scala-electric-mode)

(defun scala-electric-mode (&optional arg)
""
(interactive "P")
(setq scala-electric-mode
(if (null arg)
;; Toggle mode
(not scala-electric-mode)
;; Enable/Disable according to arg
(> (prefix-numeric-value arg) 0)))
)

(defvar scala-electric-mode-map (make-sparse-keymap)
"Keymap for scala electric minor mode.")

(define-key scala-electric-mode-map "{" 'scala-electric-curlies)
(define-key scala-electric-mode-map "(" 'scala-electric-matching-char)
(define-key scala-electric-mode-map "[" 'scala-electric-matching-char)

;;;###autoload
(or (assoc 'scala-electric-mode minor-mode-alist)
(setq minor-mode-alist
(cons '(scala-electric-mode " electric") minor-mode-alist)))

(or (assoc 'scala-electric-mode minor-mode-map-alist)
(setq minor-mode-map-alist
(cons (cons 'scala-electric-mode scala-electric-mode-map)
minor-mode-map-alist)))

;; Functions

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

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

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

(defun scala-electric-curlies(arg)
(interactive "P")
(self-insert-command (prefix-numeric-value arg))
(if (scala-electric-is-last-command-char-expandable-punct-p)
(cond ((scala-electric-code-at-point-p)
(insert " ")
(save-excursion
(if scala-electric-newline-before-closing-bracket
(newline))
(insert "}")))
((scala-electric-string-at-point-p)
(save-excursion
(backward-char 1)
(when (char-equal ?\# (preceding-char))
(forward-char 1)
(insert "}")))))))

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

(provide 'scala-electric)
4 changes: 4 additions & 0 deletions scala-mode-auto.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
;;; -*-Emacs-Lisp-*-
;;; scala-mode-auto.el - Provides autoload definitions for scala-mode.
;;; $Id$

Expand Down Expand Up @@ -44,4 +45,7 @@ Quit Scala interpreter." t nil)

;;;***

(autoload 'scala-electric-mode "scala-electric" "Minor mode for electric braces in Scala" t)
(add-hook 'scala-mode-hook 'scala-electric-mode)

(provide 'scala-mode-auto)
Loading

0 comments on commit 81af86b

Please sign in to comment.