Emacs support for embedded test/demo scripts, using %! Paul Kienzle pkienzle@kienzle.powernet.co.uk *** emacs/octave-mod.el.orig Tue May 2 19:20:38 2000 --- emacs/octave-mod.el Tue May 2 02:58:06 2000 *************** *** 532,538 **** (cond ((eq position 'bol) (beginning-of-line)) ((eq position 'eol) (end-of-line)) ! ((eq position 'boi) (back-to-indentation)) ((eq position 'bonl) (forward-line 1)) ((eq position 'bopl) (forward-line -1)) (t (error "unknown buffer position requested: %s" position))) --- 532,538 ---- (cond ((eq position 'bol) (beginning-of-line)) ((eq position 'eol) (end-of-line)) ! ((eq position 'boi) (octave-back-to-indentation)) ((eq position 'bonl) (forward-line 1)) ((eq position 'bopl) (forward-line -1)) (t (error "unknown buffer position requested: %s" position))) *************** *** 637,643 **** (if (zerop (octave-previous-code-line)) (progn (octave-beginning-of-line) ! (back-to-indentation) (setq icol (current-column)) (let ((bot (point)) (eol (octave-point 'eol))) --- 637,643 ---- (if (zerop (octave-previous-code-line)) (progn (octave-beginning-of-line) ! (octave-back-to-indentation) (setq icol (current-column)) (let ((bot (point)) (eol (octave-point 'eol))) *************** *** 659,665 **** (if is-continuation-line (setq icol (+ icol octave-continuation-offset))))))) (save-excursion ! (back-to-indentation) (cond ((and (looking-at octave-block-else-regexp) (octave-not-in-string-or-comment-p)) --- 659,665 ---- (if is-continuation-line (setq icol (+ icol octave-continuation-offset))))))) (save-excursion ! (octave-back-to-indentation) (cond ((and (looking-at octave-block-else-regexp) (octave-not-in-string-or-comment-p)) *************** *** 672,677 **** --- 672,687 ---- (setq icol (list 0 icol))) ((looking-at "\\s<\\S<") (setq icol (list comment-column icol))))) + (if (save-excursion ; if the line starts a test block, + (beginning-of-line) ; keep indent at 2 + (looking-at "%![^ \t]")) + (setq icol 2) + (if (and (not (listp icol)) ; otherwise, if it is in a test block + (< icol 3) ; and the indent wants to be less than 3 + (save-excursion ; override and set it to 3 so the %! + (beginning-of-line) ; doesn't get eaten. + (looking-at "%!"))) + (setq icol 3))) icol)) (defun octave-block-end-offset () *************** *** 705,710 **** --- 715,742 ---- (indent-for-comment) (indent-according-to-mode)) + (defun octave-back-to-indentation () + (beginning-of-line) + (if (looking-at "%!") (move-to-column 2)) + (skip-chars-forward " \t")) + + (defun octave-indent-line-to (column) + (octave-back-to-indentation) + (let ((cur-col (current-column))) + (cond ((< cur-col column) + (if (> (- column (* (/ cur-col tab-width) tab-width)) tab-width) + (delete-region (point) + (progn (skip-chars-backward " ") (point)))) + (indent-to column)) + ((> cur-col column) ; too far right (after tab?) + (delete-region (progn (move-to-column column t) (point)) + (progn (octave-back-to-indentation) (point))))))) + + (defun octave-current-indentation () + (save-excursion + (octave-back-to-indentation) + (current-column))) + (defun octave-indent-line (&optional arg) "Indent current line as Octave code. With optional ARG, use this as offset unless this line is a comment with *************** *** 712,724 **** (interactive) (or arg (setq arg 0)) (let ((icol (calculate-octave-indent)) ! (relpos (- (current-column) (current-indentation)))) (if (listp icol) (setq icol (car icol)) (setq icol (+ icol arg))) (if (< icol 0) (error "Unmatched end keyword") ! (indent-line-to icol) (if (> relpos 0) (move-to-column (+ icol relpos)))))) --- 744,756 ---- (interactive) (or arg (setq arg 0)) (let ((icol (calculate-octave-indent)) ! (relpos (- (current-column) (octave-current-indentation)))) (if (listp icol) (setq icol (car icol)) (setq icol (+ icol arg))) (if (< icol 0) (error "Unmatched end keyword") ! (octave-indent-line-to icol) (if (> relpos 0) (move-to-column (+ icol relpos)))))) *************** *** 757,768 **** (interactive "p") (or arg (setq arg 1)) (beginning-of-line) ! (let ((n 0) (inc (if (> arg 0) 1 -1))) (while (and (/= arg 0) (= n 0)) (setq n (forward-line inc)) (while (and (= n 0) ! (looking-at "\\s-*\\($\\|\\s<\\)")) (setq n (forward-line inc))) (setq arg (- arg inc))) n)) --- 789,804 ---- (interactive "p") (or arg (setq arg 1)) (beginning-of-line) ! (let ((is-test-line (looking-at "%!")) ! (n 0) (inc (if (> arg 0) 1 -1))) (while (and (/= arg 0) (= n 0)) (setq n (forward-line inc)) (while (and (= n 0) ! (if is-test-line ! (or (not (looking-at "%!")) ! (looking-at "%!\\s-*\\($\\|\\s<\\|%\\)")) ! (looking-at "\\s-*\\($\\|\\s<\\|%\\)"))) (setq n (forward-line inc))) (setq arg (- arg inc))) n))