[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: latexenc-find-file-coding-system is slow.
From: |
Lute Kamstra |
Subject: |
Re: latexenc-find-file-coding-system is slow. |
Date: |
Wed, 11 May 2005 13:48:18 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
[For some reason, I didn't see your message on emacs-devel.]
Arne Jørgensen <address@hidden> writes:
> Lute Kamstra <address@hidden> writes:
>
>> I guess the re-searching in latexenc-find-file-coding-system needs to
>> be improved.
>
> I have made a try at speeding up the search for input encoding.
Thanks.
> What is does now is search for "inputenc" with `search-forward' until
> the first match also matches (with `looking-at') an
> \inputencoding{...} or \usepackage[...]{inputenc} (that is not inside
> a comment).
That should speed things up.
> For now I have not added a limit for how far to search for this
> because I still see no way to decide this for all common cases. And
> then I would like to hear if the change has any effect on the speed as
> it is.
It's probably fast enough now.
> I limitied the search for a TeX-master/tex-main-file in the local
> variables section though. The limit is borrowed from
> `hack-local-variables'.
That should work.
[...]
I think there a some minor problems with the details of the
implementation:
> Index: lisp/international/latexenc.el
> ===================================================================
> RCS file: /cvsroot/emacs/emacs/lisp/international/latexenc.el,v
> retrieving revision 1.3
> diff -u -p -r1.3 latexenc.el
> --- lisp/international/latexenc.el 1 May 2005 11:01:49 -0000 1.3
> +++ lisp/international/latexenc.el 4 May 2005 18:12:23 -0000
> @@ -120,24 +120,33 @@ coding system names is determined from `
> (save-excursion
> ;; try to find the coding system in this file
> (goto-char (point-min))
> - (if (or
> - (re-search-forward "^[^%\n]*\\\\inputencoding{\\(.*\\)}" nil t)
> - (re-search-forward
> "^[^%\n]*\\\\usepackage\\[\\(.*\\)\\]{inputenc}" nil t))
> - (let* ((match (match-string 1))
> - (sym (intern match)))
> - (when (latexenc-inputenc-to-coding-system match)
> - (setq sym (latexenc-inputenc-to-coding-system match))
> - (when (coding-system-p sym)
> - sym
> - (if (and (require 'code-pages nil t) (coding-system-p sym))
> - sym
> - 'undecided))))
> + (if (catch 'cs
> + (let ((case-fold-search nil))
> + (while (search-forward "inputenc" nil t)
> + (goto-char (match-beginning 0))
> + (beginning-of-line)
> + (if (or (looking-at
> "[^%\n]*\\\\usepackage\\[\\(.*\\)\\]{\\(.*,\\)?inputenc\\(,.*\\)?}")
That also matches something like:
\usepackage[opt]{package} % don't use {package,inputenc}
> + (looking-at "[^%\n]*\\\\inputencoding{\\(.*\\)}"))
> + (throw 'cs (match-string 1))
Why throw (match-string 1) instead of t?
> + (goto-char (match-end 0))))))
> + (let* ((match (match-string 1))
> + (sym (intern match)))
> + (when (latexenc-inputenc-to-coding-system match)
> + (setq sym (latexenc-inputenc-to-coding-system match)))
> + (when (coding-system-p sym)
> + sym
> + (if (and (require 'code-pages nil t) (coding-system-p sym))
> + sym
> + 'undecided)))
> ;; else try to find it in the master/main file
> - (let (latexenc-main-file)
> + (let (latexenc-main-file
> + bound)
> ;; is there a TeX-master or tex-main-file in the local variable
> section
> (unless latexenc-dont-use-TeX-master-flag
> (goto-char (point-max))
> - (when (re-search-backward "^%+
> *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t)
> + (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
> 'move)
> + (setq bound (search-forward "Local Variables:" nil t))
> + (when (re-search-forward "^%+
> *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t)
> (let ((file (concat (file-name-directory (nth 1 arg-list))
> (match-string 2))))
> (if (file-exists-p file)
> (setq latexenc-main-file file)
You don't seem to use the variable bound.
Could you also write a ChangeLog entry for your patch?
Lute.