Created
August 8, 2016 20:15
-
-
Save t-bltg/f6fad93057ef12042457126564bd1080 to your computer and use it in GitHub Desktop.
Emacs fortran formatting script, according to emacs/lisp/progmodes/f90.el
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun f90-batch-indent-region () | |
"Run `f90-batch-beatify-region' on the specified filename. | |
Use this from the command line, with `-batch'; | |
it won't work in an interactive Emacs. | |
For example, invoke \"emacs -batch -l ~/.emacs-batch-f90-indent -f f90-batch-indent-region file.f\"" | |
(if (not noninteractive) | |
(error "`f90-batch-indent-region' is to be used only with -batch")) | |
(let ((make-backup-files nil) | |
(version-control nil) | |
(auto-save-default nil) | |
(find-file-run-dired nil) | |
(kept-old-versions 259259) | |
(kept-new-versions 259259)) | |
(let ((error 0) | |
file | |
(files ())) | |
(while command-line-args-left | |
(setq file (expand-file-name (car command-line-args-left))) | |
(cond ((not (file-exists-p file)) | |
(message ">> %s does not exist!" file) | |
(setq error 1 | |
command-line-args-left (cdr command-line-args-left))) | |
((file-directory-p file) | |
(setq command-line-args-left | |
(nconc (directory-files file) | |
(cdr command-line-args-left)))) | |
(t | |
(setq files (cons file files) | |
command-line-args-left (cdr command-line-args-left))))) | |
(while files | |
(setq file (car files) | |
files (cdr files)) | |
(condition-case err | |
(progn | |
(add-hook 'f90-mode-hook | |
;; These are the default values. | |
(lambda () (setq f90-do-indent 2 | |
f90-if-indent 2 | |
f90-type-indent 2 | |
f90-program-indent 2 | |
f90-continuation-indent 4 | |
f90-comment-region "!!$" | |
f90-directive-comment-re "!hpf\\$" | |
f90-indented-comment-re "!" | |
f90-break-delimiters "[-+\\*/><=,% \t]" | |
f90-break-before-delimiters t | |
f90-beginning-ampersand t | |
f90-smart-end 'blink | |
f90-auto-keyword-case nil | |
f90-leave-line-no nil | |
indent-tabs-mode nil | |
f90-font-lock-keywords f90-font-lock-keywords-2 | |
) | |
;; These are not default. | |
(abbrev-mode 1) ; turn on abbreviation mode | |
(f90-add-imenu-menu) ; extra menu with functions etc. | |
(if f90-auto-keyword-case ; change case of all keywords on startup | |
(f90-change-keywords f90-auto-keyword-case))) | |
) | |
; end customization | |
(if buffer-file-name (kill-buffer (current-buffer))) | |
(find-file file) | |
(buffer-disable-undo (current-buffer)) | |
(set-buffer-modified-p nil) | |
(f90-mode) | |
(message (file-name-nondirectory buffer-file-name)) | |
; compute indentation of first | |
; line | |
(f90-indent-subprogram) | |
; (f90-upcase-keywords) | |
(f90-downcase-keywords) | |
(save-buffer) | |
)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment