Index: lisp/progmodes/meta-mode.el =================================================================== RCS file: /sources/emacs/emacs/lisp/progmodes/meta-mode.el,v retrieving revision 1.19 diff -c -r1.19 meta-mode.el *** lisp/progmodes/meta-mode.el 26 Jul 2007 05:27:28 -0000 1.19 --- lisp/progmodes/meta-mode.el 9 Aug 2007 00:51:47 -0000 *************** *** 620,625 **** --- 620,628 ---- ((and meta-ignore-comment-regexp (looking-at meta-ignore-comment-regexp)) (current-indentation)) + ;; Beginning of buffer. + ((eq (point-at-bol) (point-min)) + 0) ;; Backindent at end of environments. ((looking-at (concat "\\<" meta-end-environment-regexp "\\>")) *************** *** 631,661 **** (t (meta-indent-calculate-last))))) (defun meta-indent-calculate-last () ! "Return the indentation of previous line of Metafont or MetaPost source." (save-restriction (widen) (skip-chars-backward "\n\t ") ! (move-to-column (current-indentation)) ! ;; Ignore comments. ! (while (and (looking-at comment-start) (not (bobp))) ! (skip-chars-backward "\n\t ") ! (if (not (bobp)) ! (move-to-column (current-indentation)))) ! (cond ! ((bobp) 0) ! (t (+ (current-indentation) ! (meta-indent-level-count) ! (cond ! ;; Compensate for backindent at end of environments. ! ((looking-at ! (concat "\\<"meta-end-environment-regexp "\\>")) ! meta-indent-level) ! ;; Compensate for backindent within environments. ! ((looking-at ! (concat "\\<" meta-within-environment-regexp "\\>")) ! meta-indent-level) ! (t 0))))) ! )) (defun meta-indent-level-count () "Count indentation change for begin-end commands in the current line." --- 634,700 ---- (t (meta-indent-calculate-last))))) (defun meta-indent-calculate-last () ! "Return the indentation of previous line of Metafont or MetaPost source. ! If the current line is a continuation, i.e. the previous line doesn't end ! up with a semicolon, add some more indentation." (save-restriction (widen) + (meta-indent-previous-line) + (+ (current-indentation) + (meta-indent-level-count) + (let ((unfinished (meta-indent-unfinished-line-p))) + (cond ((eq unfinished t) meta-indent-level) + ((and (not unfinished) + (save-excursion + (meta-indent-previous-line) + (meta-indent-unfinished-line-p))) + ;; Compensate a previous continuation indentation. + (- meta-indent-level)) + (t 0))) + (cond + ;; Compensate for backindent at end of environments. + ((looking-at + (concat "\\<" meta-end-environment-regexp "\\>")) + meta-indent-level) + ;; Compensate for backindent within environments. + ((looking-at + (concat "\\<" meta-within-environment-regexp "\\>")) + meta-indent-level) + (t 0))))) + + (defun meta-indent-previous-line () + "Go to the previous line of code, skipping comments." + (skip-chars-backward "\n\t ") + (move-to-column (current-indentation)) + ;; Ignore comments. + (while (and (looking-at comment-start) (not (bobp))) (skip-chars-backward "\n\t ") ! (if (not (bobp)) ! (move-to-column (current-indentation))))) ! ! (defun meta-indent-unfinished-line-p () ! "Tell if the current line of code ends with an unfinished expression. ! Return t if the line is the first line of the unfinished expression. ! Return 'continued if the line is a continuation. ! Return nil if the line is a finished one." ! (save-excursion ! (end-of-line) ! (if (search-backward ";" (point-at-bol) t) ! (forward-char) ! (beginning-of-line)) ! ;; See if the last statement of the line is environment-related, ! ;; or exists at all. ! (if (looking-at (concat "[ \t]*\\($\\|" (regexp-quote comment-start) ! "\\|\\<" meta-end-environment-regexp "\\>" ! "\\|\\<" meta-begin-environment-regexp "\\>" ! "\\|\\<" meta-within-environment-regexp "\\>\\)")) ! nil ! (if (or (bobp) (/= (point-at-bol) (point))) ! t ! ;; Otherwise, if there was no semicolon on the line, see if ! ;; the previous line was a continuation. ! (meta-indent-previous-line) ! (if (meta-indent-unfinished-line-p) 'continued t))))) (defun meta-indent-level-count () "Count indentation change for begin-end commands in the current line." Index: lisp/ChangeLog =================================================================== RCS file: /sources/emacs/emacs/lisp/ChangeLog,v retrieving revision 1.11534 diff -C 0 -r1.11534 ChangeLog *** lisp/ChangeLog 8 Aug 2007 16:38:31 -0000 1.11534 --- lisp/ChangeLog 9 Aug 2007 00:52:04 -0000 *************** *** 0 **** --- 1,12 ---- + 2007-08-09 Michaël Cadilhac + + * progmodes/meta-mode.el (meta-indent-calculate): Force + indentation at bop to 0. + (meta-indent-previous-line): New. Go to the previous line of code + by skipping comments backward. + (meta-indent-unfinished-line-p): New. Tell if the current line is + unfinished, i.e. contains an expression that will be ended in a + future line. + (meta-indent-calculate-last): Use it to add some more indentation + when continuing a line. +