486 |
"Keymap used in Fortran mode.") |
"Keymap used in Fortran mode.") |
487 |
|
|
488 |
(defvar fortran-mode-abbrev-table |
(defvar fortran-mode-abbrev-table |
489 |
(let ((ac abbrevs-changed)) |
(let (abbrevs-changed) |
490 |
(define-abbrev-table 'fortran-mode-abbrev-table ()) |
(define-abbrev-table 'fortran-mode-abbrev-table nil) |
491 |
(define-abbrev fortran-mode-abbrev-table ";au" "automatic" nil 0 t) |
;; Use the 6th arg (SYSTEM-FLAG) of define-abbrev if possible. |
492 |
(define-abbrev fortran-mode-abbrev-table ";b" "byte" nil 0 t) |
;; Only use `apply' to quieten the byte-compiler. |
493 |
(define-abbrev fortran-mode-abbrev-table ";bd" "block data" nil 0 t) |
(mapcar |
494 |
(define-abbrev fortran-mode-abbrev-table ";ch" "character" nil 0 t) |
(function (lambda (element) |
495 |
(define-abbrev fortran-mode-abbrev-table ";cl" "close" nil 0 t) |
(condition-case nil |
496 |
(define-abbrev fortran-mode-abbrev-table ";c" "continue" nil 0 t) |
(apply 'define-abbrev fortran-mode-abbrev-table |
497 |
(define-abbrev fortran-mode-abbrev-table ";cm" "common" nil 0 t) |
(append element '(nil 0 t))) |
498 |
(define-abbrev fortran-mode-abbrev-table ";cx" "complex" nil 0 t) |
(wrong-number-of-arguments |
499 |
(define-abbrev fortran-mode-abbrev-table ";df" "define" nil 0 t) |
(apply 'define-abbrev fortran-mode-abbrev-table |
500 |
(define-abbrev fortran-mode-abbrev-table ";di" "dimension" nil 0 t) |
(append element '(nil 0))))))) |
501 |
(define-abbrev fortran-mode-abbrev-table ";do" "double" nil 0 t) |
'((";au" "automatic" ) |
502 |
(define-abbrev fortran-mode-abbrev-table ";dc" "double complex" nil 0 t) |
(";b" "byte" ) |
503 |
(define-abbrev fortran-mode-abbrev-table ";dp" "double precision" nil 0 t) |
(";bd" "block data" ) |
504 |
(define-abbrev fortran-mode-abbrev-table ";dw" "do while" nil 0 t) |
(";ch" "character" ) |
505 |
(define-abbrev fortran-mode-abbrev-table ";e" "else" nil 0 t) |
(";cl" "close" ) |
506 |
(define-abbrev fortran-mode-abbrev-table ";ed" "enddo" nil 0 t) |
(";c" "continue" ) |
507 |
(define-abbrev fortran-mode-abbrev-table ";el" "elseif" nil 0 t) |
(";cm" "common" ) |
508 |
(define-abbrev fortran-mode-abbrev-table ";en" "endif" nil 0 t) |
(";cx" "complex" ) |
509 |
(define-abbrev fortran-mode-abbrev-table ";eq" "equivalence" nil 0 t) |
(";df" "define" ) |
510 |
(define-abbrev fortran-mode-abbrev-table ";ew" "endwhere" nil 0 t) |
(";di" "dimension" ) |
511 |
(define-abbrev fortran-mode-abbrev-table ";ex" "external" nil 0 t) |
(";do" "double" ) |
512 |
(define-abbrev fortran-mode-abbrev-table ";ey" "entry" nil 0 t) |
(";dc" "double complex" ) |
513 |
(define-abbrev fortran-mode-abbrev-table ";f" "format" nil 0 t) |
(";dp" "double precision" ) |
514 |
(define-abbrev fortran-mode-abbrev-table ";fa" ".false." nil 0 t) |
(";dw" "do while" ) |
515 |
(define-abbrev fortran-mode-abbrev-table ";fu" "function" nil 0 t) |
(";e" "else" ) |
516 |
(define-abbrev fortran-mode-abbrev-table ";g" "goto" nil 0 t) |
(";ed" "enddo" ) |
517 |
(define-abbrev fortran-mode-abbrev-table ";im" "implicit" nil 0 t) |
(";el" "elseif" ) |
518 |
(define-abbrev fortran-mode-abbrev-table ";ib" "implicit byte" nil 0 t) |
(";en" "endif" ) |
519 |
(define-abbrev fortran-mode-abbrev-table ";ic" "implicit complex" nil 0 t) |
(";eq" "equivalence" ) |
520 |
(define-abbrev fortran-mode-abbrev-table ";ich" "implicit character" nil 0 t) |
(";ew" "endwhere" ) |
521 |
(define-abbrev fortran-mode-abbrev-table ";ii" "implicit integer" nil 0 t) |
(";ex" "external" ) |
522 |
(define-abbrev fortran-mode-abbrev-table ";il" "implicit logical" nil 0 t) |
(";ey" "entry" ) |
523 |
(define-abbrev fortran-mode-abbrev-table ";ir" "implicit real" nil 0 t) |
(";f" "format" ) |
524 |
(define-abbrev fortran-mode-abbrev-table ";inc" "include" nil 0 t) |
(";fa" ".false." ) |
525 |
(define-abbrev fortran-mode-abbrev-table ";in" "integer" nil 0 t) |
(";fu" "function" ) |
526 |
(define-abbrev fortran-mode-abbrev-table ";intr" "intrinsic" nil 0 t) |
(";g" "goto" ) |
527 |
(define-abbrev fortran-mode-abbrev-table ";l" "logical" nil 0 t) |
(";im" "implicit" ) |
528 |
(define-abbrev fortran-mode-abbrev-table ";n" "namelist" nil 0 t) |
(";ib" "implicit byte" ) |
529 |
(define-abbrev fortran-mode-abbrev-table ";o" "open" nil 0 t) ; was ;op |
(";ic" "implicit complex" ) |
530 |
(define-abbrev fortran-mode-abbrev-table ";pa" "parameter" nil 0 t) |
(";ich" "implicit character") |
531 |
(define-abbrev fortran-mode-abbrev-table ";pr" "program" nil 0 t) |
(";ii" "implicit integer" ) |
532 |
(define-abbrev fortran-mode-abbrev-table ";ps" "pause" nil 0 t) |
(";il" "implicit logical" ) |
533 |
(define-abbrev fortran-mode-abbrev-table ";p" "print" nil 0 t) |
(";ir" "implicit real" ) |
534 |
(define-abbrev fortran-mode-abbrev-table ";rc" "record" nil 0 t) |
(";inc" "include" ) |
535 |
(define-abbrev fortran-mode-abbrev-table ";re" "real" nil 0 t) |
(";in" "integer" ) |
536 |
(define-abbrev fortran-mode-abbrev-table ";r" "read" nil 0 t) |
(";intr" "intrinsic" ) |
537 |
(define-abbrev fortran-mode-abbrev-table ";rt" "return" nil 0 t) |
(";l" "logical" ) |
538 |
(define-abbrev fortran-mode-abbrev-table ";rw" "rewind" nil 0 t) |
(";n" "namelist" ) |
539 |
(define-abbrev fortran-mode-abbrev-table ";s" "stop" nil 0 t) |
(";o" "open" ) ; was ;op |
540 |
(define-abbrev fortran-mode-abbrev-table ";sa" "save" nil 0 t) |
(";pa" "parameter" ) |
541 |
(define-abbrev fortran-mode-abbrev-table ";st" "structure" nil 0 t) |
(";pr" "program" ) |
542 |
(define-abbrev fortran-mode-abbrev-table ";sc" "static" nil 0 t) |
(";ps" "pause" ) |
543 |
(define-abbrev fortran-mode-abbrev-table ";su" "subroutine" nil 0 t) |
(";p" "print" ) |
544 |
(define-abbrev fortran-mode-abbrev-table ";tr" ".true." nil 0 t) |
(";rc" "record" ) |
545 |
(define-abbrev fortran-mode-abbrev-table ";ty" "type" nil 0 t) |
(";re" "real" ) |
546 |
(define-abbrev fortran-mode-abbrev-table ";vo" "volatile" nil 0 t) |
(";r" "read" ) |
547 |
(define-abbrev fortran-mode-abbrev-table ";w" "write" nil 0 t) |
(";rt" "return" ) |
548 |
(define-abbrev fortran-mode-abbrev-table ";wh" "where" nil 0 t) |
(";rw" "rewind" ) |
549 |
(setq abbrevs-changed ac) |
(";s" "stop" ) |
550 |
|
(";sa" "save" ) |
551 |
|
(";st" "structure" ) |
552 |
|
(";sc" "static" ) |
553 |
|
(";su" "subroutine" ) |
554 |
|
(";tr" ".true." ) |
555 |
|
(";ty" "type" ) |
556 |
|
(";vo" "volatile" ) |
557 |
|
(";w" "write" ) |
558 |
|
(";wh" "where" ))) |
559 |
fortran-mode-abbrev-table)) |
fortran-mode-abbrev-table)) |
560 |
|
|
561 |
(eval-when-compile ; silence compiler |
(eval-when-compile ; silence compiler |
664 |
;; (concat "\\(\\)\\(![ \t]*\\|" fortran-comment-line-start-skip "\\)") |
;; (concat "\\(\\)\\(![ \t]*\\|" fortran-comment-line-start-skip "\\)") |
665 |
"\\(\\)\\(?:^[CcDd*]\\|!\\)\\(?:\\([^ \t\n]\\)\\2+\\)?[ \t]*") |
"\\(\\)\\(?:^[CcDd*]\\|!\\)\\(?:\\([^ \t\n]\\)\\2+\\)?[ \t]*") |
666 |
(set (make-local-variable 'comment-padding) "$$$") |
(set (make-local-variable 'comment-padding) "$$$") |
667 |
(make-local-variable 'comment-start) |
(set (make-local-variable 'comment-start) fortran-comment-line-start) |
668 |
(setq comment-start fortran-comment-line-start) |
;; The syntax tables don't understand the column-0 comment-markers. |
669 |
|
(set (make-local-variable 'comment-use-syntax) nil) |
670 |
(make-local-variable 'require-final-newline) |
(make-local-variable 'require-final-newline) |
671 |
(setq require-final-newline t) |
(setq require-final-newline t) |
672 |
(make-local-variable 'abbrev-all-caps) |
(make-local-variable 'abbrev-all-caps) |
1114 |
|
|
1115 |
(defun fortran-beginning-do () |
(defun fortran-beginning-do () |
1116 |
"Search backwards for first unmatched DO [WHILE]. |
"Search backwards for first unmatched DO [WHILE]. |
1117 |
Return point or nil." |
Return point or nil. Ignores labelled DO loops (ie DO 10 ... 10 CONTINUE)." |
1118 |
(let ((case-fold-search t)) |
(let ((case-fold-search t) |
1119 |
|
(dostart-re "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+[^0-9]")) |
1120 |
(if (save-excursion |
(if (save-excursion |
1121 |
(beginning-of-line) |
(beginning-of-line) |
1122 |
(skip-chars-forward " \t0-9") |
(skip-chars-forward " \t0-9") |
1123 |
(looking-at "\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+")) |
(looking-at dostart-re)) |
1124 |
;; Sitting on one. |
;; Sitting on one. |
1125 |
(match-beginning 0) |
(match-beginning 0) |
1126 |
;; Search for one. |
;; Search for one. |
1132 |
(not (and (looking-at fortran-end-prog-re) |
(not (and (looking-at fortran-end-prog-re) |
1133 |
(fortran-check-end-prog-re)))) |
(fortran-check-end-prog-re)))) |
1134 |
(skip-chars-forward " \t0-9") |
(skip-chars-forward " \t0-9") |
1135 |
(cond ((looking-at |
(cond ((looking-at dostart-re) |
|
"\\(\\(\\sw\\|\\s_\\)+:[ \t]*\\)?do[ \t]+") |
|
1136 |
(setq count (1- count))) |
(setq count (1- count))) |
1137 |
|
;; Note labelled loop ends not considered. |
1138 |
((looking-at "end[ \t]*do\\b") |
((looking-at "end[ \t]*do\\b") |
1139 |
(setq count (1+ count))))) |
(setq count (1+ count))))) |
1140 |
(and (= count 0) |
(and (= count 0) |
1682 |
;; don't prevent a break. |
;; don't prevent a break. |
1683 |
(when (and (save-excursion |
(when (and (save-excursion |
1684 |
(beginning-of-line) |
(beginning-of-line) |
1685 |
(when (fortran-find-comment-start-skip) |
(if (not (fortran-find-comment-start-skip)) |
1686 |
|
t |
1687 |
(goto-char (match-beginning 0)) |
(goto-char (match-beginning 0)) |
1688 |
(>= (point) fill-point))) |
(>= (point) fill-point))) |
1689 |
(save-excursion |
(save-excursion |
1755 |
"Fill surrounding comment block as paragraphs, else fill statement. |
"Fill surrounding comment block as paragraphs, else fill statement. |
1756 |
Intended as the value of `fill-paragraph-function'." |
Intended as the value of `fill-paragraph-function'." |
1757 |
(interactive "P") |
(interactive "P") |
1758 |
(save-excursion |
(or (fill-comment-paragraph justify) |
1759 |
(beginning-of-line) |
(fortran-fill-statement) |
1760 |
(if (not (looking-at fortran-comment-line-start-skip)) |
t)) |
|
(fortran-fill-statement) |
|
|
;; We're in a comment block. Find the start and end of a |
|
|
;; paragraph, delimited either by non-comment lines or empty |
|
|
;; comments. (Get positions as markers, since the |
|
|
;; `indent-region' below can shift the block's end). |
|
|
(let* ((non-empty-comment |
|
|
(concat fortran-comment-line-start-skip "[^ \t\n]")) |
|
|
(start (save-excursion |
|
|
;; Find (start of) first line. |
|
|
(while (and (zerop (forward-line -1)) |
|
|
(looking-at non-empty-comment))) |
|
|
(or (looking-at non-empty-comment) |
|
|
(forward-line)) ; overshot |
|
|
(point-marker))) |
|
|
(end (save-excursion |
|
|
;; Find start of first line past region to fill. |
|
|
(while (progn |
|
|
(forward-line) |
|
|
(looking-at non-empty-comment))) |
|
|
(point-marker)))) |
|
|
;; Indent the block, find the string comprising the effective |
|
|
;; comment start skip and use that as a fill-prefix for |
|
|
;; filling the region. |
|
|
(indent-region start end nil) |
|
|
(let ((paragraph-ignore-fill-prefix nil) |
|
|
(fill-prefix (progn |
|
|
(beginning-of-line) |
|
|
(looking-at fortran-comment-line-start-skip) |
|
|
(match-string 0)))) |
|
|
(let (fill-paragraph-function) |
|
|
(fill-region start end justify))) ; with normal `fill-paragraph' |
|
|
(set-marker start nil) |
|
|
(set-marker end nil)))) |
|
|
t) |
|
1761 |
|
|
1762 |
(defun fortran-fill-statement () |
(defun fortran-fill-statement () |
1763 |
"Fill a fortran statement up to `fill-column'." |
"Fill a fortran statement up to `fill-column'." |
1798 |
;; for it. |
;; for it. |
1799 |
(defun fortran-current-defun () |
(defun fortran-current-defun () |
1800 |
"Function to use for `add-log-current-defun-function' in Fortran mode." |
"Function to use for `add-log-current-defun-function' in Fortran mode." |
1801 |
;; We must be inside function body for this to work. |
(save-excursion |
1802 |
(fortran-beginning-of-subprogram) |
;; We must be inside function body for this to work. |
1803 |
(let ((case-fold-search t)) ; case-insensitive |
(fortran-beginning-of-subprogram) |
1804 |
;; search for fortran subprogram start |
(let ((case-fold-search t)) ; case-insensitive |
1805 |
(if (re-search-forward |
;; search for fortran subprogram start |
1806 |
(concat "^[ \t]*\\(program\\|subroutine\\|function" |
(if (re-search-forward |
1807 |
"\\|[ \ta-z0-9*()]*[ \t]+function\\|" |
(concat "^[ \t]*\\(program\\|subroutine\\|function" |
1808 |
"\\(block[ \t]*data\\)\\)") |
"\\|[ \ta-z0-9*()]*[ \t]+function\\|" |
1809 |
(save-excursion (fortran-end-of-subprogram) |
"\\(block[ \t]*data\\)\\)") |
1810 |
(point)) |
(save-excursion (fortran-end-of-subprogram) |
1811 |
t) |
(point)) |
1812 |
(or (match-string-no-properties 2) |
t) |
1813 |
(progn |
(or (match-string-no-properties 2) |
1814 |
;; move to EOL or before first left paren |
(progn |
1815 |
(if (re-search-forward "[(\n]" nil t) |
;; move to EOL or before first left paren |
1816 |
(progn (backward-char) |
(if (re-search-forward "[(\n]" nil t) |
1817 |
(skip-chars-backward " \t")) |
(progn (backward-char) |
1818 |
(end-of-line)) |
(skip-chars-backward " \t")) |
1819 |
;; Use the name preceding that. |
(end-of-line)) |
1820 |
(buffer-substring-no-properties (point) (progn (backward-sexp) |
;; Use the name preceding that. |
1821 |
(point))))) |
(buffer-substring-no-properties (point) (progn (backward-sexp) |
1822 |
"main"))) |
(point))))) |
1823 |
|
"main")))) |
1824 |
|
|
1825 |
(provide 'fortran) |
(provide 'fortran) |
1826 |
|
|