aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2010-11-16 16:19:34 -0500
committerStefan Monnier2010-11-16 16:19:34 -0500
commit03f70355d8105f3dd87c07089d78950319a5f2f6 (patch)
tree44fd98c2df35a17b294ac1bebf9117024ec9d869
parent7100ff98443a6d433bbce9de8771983eb13f03c0 (diff)
downloademacs-03f70355d8105f3dd87c07089d78950319a5f2f6.tar.gz
emacs-03f70355d8105f3dd87c07089d78950319a5f2f6.zip
* 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.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/progmodes/octave-mod.el69
2 files changed, 14 insertions, 64 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b5be8544e5a..05b5c1cebd1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,14 @@
12010-11-16 Stefan Monnier <monnier@iro.umontreal.ca> 12010-11-16 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * progmodes/octave-mod.el: Rely on elecric-*-modes.
4 (octave-mode-map): Don't bind ;, SPC, and LF.
5 (octave-auto-indent, octave-auto-newline): Remove.
6 (electric-layout-rules): Declare.
7 (octave-mode): Set electric-layout-rules.
8 (octave-indent-new-comment-line): Use reindent-then-newline-and-indent.
9 (octave-reindent-then-newline-and-indent, octave-electric-semi)
10 (octave-electric-space): Remove.
11
3 * electric.el (electric-layout-mode): New minor mode. 12 * electric.el (electric-layout-mode): New minor mode.
4 (electric--after-char-pos): New function. 13 (electric--after-char-pos): New function.
5 (electric-indent-post-self-insert-function): Use it. 14 (electric-indent-post-self-insert-function): Use it.
diff --git a/lisp/progmodes/octave-mod.el b/lisp/progmodes/octave-mod.el
index 8551e09e058..cd2957f6180 100644
--- a/lisp/progmodes/octave-mod.el
+++ b/lisp/progmodes/octave-mod.el
@@ -212,9 +212,6 @@ parenthetical grouping.")
212(defvar octave-mode-map 212(defvar octave-mode-map
213 (let ((map (make-sparse-keymap))) 213 (let ((map (make-sparse-keymap)))
214 (define-key map "`" 'octave-abbrev-start) 214 (define-key map "`" 'octave-abbrev-start)
215 (define-key map ";" 'octave-electric-semi)
216 (define-key map " " 'octave-electric-space)
217 (define-key map "\n" 'octave-reindent-then-newline-and-indent)
218 (define-key map "\e\n" 'octave-indent-new-comment-line) 215 (define-key map "\e\n" 'octave-indent-new-comment-line)
219 (define-key map "\M-\C-q" 'octave-indent-defun) 216 (define-key map "\M-\C-q" 'octave-indent-defun)
220 (define-key map "\C-c\C-b" 'octave-submit-bug-report) 217 (define-key map "\C-c\C-b" 'octave-submit-bug-report)
@@ -319,16 +316,6 @@ parenthetical grouping.")
319 table) 316 table)
320 "Syntax table in use in `octave-mode' buffers.") 317 "Syntax table in use in `octave-mode' buffers.")
321 318
322(defcustom octave-auto-indent nil
323 "Non-nil means indent line after a semicolon or space in Octave mode."
324 :type 'boolean
325 :group 'octave)
326
327(defcustom octave-auto-newline nil
328 "Non-nil means automatically newline after a semicolon in Octave mode."
329 :type 'boolean
330 :group 'octave)
331
332(defcustom octave-blink-matching-block t 319(defcustom octave-blink-matching-block t
333 "Control the blinking of matching Octave block keywords. 320 "Control the blinking of matching Octave block keywords.
334Non-nil means show matching begin of block when inserting a space, 321Non-nil means show matching begin of block when inserting a space,
@@ -536,7 +523,7 @@ Non-nil means always go to the next Octave code line after sending."
536 ;; (if (smie-parent-p "switch") 4) 523 ;; (if (smie-parent-p "switch") 4)
537 0)))) 524 0))))
538 525
539(defvar electric-indent-chars) 526(defvar electric-layout-rules)
540 527
541;;;###autoload 528;;;###autoload
542(define-derived-mode octave-mode prog-mode "Octave" 529(define-derived-mode octave-mode prog-mode "Octave"
@@ -567,14 +554,6 @@ Keybindings
567Variables you can use to customize Octave mode 554Variables you can use to customize Octave mode
568============================================== 555==============================================
569 556
570`octave-auto-indent'
571 Non-nil means indent current line after a semicolon or space.
572 Default is nil.
573
574`octave-auto-newline'
575 Non-nil means auto-insert a newline and indent after a semicolon.
576 Default is nil.
577
578`octave-blink-matching-block' 557`octave-blink-matching-block'
579 Non-nil means show matching begin of block when inserting a space, 558 Non-nil means show matching begin of block when inserting a space,
580 newline or semicolon after an else or end keyword. Default is t. 559 newline or semicolon after an else or end keyword. Default is t.
@@ -636,6 +615,9 @@ including a reproducible test case and send the message."
636 615
637 (set (make-local-variable 'electric-indent-chars) 616 (set (make-local-variable 'electric-indent-chars)
638 (cons ?\; electric-indent-chars)) 617 (cons ?\; electric-indent-chars))
618 ;; IIUC matlab-mode takes the opposite approach: it makes RET insert
619 ;; a ";" at those places where it's correct (i.e. outside of parens).
620 (set (make-local-variable 'electric-layout-rules) '((?\; . after)))
639 621
640 (set (make-local-variable 'comment-start) octave-comment-start) 622 (set (make-local-variable 'comment-start) octave-comment-start)
641 (set (make-local-variable 'comment-end) "") 623 (set (make-local-variable 'comment-end) "")
@@ -736,7 +718,7 @@ The new line is properly indented."
736 (error "Cannot split a code line inside a string")) 718 (error "Cannot split a code line inside a string"))
737 (t 719 (t
738 (insert (concat " " octave-continuation-string)) 720 (insert (concat " " octave-continuation-string))
739 (octave-reindent-then-newline-and-indent)))) 721 (reindent-then-newline-and-indent))))
740 722
741(defun octave-indent-defun () 723(defun octave-indent-defun ()
742 "Properly indent the Octave function which contains point." 724 "Properly indent the Octave function which contains point."
@@ -1017,45 +999,6 @@ variables."
1017 (apply 'completion-in-region (octave-completion-at-point-function))) 999 (apply 'completion-in-region (octave-completion-at-point-function)))
1018 1000
1019;;; Electric characters && friends 1001;;; Electric characters && friends
1020(defun octave-reindent-then-newline-and-indent ()
1021 "Reindent current Octave line, insert newline, and indent the new line.
1022If Abbrev mode is on, expand abbrevs first."
1023 ;; FIXME: None of this is Octave-specific.
1024 (interactive)
1025 (reindent-then-newline-and-indent))
1026
1027(defun octave-electric-semi ()
1028 "Insert a semicolon in Octave mode.
1029Maybe expand abbrevs and blink matching block open keywords.
1030Reindent the line if `octave-auto-indent' is non-nil.
1031Insert a newline if `octave-auto-newline' is non-nil."
1032 (interactive)
1033 (setq last-command-event ?\;)
1034 (if (not (octave-not-in-string-or-comment-p))
1035 (self-insert-command 1)
1036 (if octave-auto-indent
1037 (indent-according-to-mode))
1038 (self-insert-command 1)
1039 (if octave-auto-newline
1040 (newline-and-indent))))
1041
1042(defun octave-electric-space ()
1043 "Insert a space in Octave mode.
1044Maybe expand abbrevs and blink matching block open keywords.
1045Reindent the line if `octave-auto-indent' is non-nil."
1046 (interactive)
1047 (setq last-command-event ? )
1048 (if (and octave-auto-indent
1049 (not (octave-not-in-string-or-comment-p)))
1050 (progn
1051 (indent-according-to-mode)
1052 (self-insert-command 1))
1053 (if (and octave-auto-indent
1054 (save-excursion
1055 (skip-syntax-backward " ")
1056 (not (bolp))))
1057 (indent-according-to-mode))
1058 (self-insert-command 1)))
1059 1002
1060(defun octave-abbrev-start () 1003(defun octave-abbrev-start ()
1061 "Start entering an Octave abbreviation. 1004 "Start entering an Octave abbreviation.
@@ -1213,8 +1156,6 @@ code line."
1213 octave-maintainer-address 1156 octave-maintainer-address
1214 (concat "Emacs version " emacs-version) 1157 (concat "Emacs version " emacs-version)
1215 (list 1158 (list
1216 'octave-auto-indent
1217 'octave-auto-newline
1218 'octave-blink-matching-block 1159 'octave-blink-matching-block
1219 'octave-block-offset 1160 'octave-block-offset
1220 'octave-comment-char 1161 'octave-comment-char