Mercurial > emacs
changeset 20181:fe0f0a9bb43f
(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'.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Fri, 24 Oct 1997 20:11:44 +0000 |
parents | bfbf6a2939a3 |
children | 9f3dd970927e |
files | lisp/progmodes/octave-mod.el |
diffstat | 1 files changed, 102 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/progmodes/octave-mod.el Fri Oct 24 19:58:39 1997 +0000 +++ b/lisp/progmodes/octave-mod.el Fri Oct 24 20:11:44 1997 +0000 @@ -299,8 +299,11 @@ (modify-syntax-entry ?\n ">" table) (setq octave-mode-syntax-table table))) +(defvar octave-auto-indent nil + "*Non-nil means indent line after a semicolon or space in Octave mode.") + (defvar octave-auto-newline nil - "*Non-nil means automatically newline after a semicolon in Octave mode.") + "*Non-nil means insert newline after a semicolon in Octave mode.") (defvar octave-blink-matching-block t "*Control the blinking of matching Octave block keywords. @@ -329,7 +332,7 @@ '(("for" . ("end" "endfor")) ("function" . ("end" "endfunction")) ("if" . ("else" "elseif" "end" "endif")) - ("switch" . ("case" "end" "endswitch" "otherwise")) + ("switch" . ("case" "otherwise" "end" "endswitch")) ("try" . ("catch" "end" "end_try_catch")) ("unwind_protect" . ("unwind_protect_cleanup" "end" "end_unwind_protect")) @@ -405,6 +408,10 @@ 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. @@ -580,6 +587,15 @@ (error nil)) (< pos (point))))))) +(defun octave-maybe-insert-continuation-string () + (if (or (octave-in-comment-p) + (save-excursion + (beginning-of-line) + (looking-at octave-continuation-regexp))) + nil + (delete-horizontal-space) + (insert (concat " " octave-continuation-string)))) + ;;; Comments (defun octave-comment-region (beg end &optional arg) "Comment or uncomment each line in the region as Octave code. @@ -652,7 +668,8 @@ ((and (looking-at octave-block-end-regexp) (octave-not-in-string-or-comment-p)) (setq icol (- icol (octave-block-end-offset)))) - ((looking-at "\\s<\\s<\\s<\\S<") + ((or (looking-at "\\s<\\s<\\s<\\S<") + (octave-before-magic-comment-p)) (setq icol (list 0 icol))) ((looking-at "\\s<\\S<") (setq icol (list comment-column icol))))) @@ -664,8 +681,14 @@ (* octave-block-offset (if (string-match (match-string 0) "switch") 2 1)))) +(defun octave-before-magic-comment-p () + (save-excursion + (beginning-of-line) + (and (bobp) (looking-at "\\s-*#!")))) + (defun octave-comment-indent () - (if (looking-at "\\s<\\s<\\s<") + (if (or (looking-at "\\s<\\s<\\s<") + (octave-before-magic-comment-p)) 0 (if (looking-at "\\s<\\s<") (calculate-octave-indent) @@ -1031,19 +1054,65 @@ ;;; Filling (defun octave-auto-fill () - "Perform auto-fill in Octave mode." - (if (> (current-column) (current-fill-column)) - (if (octave-in-comment-p) - (do-auto-fill) - (if (> (current-column) (current-fill-column)) - (let ((fill-column (- (current-fill-column) - (length octave-continuation-string)))) - (do-auto-fill) - (save-excursion - (forward-line -1) - (end-of-line) - (insert (concat " " octave-continuation-string))) - (indent-according-to-mode)))))) + "Perform auto-fill in Octave mode. +Returns nil if no feasible place to break the line could be found, and t +otherwise." + (let (fc give-up) + (if (or (null (setq fc (current-fill-column))) + (save-excursion + (beginning-of-line) + (and auto-fill-inhibit-regexp + (looking-at auto-fill-inhibit-regexp)))) + nil ; Can't do anything + (if (and (not (octave-in-comment-p)) + (> (current-column) fc)) + (setq fc (- fc (+ (length octave-continuation-string) 1)))) + (while (and (not give-up) (> (current-column) fc)) + (let* ((opoint (point)) + (fpoint + (save-excursion + (move-to-column (+ fc 1)) + (skip-chars-backward "^ \t\n") + ;; If we're at the beginning of the line, break after + ;; the first word + (if (bolp) + (re-search-forward "[ \t]" opoint t)) + ;; If we're in a comment line, don't break after the + ;; comment chars + (if (save-excursion + (skip-syntax-backward " <") + (bolp)) + (re-search-forward "[ \t]" (octave-point 'eol) + 'move)) + ;; If we're not in a comment line and just ahead the + ;; continuation string, don't break here. + (if (and (not (octave-in-comment-p)) + (looking-at + (concat "\\s-*" + (regexp-quote + octave-continuation-string) + "\\s-*$"))) + (end-of-line)) + (skip-chars-backward " \t") + (point)))) + (if (save-excursion + (goto-char fpoint) + (not (or (bolp) (eolp)))) + (let ((prev-column (current-column))) + (if (save-excursion + (skip-chars-backward " \t") + (= (point) fpoint)) + (progn + (octave-maybe-insert-continuation-string) + (indent-new-comment-line t)) + (save-excursion + (goto-char fpoint) + (octave-maybe-insert-continuation-string) + (indent-new-comment-line t))) + (if (>= (current-column) prev-column) + (setq give-up t))) + (setq give-up t)))) + (not give-up)))) (defun octave-fill-paragraph (&optional arg) "Fill paragraph of Octave code, handling Octave comments." @@ -1108,13 +1177,16 @@ (delete-region (match-beginning 0) (match-end 0)) (fixup-whitespace) (move-to-column cfc)))) + ;; We might also try to combine continued code lines> Perhaps + ;; some other time ... (skip-chars-forward "^ \t\n") (delete-horizontal-space) (if (or (< (current-column) cfc) (and (= (current-column) cfc) (eolp))) (forward-line 1) (if (not (eolp)) (insert " ")) - (octave-auto-fill)))) + (or (octave-auto-fill) + (forward-line 1))))) t))) @@ -1189,22 +1261,25 @@ (defun octave-electric-semi () "Insert a semicolon in Octave mode. -Always reindent the line. Insert a newline if `octave-auto-newline' is -non-nil." +Maybe expand abbrevs and blink matching block open keywords. +Reindent the line of `octave-auto-indent' is non-nil. +Insert a newline if `octave-auto-newline' is non-nil." (interactive) (if (not (octave-not-in-string-or-comment-p)) (insert ";") (if abbrev-mode (expand-abbrev)) (if octave-blink-matching-block (octave-blink-matching-block-open)) - (indent-according-to-mode) + (if octave-auto-indent + (indent-according-to-mode)) (insert ";") (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." +Maybe expand abbrevs and blink matching block open keywords. +Reindent the line of `octave-auto-indent' is non-nil." (interactive) (setq last-command-char ? ) (if (not (octave-not-in-string-or-comment-p)) @@ -1214,9 +1289,10 @@ (if abbrev-mode (expand-abbrev)) (if octave-blink-matching-block (octave-blink-matching-block-open)) - (if (save-excursion - (skip-syntax-backward " ") - (not (bolp))) + (if (and octave-auto-indent + (save-excursion + (skip-syntax-backward " ") + (not (bolp)))) (indent-according-to-mode)) (self-insert-command 1))) @@ -1398,6 +1474,7 @@ octave-maintainer-address (concat "Emacs version " emacs-version) (list + 'octave-auto-indent 'octave-auto-newline 'octave-blink-matching-block 'octave-block-offset