f90 mode

  • Follow


Hi,
I have a line 
(setq auto-mode-alist (append auto-mode-alist
     (list '("\\.F\\'"  f90-mode "non-`nil'"))))
in my .emacs. It used to work OK with older emacs'es but I upgraded recently
and files with .F extension default to fortran f77 mode rather than to f90.
How to correct that?
Thanks,
Mark
0
Reply mm5fan 7/14/2004 6:36:07 PM

mp wrote:

> (setq auto-mode-alist (append auto-mode-alist
>      (list '("\\.F\\'"  f90-mode "non-`nil'"))))

That adds the entry to the *end* of auto-mode-alist, so it gets
over-ridden by the earlier (default) entry for .F, namely fortran
mode. Put your changes at the beginning. Also, I don't see why you
would want to use the third element (ie the "non-`nil'" bit) here. So
use:

(setq auto-mode-alist (append '(("\\.F\\'" . f90-mode)) auto-mode-alist))

Personally, I prefer add-to-list:

(add-to-list 'auto-mode-alist '("\\.F\\'" . f90-mode))
0
Reply Glenn 7/15/2004 11:12:50 AM


Glenn Morris wrote:

| mp wrote:
| 
| > (setq auto-mode-alist (append auto-mode-alist
| >      (list '("\\.F\\'"  f90-mode "non-`nil'"))))
| 
| That adds the entry to the *end* of auto-mode-alist, so it gets
| over-ridden by the earlier (default) entry for .F, namely fortran
| mode. Put your changes at the beginning. Also, I don't see why you
| would want to use the third element (ie the "non-`nil'" bit) here. So
| use:
| 
| (setq auto-mode-alist (append '(("\\.F\\'" . f90-mode)) auto-mode-alist))
| 
| Personally, I prefer add-to-list:
| 
| (add-to-list 'auto-mode-alist '("\\.F\\'" . f90-mode))

How would you do that with multiple mode specifications?  My knowledge
of lists is disappointingly poor.

I have:

(add-to-list 'auto-mode-alist
             '(("\\.c$"  . c-mode)
               ("\\.html$" . html-mode)))

However, as add-to-list accepts one element only, this is not a
solution.  I'd like to avoid having one call to add-to-list for each
file type, as there are quite a few.  I'd also like to avoid append.

-- 
SB

I am so smart, so smart - s-m-r-t!  I mean, s-m-A-r-t!
	         			- Homer Simpson
0
Reply s1726 7/17/2004 5:12:09 PM

Glenn Morris wrote:

| mp wrote:
| 
| > (setq auto-mode-alist (append auto-mode-alist
| >      (list '("\\.F\\'"  f90-mode "non-`nil'"))))
| 
| That adds the entry to the *end* of auto-mode-alist, so it gets
| over-ridden by the earlier (default) entry for .F, namely fortran
| mode. Put your changes at the beginning. Also, I don't see why you
| would want to use the third element (ie the "non-`nil'" bit) here. So
| use:
| 
| (setq auto-mode-alist (append '(("\\.F\\'" . f90-mode)) auto-mode-alist))
| 
| Personally, I prefer add-to-list:
| 
| (add-to-list 'auto-mode-alist '("\\.F\\'" . f90-mode))

How would you do that with multiple mode specifications?  My knowledge
of lists is disappointingly poor.

I have (example code shortened):

(add-to-list 'auto-mode-alist
             '(("\\.c$"  . c-mode)
               ("\\.html$" . html-mode)))

However, as add-to-list accepts one element only, this is not a
solution.  I'd like to avoid having one call to add-to-list for each
file type, as there are quite a few.  I'd also like to avoid append
for the reasons you mention.

-- 
SB

I am so smart, so smart - s-m-r-t!  I mean, s-m-A-r-t!
	         			- Homer Simpson
0
Reply s1726 7/17/2004 5:13:08 PM

s1726@ii.uib.no (Steinar B.ANxrmer) writes:
> (add-to-list 'auto-mode-alist
>              '(("\\.c$"  . c-mode)
>                ("\\.html$" . html-mode)))
>
> However, as add-to-list accepts one element only, this is not a
> solution.  I'd like to avoid having one call to add-to-list for each
> file type, as there are quite a few.  I'd also like to avoid append
> for the reasons you mention.

Just use append, but put your list as the first arg (rather than the
second arg as in your original example).  `append' will append its
arguments in the order they are given.

-Miles
-- 
Somebody has to do something, and it's just incredibly pathetic that it
has to be us.  -- Jerry Garcia
0
Reply Miles 7/17/2004 9:36:45 PM

Miles Bader wrote:

| s1726@ii.uib.no (Steinar B�rmer) writes:
|
| > I'd also like to avoid append
| 
| Just use append

Thank you.  I'm looking for a way to make this work _without_ append,
as I've already stated.  The reason I ask is partly to see if it's
at all possible to do this without append.

-- 
SB

I am so smart, so smart - s-m-r-t!  I mean, s-m-A-r-t!
	         			- Homer Simpson
0
Reply s1726 7/18/2004 10:13:55 AM

s1726@ii.uib.no (Steinar B.ANxrmer) writes:
> | > I'd also like to avoid append
> | 
> | Just use append
>
> Thank you.  I'm looking for a way to make this work _without_ append,
> as I've already stated.  The reason I ask is partly to see if it's
> at all possible to do this without append.

May I ask why?  Of course you _can_ do it without append, but frankly,
given your constraints, append is the perfect solution -- the only
problem with your original attempt was that you put the arguments in the
wrong order.

You could also just use add-to-list in a loop, of course:

  (dolist (entry '(("\.for$" . fortran-mode) ...))
    (add-to-list 'auto-mode-alist entry))

-Miles
-- 
Fast, small, soon; pick any 2.
0
Reply Miles 7/18/2004 12:36:44 PM

Miles Bader wrote:

| s1726@ii.uib.no (Steinar B�rmer) writes:
|
| > Thank you.  I'm looking for a way to make this work _without_
| > append, as I've already stated.  The reason I ask is partly to see
| > if it's at all possible to do this without append.
| 
| May I ask why?  Of course you _can_ do it without append, but
| frankly, given your constraints, append is the perfect solution --
| the only problem with your original attempt was that you put the
| arguments in the wrong order.

As noted in the post I replied to,

Message-ID: <fb1xjd34nh.fsf@xpc14.ast.cam.ac.uk>

appended items can sometimes be too far into the list, and therefore
could be ignored.

I'm trying to learn something about how lists work, too.  I truly
don't know if you can "prepend" a list to a list, and how.  I'd like
to see it, mostly for the reason stated above, but also for freedom of
choice.  If you can do this, why would that not be "the perfect
solution" for me?  What are the "constraints" that make it
less-than-ideal?
 
| You could also just use add-to-list in a loop, of course:
| 
|   (dolist (entry '(("\.for$" . fortran-mode) ...))
|     (add-to-list 'auto-mode-alist entry))

Looks good, but is looping a good idea in ~/.emacs?  Again, I'm trying
to learn the why, not only yes/no.  =)

-- 
SB

I am so smart, so smart - s-m-r-t!  I mean, s-m-A-r-t!
	         			- Homer Simpson
0
Reply s1726 7/18/2004 1:11:08 PM

s1726@ii.uib.no (Steinar B�rmer) writes:

> I'm trying to learn something about how lists work, too.  I truly
> don't know if you can "prepend" a list to a list, and how.

Given two lists L1 and L2, what is the difference between appending
L2 to L1 and prepending L1 to L2?

They are the same, therefore the append function is enough:
(append L1 L2) appends L2 to L1, and also prepends L1 to L2.

Kai
0
Reply Kai 7/18/2004 7:40:17 PM

Kai Grossjohann wrote:

| s1726@ii.uib.no (Steinar B�rmer) writes:
| 
| > I'm trying to learn something about how lists work, too.  I truly
| > don't know if you can "prepend" a list to a list, and how.
| 
| Given two lists L1 and L2, what is the difference between appending
| L2 to L1 and prepending L1 to L2?
|
| They are the same, therefore the append function is enough:
| (append L1 L2) appends L2 to L1, and also prepends L1 to L2.

I seem to be more like my .sig at the moment.  Vacation desperately
needed.  Serious thanks.

*sigh*

-- 
SB

I am so smart, so smart - s-m-r-t!  I mean, s-m-A-r-t!
	         			- Homer Simpson
0
Reply s1726 7/18/2004 8:06:15 PM

Miles Bader wrote:

| s1726@ii.uib.no (Steinar B�rmer) writes:
| > (add-to-list 'auto-mode-alist
| >              '(("\\.c$"  . c-mode)
| >                ("\\.html$" . html-mode)))
| 
| Just use append, but put your list as the first arg (rather than the
| second arg as in your original example).  `append' will append its
| arguments in the order they are given.

It seems to me that there is a problem with this approach.  My current
code is like this:


(add-to-list 'auto-mode-alist
             (append '(("\\.c\\'"  . c-mode)
                       ("\\.pl\\'" . perl-mode)
                       ("\\.html\\'" . html-mode))
                       ))


Since it's a list that's being added to auto-mode-alist, the first and
last elements of my addded list get an extra parenthesis at the start
and end, respectively, like this:


C-h v auto-mode-alist RET

Value:
((("\\.c\\'" . c-mode)
  ("\\.pl\\'" . perl-mode)
  ("\\.html\\'" . html-mode))
 ("\\.py\\'" . python-mode)
 ("\\.mixal\\'" . mixal-mode)

[...]


When finding a file with one of those two extensions (in this case
c-mode or html-mode), Emacs complains:

File mode specification error: (wrong-type-argument stringp ("\\.c$" . c-mode))

and the corresponding mode is not loaded.


So it seems that adding a list to auto-mode-alist isn't a good idea at
all?  Or is there something I'm missing in my code?

-- 
SB

I am so smart, so smart - s-m-r-t!  I mean, s-m-A-r-t!
	         			- Homer Simpson
0
Reply s1726 7/19/2004 10:41:20 AM

s1726@ii.uib.no (Steinar B�rmer) writes:

> (add-to-list 'auto-mode-alist
>              (append '(("\\.c\\'"  . c-mode)
>                        ("\\.pl\\'" . perl-mode)
>                        ("\\.html\\'" . html-mode))
>                        ))

Originally, you had something like this:

(setq auto-mode-alist (append NEWVALUE auto-mode-alist))

Change this to:

(setq auto-mode-alist (append auto-mode-alist NEWVALUE))

Kai
0
Reply Kai 7/19/2004 2:11:16 PM

Kai Grossjohann <kai@emptydomain.de> writes:

| s1726@ii.uib.no (Steinar B�rmer) writes:
| 
| > (add-to-list 'auto-mode-alist
| >              (append '(("\\.c\\'"  . c-mode)
| >                        ("\\.pl\\'" . perl-mode)
| >                        ("\\.html\\'" . html-mode))
| >                        ))
| 
| Originally, you had something like this:
| 
| (setq auto-mode-alist (append NEWVALUE auto-mode-alist))
| 
| Change this to:
| 
| (setq auto-mode-alist (append auto-mode-alist NEWVALUE))

OK, thanks.

I guess I was unclear; I thought it was obvious by now that I'm trying
to learn how to work with lists in general, not just how to make
auto-mode-alist work.  I guess it's not obvious.  Using setq, I have a
working setup.  I should have specified.

So, let me rephrase:


It seems to me that using add-to-list to add a whole list to
auto-mode-alist is a bad idea.

Any opinions on that?

-- 
SB

Horses are forbidden to eat fire hydrants in Marshalltown, Iowa, USA.
0
Reply s1726 7/20/2004 7:52:44 AM

s1726@ii.uib.no (Steinar B�rmer) writes:

> It seems to me that using add-to-list to add a whole list to
> auto-mode-alist is a bad idea.

This depends.  add-to-list will also check whether the to-be-added
element is already present.  If so, add-to-list is a no-op.

I think for some number of elements, Lisp code like the following is
pretty clear:

(add-to-list 'auto-mode-alist '("\\.c\\'" . my-c-mode))
(add-to-list 'auto-mode-alist '("\\.c\\+\\+\\'" . my-c++-mode))
(add-to-list 'auto-mode-alist '("\\.java\\'" . my-java-mode))

The above code has a simple structure and is easy to maintain.  Only
with lots of elements might this become too long to edit comfortably
and perhaps also too inefficient (due to the exhaustive list search
on every add-to-list statement).

When the list becomes long, then you might wish to do something
clever, but then you'll have to live with the consequences: to
maintain it, you need to be clever ;-)

Kai
0
Reply Kai 7/21/2004 1:14:41 PM

Kai Grossjohann <kai@emptydomain.de> writes:

> I think for some number of elements, Lisp code like the following is
> pretty clear:
>
> (add-to-list 'auto-mode-alist '("\\.c\\'" . my-c-mode))
> (add-to-list 'auto-mode-alist '("\\.c\\+\\+\\'" . my-c++-mode))
> (add-to-list 'auto-mode-alist '("\\.java\\'" . my-java-mode))

An alternative can be:

(setq auto-mode-alist
      (append           
          (list
              '("\\.dcl$" . dtd-mode)
          ...               ...            ...
              '("\\.c\\'" . my-c-mode)
              '("\\.c\\+\\+\\'" . my-c++-mode)
              '("\\.java\\'" . my-java-mode))
       auto-mode-alist))

Best regards,
  John

-- 
John Robot
0
Reply John 7/22/2004 8:32:37 AM

s1726@ii.uib.no (Steinar B�rmer) writes:

> Glenn Morris wrote:
> 
> | mp wrote:
> | 
> | > (setq auto-mode-alist (append auto-mode-alist
> | >      (list '("\\.F\\'"  f90-mode "non-`nil'"))))
> | 
> | That adds the entry to the *end* of auto-mode-alist, so it gets
> | over-ridden by the earlier (default) entry for .F, namely fortran
> | mode. Put your changes at the beginning. Also, I don't see why you
> | would want to use the third element (ie the "non-`nil'" bit) here. So
> | use:
> | 
> | (setq auto-mode-alist (append '(("\\.F\\'" . f90-mode)) auto-mode-alist))
> | 
> | Personally, I prefer add-to-list:
> | 
> | (add-to-list 'auto-mode-alist '("\\.F\\'" . f90-mode))
> 
> How would you do that with multiple mode specifications?  My knowledge
> of lists is disappointingly poor.
> 
> I have (example code shortened):
> 
> (add-to-list 'auto-mode-alist
>              '(("\\.c$"  . c-mode)
>                ("\\.html$" . html-mode)))
> 
> However, as add-to-list accepts one element only, this is not a
> solution.  I'd like to avoid having one call to add-to-list for each
> file type, as there are quite a few.  I'd also like to avoid append
> for the reasons you mention.

I have some macrology for this purpose.  Maybe I should have named it
"add-to-alist" instead of "set-assoc".  It redefines an existing
association or adds a new new if none exists previously.

This defeats stack like handling of alist where you can push a new
association on front to shadow another association and then when you
pop it off, the old one becomes active again.  Maybe I should just use
PUSH, make a delete first match for pop-alist, and then an operator
for removing shadowed associations if clean up is desired.

;;; .emacs configuration file
;; make assoc nicer
(defun get-assoc (alist key)
  "get associate from searching alist with key"
  (let ((match (assoc key alist)))
    (if match
	(cdr match)
	nil)))

;; group function
(eval-and-compile
  (defun group (source n)
    "make nested list grouping source by n"
    (when (zerop n) (error "zero length"))
    (labels ((rec (source acc)
		  (let ((rest (nthcdr n source)))
		    (if (consp rest)
			(rec rest (cons (subseq source 0 n) acc))
			(nreverse (cons source acc))))))
      (if source
	  (rec source nil)
	  nil))))

;; poor man's hash table
(defmacro set-one-assoc (alist key value)
  (let ((match (gensym)))
    `(let ((,match (assoc ,key ,alist)))
       (if ,match
	   (progn
	     (rplacd ,match ,value)
	     ,alist)
	   (setq ,alist (cons (cons ,key ,value) ,alist))))))

;; allow multiple associations at one time
(defmacro set-assoc (alist &rest implicit-pairs)
  `(progn
    ,@(mapcar (lambda (pair)
		`(set-one-assoc ,alist ,@pair))
	      (group implicit-pairs 2))))



;;;--- example
(set-assoc auto-mode-alist
           "\\.c$" c-mode
           "\\.html$" html-mode)

-- 
Johan KULLSTAM <kullstj-nn@comcast.net> sysengr
0
Reply Johan 7/23/2004 2:38:02 PM

15 Replies
210 Views

(page loaded in 0.137 seconds)

Similiar Articles:


















7/22/2012 4:02:49 AM


Reply: