changeset 111562:97341bc31847

* lisp/progmodes/octave-mod.el: Rely on elecric-*-modes. (octave-mode-map): Don't bind ;, SPC, and LF. (octave-auto-indent, octave-auto-newline): Remove. (electric-layout-rules): Declare. (octave-mode): Set electric-layout-rules. (octave-indent-new-comment-line): Use reindent-then-newline-and-indent. (octave-reindent-then-newline-and-indent, octave-electric-semi) (octave-electric-space): Remove.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 16 Nov 2010 16:19:34 -0500
parents 4949f2873716
children 29fbcfeb8b02
files lisp/ChangeLog lisp/progmodes/octave-mod.el
diffstat 2 files changed, 14 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Nov 16 16:14:46 2010 -0500
+++ b/lisp/ChangeLog	Tue Nov 16 16:19:34 2010 -0500
@@ -1,5 +1,14 @@
 2010-11-16  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* progmodes/octave-mod.el: Rely on elecric-*-modes.
+	(octave-mode-map): Don't bind ;, SPC, and LF.
+	(octave-auto-indent, octave-auto-newline): Remove.
+	(electric-layout-rules): Declare.
+	(octave-mode): Set electric-layout-rules.
+	(octave-indent-new-comment-line): Use reindent-then-newline-and-indent.
+	(octave-reindent-then-newline-and-indent, octave-electric-semi)
+	(octave-electric-space): Remove.
+
 	* electric.el (electric-layout-mode): New minor mode.
 	(electric--after-char-pos): New function.
 	(electric-indent-post-self-insert-function): Use it.
--- a/lisp/progmodes/octave-mod.el	Tue Nov 16 16:14:46 2010 -0500
+++ b/lisp/progmodes/octave-mod.el	Tue Nov 16 16:19:34 2010 -0500
@@ -212,9 +212,6 @@
 (defvar octave-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "`" 'octave-abbrev-start)
-    (define-key map ";" 'octave-electric-semi)
-    (define-key map " " 'octave-electric-space)
-    (define-key map "\n" 'octave-reindent-then-newline-and-indent)
     (define-key map "\e\n" 'octave-indent-new-comment-line)
     (define-key map "\M-\C-q" 'octave-indent-defun)
     (define-key map "\C-c\C-b" 'octave-submit-bug-report)
@@ -319,16 +316,6 @@
     table)
   "Syntax table in use in `octave-mode' buffers.")
 
-(defcustom octave-auto-indent nil
-  "Non-nil means indent line after a semicolon or space in Octave mode."
-  :type 'boolean
-  :group 'octave)
-
-(defcustom octave-auto-newline nil
-  "Non-nil means automatically newline after a semicolon in Octave mode."
-  :type 'boolean
-  :group 'octave)
-
 (defcustom octave-blink-matching-block t
   "Control the blinking of matching Octave block keywords.
 Non-nil means show matching begin of block when inserting a space,
@@ -536,7 +523,7 @@
        ;; (if (smie-parent-p "switch") 4)
        0))))
 
-(defvar electric-indent-chars)
+(defvar electric-layout-rules)
 
 ;;;###autoload
 (define-derived-mode octave-mode prog-mode "Octave"
@@ -567,14 +554,6 @@
 Variables you can use to customize Octave mode
 ==============================================
 
-`octave-auto-indent'
-  Non-nil means indent current line after a semicolon or space.
-  Default is nil.
-
-`octave-auto-newline'
-  Non-nil means auto-insert a newline and indent after a semicolon.
-  Default is nil.
-
 `octave-blink-matching-block'
   Non-nil means show matching begin of block when inserting a space,
   newline or semicolon after an else or end keyword.  Default is t.
@@ -636,6 +615,9 @@
 
   (set (make-local-variable 'electric-indent-chars)
        (cons ?\; electric-indent-chars))
+  ;; IIUC matlab-mode takes the opposite approach: it makes RET insert
+  ;; a ";" at those places where it's correct (i.e. outside of parens).
+  (set (make-local-variable 'electric-layout-rules) '((?\; . after)))
 
   (set (make-local-variable 'comment-start) octave-comment-start)
   (set (make-local-variable 'comment-end) "")
@@ -736,7 +718,7 @@
     (error "Cannot split a code line inside a string"))
    (t
     (insert (concat " " octave-continuation-string))
-    (octave-reindent-then-newline-and-indent))))
+    (reindent-then-newline-and-indent))))
 
 (defun octave-indent-defun ()
   "Properly indent the Octave function which contains point."
@@ -1017,45 +999,6 @@
   (apply 'completion-in-region (octave-completion-at-point-function)))
 
 ;;; Electric characters && friends
-(defun octave-reindent-then-newline-and-indent ()
-  "Reindent current Octave line, insert newline, and indent the new line.
-If Abbrev mode is on, expand abbrevs first."
-  ;; FIXME: None of this is Octave-specific.
-  (interactive)
-  (reindent-then-newline-and-indent))
-
-(defun octave-electric-semi ()
-  "Insert a semicolon in Octave mode.
-Maybe expand abbrevs and blink matching block open keywords.
-Reindent the line if `octave-auto-indent' is non-nil.
-Insert a newline if `octave-auto-newline' is non-nil."
-  (interactive)
-  (setq last-command-event ?\;)
-  (if (not (octave-not-in-string-or-comment-p))
-      (self-insert-command 1)
-    (if octave-auto-indent
-	(indent-according-to-mode))
-    (self-insert-command 1)
-    (if octave-auto-newline
-	(newline-and-indent))))
-
-(defun octave-electric-space ()
-  "Insert a space in Octave mode.
-Maybe expand abbrevs and blink matching block open keywords.
-Reindent the line if `octave-auto-indent' is non-nil."
-  (interactive)
-  (setq last-command-event ? )
-  (if (and octave-auto-indent
-	   (not (octave-not-in-string-or-comment-p)))
-      (progn
-	(indent-according-to-mode)
-	(self-insert-command 1))
-    (if (and octave-auto-indent
-	     (save-excursion
-	       (skip-syntax-backward " ")
-	       (not (bolp))))
-	(indent-according-to-mode))
-    (self-insert-command 1)))
 
 (defun octave-abbrev-start ()
   "Start entering an Octave abbreviation.
@@ -1213,8 +1156,6 @@
     octave-maintainer-address
     (concat "Emacs version " emacs-version)
     (list
-     'octave-auto-indent
-     'octave-auto-newline
      'octave-blink-matching-block
      'octave-block-offset
      'octave-comment-char