diff options
| author | Karl Heuer | 1997-10-24 20:11:44 +0000 |
|---|---|---|
| committer | Karl Heuer | 1997-10-24 20:11:44 +0000 |
| commit | d83ee5785220c1d3425c64a57f07c4686d97d1bf (patch) | |
| tree | c967ba0bb2ef8cbb7acec769108cfc3025b251a6 | |
| parent | 8bcee03ecf51ab4b88f00c6252b97833594ab3af (diff) | |
| download | emacs-d83ee5785220c1d3425c64a57f07c4686d97d1bf.tar.gz emacs-d83ee5785220c1d3425c64a57f07c4686d97d1bf.zip | |
(octave-auto-indent): New variable.
(octave-electric-semi, octave-electric-space): Use it.
(octave-before-magic-comment-p): New func.
(calculate-octave-indent, octave-comment-indent): Use it.
(octave-auto-indent): New variable.
(octave-electric-semi, octave-electric-space): Use it.
(octave-maybe-insert-continuation-string):
New function.
(octave-auto-fill): No longer calls do-auto-fill. Should now
avoid breaking lines after comment starts or before code line
continuation expressions.
(octave-fill-paragraph): Move forward a line if octave-auto-fill
gave up.
(octave-before-magic-comment-p): New func.
(octave-comment-indent): Handle magic comments correctly.
(calculate-octave-indent): Handle magic comments correctly.
(octave-abbrev-table): Added abbrevs for
switch, case, otherwise, and endswitch.
(octave-begin-keywords): Added switch.
(octave-else-keywords): Added case and otherwise.
(octave-end-keywords): Added endswitch.
(octave-block-match-alist): Added an entry for switch syntax.
(calculate-octave-indent): Added support for switch syntax.
(octave-block-end-offset): New function.
(octave-comment-indent): Fix a typo.
(octave-block-match-alist): Move
`otherwise' to right after `case' to have octave-close-block()
correctly close a `switch' block by `endswitch'.
| -rw-r--r-- | lisp/progmodes/octave-mod.el | 127 |
1 files changed, 102 insertions, 25 deletions
diff --git a/lisp/progmodes/octave-mod.el b/lisp/progmodes/octave-mod.el index f628a8896c3..8f5ff1d18be 100644 --- a/lisp/progmodes/octave-mod.el +++ b/lisp/progmodes/octave-mod.el | |||
| @@ -299,8 +299,11 @@ parenthetical grouping.") | |||
| 299 | (modify-syntax-entry ?\n ">" table) | 299 | (modify-syntax-entry ?\n ">" table) |
| 300 | (setq octave-mode-syntax-table table))) | 300 | (setq octave-mode-syntax-table table))) |
| 301 | 301 | ||
| 302 | (defvar octave-auto-indent nil | ||
| 303 | "*Non-nil means indent line after a semicolon or space in Octave mode.") | ||
| 304 | |||
| 302 | (defvar octave-auto-newline nil | 305 | (defvar octave-auto-newline nil |
| 303 | "*Non-nil means automatically newline after a semicolon in Octave mode.") | 306 | "*Non-nil means insert newline after a semicolon in Octave mode.") |
| 304 | 307 | ||
| 305 | (defvar octave-blink-matching-block t | 308 | (defvar octave-blink-matching-block t |
| 306 | "*Control the blinking of matching Octave block keywords. | 309 | "*Control the blinking of matching Octave block keywords. |
| @@ -329,7 +332,7 @@ newline or semicolon after an else or end keyword.") | |||
| 329 | '(("for" . ("end" "endfor")) | 332 | '(("for" . ("end" "endfor")) |
| 330 | ("function" . ("end" "endfunction")) | 333 | ("function" . ("end" "endfunction")) |
| 331 | ("if" . ("else" "elseif" "end" "endif")) | 334 | ("if" . ("else" "elseif" "end" "endif")) |
| 332 | ("switch" . ("case" "end" "endswitch" "otherwise")) | 335 | ("switch" . ("case" "otherwise" "end" "endswitch")) |
| 333 | ("try" . ("catch" "end" "end_try_catch")) | 336 | ("try" . ("catch" "end" "end_try_catch")) |
| 334 | ("unwind_protect" . ("unwind_protect_cleanup" "end" | 337 | ("unwind_protect" . ("unwind_protect_cleanup" "end" |
| 335 | "end_unwind_protect")) | 338 | "end_unwind_protect")) |
| @@ -405,6 +408,10 @@ Keybindings | |||
| 405 | Variables you can use to customize Octave mode | 408 | Variables you can use to customize Octave mode |
| 406 | ============================================== | 409 | ============================================== |
| 407 | 410 | ||
| 411 | octave-auto-indent | ||
| 412 | Non-nil means indent current line after a semicolon or space. | ||
| 413 | Default is nil. | ||
| 414 | |||
| 408 | octave-auto-newline | 415 | octave-auto-newline |
| 409 | Non-nil means auto-insert a newline and indent after a semicolon. | 416 | Non-nil means auto-insert a newline and indent after a semicolon. |
| 410 | Default is nil. | 417 | Default is nil. |
| @@ -580,6 +587,15 @@ the end keyword." | |||
| 580 | (error nil)) | 587 | (error nil)) |
| 581 | (< pos (point))))))) | 588 | (< pos (point))))))) |
| 582 | 589 | ||
| 590 | (defun octave-maybe-insert-continuation-string () | ||
| 591 | (if (or (octave-in-comment-p) | ||
| 592 | (save-excursion | ||
| 593 | (beginning-of-line) | ||
| 594 | (looking-at octave-continuation-regexp))) | ||
| 595 | nil | ||
| 596 | (delete-horizontal-space) | ||
| 597 | (insert (concat " " octave-continuation-string)))) | ||
| 598 | |||
| 583 | ;;; Comments | 599 | ;;; Comments |
| 584 | (defun octave-comment-region (beg end &optional arg) | 600 | (defun octave-comment-region (beg end &optional arg) |
| 585 | "Comment or uncomment each line in the region as Octave code. | 601 | "Comment or uncomment each line in the region as Octave code. |
| @@ -652,7 +668,8 @@ level." | |||
| 652 | ((and (looking-at octave-block-end-regexp) | 668 | ((and (looking-at octave-block-end-regexp) |
| 653 | (octave-not-in-string-or-comment-p)) | 669 | (octave-not-in-string-or-comment-p)) |
| 654 | (setq icol (- icol (octave-block-end-offset)))) | 670 | (setq icol (- icol (octave-block-end-offset)))) |
| 655 | ((looking-at "\\s<\\s<\\s<\\S<") | 671 | ((or (looking-at "\\s<\\s<\\s<\\S<") |
| 672 | (octave-before-magic-comment-p)) | ||
| 656 | (setq icol (list 0 icol))) | 673 | (setq icol (list 0 icol))) |
| 657 | ((looking-at "\\s<\\S<") | 674 | ((looking-at "\\s<\\S<") |
| 658 | (setq icol (list comment-column icol))))) | 675 | (setq icol (list comment-column icol))))) |
| @@ -664,8 +681,14 @@ level." | |||
| 664 | (* octave-block-offset | 681 | (* octave-block-offset |
| 665 | (if (string-match (match-string 0) "switch") 2 1)))) | 682 | (if (string-match (match-string 0) "switch") 2 1)))) |
| 666 | 683 | ||
| 684 | (defun octave-before-magic-comment-p () | ||
| 685 | (save-excursion | ||
| 686 | (beginning-of-line) | ||
| 687 | (and (bobp) (looking-at "\\s-*#!")))) | ||
| 688 | |||
| 667 | (defun octave-comment-indent () | 689 | (defun octave-comment-indent () |
| 668 | (if (looking-at "\\s<\\s<\\s<") | 690 | (if (or (looking-at "\\s<\\s<\\s<") |
| 691 | (octave-before-magic-comment-p)) | ||
| 669 | 0 | 692 | 0 |
| 670 | (if (looking-at "\\s<\\s<") | 693 | (if (looking-at "\\s<\\s<") |
| 671 | (calculate-octave-indent) | 694 | (calculate-octave-indent) |
| @@ -1031,19 +1054,65 @@ The function marked is the one containing point or following point." | |||
| 1031 | 1054 | ||
| 1032 | ;;; Filling | 1055 | ;;; Filling |
| 1033 | (defun octave-auto-fill () | 1056 | (defun octave-auto-fill () |
| 1034 | "Perform auto-fill in Octave mode." | 1057 | "Perform auto-fill in Octave mode. |
| 1035 | (if (> (current-column) (current-fill-column)) | 1058 | Returns nil if no feasible place to break the line could be found, and t |
| 1036 | (if (octave-in-comment-p) | 1059 | otherwise." |
| 1037 | (do-auto-fill) | 1060 | (let (fc give-up) |
| 1038 | (if (> (current-column) (current-fill-column)) | 1061 | (if (or (null (setq fc (current-fill-column))) |
| 1039 | (let ((fill-column (- (current-fill-column) | 1062 | (save-excursion |
| 1040 | (length octave-continuation-string)))) | 1063 | (beginning-of-line) |
| 1041 | (do-auto-fill) | 1064 | (and auto-fill-inhibit-regexp |
| 1042 | (save-excursion | 1065 | (looking-at auto-fill-inhibit-regexp)))) |
| 1043 | (forward-line -1) | 1066 | nil ; Can't do anything |
| 1044 | (end-of-line) | 1067 | (if (and (not (octave-in-comment-p)) |
| 1045 | (insert (concat " " octave-continuation-string))) | 1068 | (> (current-column) fc)) |
| 1046 | (indent-according-to-mode)))))) | 1069 | (setq fc (- fc (+ (length octave-continuation-string) 1)))) |
| 1070 | (while (and (not give-up) (> (current-column) fc)) | ||
| 1071 | (let* ((opoint (point)) | ||
| 1072 | (fpoint | ||
| 1073 | (save-excursion | ||
| 1074 | (move-to-column (+ fc 1)) | ||
| 1075 | (skip-chars-backward "^ \t\n") | ||
| 1076 | ;; If we're at the beginning of the line, break after | ||
| 1077 | ;; the first word | ||
| 1078 | (if (bolp) | ||
| 1079 | (re-search-forward "[ \t]" opoint t)) | ||
| 1080 | ;; If we're in a comment line, don't break after the | ||
| 1081 | ;; comment chars | ||
| 1082 | (if (save-excursion | ||
| 1083 | (skip-syntax-backward " <") | ||
| 1084 | (bolp)) | ||
| 1085 | (re-search-forward "[ \t]" (octave-point 'eol) | ||
| 1086 | 'move)) | ||
| 1087 | ;; If we're not in a comment line and just ahead the | ||
| 1088 | ;; continuation string, don't break here. | ||
| 1089 | (if (and (not (octave-in-comment-p)) | ||
| 1090 | (looking-at | ||
| 1091 | (concat "\\s-*" | ||
| 1092 | (regexp-quote | ||
| 1093 | octave-continuation-string) | ||
| 1094 | "\\s-*$"))) | ||
| 1095 | (end-of-line)) | ||
| 1096 | (skip-chars-backward " \t") | ||
| 1097 | (point)))) | ||
| 1098 | (if (save-excursion | ||
| 1099 | (goto-char fpoint) | ||
| 1100 | (not (or (bolp) (eolp)))) | ||
| 1101 | (let ((prev-column (current-column))) | ||
| 1102 | (if (save-excursion | ||
| 1103 | (skip-chars-backward " \t") | ||
| 1104 | (= (point) fpoint)) | ||
| 1105 | (progn | ||
| 1106 | (octave-maybe-insert-continuation-string) | ||
| 1107 | (indent-new-comment-line t)) | ||
| 1108 | (save-excursion | ||
| 1109 | (goto-char fpoint) | ||
| 1110 | (octave-maybe-insert-continuation-string) | ||
| 1111 | (indent-new-comment-line t))) | ||
| 1112 | (if (>= (current-column) prev-column) | ||
| 1113 | (setq give-up t))) | ||
| 1114 | (setq give-up t)))) | ||
| 1115 | (not give-up)))) | ||
| 1047 | 1116 | ||
| 1048 | (defun octave-fill-paragraph (&optional arg) | 1117 | (defun octave-fill-paragraph (&optional arg) |
| 1049 | "Fill paragraph of Octave code, handling Octave comments." | 1118 | "Fill paragraph of Octave code, handling Octave comments." |
| @@ -1108,13 +1177,16 @@ The function marked is the one containing point or following point." | |||
| 1108 | (delete-region (match-beginning 0) (match-end 0)) | 1177 | (delete-region (match-beginning 0) (match-end 0)) |
| 1109 | (fixup-whitespace) | 1178 | (fixup-whitespace) |
| 1110 | (move-to-column cfc)))) | 1179 | (move-to-column cfc)))) |
| 1180 | ;; We might also try to combine continued code lines> Perhaps | ||
| 1181 | ;; some other time ... | ||
| 1111 | (skip-chars-forward "^ \t\n") | 1182 | (skip-chars-forward "^ \t\n") |
| 1112 | (delete-horizontal-space) | 1183 | (delete-horizontal-space) |
| 1113 | (if (or (< (current-column) cfc) | 1184 | (if (or (< (current-column) cfc) |
| 1114 | (and (= (current-column) cfc) (eolp))) | 1185 | (and (= (current-column) cfc) (eolp))) |
| 1115 | (forward-line 1) | 1186 | (forward-line 1) |
| 1116 | (if (not (eolp)) (insert " ")) | 1187 | (if (not (eolp)) (insert " ")) |
| 1117 | (octave-auto-fill)))) | 1188 | (or (octave-auto-fill) |
| 1189 | (forward-line 1))))) | ||
| 1118 | t))) | 1190 | t))) |
| 1119 | 1191 | ||
| 1120 | 1192 | ||
| @@ -1189,22 +1261,25 @@ If Abbrev mode is on, expand abbrevs first." | |||
| 1189 | 1261 | ||
| 1190 | (defun octave-electric-semi () | 1262 | (defun octave-electric-semi () |
| 1191 | "Insert a semicolon in Octave mode. | 1263 | "Insert a semicolon in Octave mode. |
| 1192 | Always reindent the line. Insert a newline if `octave-auto-newline' is | 1264 | Maybe expand abbrevs and blink matching block open keywords. |
| 1193 | non-nil." | 1265 | Reindent the line of `octave-auto-indent' is non-nil. |
| 1266 | Insert a newline if `octave-auto-newline' is non-nil." | ||
| 1194 | (interactive) | 1267 | (interactive) |
| 1195 | (if (not (octave-not-in-string-or-comment-p)) | 1268 | (if (not (octave-not-in-string-or-comment-p)) |
| 1196 | (insert ";") | 1269 | (insert ";") |
| 1197 | (if abbrev-mode (expand-abbrev)) | 1270 | (if abbrev-mode (expand-abbrev)) |
| 1198 | (if octave-blink-matching-block | 1271 | (if octave-blink-matching-block |
| 1199 | (octave-blink-matching-block-open)) | 1272 | (octave-blink-matching-block-open)) |
| 1200 | (indent-according-to-mode) | 1273 | (if octave-auto-indent |
| 1274 | (indent-according-to-mode)) | ||
| 1201 | (insert ";") | 1275 | (insert ";") |
| 1202 | (if octave-auto-newline | 1276 | (if octave-auto-newline |
| 1203 | (newline-and-indent)))) | 1277 | (newline-and-indent)))) |
| 1204 | 1278 | ||
| 1205 | (defun octave-electric-space () | 1279 | (defun octave-electric-space () |
| 1206 | "Insert a space in Octave mode. | 1280 | "Insert a space in Octave mode. |
| 1207 | Maybe expand abbrevs and blink matching block open keywords." | 1281 | Maybe expand abbrevs and blink matching block open keywords. |
| 1282 | Reindent the line of `octave-auto-indent' is non-nil." | ||
| 1208 | (interactive) | 1283 | (interactive) |
| 1209 | (setq last-command-char ? ) | 1284 | (setq last-command-char ? ) |
| 1210 | (if (not (octave-not-in-string-or-comment-p)) | 1285 | (if (not (octave-not-in-string-or-comment-p)) |
| @@ -1214,9 +1289,10 @@ Maybe expand abbrevs and blink matching block open keywords." | |||
| 1214 | (if abbrev-mode (expand-abbrev)) | 1289 | (if abbrev-mode (expand-abbrev)) |
| 1215 | (if octave-blink-matching-block | 1290 | (if octave-blink-matching-block |
| 1216 | (octave-blink-matching-block-open)) | 1291 | (octave-blink-matching-block-open)) |
| 1217 | (if (save-excursion | 1292 | (if (and octave-auto-indent |
| 1218 | (skip-syntax-backward " ") | 1293 | (save-excursion |
| 1219 | (not (bolp))) | 1294 | (skip-syntax-backward " ") |
| 1295 | (not (bolp)))) | ||
| 1220 | (indent-according-to-mode)) | 1296 | (indent-according-to-mode)) |
| 1221 | (self-insert-command 1))) | 1297 | (self-insert-command 1))) |
| 1222 | 1298 | ||
| @@ -1398,6 +1474,7 @@ code line." | |||
| 1398 | octave-maintainer-address | 1474 | octave-maintainer-address |
| 1399 | (concat "Emacs version " emacs-version) | 1475 | (concat "Emacs version " emacs-version) |
| 1400 | (list | 1476 | (list |
| 1477 | 'octave-auto-indent | ||
| 1401 | 'octave-auto-newline | 1478 | 'octave-auto-newline |
| 1402 | 'octave-blink-matching-block | 1479 | 'octave-blink-matching-block |
| 1403 | 'octave-block-offset | 1480 | 'octave-block-offset |