108 |
(defcustom fortran-comment-indent-style 'fixed |
(defcustom fortran-comment-indent-style 'fixed |
109 |
"*How to indent comments. |
"*How to indent comments. |
110 |
nil forces comment lines not to be touched, |
nil forces comment lines not to be touched, |
111 |
'fixed makes fixed comment indentation to `fortran-comment-line-extra-indent' |
`fixed' makes fixed comment indentation to `fortran-comment-line-extra-indent' |
112 |
columns beyond `fortran-minimum-statement-indent-fixed' (for |
columns beyond `fortran-minimum-statement-indent-fixed' (for |
113 |
`indent-tabs-mode' of nil) or `fortran-minimum-statement-indent-tab' (for |
`indent-tabs-mode' of nil) or `fortran-minimum-statement-indent-tab' (for |
114 |
`indent-tabs-mode' of t), and 'relative indents to current |
`indent-tabs-mode' of t), and |
115 |
Fortran indentation plus `fortran-comment-line-extra-indent'." |
`relative' indents to current Fortran indentation plus |
116 |
|
`fortran-comment-line-extra-indent'." |
117 |
:type '(radio (const :tag "Untouched" nil) (const fixed) (const relative)) |
:type '(radio (const :tag "Untouched" nil) (const fixed) (const relative)) |
118 |
:group 'fortran-indent) |
:group 'fortran-indent) |
119 |
|
|
638 |
(setq indent-line-function 'fortran-indent-line) |
(setq indent-line-function 'fortran-indent-line) |
639 |
(make-local-variable 'comment-indent-function) |
(make-local-variable 'comment-indent-function) |
640 |
(setq comment-indent-function 'fortran-comment-indent) |
(setq comment-indent-function 'fortran-comment-indent) |
641 |
(make-local-variable 'comment-start-skip) |
(set (make-local-variable 'comment-start-skip) |
642 |
(setq comment-start-skip "![ \t]*") |
;; We can't reuse `fortran-comment-line-start-skip' directly because |
643 |
|
;; it contains backrefs whereas we need submatch-1 to end at the |
644 |
|
;; beginning of the comment delimiter. |
645 |
|
;; (concat "\\(\\)\\(![ \t]*\\|" fortran-comment-line-start-skip "\\)") |
646 |
|
"\\(\\)\\(?:^[CcDd*]\\|!\\)\\(?:\\([^ \t\n]\\)\\2+\\)?[ \t]*") |
647 |
|
(set (make-local-variable 'comment-padding) "$$$") |
648 |
(make-local-variable 'comment-start) |
(make-local-variable 'comment-start) |
649 |
(setq comment-start fortran-comment-line-start) |
(setq comment-start fortran-comment-line-start) |
650 |
(make-local-variable 'require-final-newline) |
(make-local-variable 'require-final-newline) |
687 |
|
|
688 |
(defsubst fortran-comment-indent () |
(defsubst fortran-comment-indent () |
689 |
(save-excursion |
(save-excursion |
690 |
(skip-chars-backward " \t") |
(if (looking-at fortran-comment-line-start-skip) 0 |
691 |
(max (+ 1 (current-column)) |
(skip-chars-backward " \t") |
692 |
comment-column))) |
(max (+ 1 (current-column)) |
693 |
|
comment-column)))) |
694 |
|
|
695 |
(defun fortran-indent-comment () |
(defun fortran-indent-comment () |
696 |
"Align or create comment on current line. |
"Align or create comment on current line. |
697 |
Existing comments of all types are recognized and aligned. |
Existing comments of all types are recognized and aligned. |
698 |
If the line has no comment, a side-by-side comment is inserted and aligned |
If the line has no comment, a side-by-side comment is inserted and aligned |
699 |
if the value of `comment-start' is not nil. |
if the value of `comment-start' is not nil and allows such comments. |
700 |
Otherwise, a separate-line comment is inserted, on this line |
Otherwise, a separate-line comment is inserted, on this line |
701 |
or on a new line inserted before this line if this line is not blank." |
or on a new line inserted before this line if this line is not blank." |
702 |
(interactive) |
(interactive) |
703 |
(beginning-of-line) |
(beginning-of-line) |
704 |
;; Recognize existing comments of either kind. |
;; Recognize existing comments of either kind. |
705 |
(cond ((looking-at fortran-comment-line-start-skip) |
(cond ((fortran-find-comment-start-skip 'all) |
706 |
(fortran-indent-line)) |
(goto-char (match-beginning 0)) |
707 |
((fortran-find-comment-start-skip) ; catches any inline comment and |
(if (bolp) |
708 |
; leaves point after comment-start-skip |
(fortran-indent-line) |
709 |
(if comment-start-skip |
(if (not (= (current-column) |
710 |
(progn (goto-char (match-beginning 0)) |
(fortran-comment-indent))) |
711 |
(if (not (= (current-column) |
(progn (delete-horizontal-space) |
712 |
(fortran-comment-indent))) |
(indent-to (fortran-comment-indent)))))) |
|
(progn (delete-horizontal-space) |
|
|
(indent-to (fortran-comment-indent))))) |
|
|
(end-of-line))) ; otherwise goto end of line or sth else? |
|
713 |
;; No existing comment. |
;; No existing comment. |
714 |
;; If side-by-side comments are defined, insert one, |
;; If side-by-side comments are defined, insert one, |
715 |
;; unless line is now blank. |
;; unless line is now blank. |
716 |
((and comment-start (not (looking-at "^[ \t]*$"))) |
((and comment-start (not (looking-at "[ \t]*$")) |
717 |
|
(string-match comment-start-skip (concat " " comment-start))) |
718 |
(end-of-line) |
(end-of-line) |
719 |
(delete-horizontal-space) |
(delete-horizontal-space) |
720 |
(indent-to (fortran-comment-indent)) |
(indent-to (fortran-comment-indent)) |
846 |
(if (save-excursion |
(if (save-excursion |
847 |
(beginning-of-line) |
(beginning-of-line) |
848 |
(looking-at fortran-comment-line-start-skip)) |
(looking-at fortran-comment-line-start-skip)) |
849 |
(insert ?\n fortran-comment-line-start ? ) |
(insert ?\n (match-string 0)) |
850 |
(if indent-tabs-mode |
(if indent-tabs-mode |
851 |
(insert ?\n ?\t (fortran-numerical-continuation-char)) |
(insert ?\n ?\t (fortran-numerical-continuation-char)) |
852 |
(insert "\n " fortran-continuation-string))) ; Space after \n important |
(insert "\n " fortran-continuation-string))) ; Space after \n important |
1242 |
(not (fortran-line-number-indented-correctly-p)))) |
(not (fortran-line-number-indented-correctly-p)))) |
1243 |
(fortran-indent-to-column cfi) |
(fortran-indent-to-column cfi) |
1244 |
(beginning-of-line) |
(beginning-of-line) |
1245 |
(if (and (not (looking-at fortran-comment-line-start-skip)) |
(if (fortran-find-comment-start-skip) |
|
(fortran-find-comment-start-skip)) |
|
1246 |
(fortran-indent-comment)))) |
(fortran-indent-comment)))) |
1247 |
;; Never leave point in left margin. |
;; Never leave point in left margin. |
1248 |
(if (< (current-column) cfi) |
(if (< (current-column) cfi) |
1269 |
(not (fortran-line-number-indented-correctly-p)))) |
(not (fortran-line-number-indented-correctly-p)))) |
1270 |
(fortran-indent-to-column cfi) |
(fortran-indent-to-column cfi) |
1271 |
(beginning-of-line) |
(beginning-of-line) |
1272 |
(if (and (not (looking-at fortran-comment-line-start-skip)) |
(if (fortran-find-comment-start-skip) |
|
(fortran-find-comment-start-skip)) |
|
1273 |
(fortran-indent-comment)))) |
(fortran-indent-comment)))) |
1274 |
(fortran-fill) |
(fortran-fill) |
1275 |
;; Never leave point in left margin. |
;; Never leave point in left margin. |
1468 |
(delete-horizontal-space) |
(delete-horizontal-space) |
1469 |
(indent-to col) |
(indent-to col) |
1470 |
;; Indent any comment following code on the same line. |
;; Indent any comment following code on the same line. |
1471 |
(if (and comment-start-skip |
(if (fortran-find-comment-start-skip) |
|
(fortran-find-comment-start-skip)) |
|
1472 |
(progn (goto-char (match-beginning 0)) |
(progn (goto-char (match-beginning 0)) |
1473 |
(if (not (= (current-column) |
(if (not (= (current-column) (fortran-comment-indent))) |
|
(fortran-comment-indent))) |
|
1474 |
(progn (delete-horizontal-space) |
(progn (delete-horizontal-space) |
1475 |
(indent-to (fortran-comment-indent))))))))) |
(indent-to (fortran-comment-indent))))))))) |
1476 |
|
|
1514 |
(concat "^[ \t0-9]*do[ \t]*0*" |
(concat "^[ \t0-9]*do[ \t]*0*" |
1515 |
charnum)))))))))) |
charnum)))))))))) |
1516 |
|
|
1517 |
(defun fortran-find-comment-start-skip () |
(defun fortran-find-comment-start-skip (&optional all) |
1518 |
"Move to past `comment-start-skip' found on current line. |
"Move to past `comment-start-skip' found on current line. |
1519 |
Return t if `comment-start-skip' found, nil if not." |
Return non-nil if `comment-start-skip' found, nil if not. |
1520 |
;; In order to move point only if comment-start-skip is found, this |
If ALL is nil, only match comments that start in column > 0." |
|
;; one uses a lot of save-excursions. Note that re-search-forward |
|
|
;; moves point even if comment-start-skip is inside a string-constant. |
|
|
;; Some code expects certain values for match-beginning and end. |
|
1521 |
(interactive) |
(interactive) |
1522 |
(if (and comment-start-skip |
;; Hopefully at some point we can just use the line below! -stef |
1523 |
(save-excursion |
;; (comment-search-forward (line-end-position) t)) |
1524 |
(re-search-forward comment-start-skip (line-end-position) t))) |
(when (or all comment-start-skip) |
1525 |
(let ((save-match-beginning (match-beginning 0)) |
(let ((pos (point)) |
1526 |
(save-match-end (match-end 0))) |
(css (if comment-start-skip |
1527 |
(if (fortran-is-in-string-p (match-beginning 0)) |
(concat fortran-comment-line-start-skip |
1528 |
(save-excursion |
"\\|" comment-start-skip) |
1529 |
(goto-char save-match-end) |
fortran-comment-line-start-skip))) |
1530 |
(fortran-find-comment-start-skip)) ; recurse for rest of line |
(when (re-search-forward css (line-end-position) t) |
1531 |
(goto-char save-match-beginning) |
(if (and (or all (> (match-beginning 0) (line-beginning-position))) |
1532 |
(re-search-forward comment-start-skip (line-end-position) t) |
(or (save-match-data |
1533 |
(goto-char (match-end 0)) |
(not (fortran-is-in-string-p (match-beginning 0)))) |
1534 |
t)))) |
;; Recurse for rest of line. |
1535 |
|
(fortran-find-comment-start-skip all))) |
1536 |
|
(point) |
1537 |
|
(goto-char pos) |
1538 |
|
nil))))) |
1539 |
|
|
1540 |
;;From: ralf@up3aud1.gwdg.de (Ralf Fassel) |
;;From: ralf@up3aud1.gwdg.de (Ralf Fassel) |
1541 |
;; Test if TAB format continuation lines work. |
;; Test if TAB format continuation lines work. |
1651 |
;; |
;; |
1652 |
;; Need to use fortran-find-comment-start-skip to make sure that quoted !'s |
;; Need to use fortran-find-comment-start-skip to make sure that quoted !'s |
1653 |
;; don't prevent a break. |
;; don't prevent a break. |
1654 |
(if (not (or (save-excursion |
(when (and (save-excursion |
1655 |
(if (and comment-start-skip |
(beginning-of-line) |
1656 |
(re-search-backward comment-start-skip bol t) |
(when (fortran-find-comment-start-skip) |
1657 |
(not (fortran-is-in-string-p (point)))) |
(goto-char (match-beginning 0)) |
1658 |
(progn |
(>= (point) fill-point))) |
1659 |
(skip-chars-backward " \t") |
(save-excursion |
1660 |
(< (current-column) (1+ fill-column))))) |
(goto-char fill-point) |
1661 |
(save-excursion |
(not (bolp))) |
1662 |
(goto-char fill-point) |
(> (save-excursion |
1663 |
(bolp)))) |
(goto-char opoint) |
1664 |
(when (> (save-excursion |
(current-column)) |
1665 |
(goto-char opoint) |
(min (1+ fill-column) |
1666 |
(current-column)) |
(+ (fortran-calculate-indent) |
1667 |
(min (1+ fill-column) |
fortran-continuation-indent)))) |
1668 |
(+ (fortran-calculate-indent) |
(goto-char fill-point) |
1669 |
fortran-continuation-indent))) |
(fortran-break-line) |
1670 |
(goto-char fill-point) |
(end-of-line)))) |
|
(fortran-break-line) |
|
|
(end-of-line))))) |
|
1671 |
|
|
1672 |
(defun fortran-break-line () |
(defun fortran-break-line () |
1673 |
(let ((opoint (point)) |
(let ((opoint (point)) |
1674 |
(bol (line-beginning-position)) |
(bol (line-beginning-position)) |
1675 |
(eol (line-end-position)) |
(comment-string |
1676 |
(comment-string nil)) |
(save-excursion |
1677 |
(save-excursion |
(if (fortran-find-comment-start-skip) |
1678 |
(if (and comment-start-skip (fortran-find-comment-start-skip)) |
(delete-and-extract-region |
1679 |
(progn |
(match-beginning 0) (line-end-position)))))) |
|
(re-search-backward comment-start-skip bol t) |
|
|
(setq comment-string (buffer-substring (point) eol)) |
|
|
(delete-region (point) eol)))) |
|
1680 |
;; Forward line 1 really needs to go to next non white line |
;; Forward line 1 really needs to go to next non white line |
1681 |
(if (save-excursion (forward-line) |
(if (save-excursion (forward-line) |
1682 |
(or (looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]"))) |
(looking-at " \\{5\\}[^ 0\n]\\|\t[1-9]")) |
1683 |
(progn |
(progn |
1684 |
(end-of-line) |
(end-of-line) |
1685 |
(delete-region (point) (match-end 0)) |
(delete-region (point) (match-end 0)) |
1772 |
(or (looking-at "[ \t]*$") |
(or (looking-at "[ \t]*$") |
1773 |
(looking-at fortran-comment-line-start-skip) |
(looking-at fortran-comment-line-start-skip) |
1774 |
(and comment-start-skip |
(and comment-start-skip |
1775 |
(looking-at (concat "[ \t]*" |
(looking-at (concat "[ \t]*" comment-start-skip)))))) |
|
comment-start-skip)))))) |
|
1776 |
(save-excursion |
(save-excursion |
1777 |
;; Find beginning of statement. |
;; Find beginning of statement. |
1778 |
(fortran-next-statement) |
(fortran-next-statement) |