From a0099d31a646b16ee0bbc65c423f327066d59e54 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Mon, 10 Dec 2012 20:42:49 -0800 Subject: [PATCH] Fix for indentation of f90 preproc lines embedded in continuations * lisp/progmodes/f90.el (f90-line-continued, f90-indent-region): Treat preprocessor lines embedded in continuations like comments. (f90-indent-line): Special-case preprocessor lines. * test/automated/f90.el (f90-test-bug13138): New test. --- lisp/ChangeLog | 6 ++++++ lisp/progmodes/f90.el | 33 +++++++++++++++++++-------------- test/ChangeLog | 4 ++++ test/automated/f90.el | 18 ++++++++++++++++++ 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ebce9305f31..2aafbd758d7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2012-12-11 Glenn Morris + + * progmodes/f90.el (f90-line-continued, f90-indent-region): + Treat preprocessor lines embedded in continuations like comments. + (f90-indent-line): Special-case preprocessor lines. (Bug#13138) + 2012-12-11 Jay Belanger * calc/calc.el (calc-standard-date-formats): Add more date diff --git a/lisp/progmodes/f90.el b/lisp/progmodes/f90.el index f42952685d0..59dda170b77 100644 --- a/lisp/progmodes/f90.el +++ b/lisp/progmodes/f90.el @@ -1178,11 +1178,11 @@ and lies before point." (defsubst f90-line-continued () "Return t if the current line is a continued one. -This includes comment lines embedded in continued lines, but -not the last line of a continued statement." +This includes comment or preprocessor lines embedded in continued lines, +but not the last line of a continued statement." (save-excursion (beginning-of-line) - (while (and (looking-at "[ \t]*\\(!\\|$\\)") (zerop (forward-line -1)))) + (while (and (looking-at "[ \t]*\\([!#]\\|$\\)") (zerop (forward-line -1)))) (end-of-line) (while (f90-in-comment) (search-backward "!" (line-beginning-position)) @@ -1832,11 +1832,15 @@ after indenting." (f90-indent-line-no) (setq no-line-number t) (skip-chars-forward " \t")) - (if (looking-at "!") - (setq indent (f90-comment-indent)) - (and f90-smart-end (looking-at "end") - (f90-match-end)) - (setq indent (f90-calculate-indent))) + ;; FIXME This means f90-calculate-indent gives different answers + ;; for comments and preprocessor lines to this function. + ;; Better to make f90-calculate-indent return the correct answer? + (cond ((looking-at "!") (setq indent (f90-comment-indent))) + ((looking-at "#") (setq indent 0)) + (t + (and f90-smart-end (looking-at "end") + (f90-match-end)) + (setq indent (f90-calculate-indent)))) (or (= indent (current-column)) (f90-indent-to indent no-line-number)) ;; If initial point was within line's indentation, @@ -1973,12 +1977,13 @@ If run in the middle of a line, the line is not broken." (f90-indent-to ind-curr)) (while (and (f90-line-continued) (zerop (forward-line 1)) (< (point) end-region-mark)) - (if (looking-at "[ \t]*!") - (f90-indent-to (f90-comment-indent)) - (or (= (current-indentation) - (+ ind-curr f90-continuation-indent)) - (f90-indent-to - (+ ind-curr f90-continuation-indent) 'no-line-no))))) + (cond ((looking-at "[ \t]*#") (f90-indent-to 0)) + ((looking-at "[ \t]*!") (f90-indent-to (f90-comment-indent))) + (t + (or (= (current-indentation) + (+ ind-curr f90-continuation-indent)) + (f90-indent-to + (+ ind-curr f90-continuation-indent) 'no-line-no)))))) ;; Restore point, etc. (setq f90-cache-position nil) (goto-char save-point) diff --git a/test/ChangeLog b/test/ChangeLog index 7633d974f57..142dfcb42fd 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2012-12-11 Glenn Morris + + * automated/f90.el (f90-test-bug13138): New test. + 2012-12-10 Rüdiger Sonderfeld * automated/inotify-test.el: New test. diff --git a/test/automated/f90.el b/test/automated/f90.el index 25b77f07ad3..7f412568ae3 100644 --- a/test/automated/f90.el +++ b/test/automated/f90.el @@ -154,5 +154,23 @@ end module modname") (f90-indent-line) (should (= 0 (current-indentation))))) +(ert-deftest f90-test-bug13138 () + "Test for http://debbugs.gnu.org/13138 ." + (with-temp-buffer + (f90-mode) + (insert "program prog + integer :: i = & +#ifdef foo + & 1 +#else + & 2 +#endif + + write(*,*) i +end program prog") + (goto-char (point-min)) + (forward-line 2) + (f90-indent-subprogram) + (should (= 0 (current-indentation))))) ;;; f90.el ends here -- 2.39.5