aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love2000-03-09 23:02:51 +0000
committerDave Love2000-03-09 23:02:51 +0000
commit68ca306cb534e802cae26ce2fd4c3f22c8901e1b (patch)
treef3a7b317f711fd4379b3334b015792e0a33b229b
parent852eeeafd2e84ea9badb85529de2bacda63ae99e (diff)
downloademacs-68ca306cb534e802cae26ce2fd4c3f22c8901e1b.tar.gz
emacs-68ca306cb534e802cae26ce2fd4c3f22c8901e1b.zip
(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.
-rw-r--r--lisp/progmodes/fortran.el133
1 files changed, 83 insertions, 50 deletions
diff --git a/lisp/progmodes/fortran.el b/lisp/progmodes/fortran.el
index d53268441f0..9ae439f192e 100644
--- a/lisp/progmodes/fortran.el
+++ b/lisp/progmodes/fortran.el
@@ -121,16 +121,20 @@ Fortran indentation plus `fortran-comment-line-extra-indent'."
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.
126You 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
@@ -264,7 +268,7 @@ format style.")
264 "`font-lock-syntactic-keywords' for Fortran. 268 "`font-lock-syntactic-keywords' for Fortran.
265These get fixed-format comments fontified.") 269These 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
@@ -363,6 +367,9 @@ These get fixed-format comments fontified.")
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)
@@ -423,12 +430,13 @@ These get fixed-format comments fontified.")
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)]
@@ -630,15 +638,10 @@ with no args, if that value is non-nil."
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)
@@ -671,6 +674,8 @@ with no args, if that value is non-nil."
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 ()
@@ -1714,43 +1719,45 @@ file before the end or the first `fortran-analyze-depth' lines."
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
1718Intended as the value of `fill-paragraph-function'." 1722Intended 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 ()
@@ -1789,6 +1796,32 @@ prefix arg DO-SPACE prevent stripping the whitespace."
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