comparison emacs/octave.el @ 1628:40fe8e7c4ee9

[project @ 1995-11-14 15:22:47 by jwe]
author jwe
date Tue, 14 Nov 1995 15:22:47 +0000
parents 3b94ebd59353
children d01f27049f54
comparison
equal deleted inserted replaced
1627:8f798f963805 1628:40fe8e7c4ee9
450 (interactive) 450 (interactive)
451 (octave-end-of-subprogram) 451 (octave-end-of-subprogram)
452 (push-mark (point)) 452 (push-mark (point))
453 (octave-beginning-of-subprogram)) 453 (octave-beginning-of-subprogram))
454 454
455 (defun octave-is-continuation-line ()
456 "Returns t if the current line is a continuation line, nil otherwise."
457 (save-excursion
458 (beginning-of-line)
459 (looking-at "^\\S<*\\(\\\\\\|\\.\\.\\.\\)[ \t]*\\(\\s<.*\\)?$")))
460
461 (defun octave-point (position)
462 "Returns the value of point at certain positions."
463 (save-excursion
464 (cond
465 ((eq position 'bol) (beginning-of-line))
466 ((eq position 'eol) (end-of-line))
467 ((eq position 'boi) (back-to-indentation))
468 ((eq position 'bonl) (forward-line 1))
469 ((eq position 'bopl) (forward-line -1))
470 (t (error "unknown buffer position requested: %s" position)))
471 (point)))
472
473 (defun octave-previous-line ()
474 "Moves point to beginning of the previous Octave code line (i.e.,
475 skips past all empty and comment lines."
476 (interactive)
477 (beginning-of-line)
478 (while (progn
479 (forward-line -1)
480 (or (looking-at octave-comment-line-start-skip)
481 (looking-at "[ \t]*$")))))
482
455 (defun octave-previous-statement () 483 (defun octave-previous-statement ()
456 "Moves point to beginning of the previous Octave statement. 484 "Moves point to beginning of the previous Octave statement.
457 Returns `first-statement' if that statement is the first 485 Returns `first-statement' if that statement is the first
458 non-comment Octave statement in the file, and nil otherwise." 486 non-comment Octave statement in the file, and nil otherwise."
459 (interactive) 487 (interactive)
460 (let (not-first-statement) 488 (let ((eol (octave-point 'eol))
489 not-first-statement)
461 (beginning-of-line) 490 (beginning-of-line)
462 (while (and (setq not-first-statement (= (forward-line -1) 0)) 491 (while (and (setq not-first-statement (= (forward-line -1) 0))
463 (or (looking-at octave-comment-line-start-skip) 492 (or (looking-at octave-comment-line-start-skip)
464 (looking-at "[ \t]*$") 493 (looking-at "[ \t]*$")
465 (save-excursion 494 (< (car (save-excursion
466 (forward-line -1) 495 (parse-partial-sexp (octave-point 'bol)
467 (looking-at octave-continuation-regexp)) 496 eol)))
468 (looking-at 497 0)
469 (concat "[ \t]*" octave-comment-start-skip))))) 498 (save-excursion
499 (forward-line -1)
500 (looking-at octave-continuation-regexp))
501 (looking-at
502 (concat "[ \t]*" octave-comment-start-skip)))))
470 (if (not not-first-statement) 503 (if (not not-first-statement)
471 'first-statement))) 504 'first-statement)))
472 505
473 (defun octave-next-statement () 506 (defun octave-next-statement ()
474 "Moves point to beginning of the next Octave statement. 507 "Moves point to beginning of the next Octave statement.
656 (and (= count 0) 689 (and (= count 0)
657 ;; All pairs accounted for. 690 ;; All pairs accounted for.
658 (point)))))) 691 (point))))))
659 692
660 (defun octave-indent-line () 693 (defun octave-indent-line ()
661 "Indents current Octave line based on its contents and on previous lines." 694 "Indents current Octave line based on its contents and on previous
695 lines."
662 (interactive) 696 (interactive)
663 (let ((cfi (octave-calculate-indent)) 697 (let ((cfi (octave-calculate-indent))
664 (prev-indent (current-indentation)) 698 (prev-indent (current-indentation))
665 (prev-point (point)) 699 (prev-column (current-column)))
666 new-indent new-point new-eol new-bol new-indent-point)
667 (if (save-excursion 700 (if (save-excursion
668 (beginning-of-line) 701 (beginning-of-line)
669 (and (not (looking-at octave-comment-line-start-skip)) 702 (and (not (looking-at octave-comment-line-start-skip))
670 (not (octave-find-comment-start-skip)))) 703 (not (octave-find-comment-start-skip))))
671 (progn 704 (progn
672 (beginning-of-line) 705 (beginning-of-line)
673 (delete-horizontal-space) 706 (delete-horizontal-space)
674 ;; 707 (indent-to cfi)
675 ;; There must be a better way! 708 (if (> prev-column prev-indent)
676 ;; 709 (goto-char (+ (point) (- prev-column prev-indent)))))
677 (setq new-indent (indent-to cfi))
678 (setq new-point (+ prev-point (- new-indent prev-indent)))
679 (setq new-eol (save-excursion (end-of-line) (point)))
680 (setq new-bol (save-excursion (beginning-of-line) (point)))
681 (setq new-indent-point (+ new-bol new-indent))
682 (cond
683 ((> prev-point new-eol)
684 (goto-char new-eol))
685 ((< new-point new-indent-point)
686 (goto-char new-indent-point))
687 (t
688 (goto-char new-point))))
689 (octave-indent-comment)) 710 (octave-indent-comment))
690 (if (and auto-fill-function 711 (if (and auto-fill-function
691 (> (save-excursion (end-of-line) (current-column)) fill-column)) 712 (> (save-excursion (end-of-line) (current-column))
713 fill-column))
692 (save-excursion 714 (save-excursion
693 (end-of-line) 715 (end-of-line)
694 (octave-do-auto-fill))) 716 (octave-do-auto-fill)))
695 (if octave-blink-matching-blocks 717 (if octave-blink-matching-blocks
696 (progn 718 (progn
791 (forward-char))) 813 (forward-char)))
792 icol)) 814 icol))
793 815
794 (defun octave-calculate-indent () 816 (defun octave-calculate-indent ()
795 "Calculates the Octave indent column based on previous lines." 817 "Calculates the Octave indent column based on previous lines."
796 (let ((indent-col 0) 818 (interactive)
797 first-statement) 819 (let* ((prev-line-is-continuation-line
820 (save-excursion
821 (octave-previous-line)
822 (octave-is-continuation-line)))
823 (indent-col 0)
824 first-statement)
798 (save-excursion 825 (save-excursion
799 (setq first-statement (octave-previous-statement)) 826 (beginning-of-line)
800 (if (not first-statement) 827 (if (condition-case nil
801 (progn 828 (progn
802 (skip-chars-forward " \t") 829 (up-list -1)
803 (setq indent-col (+ (octave-current-line-indentation) 830 t)
804 (octave-calc-indent-this-line 1 0)))))) 831 (error nil))
832 (setq indent-col (+ 1 (current-column)))
833 (setq first-statement (octave-previous-statement))
834 (if (not first-statement)
835 (progn
836 (skip-chars-forward " \t")
837 (setq indent-col (+ (octave-current-line-indentation)
838 (octave-calc-indent-this-line 1 0)))
839 (if (and prev-line-is-continuation-line
840 (octave-is-continuation-line))
841 (setq indent-col (+ indent-col
842 octave-continuation-indent)))))))
843
805 ;; This fixes things if the line we are on is and else- or 844 ;; This fixes things if the line we are on is and else- or
806 ;; end-type statement. 845 ;; end-type statement.
807
808 (if (save-excursion 846 (if (save-excursion
809 (beginning-of-line) 847 (beginning-of-line)
810 (skip-chars-forward " \t") 848 (skip-chars-forward " \t")
811 (looking-at "\\(end\\|else\\|catch\\|unwind_protect_cleanup\\)")) 849 (looking-at "\\(end\\|else\\|catch\\|unwind_protect_cleanup\\)"))
812 (setq indent-col (+ indent-col 850 (setq indent-col (+ indent-col
813 (octave-calc-indent-this-line -1 1)))) 851 (octave-calc-indent-this-line -1 1))))
814 indent-col)) 852 indent-col))
815 853
816 (defun octave-electric-semi () 854 (defun octave-electric-semi ()
817 (interactive) 855 (interactive)
818 (if (and (not (octave-is-in-string-p (point))) octave-auto-newline) 856 (if (and (not (octave-is-in-string-p (point))) octave-auto-newline)