Mercurial > emacs
comparison lisp/progmodes/fortran.el @ 28079:07cbc9269fbc
(fortran-comment-line-start): Define as
"C".
(fortran-comment-line-start-skip): Don't match cpp stuff.
(font-lock-keywords): Add * to comment-chars. Grok cpp stuff.
(fortran-mode-map): Remove over-eager custom-menu-create for now.
(fortran-mode): Don't set fortran-comment-line-start-skip,
fortran-comment-line-start here. Set comment-start,
add-log-current-defun.
(fortran-fill-paragraph): Adjust to try to DTRT with cpp stuff.
(fortran-current-defun): New function.
author | Dave Love <fx@gnu.org> |
---|---|
date | Thu, 09 Mar 2000 23:02:51 +0000 |
parents | 0d4776018e39 |
children | 1c8c6dbfcfb9 |
comparison
equal
deleted
inserted
replaced
28078:99865d22cc31 | 28079:07cbc9269fbc |
---|---|
119 "*Amount of extra indentation for text within full-line comments." | 119 "*Amount of extra indentation for text within full-line comments." |
120 :type 'integer | 120 :type 'integer |
121 :group 'fortran-indent | 121 :group 'fortran-indent |
122 :group 'fortran-comment) | 122 :group 'fortran-comment) |
123 | 123 |
124 (defcustom fortran-comment-line-start nil | 124 (defcustom fortran-comment-line-start "C" |
125 "*Delimiter inserted to start new full-line comment." | 125 "*Delimiter inserted to start new full-line comment. |
126 You might want to change this to \"*\", for instance." | |
126 :version "21.1" | 127 :version "21.1" |
127 :type '(choice string (const nil)) | 128 :type 'string |
128 :group 'fortran-comment) | 129 :group 'fortran-comment) |
129 | 130 |
130 (defcustom fortran-comment-line-start-skip nil | 131 ;; This used to match preprocessor lines too, but that messes up |
132 ;; filling and doesn't seem to be necessary. | |
133 (defcustom fortran-comment-line-start-skip | |
134 "^[CcDd*!]\\(\\([^ \t\n]\\)\\2\\2*\\)?[ \t]*" | |
131 "*Regexp to match the start of a full-line comment." | 135 "*Regexp to match the start of a full-line comment." |
132 :version "21.1" | 136 :version "21.1" |
133 :type '(choice string (const nil)) | 137 :type 'regexp |
134 :group 'fortran-comment) | 138 :group 'fortran-comment) |
135 | 139 |
136 (defcustom fortran-minimum-statement-indent-fixed 6 | 140 (defcustom fortran-minimum-statement-indent-fixed 6 |
137 "*Minimum statement indentation for fixed format continuation style." | 141 "*Minimum statement indentation for fixed format continuation style." |
138 :type 'integer | 142 :type 'integer |
262 | 266 |
263 (defconst fortran-font-lock-syntactic-keywords nil | 267 (defconst fortran-font-lock-syntactic-keywords nil |
264 "`font-lock-syntactic-keywords' for Fortran. | 268 "`font-lock-syntactic-keywords' for Fortran. |
265 These get fixed-format comments fontified.") | 269 These get fixed-format comments fontified.") |
266 | 270 |
267 (let ((comment-chars "cd") ; `d' for `debugging' comments | 271 (let ((comment-chars "cd\\*") ; `d' for `debugging' comments |
268 (fortran-type-types | 272 (fortran-type-types |
269 (eval-when-compile | 273 (eval-when-compile |
270 (let ((re (regexp-opt | 274 (let ((re (regexp-opt |
271 (let ((simple-types | 275 (let ((simple-types |
272 '("character" "byte" "integer" "logical" | 276 '("character" "byte" "integer" "logical" |
361 (1 font-lock-keyword-face) (4 font-lock-constant-face nil t)) | 365 (1 font-lock-keyword-face) (4 font-lock-constant-face nil t)) |
362 ;; Highlight standard continuation character and in a | 366 ;; Highlight standard continuation character and in a |
363 ;; TAB-formatted line. | 367 ;; TAB-formatted line. |
364 '("^ \\([^ 0]\\)" 1 font-lock-string-face) | 368 '("^ \\([^ 0]\\)" 1 font-lock-string-face) |
365 '("^\t\\([1-9]\\)" 1 font-lock-string-face)) | 369 '("^\t\\([1-9]\\)" 1 font-lock-string-face)) |
370 (list | |
371 ;; cpp stuff (ugh) | |
372 '("^# *[a-z]+" . font-lock-keyword-face)) | |
366 ;; The list `fortran-font-lock-keywords-2' less that for types | 373 ;; The list `fortran-font-lock-keywords-2' less that for types |
367 ;; (see above). | 374 ;; (see above). |
368 (cdr (nthcdr (length fortran-font-lock-keywords-1) | 375 (cdr (nthcdr (length fortran-font-lock-keywords-1) |
369 fortran-font-lock-keywords-2))))) | 376 fortran-font-lock-keywords-2))))) |
370 | 377 |
421 (unless (boundp 'fortran-mode-menu) | 428 (unless (boundp 'fortran-mode-menu) |
422 (easy-menu-define | 429 (easy-menu-define |
423 fortran-mode-menu fortran-mode-map "" | 430 fortran-mode-menu fortran-mode-map "" |
424 `("Fortran" | 431 `("Fortran" |
425 ["Manual" (info "(emacs)Fortran")] | 432 ["Manual" (info "(emacs)Fortran")] |
426 ,(customize-menu-create 'fortran) | 433 ;;; This loads cus-edit as things stand -- needs to be done lazily. |
427 ["Set" Custom-set t] | 434 ;;; ,(customize-menu-create 'fortran) |
428 ["Save" Custom-save t] | 435 ;;; ["Set" Custom-set t] |
429 ["Reset to Current" Custom-reset-current t] | 436 ;;; ["Save" Custom-save t] |
430 ["Reset to Saved" Custom-reset-saved t] | 437 ;;; ["Reset to Current" Custom-reset-current t] |
431 ["Reset to Standard Settings" Custom-reset-standard t] | 438 ;;; ["Reset to Saved" Custom-reset-saved t] |
439 ;;; ["Reset to Standard Settings" Custom-reset-standard t] | |
432 "----" | 440 "----" |
433 ["Toggle Auto-fill" fortran-auto-fill-mode :style toggle | 441 ["Toggle Auto-fill" fortran-auto-fill-mode :style toggle |
434 :selected (eq auto-fill-function 'fortran-do-auto-fill)] | 442 :selected (eq auto-fill-function 'fortran-do-auto-fill)] |
435 ["Toggle abbrev-mode" abbrev-mode :style toggle :selected abbrev-mode] | 443 ["Toggle abbrev-mode" abbrev-mode :style toggle :selected abbrev-mode] |
436 "----" | 444 "----" |
628 (setq fortran-break-before-delimiters t) | 636 (setq fortran-break-before-delimiters t) |
629 (make-local-variable 'indent-line-function) | 637 (make-local-variable 'indent-line-function) |
630 (setq indent-line-function 'fortran-indent-line) | 638 (setq indent-line-function 'fortran-indent-line) |
631 (make-local-variable 'comment-indent-function) | 639 (make-local-variable 'comment-indent-function) |
632 (setq comment-indent-function 'fortran-comment-indent-function) | 640 (setq comment-indent-function 'fortran-comment-indent-function) |
633 (make-local-variable 'fortran-comment-line-start-skip) | |
634 (setq fortran-comment-line-start-skip | |
635 "^[Cc*]\\(\\([^ \t\n]\\)\\2\\2*\\)?[ \t]*\\|^#.*") | |
636 (make-local-variable 'fortran-comment-line-start) | |
637 (setq fortran-comment-line-start "c") | |
638 (make-local-variable 'comment-start-skip) | 641 (make-local-variable 'comment-start-skip) |
639 (setq comment-start-skip "![ \t]*") | 642 (setq comment-start-skip "![ \t]*") |
640 (make-local-variable 'comment-start) | 643 (make-local-variable 'comment-start) |
641 (setq comment-start nil) | 644 (setq comment-start "C") |
642 (make-local-variable 'require-final-newline) | 645 (make-local-variable 'require-final-newline) |
643 (setq require-final-newline t) | 646 (setq require-final-newline t) |
644 (make-local-variable 'abbrev-all-caps) | 647 (make-local-variable 'abbrev-all-caps) |
645 (setq abbrev-all-caps t) | 648 (setq abbrev-all-caps t) |
646 (make-local-variable 'indent-tabs-mode) | 649 (make-local-variable 'indent-tabs-mode) |
669 (indent-region start end nil)))) | 672 (indent-region start end nil)))) |
670 (set (make-local-variable 'beginning-of-defun-function) | 673 (set (make-local-variable 'beginning-of-defun-function) |
671 #'fortran-beginning-of-subprogram) | 674 #'fortran-beginning-of-subprogram) |
672 (set (make-local-variable 'end-of-defun-function) | 675 (set (make-local-variable 'end-of-defun-function) |
673 #'fortran-end-of-subprogram) | 676 #'fortran-end-of-subprogram) |
677 (set (make-local-variable 'add-log-current-defun-function) | |
678 #'fortran-current-defun) | |
674 (run-hooks 'fortran-mode-hook)) | 679 (run-hooks 'fortran-mode-hook)) |
675 | 680 |
676 (defun fortran-comment-indent-function () | 681 (defun fortran-comment-indent-function () |
677 (save-excursion | 682 (save-excursion |
678 (skip-chars-backward " \t") | 683 (skip-chars-backward " \t") |
1712 (indent-tabs-mode fortran-tab-mode-string)) | 1717 (indent-tabs-mode fortran-tab-mode-string)) |
1713 minor-mode-alist))) | 1718 minor-mode-alist))) |
1714 | 1719 |
1715 (defun fortran-fill-paragraph (&optional justify) | 1720 (defun fortran-fill-paragraph (&optional justify) |
1716 "Fill surrounding comment block as paragraphs, else fill statement. | 1721 "Fill surrounding comment block as paragraphs, else fill statement. |
1717 | |
1718 Intended as the value of `fill-paragraph-function'." | 1722 Intended as the value of `fill-paragraph-function'." |
1719 (interactive "P") | 1723 (interactive "P") |
1720 (save-excursion | 1724 (save-excursion |
1721 (beginning-of-line) | 1725 (beginning-of-line) |
1722 (if (not (looking-at "[Cc*]")) | 1726 (if (not (looking-at fortran-comment-line-start-skip)) |
1723 (fortran-fill-statement) | 1727 (fortran-fill-statement) |
1724 ;; We're in a comment block. Find the start and end of a | 1728 ;; We're in a comment block. Find the start and end of a |
1725 ;; paragraph, delimited either by non-comment lines or empty | 1729 ;; paragraph, delimited either by non-comment lines or empty |
1726 ;; comments. (Get positions as markers, since the | 1730 ;; comments. (Get positions as markers, since the |
1727 ;; `indent-region' below can shift the block's end). | 1731 ;; `indent-region' below can shift the block's end). |
1728 (let* ((non-empty-comment (concat "\\(" fortran-comment-line-start-skip | 1732 (let* ((non-empty-comment |
1729 "\\)" "[^ \t\n]")) | 1733 (concat "\\(" fortran-comment-line-start-skip "\\)" |
1730 (start (save-excursion | 1734 "[^ \t\n]")) |
1731 ;; Find (start of) first line. | 1735 (start (save-excursion |
1732 (while (and (zerop (forward-line -1)) | 1736 ;; Find (start of) first line. |
1733 (looking-at non-empty-comment))) | 1737 (while (and (zerop (forward-line -1)) |
1734 (or (looking-at non-empty-comment) | 1738 (looking-at non-empty-comment))) |
1735 (forward-line)) ; overshot | 1739 (or (looking-at non-empty-comment) |
1736 (point-marker))) | 1740 (forward-line)) ; overshot |
1737 (end (save-excursion | 1741 (point-marker))) |
1738 ;; Find start of first line past region to fill. | 1742 (end (save-excursion |
1739 (while (progn (forward-line) | 1743 ;; Find start of first line past region to fill. |
1740 (looking-at non-empty-comment))) | 1744 (while (progn |
1741 (point-marker)))) | 1745 (forward-line) |
1742 ;; Indent the block, find the string comprising the effective | 1746 (looking-at non-empty-comment))) |
1743 ;; comment start skip and use that as a fill-prefix for | 1747 (point-marker)))) |
1744 ;; filling the region. | 1748 ;; Indent the block, find the string comprising the effective |
1745 (indent-region start end nil) | 1749 ;; comment start skip and use that as a fill-prefix for |
1746 (let ((paragraph-ignore-fill-prefix nil) | 1750 ;; filling the region. |
1747 (fill-prefix (progn (beginning-of-line) | 1751 (indent-region start end nil) |
1748 (looking-at fortran-comment-line-start-skip) | 1752 (let ((paragraph-ignore-fill-prefix nil) |
1749 (match-string 0)))) | 1753 (fill-prefix (progn |
1750 (let (fill-paragraph-function) | 1754 (beginning-of-line) |
1751 (fill-region start end justify))) ; with normal `fill-paragraph' | 1755 (looking-at fortran-comment-line-start-skip) |
1752 (set-marker start nil) | 1756 (match-string 0)))) |
1753 (set-marker end nil)))) | 1757 (let (fill-paragraph-function) |
1758 (fill-region start end justify))) ; with normal `fill-paragraph' | |
1759 (set-marker start nil) | |
1760 (set-marker end nil)))) | |
1754 t) | 1761 t) |
1755 | 1762 |
1756 (defun fortran-fill-statement () | 1763 (defun fortran-fill-statement () |
1757 "Fill a fortran statement up to `fill-column'." | 1764 "Fill a fortran statement up to `fill-column'." |
1758 (interactive) | 1765 (interactive) |
1787 (while (re-search-forward (concat "^" (make-string 72 ?.)" \\(.*\\)") | 1794 (while (re-search-forward (concat "^" (make-string 72 ?.)" \\(.*\\)") |
1788 nil t) | 1795 nil t) |
1789 (replace-match "" nil nil nil 1) | 1796 (replace-match "" nil nil nil 1) |
1790 (unless do-space (delete-horizontal-space))))) | 1797 (unless do-space (delete-horizontal-space))))) |
1791 | 1798 |
1799 ;; This code used to live in add-log.el, but this is a better place | |
1800 ;; for it. | |
1801 (defun fortran-current-defun () | |
1802 "Function to use for `add-log-current-defun-function' in Fortran mode." | |
1803 ;; We must be inside function body for this to work. | |
1804 (fortran-beginning-of-subprogram) | |
1805 (let ((case-fold-search t)) ; case-insensitive | |
1806 ;; search for fortran subprogram start | |
1807 (if (re-search-forward | |
1808 "^[ \t]*\\(program\\|subroutine\\|function\ | |
1809 \\|[ \ta-z0-9*()]*[ \t]+function\\|\\(block[ \t]*data\\)\\)" | |
1810 (save-excursion (fortran-end-of-subprogram) | |
1811 (point)) | |
1812 t) | |
1813 (or (match-string-no-properties 2) | |
1814 (progn | |
1815 ;; move to EOL or before first left paren | |
1816 (if (re-search-forward "[(\n]" nil t) | |
1817 (progn (backward-char) | |
1818 (skip-chars-backward " \t")) | |
1819 (end-of-line)) | |
1820 ;; Use the name preceding that. | |
1821 (buffer-substring-no-properties (point) (progn (backward-sexp) | |
1822 (point))))) | |
1823 "main"))) | |
1824 | |
1792 (provide 'fortran) | 1825 (provide 'fortran) |
1793 | 1826 |
1794 ;;; fortran.el ends here | 1827 ;;; fortran.el ends here |