help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: distinguish .h files


From: Andrea Crotti
Subject: Re: distinguish .h files
Date: Thu, 21 Oct 2010 16:47:59 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin)

Tassilo Horn <address@hidden> writes:

>
> It took me also some seconds to get the context again.  Oleksandr asked
> in some previous posting how near to the buffer start the match for
> (REGEX . MODE-FN) in magic-mode-alist has to occur.  The 4000 then
> either means that Oleksandr's test file was exactly 4000 characters in
> size (unlikely), or that the REGEXs (and MATCH-FNs) defined in
> magic-mode-alist are checked with a buffer narrowed to the first 4000
> characters (likely, *looking at the code*,..., confirmed!).
>
> So my match function won't do the trick if the first "class" occurence
> is after the first 4000 characters, maybe because of a long comment at
> the start.  I guess, that restriction is made for performance reasons.
> This one ignores the restriction and will even work if the first class
> is declared after gigabytes of introductory text:
>
> (defun th-c++-header-file-p ()
>   "Return non-nil, if in a C++ header."
>   (and (string-match "\\.h$"
>                    (or (buffer-file-name)
>                        (buffer-name)))
>        (save-excursion
>        (save-restriction
>          (widen)
>          (re-search-forward "\\_<class\\_>" nil t)))))
>
> (add-to-list 'magic-mode-alist
>            '(th-c++-header-file-p . c++-mode))
>
> Bye,
> Tassilo

Yes well but the limit is not so wrong.
I mean I prefer to manually (eventually because if I only read I don't
care so much) switch the mode instead of waiting 10 seconds for getting
the file open.

I don't know maybe it's very fast but I think that in general is correct...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]