color coding comment in f90-mode using "c" [SOLVED]
color coding comment in f90-mode using "c" [SOLVED]
Hi guys,
I am rather new to lisp, and I hope you will forgive me ignorance.
I have been a emacs user for a while now, and recently I converted a program from f77 to f90.
Here is the problem: if I use fortran-mode, all what is past the 72 columns is commented out, which is ugly to work with. On the other hand, I have a bunch of comments starting with "c" on the first column that were left from the f77 version, and if I use f90-mode they are not displayed as comment, which is also ugly to work with.
If there a way I can tell f90-mode to color-code "comment" all the lines that have a "c" on the first column?
Thanks,
Efo
I am rather new to lisp, and I hope you will forgive me ignorance.
I have been a emacs user for a while now, and recently I converted a program from f77 to f90.
Here is the problem: if I use fortran-mode, all what is past the 72 columns is commented out, which is ugly to work with. On the other hand, I have a bunch of comments starting with "c" on the first column that were left from the f77 version, and if I use f90-mode they are not displayed as comment, which is also ugly to work with.
If there a way I can tell f90-mode to color-code "comment" all the lines that have a "c" on the first column?
Thanks,
Efo
Last edited by Efo on Wed Apr 14, 2010 5:19 pm, edited 1 time in total.
Re: color coding comment in f90-mode using "c"
As I look at fortran.el, the F77 comment syntax is implemented as hack, as Emacs doesn't really support positional syntax. The correct thing to do would be to replace all old syntax comments with new, with for example M-x query replace<RET>^c<RET>!<RET> . The less correct thing to do is add to .emacs:
which seems to work, but I don't guarantee anything.
Code: Select all
(add-hook f90-mode-hook
(lambda ()
(set (make-local-variable 'font-lock-syntactic-keywords)
(fortran-font-lock-syntactic-keywords))))
Re: color coding comment in f90-mode using "c"
Hi Ramarren,
Thank you for the prompt response.
The first solution seems to be a little cumbersome given the different files and lines of code... but I guess I could do that as I go, even though I am not sure if other people using subversion are going to like that.
I suppose the "^" indicates the first line, I tried it and I get "Replaced 0 occurences"
The second, less correct, solution seems to fit me better (I put it into .emac), but I get:
͂͂
Warning (initialization): An error occurred while loading `/home/efo/.emacs':
Symbol's value as variable is void: f90-mode-hook
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
With --debug-init:
Debugger entered--Lisp error: (void-variable f90-mode-hook)
(add-hook f90-mode-hook (lambda nil (set ... ...)))
eval-buffer(#<buffer *load*> nil "/home/efo/.emacs" nil t) ; Reading at buffer position 7334
load-with-code-conversion("/home/efo/.emacs" "/home/efo/.emacs" t t)
load("~/.emacs" t t)
#[nil …´
*** bunch of symbols dont paste correctly such as "^H\205\264\^@" displayed as "‰" ***
#))‡" [init-file-user system-type user-init-file-1 user-init-file otherfile source ms-dos "~" "/_emacs" windows-nt directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" "~/_emacs" "/.emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default" alt inhibit-default-init inhibit-startup-screen] 7]()
command-line()
normal-top-level()
Am I missing some package?
Thanks again.
Efo
Thank you for the prompt response.
The first solution seems to be a little cumbersome given the different files and lines of code... but I guess I could do that as I go, even though I am not sure if other people using subversion are going to like that.
I suppose the "^" indicates the first line, I tried it and I get "Replaced 0 occurences"
The second, less correct, solution seems to fit me better (I put it into .emac), but I get:
͂͂
Warning (initialization): An error occurred while loading `/home/efo/.emacs':
Symbol's value as variable is void: f90-mode-hook
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
With --debug-init:
Debugger entered--Lisp error: (void-variable f90-mode-hook)
(add-hook f90-mode-hook (lambda nil (set ... ...)))
eval-buffer(#<buffer *load*> nil "/home/efo/.emacs" nil t) ; Reading at buffer position 7334
load-with-code-conversion("/home/efo/.emacs" "/home/efo/.emacs" t t)
load("~/.emacs" t t)
#[nil …´
*** bunch of symbols dont paste correctly such as "^H\205\264\^@" displayed as "‰" ***
#))‡" [init-file-user system-type user-init-file-1 user-init-file otherfile source ms-dos "~" "/_emacs" windows-nt directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" "~/_emacs" "/.emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default" alt inhibit-default-init inhibit-startup-screen] 7]()
command-line()
normal-top-level()
Am I missing some package?
Thanks again.
Efo
Re: color coding comment in f90-mode using "c"
You could use findr which can do query-replace recursively in a directory.Efo wrote:The first solution seems to be a little cumbersome given the different files and lines of code... but I guess I could do that as I go, even though I am not sure if other people using subversion are going to like that.
Sorry, I meant query-replace-regexp as a command. "^" means beginning of line. You could also use just replace-regexp, but I suppose confirming the changes would be better in this case.Efo wrote:I suppose the "^" indicates the first line, I tried it and I get "Replaced 0 occurences"
You have to (require 'f90) first, or use:Efo wrote:The second, less correct, solution seems to fit me better (I put it into .emac), but I get:
Code: Select all
(eval-after-load "f90"
(add-hook f90-mode-hook
(lambda ()
(set (make-local-variable 'font-lock-syntactic-keywords)
(fortran-font-lock-syntactic-keywords)))))
Re: color coding comment in f90-mode using "c"
Thanks Ramarren,
I meant "^" first column (or beginning of line), not line... it was late at night
Anyway, query-replace-regexp worked. But I still have the problem that the code is shared by different developers, and I dont want to mess the comments up for a color coding problem.
I tried the new piece of code you provided, but Istill get:
Debugger entered--Lisp error: (void-variable f90-mode-hook)
(add-hook f90-mode-hook (lambda nil (set ... ...)))
(eval-after-load "f90" (add-hook f90-mode-hook (lambda nil ...)))
eval-buffer(#<buffer *load*> nil "/home/efo/.emacs" nil t) ; Reading at buffer position 7366
load-with-code-conversion("/home/efo/.emacs" "/home/efo/.emacs" t t)
load("~/.emacs" t t)
#[nil
....
" [init-file-user system-type user-init-file-1 user-init-file otherfile source ms-dos "~" "/_emacs" windows-nt directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" "~/_emacs" "/.emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default" alt inhibit-default-init inhibit-startup-screen] 7]()
command-line()
normal-top-level()
I meant "^" first column (or beginning of line), not line... it was late at night

Anyway, query-replace-regexp worked. But I still have the problem that the code is shared by different developers, and I dont want to mess the comments up for a color coding problem.
I tried the new piece of code you provided, but Istill get:
Debugger entered--Lisp error: (void-variable f90-mode-hook)
(add-hook f90-mode-hook (lambda nil (set ... ...)))
(eval-after-load "f90" (add-hook f90-mode-hook (lambda nil ...)))
eval-buffer(#<buffer *load*> nil "/home/efo/.emacs" nil t) ; Reading at buffer position 7366
load-with-code-conversion("/home/efo/.emacs" "/home/efo/.emacs" t t)
load("~/.emacs" t t)
#[nil
....
" [init-file-user system-type user-init-file-1 user-init-file otherfile source ms-dos "~" "/_emacs" windows-nt directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" "~/_emacs" "/.emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default" alt inhibit-default-init inhibit-startup-screen] 7]()
command-line()
normal-top-level()
Re: color coding comment in f90-mode using "c"
Sorry again, I am not that used to Emacs Lisp and keep doing mistakes... you have to quote the form. Hopefully this works, I haven't really understood syntax highlighting in Emacs.Efo wrote:I tried the new piece of code you provided, but Istill get:
Code: Select all
(eval-after-load "f90"
'(add-hook f90-mode-hook
(lambda ()
(set (make-local-variable 'font-lock-syntactic-keywords)
(fortran-font-lock-syntactic-keywords)))))
Re: color coding comment in f90-mode using "c"
No problem, you are much more knowledgeable than I am, and I certainly appreciate your help.
No errors with the new code, but now the f90 file has none of its color coding. If I M-x f90-mode, then I am back to the original problem (i.e. color coding ok except for comments starting with "c").
No errors with the new code, but now the f90 file has none of its color coding. If I M-x f90-mode, then I am back to the original problem (i.e. color coding ok except for comments starting with "c").
Re: color coding comment in f90-mode using "c"
This is getting embarrassing... well, testing this properly requires restarting Emacs, since when I tested that before I already had loaded most of the modules, and I tested only the inner form so I got quoting wrong when wrapping. Anyway, what I just tested and hopefully will work this time:
Code: Select all
(eval-after-load "f90"
'(progn
(require 'fortran)
(add-hook 'f90-mode-hook
'(lambda ()
(set (make-local-variable 'font-lock-syntactic-keywords)
(fortran-font-lock-syntactic-keywords))))))
Re: color coding comment in f90-mode using "c"
Now I have color-coding back, but it looks like I am in fortran-mode. Everything past the 72nd column is commented.
Re: color coding comment in f90-mode using "c"
I should probably give up, since obviously I have a rather vague idea of what I am doing, but...
Code: Select all
(eval-after-load "f90"
'(progn
(add-hook 'f90-mode-hook
'(lambda ()
(set (make-local-variable 'font-lock-syntactic-keywords)
'(("^[cd\\*]" 0 (11))))))))