From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?utf-8?Q?Arne_J=C3=B8rgensen?= Newsgroups: gmane.emacs.devel Subject: Re: latexenc-find-file-coding-system is slow. Date: Wed, 11 May 2005 19:21:24 +0200 Organization: Arne Joergensen -- http://arnested.dk/ Message-ID: <87sm0tu19n.fsf@arnested.dk> References: <87ekcxrbb8.fsf@arnested.dk> <87u0lpye89.fsf_-_@xs4all.nl> <871x8m96p6.fsf@arnested.dk> <87psvykmpp.fsf@xs4all.nl> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1115832139 4567 80.91.229.2 (11 May 2005 17:22:19 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 11 May 2005 17:22:19 +0000 (UTC) Cc: Thien-Thi Nguyen , Stefan Monnier , Lute Kamstra , Richard Stallman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 11 19:22:16 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DVuth-0005Kl-EN for ged-emacs-devel@m.gmane.org; Wed, 11 May 2005 19:21:25 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DVv2T-0000NY-Hj for ged-emacs-devel@m.gmane.org; Wed, 11 May 2005 13:30:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DVuzM-0006Zi-LL for emacs-devel@gnu.org; Wed, 11 May 2005 13:27:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DVuzD-0006UY-E4 for emacs-devel@gnu.org; Wed, 11 May 2005 13:27:11 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DVuzC-0006Tb-Qk for emacs-devel@gnu.org; Wed, 11 May 2005 13:27:06 -0400 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtp (TLS-1.0:RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1DVv1S-0003bS-Lh for emacs-devel@gnu.org; Wed, 11 May 2005 13:29:27 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1DVun1-00040B-Pt for emacs-devel@gnu.org; Wed, 11 May 2005 19:14:31 +0200 Original-Received: from 213.237.94.152 ([213.237.94.152]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 11 May 2005 19:14:31 +0200 Original-Received: from arne by 213.237.94.152 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 11 May 2005 19:14:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: emacs-devel@gnu.org Original-Lines: 180 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 213.237.94.152 X-Face: 5t,7/Y$&<1A_t.$vC2{pWZ{m@3_06; kcm]no{hgEL/}Uz(>XV6cl4}xO\v?-h3%>znNaZtq `~rf,GY1T%r=a.zH`hOb(-]'x)nI088Z&|e;V^h;/TShou User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:Rs8wtb3xrCoJW2VV7yPngQgmY5M= X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:36988 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:36988 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lute Kamstra writes: > [For some reason, I didn't see your message on emacs-devel.] Neither did I. It got lost again as most of my mail to @gnu.org addresses do. This is posted through Gmane instead. > Arne Jørgensen writes: [...] > 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} Right. I should be fixed now. >> + (looking-at "[^%\n]*\\\\inputencoding{\\(.*\\)}")) >> + (throw 'cs (match-string 1)) > > Why throw (match-string 1) instead of t? You're right. >> + (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. No. It's gone now. (I was probably tired). > Could you also write a ChangeLog entry for your patch? Done. New patch attached. Thanks and kind regard, -- Arne Jørgensen --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=latexenc.patch Content-Transfer-Encoding: 8bit Index: lisp/ChangeLog =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/ChangeLog,v retrieving revision 1.7484 diff -u -p -r1.7484 ChangeLog --- lisp/ChangeLog 11 May 2005 16:42:40 -0000 1.7484 +++ lisp/ChangeLog 11 May 2005 17:14:03 -0000 @@ -1,3 +1,11 @@ +2005-05-11 Arne J,Ax(Brgensen + + * international/latexenc.el (latexenc-find-file-coding-system): + Avoid `re-search-forward' when looking for input encoding because + of speed and safety. Better regexp's for recognizing input + encoding. Limit a search for TeX-master/tex-main-file to the local + variable section. + 2005-05-11 Stefan Monnier * files.el (executable-find): Move from executable.el. Use locate-file. 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 11 May 2005 17:14:03 -0000 @@ -120,24 +120,32 @@ 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\\(,[^}]*\\)?}") + (looking-at "[^%\n]*\\\\inputencoding{\\([^}]*\\)}")) + (throw 'cs 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) ;; 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) + (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) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--