Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-31 Thread Lennart Borgman (gmail)

Juanma Barranquero wrote:

On 12/31/06, Lennart Borgman <[EMAIL PROTECTED]> wrote:


Would it perhaps be better to have default t on systems where file name
case does not matter?


You should've read the docstring...


Yes, or I should have just understood it probably had been made this way 
 ;-)




(defcustom auto-mode-case-fold nil
 "Non-nil means to try second pass through `auto-mode-alist'.
This means that if the first case-sensitive search through the alist 
fails

to find a matching major mode, a second case-insensitive search is made.
On systems with case-insensitive file names, this variable is ignored,
since only a single case-insensitive search through the alist is made."
 :group 'files
 :version "22.1"
 :type 'boolean) 




___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-31 Thread Juanma Barranquero

On 12/31/06, Lennart Borgman <[EMAIL PROTECTED]> wrote:


Would it perhaps be better to have default t on systems where file name
case does not matter?


You should've read the docstring...

(defcustom auto-mode-case-fold nil
 "Non-nil means to try second pass through `auto-mode-alist'.
This means that if the first case-sensitive search through the alist fails
to find a matching major mode, a second case-insensitive search is made.
On systems with case-insensitive file names, this variable is ignored,
since only a single case-insensitive search through the alist is made."
 :group 'files
 :version "22.1"
 :type 'boolean)

   /L/e/k/t/u


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-30 Thread Lennart Borgman

Kim F. Storm wrote:


Done.  The new option is called auto-mode-case-fold -- defaulting to nil.



Would it perhaps be better to have default t on systems where file name 
case does not matter?



___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-30 Thread Kim F. Storm
Stefan Monnier <[EMAIL PROTECTED]> writes:

>>> What was the conclusion on how to associate .PY files with python-mode?
>>> And what about .TXT files, .HTM files, .TAR files, and so on?
>>> 
>>> I think it is a mistake to do that, in general.
>>> I would not object to a user option to enable such matching,
>>> but it should not be enabled by default.
>
>> That is good news.  Thanks!
>> Stefan, can you modify your patch to include a user option.
>
> Feel free to go ahead and adapt my code.  I'm on-the-road, so it's
> bit inconvenient.

Done.  The new option is called auto-mode-case-fold -- defaulting to nil.

I updated NEWS and the Emacs Manual accordingly.

-- 
Kim F. Storm <[EMAIL PROTECTED]> http://www.cua.dk



___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-30 Thread Stefan Monnier
>> What was the conclusion on how to associate .PY files with python-mode?
>> And what about .TXT files, .HTM files, .TAR files, and so on?
>> 
>> I think it is a mistake to do that, in general.
>> I would not object to a user option to enable such matching,
>> but it should not be enabled by default.

> That is good news.  Thanks!
> Stefan, can you modify your patch to include a user option.

Feel free to go ahead and adapt my code.  I'm on-the-road, so it's
bit inconvenient.


Stefan


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-30 Thread Stefan Monnier
> What was the conclusion on how to associate .PY files with python-mode?
> And what about .TXT files, .HTM files, .TAR files, and so on?
> I think it is a mistake to do that, in general.

I'm still waiting for an explanation of this thought.
Can't you come up with one anecdotal/hypothetical case where it could be
potentially remotely harmful?


Stefan


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-30 Thread Kim F. Storm
Richard Stallman <[EMAIL PROTECTED]> writes:

> What was the conclusion on how to associate .PY files with python-mode?
> And what about .TXT files, .HTM files, .TAR files, and so on?
>
> I think it is a mistake to do that, in general.
> I would not object to a user option to enable such matching,
> but it should not be enabled by default.

That is good news.  Thanks!

Stefan, can you modify your patch to include a user option.

-- 
Kim F. Storm <[EMAIL PROTECTED]> http://www.cua.dk



___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-30 Thread Richard Stallman
What was the conclusion on how to associate .PY files with python-mode?
And what about .TXT files, .HTM files, .TAR files, and so on?

I think it is a mistake to do that, in general.
I would not object to a user option to enable such matching,
but it should not be enabled by default.


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-29 Thread Juanma Barranquero

On 12/29/06, Richard Stallman <[EMAIL PROTECTED]> wrote:


This change is ok.


OK, I've installed it.

Kim, you talked about auto-detecting only JPEG image files. If you
think it is better to do that right now (I really don't have an
opinion), just set the values of the other image types to nil in
`image-type-auto-detectable'.

Better names or docstrings for `image-type-auto-detectable' and
`image-type-auto-detected-p' very welcome.

And BTW, I still think Stefan's patch should be committed. No good
arguments for preferring fundamental-mode for .PY, .SH, etc. have been
exposed. Yeah, yeah, I know, that discussion is settled, etc.

   /L/e/k/t/u


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-29 Thread Kim F. Storm
Stefan Monnier <[EMAIL PROTECTED]> writes:

>> I am not going to approve this change.  It is basically not correct.
>
> It's still not clear to me why fundamental-mode is more correct than
> a major-mode derived from case-insensitive matching.  But I'll just wait
> a couple years and hope you'll see the light in the mean time,

What was the conclusion on how to associate .PY files with python-mode?

And what about .TXT files, .HTM files, .TAR files, and so on?

I have absolutely no idea why anybody can argue that it is more
correct to open these files in fundamental-mode than in the
"obviously" associated mode.

This is a genuine problem when reading files from eg. a CD-ROM written
in old-style 8.3 file names ...  and believe me, they do exist!

Too bad the lights went out :-|

-- 
Kim F. Storm <[EMAIL PROTECTED]> http://www.cua.dk



___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-29 Thread Stefan Monnier
> I am not going to approve this change.  It is basically not correct.

It's still not clear to me why fundamental-mode is more correct than
a major-mode derived from case-insensitive matching.  But I'll just wait
a couple years and hope you'll see the light in the mean time,


Stefan


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-29 Thread Richard Stallman
> I am not going to approve this change.  It is basically not correct.

Which one? The change for case-insensitive checking, or the other?

I was responding to the change for case-insensitive checking.


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-29 Thread Richard Stallman
It uses a separate `image-type-auto-detectable' alist (which makes
more sense IMO) and a new `image-type-auto-detected-p' function for
`magic-mode-alist'. (I'm not particularly fond of the names, BTW.)

This change is ok.


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-29 Thread Richard Stallman
>  - Adding `image-type-from-buffer' to `magic-mode-alist'. That's not
> good because there is one type of file (postscript) whose
> interpretation is ambiguous under that function. 

It isn't ambiguous.  This works correctly now.


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-28 Thread Juanma Barranquero

On 12/28/06, Richard Stallman <[EMAIL PROTECTED]> wrote:


I am not going to approve this change.  It is basically not correct.


Which one? The change for case-insensitive checking, or the other?

   /L/e/k/t/u


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-28 Thread Richard Stallman
I am not going to approve this change.  It is basically not correct.


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-28 Thread Juanma Barranquero

On 12/28/06, Kim F. Storm <[EMAIL PROTECTED]> wrote:


Sure, but if we had just added Stefan patch now, the rest of the patches
would not have been needed "before the release".


BTW, wasn't the approach in Stefan's patch more-or-less vetoed by
Richard (even if most of us find this fix good and non-intrusive)? Or
am I mixing things?

   /L/e/k/t/u


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-28 Thread Juanma Barranquero

On 12/28/06, Kim F. Storm <[EMAIL PROTECTED]> wrote:


Sure, but if we had just added Stefan patch now, the rest of the patches
would not have been needed "before the release".


Yes, of course. (BTW, I'm not particularly interested in this stuff,
or in getting it "in", just trying to be helpful.)


Correct, but we have not had reports of bad effects of the simpler regexp.


Right.


Ok. So we could detect _just_ JPEG via magic-mode-alist, supposing
that format is sufficiently different from anything else.


Well, I don't really know whether it is common to find other image
files with no descriptive file extension.


Agree ... for a _very limited set_ of image types, which cannot always
be detected by their file suffixes...


I don't necessarily disagree... but I'm not sure either than doing
such a specific fix is better than going the generic route (which is
dead easy, as shown in the patch I just sent). I'm ready to be
convinced otherwise, though.

   /L/e/k/t/u


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-28 Thread Kim F. Storm
"Juanma Barranquero" <[EMAIL PROTECTED]> writes:

> On 12/27/06, Kim F. Storm <[EMAIL PROTECTED]> wrote:
>
>> In contrast, the "recognize images by file contents" approach has already
>> required three rounds of bug-fixing ... and there's no guarantee that there
>> are not more "surprises"...
>
> Well, I think that's not entirely fair. Patches for that approach have
> conflated several different things:

Sure, but if we had just added Stefan patch now, the rest of the patches
would not have been needed "before the release".

That said, I agree that _some_ of the changes are good.
>
>  - The possibility of adding matcher functions to `magic-mode-alist'.
> That's good IMO.
Yes.

>
>  - Fixes to regexps in `image-type-header-regexps'. These are good
> too. "^P[1-6]" matching PBM files would be over-eager even if
> `image-type-from-buffer' were not added to `magic-mode-alist'.
Correct, but we have not had reports of bad effects of the simpler regexp.

>  - Adding `image-type-from-buffer' to `magic-mode-alist'. That's not
> good because there is one type of file (postscript) whose
> interpretation is ambiguous under that function. 

Yes, that is the part of this approach which I think is going in a
very bad direction ... trying to fix things in the wrong way.


>  The right approach
> would be to add to `magic-mode-alist' a function specifically designed
> to detect images; it should also take into account
> `image-type-available-p' (it never makes sense to identify a .ps file
> as an image on Windows, for example, as the Windows port does not
> support postscript images).

I agree!

>
> - Modifying `image-type-header-regexps' to support NOT-ALWAYS. Not
> good IMO because it adds interface complexity just to fix one case.

Precisely.  This is the part which should be reverted.

> Not entirely true. Someone noted that he wanted Emacs to autodetect
> JPEG thumb files that had no recognizable extension, for example.
> That's not fixed by Stefan's patch (which I think is good, BTW).

Ok. So we could detect _just_ JPEG via magic-mode-alist, supposing
that format is sufficiently different from anything else.

>
> I think a good approach would be to add Stefan patch, remove the
> NOT-ALWAYS stuff and fix `magic-mode-alist' to use a function
> specifically designed to detect image types.

Agree ... for a _very limited set_ of image types, which cannot always
be detected by their file suffixes...

-- 
Kim F. Storm <[EMAIL PROTECTED]> http://www.cua.dk



___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-28 Thread Juanma Barranquero

On 12/28/06, Juanma Barranquero <[EMAIL PROTECTED]> wrote:


I think a good approach would be to add Stefan patch, remove the
NOT-ALWAYS stuff and fix `magic-mode-alist' to use a function
specifically designed to detect image types.


(I should've said "to detect image files").

The following is an example patch which removes the NOT-ALWAYS stuff,
decoupling image autodetection from auto-determination of image-mode
for image files.

It uses a separate `image-type-auto-detectable' alist (which makes
more sense IMO) and a new `image-type-auto-detected-p' function for
`magic-mode-alist'. (I'm not particularly fond of the names, BTW.)

   /L/e/k/t/u



Index: lisp/files.el
===
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.870
diff -u -2 -r1.870 files.el
--- lisp/files.el   19 Dec 2006 09:04:30 -  1.870
+++ lisp/files.el   28 Dec 2006 11:27:20 -
@@ -2116,5 +2116,5 @@

 (defvar magic-mode-alist
-  `((image-type-from-buffer . image-mode)
+  `((image-type-auto-detected-p . image-mode)
;; The < comes before the groups (but the first) to reduce backtracking.
;; TODO: UTF-16 http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-27 Thread Juanma Barranquero

On 12/27/06, Kim F. Storm <[EMAIL PROTECTED]> wrote:


In contrast, the "recognize images by file contents" approach has already
required three rounds of bug-fixing ... and there's no guarantee that there
are not more "surprises"...


Well, I think that's not entirely fair. Patches for that approach have
conflated several different things:

 - The possibility of adding matcher functions to `magic-mode-alist'.
That's good IMO.

 - Fixes to regexps in `image-type-header-regexps'. These are good
too. "^P[1-6]" matching PBM files would be over-eager even if
`image-type-from-buffer' were not added to `magic-mode-alist'.

 - Adding `image-type-from-buffer' to `magic-mode-alist'. That's not
good because there is one type of file (postscript) whose
interpretation is ambiguous under that function. The right approach
would be to add to `magic-mode-alist' a function specifically designed
to detect images; it should also take into account
`image-type-available-p' (it never makes sense to identify a .ps file
as an image on Windows, for example, as the Windows port does not
support postscript images).

- Modifying `image-type-header-regexps' to support NOT-ALWAYS. Not
good IMO because it adds interface complexity just to fix one case.


I strongly support installing this, _and_ reverting the recent image-mode 
related
patches which would no longer be needed with this patch.


Not entirely true. Someone noted that he wanted Emacs to autodetect
JPEG thumb files that had no recognizable extension, for example.
That's not fixed by Stefan's patch (which I think is good, BTW).

I think a good approach would be to add Stefan patch, remove the
NOT-ALWAYS stuff and fix `magic-mode-alist' to use a function
specifically designed to detect image types.

   /L/e/k/t/u


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-27 Thread Kim F. Storm
Stefan Monnier <[EMAIL PROTECTED]> writes:

> It's at the very best a misfeature.  Far from a feature.
> See sample patch below to fix this problem.

This code is exactly what we need!

It is simple, localized, easy to document, and have no really severe
effects if it guesses wrong - as the worst effect of a wrong choice is
to not to enter fundamental-mode (which is usually pretty useless).

In contrast, the "recognize images by file contents" approach has already
required three rounds of bug-fixing ... and there's no guarantee that there
are not more "surprises"...

I strongly support installing this, _and_ reverting the recent image-mode 
related
patches which would no longer be needed with this patch.

>
>
> Stefan
>
>
> --- orig/lisp/files.el
> +++ mod/lisp/files.el
> @@ -2234,15 +2234,22 @@
> (setq name (file-name-sans-versions name))
> (while name
>   ;; Find first matching alist entry.
> - (let ((case-fold-search
> -(memq system-type '(vax-vms windows-nt cygwin
> -   (if (and (setq mode (assoc-default name auto-mode-alist
> -  'string-match))
> -(consp mode)
> -(cadr mode))
> -   (setq mode (car mode)
> - name (substring name 0 (match-beginning 0)))
> - (setq name)))
> +(if (and (setq mode
> +   (or (unless (memq system-type '(vax-vms 
> windows-nt cygwin))
> + ;; First match case-sensitively if the
> + ;; system is case-sensitive.
> + (let ((case-fold-search nil))
> +   (assoc-default name auto-mode-alist
> +  'string-match)))
> +   ;; Fallback to case-insensitive match.
> +   (let ((case-fold-search t))
> + (assoc-default name auto-mode-alist
> +'string-match
> + (consp mode)
> + (cadr mode))
> +(setq mode (car mode)
> +  name (substring name 0 (match-beginning 0)))
> +  (setq name))
>   (when mode
> (set-auto-mode-0 mode keep-mode-if-same)

-- 
Kim F. Storm <[EMAIL PROTECTED]> http://www.cua.dk



___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-27 Thread Stefan Monnier
>> I'm browsing some old Python sources on a CD, and they're all opening
>> in fundamental-mode instead of python-mode.
>> 
>> All the filenames on the CD are in uppercase.
>> 
>> Perhaps python-mode.el could be modified to recognise .PY files as
>> well as .py files as containing Python code?

> That's not a bug, that's a feature!  But you can work around it in your
> ~/.emacs:

> (setq auto-mode-alist
>   (cons '("\\.PY\\'" . python-mode) auto-mode-alist))

It's at the very best a misfeature.  Far from a feature.
See sample patch below to fix this problem.


Stefan


--- orig/lisp/files.el
+++ mod/lisp/files.el
@@ -2234,15 +2234,22 @@
  (setq name (file-name-sans-versions name))
  (while name
;; Find first matching alist entry.
-   (let ((case-fold-search
-  (memq system-type '(vax-vms windows-nt cygwin
- (if (and (setq mode (assoc-default name auto-mode-alist
-'string-match))
-  (consp mode)
-  (cadr mode))
- (setq mode (car mode)
-   name (substring name 0 (match-beginning 0)))
-   (setq name)))
+(if (and (setq mode
+   (or (unless (memq system-type '(vax-vms 
windows-nt cygwin))
+ ;; First match case-sensitively if the
+ ;; system is case-sensitive.
+ (let ((case-fold-search nil))
+   (assoc-default name auto-mode-alist
+  'string-match)))
+   ;; Fallback to case-insensitive match.
+   (let ((case-fold-search t))
+ (assoc-default name auto-mode-alist
+'string-match
+ (consp mode)
+ (cadr mode))
+(setq mode (car mode)
+  name (substring name 0 (match-beginning 0)))
+  (setq name))
(when mode
  (set-auto-mode-0 mode keep-mode-if-same)
 


___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug


Re: python-mode.el doesn't associate python-mode with .PY files

2006-12-26 Thread Kevin Rodgers

Chris Moore wrote:

I'm browsing some old Python sources on a CD, and they're all opening
in fundamental-mode instead of python-mode.

All the filenames on the CD are in uppercase.

Perhaps python-mode.el could be modified to recognise .PY files as
well as .py files as containing Python code?


That's not a bug, that's a feature!  But you can work around it in your
~/.emacs:

(setq auto-mode-alist
  (cons '("\\.PY\\'" . python-mode) auto-mode-alist))


I've not tried opening any Perl sources yet, but when I do I'll be
sure to check that they open with the correct mode.


--
Kevin Rodgers
Denver, Colorado, USA



___
emacs-pretest-bug mailing list
emacs-pretest-bug@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug